Skip to content

Commit 9bbc984

Browse files
committed
Fix StreamInfoItem
1 parent f7992b8 commit 9bbc984

File tree

14 files changed

+93
-101
lines changed

14 files changed

+93
-101
lines changed

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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
22

3+
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
4+
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
5+
36
import com.grack.nanojson.JsonObject;
7+
48
import org.schabi.newpipe.extractor.exceptions.ParsingException;
59
import org.schabi.newpipe.extractor.localization.DateWrapper;
610
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
711
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
8-
import org.schabi.newpipe.extractor.stream.StreamType;
912

1013
import javax.annotation.Nullable;
1114

12-
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
13-
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
14-
1515
public class SoundcloudStreamInfoItemExtractor implements StreamInfoItemExtractor {
1616

1717
protected final JsonObject itemObject;
@@ -20,6 +20,11 @@ public SoundcloudStreamInfoItemExtractor(final JsonObject itemObject) {
2020
this.itemObject = itemObject;
2121
}
2222

23+
@Override
24+
public boolean isAudioOnly() {
25+
return true;
26+
}
27+
2328
@Override
2429
public String getUrl() {
2530
return replaceHttpWithHttps(itemObject.getString("permalink_url"));
@@ -80,11 +85,6 @@ public String getThumbnailUrl() {
8085
return artworkUrl.replace("large.jpg", "crop.jpg");
8186
}
8287

83-
@Override
84-
public StreamType getStreamType() {
85-
return StreamType.AUDIO_STREAM;
86-
}
87-
8888
@Override
8989
public boolean isAd() {
9090
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: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
1616
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
1717
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
18-
import org.schabi.newpipe.extractor.stream.StreamType;
1918
import org.schabi.newpipe.extractor.utils.JsonUtils;
2019
import org.schabi.newpipe.extractor.utils.Utils;
2120

@@ -47,7 +46,7 @@
4746
public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
4847
private final JsonObject videoInfo;
4948
private final TimeAgoParser timeAgoParser;
50-
private StreamType cachedStreamType;
49+
private Boolean cachedIsLive;
5150

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

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

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

@@ -83,13 +86,11 @@ public StreamType getStreamType() {
8386
.getObject("thumbnailOverlayTimeStatusRenderer")
8487
.getString("style", EMPTY_STRING);
8588
if (style.equalsIgnoreCase("LIVE")) {
86-
cachedStreamType = StreamType.LIVE_STREAM;
87-
return cachedStreamType;
89+
return true;
8890
}
8991
}
9092

91-
cachedStreamType = StreamType.VIDEO_STREAM;
92-
return cachedStreamType;
93+
return false;
9394
}
9495

9596
@Override
@@ -119,7 +120,7 @@ public String getName() throws ParsingException {
119120

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

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

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

0 commit comments

Comments
 (0)