diff --git a/src/main/java/org/schabi/newpipe/extractor/Extractor.java b/src/main/java/org/schabi/newpipe/extractor/Extractor.java index e71321836..d47150464 100644 --- a/src/main/java/org/schabi/newpipe/extractor/Extractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/Extractor.java @@ -66,6 +66,10 @@ public abstract class Extractor { if(!pageFetched) throw new IllegalStateException("Page is not fetched. Make sure you call fetchPage()"); } + protected boolean isPageFetched() { + return pageFetched; + } + /** * Fetch the current page. * @param downloader the download to use diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java index 6bb56930d..7e5c6f979 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java @@ -52,10 +52,18 @@ public class YoutubeChannelExtractor extends ChannelExtractor { */ private Document nextStreamsAjax; + /** + * Unfortunately, we have to fetch the page even if we are only getting next streams, + * as they don't deliver enough information on their own (the channel name, for example). + *
+ * This help us to keep track on what are we fetching. + */ private boolean fetchingNextStreams; public YoutubeChannelExtractor(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException { super(service, url, nextStreamsUrl); + + fetchingNextStreams = nextStreamsUrl != null && !nextStreamsUrl.isEmpty(); } @Override @@ -168,10 +176,11 @@ public class YoutubeChannelExtractor extends ChannelExtractor { throw new ExtractionException("Channel doesn't have more streams"); } - StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId()); + if (!isPageFetched()) { + fetchPage(); + } - //TODO: This is a horrible hack and should be fixed (the whole F*** architecture of ListExtractor is broken) - onFetchPage(NewPipe.getDownloader()); + StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId()); setupNextStreamsAjax(NewPipe.getDownloader()); collectStreamsFrom(collector, nextStreamsAjax.select("body").first());