Skip to content

Commit df28a08

Browse files
authored
Merge pull request #337 from wb9688/next-stream
Remove getNextStream() from StreamExtractor
2 parents 186193d + fc3a63f commit df28a08

7 files changed

Lines changed: 24 additions & 72 deletions

File tree

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.schabi.newpipe.extractor.stream.AudioStream;
1616
import org.schabi.newpipe.extractor.stream.Description;
1717
import org.schabi.newpipe.extractor.stream.StreamExtractor;
18-
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1918
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
2019
import org.schabi.newpipe.extractor.stream.StreamType;
2120
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
@@ -215,11 +214,6 @@ public StreamType getStreamType() {
215214
return StreamType.VIDEO_STREAM;
216215
}
217216

218-
@Override
219-
public StreamInfoItem getNextStream() {
220-
return null;
221-
}
222-
223217
@Override
224218
public StreamInfoItemsCollector getRelatedStreams() {
225219
return new StreamInfoItemsCollector(getServiceId());

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.schabi.newpipe.extractor.stream.Description;
2222
import org.schabi.newpipe.extractor.stream.Stream;
2323
import org.schabi.newpipe.extractor.stream.StreamExtractor;
24-
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
2524
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
2625
import org.schabi.newpipe.extractor.stream.StreamType;
2726
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
@@ -242,11 +241,6 @@ public StreamType getStreamType() {
242241
return StreamType.VIDEO_STREAM;
243242
}
244243

245-
@Override
246-
public StreamInfoItem getNextStream() {
247-
return null;
248-
}
249-
250244
@Override
251245
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
252246
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.schabi.newpipe.extractor.stream.AudioStream;
2020
import org.schabi.newpipe.extractor.stream.Description;
2121
import org.schabi.newpipe.extractor.stream.StreamExtractor;
22-
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
2322
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
2423
import org.schabi.newpipe.extractor.stream.StreamType;
2524
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
@@ -261,11 +260,6 @@ public StreamType getStreamType() {
261260
return StreamType.AUDIO_STREAM;
262261
}
263262

264-
@Override
265-
public StreamInfoItem getNextStream() throws IOException, ExtractionException {
266-
return null;
267-
}
268-
269263
@Override
270264
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
271265
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
2222
import org.schabi.newpipe.extractor.localization.TimeAgoPatternsManager;
2323
import org.schabi.newpipe.extractor.services.youtube.ItagItem;
24-
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
2524
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
25+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
2626
import org.schabi.newpipe.extractor.stream.AudioStream;
2727
import org.schabi.newpipe.extractor.stream.Description;
2828
import org.schabi.newpipe.extractor.stream.Frameset;
2929
import org.schabi.newpipe.extractor.stream.Stream;
3030
import org.schabi.newpipe.extractor.stream.StreamExtractor;
31-
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
31+
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
3232
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
3333
import org.schabi.newpipe.extractor.stream.StreamType;
3434
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
@@ -52,7 +52,10 @@
5252
import javax.annotation.Nonnull;
5353
import javax.annotation.Nullable;
5454

55-
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*;
55+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.fixThumbnailUrl;
56+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse;
57+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
58+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
5659
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
5760
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
5861

@@ -508,12 +511,7 @@ public StreamType getStreamType() throws ParsingException {
508511
return StreamType.VIDEO_STREAM;
509512
}
510513

511-
@Override
512-
public StreamInfoItem getNextStream() throws ExtractionException {
513-
assertPageFetched();
514-
515-
if (getAgeLimit() != NO_AGE_LIMIT) return null;
516-
514+
private StreamInfoItemExtractor getNextStream() throws ExtractionException {
517515
try {
518516
final JsonObject firstWatchNextItem = initialData.getObject("contents")
519517
.getObject("twoColumnWatchNextResults").getObject("secondaryResults")
@@ -527,11 +525,7 @@ public StreamInfoItem getNextStream() throws ExtractionException {
527525
final JsonObject videoInfo = firstWatchNextItem.getObject("compactAutoplayRenderer")
528526
.getArray("contents").getObject(0).getObject("compactVideoRenderer");
529527

530-
final TimeAgoParser timeAgoParser = getTimeAgoParser();
531-
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
532-
533-
collector.commit(new YoutubeStreamInfoItemExtractor(videoInfo, timeAgoParser));
534-
return collector.getItems().get(0);
528+
return new YoutubeStreamInfoItemExtractor(videoInfo, getTimeAgoParser());
535529
} catch (Exception e) {
536530
throw new ParsingException("Could not get next video", e);
537531
}
@@ -544,13 +538,19 @@ public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException {
544538
if (getAgeLimit() != NO_AGE_LIMIT) return null;
545539

546540
try {
547-
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
548-
JsonArray results = initialData.getObject("contents").getObject("twoColumnWatchNextResults")
541+
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
542+
543+
final StreamInfoItemExtractor nextStream = getNextStream();
544+
if (nextStream != null) {
545+
collector.commit(nextStream);
546+
}
547+
548+
final JsonArray results = initialData.getObject("contents").getObject("twoColumnWatchNextResults")
549549
.getObject("secondaryResults").getObject("secondaryResults").getArray("results");
550550

551551
final TimeAgoParser timeAgoParser = getTimeAgoParser();
552552

553-
for (Object ul : results) {
553+
for (final Object ul : results) {
554554
if (((JsonObject) ul).has("compactVideoRenderer")) {
555555
collector.commit(new YoutubeStreamInfoItemExtractor(((JsonObject) ul).getObject("compactVideoRenderer"), timeAgoParser));
556556
}

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
import org.schabi.newpipe.extractor.localization.DateWrapper;
3131
import org.schabi.newpipe.extractor.utils.Parser;
3232

33-
import javax.annotation.Nonnull;
34-
import javax.annotation.Nullable;
3533
import java.io.IOException;
3634
import java.util.Collections;
3735
import java.util.List;
3836
import java.util.Locale;
3937

38+
import javax.annotation.Nonnull;
39+
import javax.annotation.Nullable;
40+
4041
/**
4142
* Scrapes information from a video/audio streaming service (eg, YouTube).
4243
*/
@@ -309,23 +310,12 @@ public StreamExtractor(StreamingService service, LinkHandler linkHandler) {
309310
*/
310311
public abstract StreamType getStreamType() throws ParsingException;
311312

312-
/**
313-
* Should return the url of the next stream. NewPipe will automatically play
314-
* the next stream if the user wants that.
315-
* If the next stream is is not available simply return null
316-
*
317-
* @return the InfoItem of the next stream
318-
* @throws IOException
319-
* @throws ExtractionException
320-
*/
321-
public abstract StreamInfoItem getNextStream() throws IOException, ExtractionException;
322-
323313
/**
324314
* Should return a list of streams related to the current handled. Many services show suggested
325315
* streams. If you don't like suggested streams you should implement them anyway since they can
326-
* be disabled by the user later in the frontend.
327-
* This list MUST NOT contain the next available video as this should be return through getNextStream()
328-
* If it is not available simply return null
316+
* be disabled by the user later in the frontend. The first related stream might be what was
317+
* previously known as a next stream.
318+
* If related streams aren't available simply return {@code null}.
329319
*
330320
* @return a list of InfoItems showing the related videos/streams
331321
* @throws IOException
@@ -337,11 +327,10 @@ public StreamExtractor(StreamingService service, LinkHandler linkHandler) {
337327
* Should return a list of Frameset object that contains preview of stream frames
338328
*
339329
* @return list of preview frames or empty list if frames preview is not supported or not found for specified stream
340-
* @throws IOException
341330
* @throws ExtractionException
342331
*/
343332
@Nonnull
344-
public List<Frameset> getFrames() throws IOException, ExtractionException {
333+
public List<Frameset> getFrames() throws ExtractionException {
345334
return Collections.emptyList();
346335
}
347336

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,6 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
282282
} catch (Exception e) {
283283
streamInfo.addError(e);
284284
}
285-
try {
286-
streamInfo.setNextVideo(extractor.getNextStream());
287-
} catch (Exception e) {
288-
streamInfo.addError(e);
289-
}
290285
try {
291286
streamInfo.setSubtitles(extractor.getSubtitlesDefault());
292287
} catch (Exception e) {
@@ -366,7 +361,6 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
366361

367362

368363
private String hlsUrl = "";
369-
private StreamInfoItem nextVideo;
370364
private List<InfoItem> relatedStreams = new ArrayList<>();
371365

372366
private long startPosition = 0;
@@ -597,14 +591,6 @@ public void setHlsUrl(String hlsUrl) {
597591
this.hlsUrl = hlsUrl;
598592
}
599593

600-
public StreamInfoItem getNextVideo() {
601-
return nextVideo;
602-
}
603-
604-
public void setNextVideo(StreamInfoItem nextVideo) {
605-
this.nextVideo = nextVideo;
606-
}
607-
608594
public List<InfoItem> getRelatedStreams() {
609595
return relatedStreams;
610596
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ public void testStreamType() throws ParsingException {
129129
assertSame(StreamType.VIDEO_STREAM, extractor.getStreamType());
130130
}
131131

132-
@Test
133-
public void testGetNextVideo() throws ExtractionException {
134-
assertNull(extractor.getNextStream());
135-
}
136-
137132
@Test
138133
public void testGetRelatedVideos() throws ExtractionException {
139134
StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams();

0 commit comments

Comments
 (0)