Remove getNextStream() from StreamExtractor

This commit is contained in:
wb9688 2020-05-30 10:25:43 +02:00
parent 186193d366
commit ff560e907a
7 changed files with 20 additions and 68 deletions

View File

@ -15,7 +15,6 @@ import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.SubtitlesStream; import org.schabi.newpipe.extractor.stream.SubtitlesStream;
@ -215,11 +214,6 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
return StreamType.VIDEO_STREAM; return StreamType.VIDEO_STREAM;
} }
@Override
public StreamInfoItem getNextStream() {
return null;
}
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() { public StreamInfoItemsCollector getRelatedStreams() {
return new StreamInfoItemsCollector(getServiceId()); return new StreamInfoItemsCollector(getServiceId());

View File

@ -21,7 +21,6 @@ import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.stream.Stream;
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.SubtitlesStream; import org.schabi.newpipe.extractor.stream.SubtitlesStream;
@ -242,11 +241,6 @@ public class PeertubeStreamExtractor extends StreamExtractor {
return StreamType.VIDEO_STREAM; return StreamType.VIDEO_STREAM;
} }
@Override
public StreamInfoItem getNextStream() {
return null;
}
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());

View File

@ -19,7 +19,6 @@ import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.SubtitlesStream; import org.schabi.newpipe.extractor.stream.SubtitlesStream;
@ -261,11 +260,6 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
return StreamType.AUDIO_STREAM; return StreamType.AUDIO_STREAM;
} }
@Override
public StreamInfoItem getNextStream() throws IOException, ExtractionException {
return null;
}
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());

View File

@ -21,14 +21,14 @@ import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.localization.TimeAgoParser; import org.schabi.newpipe.extractor.localization.TimeAgoParser;
import org.schabi.newpipe.extractor.localization.TimeAgoPatternsManager; import org.schabi.newpipe.extractor.localization.TimeAgoPatternsManager;
import org.schabi.newpipe.extractor.services.youtube.ItagItem; import org.schabi.newpipe.extractor.services.youtube.ItagItem;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.Frameset; import org.schabi.newpipe.extractor.stream.Frameset;
import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.stream.Stream;
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.SubtitlesStream; import org.schabi.newpipe.extractor.stream.SubtitlesStream;
@ -52,7 +52,10 @@ import java.util.Map;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.fixThumbnailUrl;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
@ -508,12 +511,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
return StreamType.VIDEO_STREAM; return StreamType.VIDEO_STREAM;
} }
@Override private StreamInfoItemExtractor getNextStream() throws ExtractionException {
public StreamInfoItem getNextStream() throws ExtractionException {
assertPageFetched();
if (getAgeLimit() != NO_AGE_LIMIT) return null;
try { try {
final JsonObject firstWatchNextItem = initialData.getObject("contents") final JsonObject firstWatchNextItem = initialData.getObject("contents")
.getObject("twoColumnWatchNextResults").getObject("secondaryResults") .getObject("twoColumnWatchNextResults").getObject("secondaryResults")
@ -527,11 +525,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final JsonObject videoInfo = firstWatchNextItem.getObject("compactAutoplayRenderer") final JsonObject videoInfo = firstWatchNextItem.getObject("compactAutoplayRenderer")
.getArray("contents").getObject(0).getObject("compactVideoRenderer"); .getArray("contents").getObject(0).getObject("compactVideoRenderer");
final TimeAgoParser timeAgoParser = getTimeAgoParser(); return new YoutubeStreamInfoItemExtractor(videoInfo, getTimeAgoParser());
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
collector.commit(new YoutubeStreamInfoItemExtractor(videoInfo, timeAgoParser));
return collector.getItems().get(0);
} catch (Exception e) { } catch (Exception e) {
throw new ParsingException("Could not get next video", e); throw new ParsingException("Could not get next video", e);
} }
@ -544,13 +538,19 @@ public class YoutubeStreamExtractor extends StreamExtractor {
if (getAgeLimit() != NO_AGE_LIMIT) return null; if (getAgeLimit() != NO_AGE_LIMIT) return null;
try { try {
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
JsonArray results = initialData.getObject("contents").getObject("twoColumnWatchNextResults")
final StreamInfoItemExtractor nextStream = getNextStream();
if (nextStream != null) {
collector.commit(nextStream);
}
final JsonArray results = initialData.getObject("contents").getObject("twoColumnWatchNextResults")
.getObject("secondaryResults").getObject("secondaryResults").getArray("results"); .getObject("secondaryResults").getObject("secondaryResults").getArray("results");
final TimeAgoParser timeAgoParser = getTimeAgoParser(); final TimeAgoParser timeAgoParser = getTimeAgoParser();
for (Object ul : results) { for (final Object ul : results) {
if (((JsonObject) ul).has("compactVideoRenderer")) { if (((JsonObject) ul).has("compactVideoRenderer")) {
collector.commit(new YoutubeStreamInfoItemExtractor(((JsonObject) ul).getObject("compactVideoRenderer"), timeAgoParser)); collector.commit(new YoutubeStreamInfoItemExtractor(((JsonObject) ul).getObject("compactVideoRenderer"), timeAgoParser));
} }

View File

@ -30,13 +30,14 @@ import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/** /**
* Scrapes information from a video/audio streaming service (eg, YouTube). * Scrapes information from a video/audio streaming service (eg, YouTube).
*/ */
@ -309,22 +310,10 @@ public abstract class StreamExtractor extends Extractor {
*/ */
public abstract StreamType getStreamType() throws ParsingException; public abstract StreamType getStreamType() throws ParsingException;
/**
* Should return the url of the next stream. NewPipe will automatically play
* the next stream if the user wants that.
* If the next stream is is not available simply return null
*
* @return the InfoItem of the next stream
* @throws IOException
* @throws ExtractionException
*/
public abstract StreamInfoItem getNextStream() throws IOException, ExtractionException;
/** /**
* Should return a list of streams related to the current handled. Many services show suggested * Should return a list of streams related to the current handled. Many services show suggested
* streams. If you don't like suggested streams you should implement them anyway since they can * streams. If you don't like suggested streams you should implement them anyway since they can
* be disabled by the user later in the frontend. * be disabled by the user later in the frontend.
* This list MUST NOT contain the next available video as this should be return through getNextStream()
* If it is not available simply return null * If it is not available simply return null
* *
* @return a list of InfoItems showing the related videos/streams * @return a list of InfoItems showing the related videos/streams

View File

@ -282,11 +282,6 @@ public class StreamInfo extends Info {
} catch (Exception e) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
try {
streamInfo.setNextVideo(extractor.getNextStream());
} catch (Exception e) {
streamInfo.addError(e);
}
try { try {
streamInfo.setSubtitles(extractor.getSubtitlesDefault()); streamInfo.setSubtitles(extractor.getSubtitlesDefault());
} catch (Exception e) { } catch (Exception e) {
@ -366,7 +361,6 @@ public class StreamInfo extends Info {
private String hlsUrl = ""; private String hlsUrl = "";
private StreamInfoItem nextVideo;
private List<InfoItem> relatedStreams = new ArrayList<>(); private List<InfoItem> relatedStreams = new ArrayList<>();
private long startPosition = 0; private long startPosition = 0;
@ -597,14 +591,6 @@ public class StreamInfo extends Info {
this.hlsUrl = hlsUrl; this.hlsUrl = hlsUrl;
} }
public StreamInfoItem getNextVideo() {
return nextVideo;
}
public void setNextVideo(StreamInfoItem nextVideo) {
this.nextVideo = nextVideo;
}
public List<InfoItem> getRelatedStreams() { public List<InfoItem> getRelatedStreams() {
return relatedStreams; return relatedStreams;
} }

View File

@ -129,11 +129,6 @@ public class YoutubeStreamExtractorUnlistedTest {
assertSame(StreamType.VIDEO_STREAM, extractor.getStreamType()); assertSame(StreamType.VIDEO_STREAM, extractor.getStreamType());
} }
@Test
public void testGetNextVideo() throws ExtractionException {
assertNull(extractor.getNextStream());
}
@Test @Test
public void testGetRelatedVideos() throws ExtractionException { public void testGetRelatedVideos() throws ExtractionException {
StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams(); StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams();