fix yt trending contains to less items

This commit is contained in:
Christian Schabesberger 2018-01-04 04:46:27 +01:00
parent a0e5c88b13
commit 5f2d0cf6b5
2 changed files with 71 additions and 68 deletions

View File

@ -23,6 +23,7 @@ package org.schabi.newpipe.extractor.services.youtube;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -81,7 +82,8 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
@Override
public StreamInfoItemCollector getStreams() throws ParsingException {
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
Element ul = doc.select("ul[class*=\"expanded-shelf-content-list\"]").first();
Elements uls = doc.select("ul[class*=\"expanded-shelf-content-list\"]");
for(Element ul : uls) {
for(final Element li : ul.children()) {
final Element el = li.select("div[class*=\"yt-lockup-dismissable\"]").first();
collector.commit(new YoutubeStreamInfoItemExtractor(li) {
@ -109,7 +111,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
public String getUploaderUrl() throws ParsingException {
try {
String link = getUploaderLink().attr("href");
if(link.isEmpty()) {
if (link.isEmpty()) {
throw new IllegalArgumentException("is empty");
}
return link;
@ -152,6 +154,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
}
});
}
}
return collector;
}

View File

@ -67,10 +67,10 @@ public class YoutubeTrendingExtractorTest {
}
@Test
public void testGetStreams() throws Exception {
public void testGetStreamsQuantity() throws Exception {
StreamInfoItemCollector collector = extractor.getStreams();
Utils.printErrors(collector);
assertFalse("no streams are received", collector.getItemList().isEmpty());
assertTrue("no streams are received", collector.getItemList().size() >= 20);
}
@Test