Skip to content

Commit b5b25a4

Browse files
Merge pull request #14 from mauriciocolli/refactor-extractor
Fix dash parser and more refactor
2 parents bda65e8 + b1989c0 commit b5b25a4

41 files changed

Lines changed: 791 additions & 740 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Extractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public Extractor(UrlIdHandler urlIdHandler, int serviceId, String url) {
1414
this.urlIdHandler = urlIdHandler;
1515
this.serviceId = serviceId;
1616
this.url = url;
17-
this.previewInfoCollector = new StreamInfoItemCollector(urlIdHandler, serviceId);
17+
this.previewInfoCollector = new StreamInfoItemCollector(serviceId);
1818
}
1919

2020
public String getUrl() {

Info.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public abstract class Info implements Serializable {
1111
* Id of this Info object <br>
1212
* e.g. Youtube: https://www.youtube.com/watch?v=RER5qCTzZ7 > RER5qCTzZ7
1313
*/
14-
public String id = "";
15-
public String url = "";
16-
public String name = "";
14+
public String id;
15+
public String url;
16+
public String name;
1717

1818
public List<Throwable> errors = new Vector<>();
1919
}

InfoItem.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.schabi.newpipe.extractor;
22

3-
import java.io.Serializable;
4-
53
/*
64
* Created by the-scrabi on 11.02.17.
75
*
@@ -22,14 +20,21 @@
2220
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2321
*/
2422

25-
public interface InfoItem extends Serializable {
26-
enum InfoType {
23+
import java.io.Serializable;
24+
25+
public abstract class InfoItem implements Serializable {
26+
public enum InfoType {
2727
STREAM,
2828
PLAYLIST,
2929
CHANNEL
3030
}
3131

32-
InfoType infoType();
33-
String getTitle();
34-
String getLink();
32+
public InfoItem(InfoType infoType) {
33+
this.info_type = infoType;
34+
}
35+
36+
public final InfoType info_type;
37+
public int service_id = -1;
38+
public String url;
39+
public String name;
3540
}

InfoItemCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2626
*/
2727

28-
public class InfoItemCollector {
28+
public abstract class InfoItemCollector {
2929
private List<InfoItem> itemList = new Vector<>();
3030
private List<Throwable> errors = new Vector<>();
3131
private int serviceId = -1;

MediaFormat.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,17 @@ public static String getMimeById(int ident) {
9191
}
9292
return "";
9393
}
94+
95+
/**
96+
* Return the MediaFormat with the supplied mime type
97+
*
98+
* @return MediaFormat associated with this mime type,
99+
* or null if none match it.
100+
*/
101+
public static MediaFormat getFromMimeType(String mimeType) {
102+
for (MediaFormat vf : MediaFormat.values()) {
103+
if (vf.mimeType.equals(mimeType)) return vf;
104+
}
105+
return null;
106+
}
94107
}

channel/ChannelExtractor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.schabi.newpipe.extractor.channel;
22

3-
import org.schabi.newpipe.extractor.Extractor;
43
import org.schabi.newpipe.extractor.ListExtractor;
54
import org.schabi.newpipe.extractor.UrlIdHandler;
65
import org.schabi.newpipe.extractor.exceptions.ExtractionException;

channel/ChannelInfo.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,16 @@
2929

3030
public class ChannelInfo extends Info {
3131

32-
public static ChannelInfo getInfo(ChannelExtractor extractor)
33-
throws ParsingException {
32+
public static ChannelInfo getInfo(ChannelExtractor extractor) throws ParsingException {
3433
ChannelInfo info = new ChannelInfo();
3534

3635
// important data
3736
info.service_id = extractor.getServiceId();
3837
info.url = extractor.getUrl();
38+
info.id = extractor.getChannelId();
3939
info.name = extractor.getChannelName();
40-
info.hasMoreStreams = extractor.hasMoreStreams();
40+
info.has_more_streams = extractor.hasMoreStreams();
4141

42-
try {
43-
info.id = extractor.getChannelId();
44-
} catch (Exception e) {
45-
info.errors.add(e);
46-
}
4742
try {
4843
info.avatar_url = extractor.getAvatarUrl();
4944
} catch (Exception e) {
@@ -75,10 +70,10 @@ public static ChannelInfo getInfo(ChannelExtractor extractor)
7570
return info;
7671
}
7772

78-
public String avatar_url = "";
79-
public String banner_url = "";
80-
public String feed_url = "";
81-
public List<InfoItem> related_streams = null;
73+
public String avatar_url;
74+
public String banner_url;
75+
public String feed_url;
76+
public List<InfoItem> related_streams;
8277
public long subscriber_count = -1;
83-
public boolean hasMoreStreams = false;
78+
public boolean has_more_streams = false;
8479
}

channel/ChannelInfoItem.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,14 @@
2222
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2323
*/
2424

25-
public class ChannelInfoItem implements InfoItem {
25+
public class ChannelInfoItem extends InfoItem {
2626

27-
public int serviceId = -1;
28-
public String channelName = "";
29-
public String thumbnailUrl = "";
30-
public String webPageUrl = "";
31-
public String description = "";
32-
public long subscriberCount = -1;
33-
public long viewCount = -1;
27+
public String thumbnail_url;
28+
public String description;
29+
public long subscriber_count = -1;
30+
public long view_count = -1;
3431

35-
public InfoType infoType() {
36-
return InfoType.CHANNEL;
37-
}
38-
39-
public String getTitle() {
40-
return channelName;
41-
}
42-
43-
public String getLink() {
44-
return webPageUrl;
32+
public ChannelInfoItem() {
33+
super(InfoType.CHANNEL);
4534
}
4635
}

channel/ChannelInfoItemCollector.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ public ChannelInfoItemCollector(int serviceId) {
3131
public ChannelInfoItem extract(ChannelInfoItemExtractor extractor) throws ParsingException {
3232
ChannelInfoItem resultItem = new ChannelInfoItem();
3333
// important information
34-
resultItem.channelName = extractor.getChannelName();
34+
resultItem.name = extractor.getChannelName();
3535

36-
resultItem.serviceId = getServiceId();
37-
resultItem.webPageUrl = extractor.getWebPageUrl();
36+
resultItem.service_id = getServiceId();
37+
resultItem.url = extractor.getWebPageUrl();
3838

3939
// optional information
4040
try {
41-
resultItem.subscriberCount = extractor.getSubscriberCount();
41+
resultItem.subscriber_count = extractor.getSubscriberCount();
4242
} catch (Exception e) {
4343
addError(e);
4444
}
4545
try {
46-
resultItem.viewCount = extractor.getViewCount();
46+
resultItem.view_count = extractor.getViewCount();
4747
} catch (Exception e) {
4848
addError(e);
4949
}
5050
try {
51-
resultItem.thumbnailUrl = extractor.getThumbnailUrl();
51+
resultItem.thumbnail_url = extractor.getThumbnailUrl();
5252
} catch (Exception e) {
5353
addError(e);
5454
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.schabi.newpipe.extractor.exceptions;
2+
3+
public class ContentNotAvailableException extends ParsingException {
4+
public ContentNotAvailableException(String message) {
5+
super(message);
6+
}
7+
8+
public ContentNotAvailableException(String message, Throwable cause) {
9+
super(message, cause);
10+
}
11+
}

0 commit comments

Comments
 (0)