Skip to content

Commit a2df180

Browse files
committed
Fix StreamInfoItem
1 parent 32e85d3 commit a2df180

14 files changed

Lines changed: 91 additions & 100 deletions

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioInfoItemExtractor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
44

5+
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_URL;
6+
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl;
7+
58
import com.grack.nanojson.JsonObject;
9+
610
import org.schabi.newpipe.extractor.exceptions.ParsingException;
711
import org.schabi.newpipe.extractor.localization.DateWrapper;
812
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
9-
import org.schabi.newpipe.extractor.stream.StreamType;
1013

1114
import javax.annotation.Nullable;
1215

13-
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_URL;
14-
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl;
15-
1616
public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
1717

1818
private final JsonObject show;
@@ -58,8 +58,8 @@ public String getThumbnailUrl() {
5858
}
5959

6060
@Override
61-
public StreamType getStreamType() {
62-
return StreamType.AUDIO_STREAM;
61+
public boolean isAudioOnly() {
62+
return true;
6363
}
6464

6565
@Override

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/streaminfoitem/BandcampSearchStreamInfoItemExtractor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ public BandcampSearchStreamInfoItemExtractor(final Element searchResult,
2222
public String getUploaderName() {
2323
final String subhead = resultInfo.getElementsByClass("subhead").text();
2424
final String[] splitBy = subhead.split("by ");
25-
if (splitBy.length > 1) {
26-
return splitBy[1];
27-
} else {
28-
return splitBy[0];
29-
}
25+
return splitBy.length > 1 ? splitBy[1] : splitBy[0];
3026
}
3127

3228
@Nullable

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/streaminfoitem/BandcampStreamInfoItemExtractor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.schabi.newpipe.extractor.exceptions.ParsingException;
44
import org.schabi.newpipe.extractor.localization.DateWrapper;
55
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
6-
import org.schabi.newpipe.extractor.stream.StreamType;
76

87
import javax.annotation.Nullable;
98

@@ -13,13 +12,13 @@
1312
public abstract class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor {
1413
private final String uploaderUrl;
1514

16-
public BandcampStreamInfoItemExtractor(final String uploaderUrl) {
15+
protected BandcampStreamInfoItemExtractor(final String uploaderUrl) {
1716
this.uploaderUrl = uploaderUrl;
1817
}
1918

2019
@Override
21-
public StreamType getStreamType() {
22-
return StreamType.AUDIO_STREAM;
20+
public boolean isAudioOnly() {
21+
return true;
2322
}
2423

2524
@Override

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamKioskExtractor.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.schabi.newpipe.extractor.services.media_ccc.extractors;
22

33
import com.grack.nanojson.JsonObject;
4+
45
import org.schabi.newpipe.extractor.exceptions.ParsingException;
56
import org.schabi.newpipe.extractor.localization.DateWrapper;
67
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
7-
import org.schabi.newpipe.extractor.stream.StreamType;
88

99
import javax.annotation.Nullable;
1010

@@ -38,15 +38,16 @@ public String getThumbnailUrl() throws ParsingException {
3838
}
3939

4040
@Override
41-
public StreamType getStreamType() throws ParsingException {
42-
boolean isVideo = false;
43-
for (final Object stream : roomInfo.getArray("streams")) {
44-
if ("video".equals(((JsonObject) stream).getString("type"))) {
45-
isVideo = true;
46-
break;
47-
}
48-
}
49-
return isVideo ? StreamType.LIVE_STREAM : StreamType.AUDIO_LIVE_STREAM;
41+
public boolean isLive() {
42+
return true;
43+
}
44+
45+
@Override
46+
public boolean isAudioOnly() {
47+
return roomInfo.getArray("streams").stream()
48+
.filter(JsonObject.class::isInstance)
49+
.map(JsonObject.class::cast)
50+
.noneMatch(s -> "video".equalsIgnoreCase(s.getString("type")));
5051
}
5152

5253
@Override

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKioskExtractor.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.schabi.newpipe.extractor.localization.DateWrapper;
77
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferenceLinkHandlerFactory;
88
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
9-
import org.schabi.newpipe.extractor.stream.StreamType;
109

1110
import java.time.ZonedDateTime;
1211
import java.time.format.DateTimeFormatter;
@@ -36,11 +35,6 @@ public String getThumbnailUrl() throws ParsingException {
3635
return event.getString("thumb_url");
3736
}
3837

39-
@Override
40-
public StreamType getStreamType() throws ParsingException {
41-
return StreamType.VIDEO_STREAM;
42-
}
43-
4438
@Override
4539
public boolean isAd() {
4640
return false;

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/infoItems/MediaCCCStreamInfoItemExtractor.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.schabi.newpipe.extractor.services.media_ccc.extractors.infoItems;
22

33
import com.grack.nanojson.JsonObject;
4+
45
import org.schabi.newpipe.extractor.exceptions.ParsingException;
56
import org.schabi.newpipe.extractor.localization.DateWrapper;
67
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCParsingHelper;
78
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
8-
import org.schabi.newpipe.extractor.stream.StreamType;
99

1010
import javax.annotation.Nullable;
1111

@@ -16,11 +16,6 @@ public MediaCCCStreamInfoItemExtractor(final JsonObject event) {
1616
this.event = event;
1717
}
1818

19-
@Override
20-
public StreamType getStreamType() {
21-
return StreamType.VIDEO_STREAM;
22-
}
23-
2419
@Override
2520
public boolean isAd() {
2621
return false;

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamInfoItemExtractor.java

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

33
import com.grack.nanojson.JsonObject;
4+
45
import org.schabi.newpipe.extractor.ServiceList;
56
import org.schabi.newpipe.extractor.exceptions.ParsingException;
67
import org.schabi.newpipe.extractor.localization.DateWrapper;
78
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
89
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
9-
import org.schabi.newpipe.extractor.stream.StreamType;
1010
import org.schabi.newpipe.extractor.utils.JsonUtils;
1111

1212
import javax.annotation.Nullable;
@@ -93,8 +93,8 @@ public DateWrapper getUploadDate() throws ParsingException {
9393
}
9494

9595
@Override
96-
public StreamType getStreamType() {
97-
return item.getBoolean("isLive") ? StreamType.LIVE_STREAM : StreamType.VIDEO_STREAM;
96+
public boolean isLive() {
97+
return item.getBoolean("isLive");
9898
}
9999

100100
@Override

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamInfoItemExtractor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.schabi.newpipe.extractor.localization.DateWrapper;
99
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
1010
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
11-
import org.schabi.newpipe.extractor.stream.StreamType;
1211

1312
import javax.annotation.Nullable;
1413

@@ -20,6 +19,11 @@ public SoundcloudStreamInfoItemExtractor(final JsonObject itemObject) {
2019
this.itemObject = itemObject;
2120
}
2221

22+
@Override
23+
public boolean isAudioOnly() {
24+
return true;
25+
}
26+
2327
@Override
2428
public String getUrl() {
2529
return replaceHttpWithHttps(itemObject.getString("permalink_url"));
@@ -80,11 +84,6 @@ public String getThumbnailUrl() {
8084
return artworkUrl.replace("large.jpg", "crop.jpg");
8185
}
8286

83-
@Override
84-
public StreamType getStreamType() {
85-
return StreamType.AUDIO_STREAM;
86-
}
87-
8887
@Override
8988
public boolean isAd() {
9089
return false;

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeFeedInfoItemExtractor.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,19 @@
44
import org.schabi.newpipe.extractor.exceptions.ParsingException;
55
import org.schabi.newpipe.extractor.localization.DateWrapper;
66
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
7-
import org.schabi.newpipe.extractor.stream.StreamType;
87

9-
import javax.annotation.Nullable;
108
import java.time.OffsetDateTime;
119
import java.time.format.DateTimeParseException;
1210

11+
import javax.annotation.Nullable;
12+
1313
public class YoutubeFeedInfoItemExtractor implements StreamInfoItemExtractor {
1414
private final Element entryElement;
1515

1616
public YoutubeFeedInfoItemExtractor(final Element entryElement) {
1717
this.entryElement = entryElement;
1818
}
1919

20-
@Override
21-
public StreamType getStreamType() {
22-
// It is not possible to determine the stream type using the feed endpoint.
23-
// All entries are considered a video stream.
24-
return StreamType.VIDEO_STREAM;
25-
}
26-
2720
@Override
2821
public boolean isAd() {
2922
return false;

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
1515
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
1616
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
17-
import org.schabi.newpipe.extractor.stream.StreamType;
1817
import org.schabi.newpipe.extractor.utils.JsonUtils;
1918
import org.schabi.newpipe.extractor.utils.Utils;
2019

@@ -46,7 +45,7 @@
4645
public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
4746
private final JsonObject videoInfo;
4847
private final TimeAgoParser timeAgoParser;
49-
private StreamType cachedStreamType;
48+
private Boolean cachedIsLive;
5049

5150
/**
5251
* Creates an extractor of StreamInfoItems from a YouTube page.
@@ -61,19 +60,23 @@ public YoutubeStreamInfoItemExtractor(final JsonObject videoInfoItem,
6160
}
6261

6362
@Override
64-
public StreamType getStreamType() {
65-
if (cachedStreamType != null) {
66-
return cachedStreamType;
63+
public boolean isLive() {
64+
if (cachedIsLive != null) {
65+
return cachedIsLive;
6766
}
6867

68+
cachedIsLive = determineIfIsLive();
69+
return cachedIsLive;
70+
}
71+
72+
private boolean determineIfIsLive() {
6973
final JsonArray badges = videoInfo.getArray("badges");
7074
for (final Object badge : badges) {
7175
final JsonObject badgeRenderer
7276
= ((JsonObject) badge).getObject("metadataBadgeRenderer");
73-
if (badgeRenderer.getString("style", "").equals("BADGE_STYLE_TYPE_LIVE_NOW")
74-
|| badgeRenderer.getString("label", "").equals("LIVE NOW")) {
75-
cachedStreamType = StreamType.LIVE_STREAM;
76-
return cachedStreamType;
77+
if ("BADGE_STYLE_TYPE_LIVE_NOW".equals(badgeRenderer.getString("style"))
78+
|| "LIVE NOW".equals(badgeRenderer.getString("label"))) {
79+
return true;
7780
}
7881
}
7982

@@ -82,13 +85,11 @@ public StreamType getStreamType() {
8285
.getObject("thumbnailOverlayTimeStatusRenderer")
8386
.getString("style", "");
8487
if (style.equalsIgnoreCase("LIVE")) {
85-
cachedStreamType = StreamType.LIVE_STREAM;
86-
return cachedStreamType;
88+
return true;
8789
}
8890
}
8991

90-
cachedStreamType = StreamType.VIDEO_STREAM;
91-
return cachedStreamType;
92+
return false;
9293
}
9394

9495
@Override
@@ -118,7 +119,7 @@ public String getName() throws ParsingException {
118119

119120
@Override
120121
public long getDuration() throws ParsingException {
121-
if (getStreamType() == StreamType.LIVE_STREAM || isPremiere()) {
122+
if (isLive() || isPremiere()) {
122123
return -1;
123124
}
124125

@@ -212,7 +213,7 @@ public boolean isUploaderVerified() throws ParsingException {
212213
@Nullable
213214
@Override
214215
public String getTextualUploadDate() throws ParsingException {
215-
if (getStreamType().equals(StreamType.LIVE_STREAM)) {
216+
if (isLive()) {
216217
return null;
217218
}
218219

@@ -232,7 +233,7 @@ public String getTextualUploadDate() throws ParsingException {
232233
@Nullable
233234
@Override
234235
public DateWrapper getUploadDate() throws ParsingException {
235-
if (getStreamType().equals(StreamType.LIVE_STREAM)) {
236+
if (isLive()) {
236237
return null;
237238
}
238239

0 commit comments

Comments
 (0)