Fix getNextStreams from Youtube's channel extractor

This commit is contained in:
Mauricio Colli 2018-01-13 17:09:31 -02:00
parent cfd3ab3500
commit a693c0d61d
2 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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).
* <br/>
* 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());