fix failing tests
This commit is contained in:
parent
dacffda194
commit
16b77b56cc
|
@ -96,11 +96,18 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
|||
|
||||
@Override
|
||||
public String getUploaderUrl() throws ParsingException {
|
||||
try {
|
||||
try {
|
||||
return item.select("div[class=\"yt-lockup-byline\"]").first()
|
||||
.select("a").first()
|
||||
.attr("href");
|
||||
} catch (Exception e){}
|
||||
|
||||
// try this if the first didn't work
|
||||
return item.select("span[class=\"title\"")
|
||||
.text().split(" - ")[0];
|
||||
} catch (Exception e) {
|
||||
System.out.println(item.html());
|
||||
throw new ParsingException("Could not get uploader", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package org.schabi.newpipe.extractor.utils;
|
||||
|
||||
import org.schabi.newpipe.extractor.Collector;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Utils {
|
||||
private Utils() {
|
||||
//no instance
|
||||
|
@ -35,4 +38,13 @@ public class Utils {
|
|||
throw new ParsingException("Url don't match the pattern");
|
||||
}
|
||||
}
|
||||
|
||||
public static void printErrors(Collector c) {
|
||||
List<Throwable> errors = c.getErrors();
|
||||
for(Throwable e : errors) {
|
||||
e.printStackTrace();
|
||||
System.err.println("----------------");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.NewPipe;
|
|||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.stream.*;
|
||||
import org.schabi.newpipe.extractor.utils.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
@ -45,7 +46,7 @@ public class YoutubeStreamExtractorDefaultTest {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
extractor = YouTube.getService().getStreamExtractor("https://www.youtube.com/watch?v=YQHsXMglC9A");
|
||||
extractor = YouTube.getService().getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,8 +86,8 @@ public class YoutubeStreamExtractorDefaultTest {
|
|||
|
||||
@Test
|
||||
public void testGetViewCount() throws ParsingException {
|
||||
assertTrue(Long.toString(extractor.getViewCount()),
|
||||
extractor.getViewCount() > /* specific to that video */ 1224000074);
|
||||
Long count = extractor.getViewCount();
|
||||
assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -141,13 +142,8 @@ public class YoutubeStreamExtractorDefaultTest {
|
|||
@Test
|
||||
public void testGetRelatedVideos() throws ExtractionException, IOException {
|
||||
StreamInfoItemCollector relatedVideos = extractor.getRelatedVideos();
|
||||
Utils.printErrors(relatedVideos);
|
||||
assertFalse(relatedVideos.getItemList().isEmpty());
|
||||
if(!relatedVideos.getErrors().isEmpty()) {
|
||||
for(Throwable e : relatedVideos.getErrors()) {
|
||||
e.printStackTrace();
|
||||
System.err.println("----------------------");
|
||||
}
|
||||
}
|
||||
assertTrue(relatedVideos.getErrors().isEmpty());
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.junit.Test;
|
|||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
|
||||
import org.schabi.newpipe.extractor.utils.Utils;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -68,6 +69,7 @@ public class YoutubeTrendingExtractorTest {
|
|||
@Test
|
||||
public void testGetStreams() throws Exception {
|
||||
StreamInfoItemCollector collector = extractor.getStreams();
|
||||
Utils.printErrors(collector);
|
||||
assertTrue("no streams are received", collector.getItemList().isEmpty());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue