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