Skip to content

Commit a693c0d

Browse files
committed
Fix getNextStreams from Youtube's channel extractor
1 parent cfd3ab3 commit a693c0d

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/main/java/org/schabi/newpipe/extractor/Extractor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ protected void assertPageFetched() {
6666
if(!pageFetched) throw new IllegalStateException("Page is not fetched. Make sure you call fetchPage()");
6767
}
6868

69+
protected boolean isPageFetched() {
70+
return pageFetched;
71+
}
72+
6973
/**
7074
* Fetch the current page.
7175
* @param downloader the download to use

src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
5252
*/
5353
private Document nextStreamsAjax;
5454

55+
/**
56+
* Unfortunately, we have to fetch the page even if we are only getting next streams,
57+
* as they don't deliver enough information on their own (the channel name, for example).
58+
* <br/>
59+
* This help us to keep track on what are we fetching.
60+
*/
5561
private boolean fetchingNextStreams;
5662

5763
public YoutubeChannelExtractor(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException {
5864
super(service, url, nextStreamsUrl);
65+
66+
fetchingNextStreams = nextStreamsUrl != null && !nextStreamsUrl.isEmpty();
5967
}
6068

6169
@Override
@@ -168,10 +176,11 @@ public NextItemsResult getNextStreams() throws IOException, ExtractionException
168176
throw new ExtractionException("Channel doesn't have more streams");
169177
}
170178

171-
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
179+
if (!isPageFetched()) {
180+
fetchPage();
181+
}
172182

173-
//TODO: This is a horrible hack and should be fixed (the whole F*** architecture of ListExtractor is broken)
174-
onFetchPage(NewPipe.getDownloader());
183+
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
175184

176185
setupNextStreamsAjax(NewPipe.getDownloader());
177186
collectStreamsFrom(collector, nextStreamsAjax.select("body").first());

0 commit comments

Comments
 (0)