Merge pull request #59 from coffeemakr/bugfix-test-urls-and-relative-fix
Add more tests and fix 2 bugs
This commit is contained in:
commit
179c38c619
|
@ -0,0 +1,35 @@
|
||||||
|
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||||
|
|
||||||
|
import com.grack.nanojson.JsonObject;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class SoundcloudExtractorHelper {
|
||||||
|
|
||||||
|
private static final String HTTP = "http://";
|
||||||
|
private static final String HTTPS = "https://";
|
||||||
|
|
||||||
|
|
||||||
|
private static String replaceHttpWithHttps(final String url) {
|
||||||
|
if(!url.isEmpty() && url.startsWith(HTTP)) {
|
||||||
|
return HTTPS + url.substring(HTTP.length());
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
static String getUploaderUrl(JsonObject object) {
|
||||||
|
String url = object.getObject("user").getString("permalink_url", "");
|
||||||
|
return replaceHttpWithHttps(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
static String getAvatarUrl(JsonObject object) {
|
||||||
|
String url = object.getObject("user", new JsonObject()).getString("avatar_url", "");
|
||||||
|
return replaceHttpWithHttps(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUploaderName(JsonObject object) {
|
||||||
|
return object.getObject("user").getString("username", "");
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,6 @@ import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
import org.schabi.newpipe.extractor.Downloader;
|
import org.schabi.newpipe.extractor.Downloader;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
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;
|
||||||
|
@ -69,17 +68,17 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderUrl() {
|
public String getUploaderUrl() {
|
||||||
return playlist.getObject("user").getString("permalink_url", "");
|
return SoundcloudExtractorHelper.getUploaderUrl(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderName() {
|
public String getUploaderName() {
|
||||||
return playlist.getObject("user").getString("username", "");
|
return SoundcloudExtractorHelper.getUploaderName(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderAvatarUrl() {
|
public String getUploaderAvatarUrl() {
|
||||||
return playlist.getObject("user", new JsonObject()).getString("avatar_url", "");
|
return SoundcloudExtractorHelper.getAvatarUrl(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -102,19 +102,19 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderUrl() {
|
public String getUploaderUrl() {
|
||||||
return track.getObject("user").getString("permalink_url", "");
|
return SoundcloudExtractorHelper.getUploaderUrl(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderName() {
|
public String getUploaderName() {
|
||||||
return track.getObject("user").getString("username", "");
|
return SoundcloudExtractorHelper.getUploaderName(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderAvatarUrl() {
|
public String getUploaderAvatarUrl() {
|
||||||
return track.getObject("user", new JsonObject()).getString("avatar_url", "");
|
return SoundcloudExtractorHelper.getAvatarUrl(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -265,7 +265,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderUrl() throws ParsingException {
|
public String getUploaderUrl() throws ParsingException {
|
||||||
return getUploaderLink().attr("href");
|
return getUploaderLink().attr("abs:href");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
try {
|
try {
|
||||||
return item.select("div[class=\"yt-lockup-byline\"]").first()
|
return item.select("div[class=\"yt-lockup-byline\"]").first()
|
||||||
.select("a").first()
|
.select("a").first()
|
||||||
.attr("href");
|
.attr("abs:href");
|
||||||
} catch (Exception e){}
|
} catch (Exception e){}
|
||||||
|
|
||||||
// try this if the first didn't work
|
// try this if the first didn't work
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderUrl() throws ParsingException {
|
public String getUploaderUrl() throws ParsingException {
|
||||||
try {
|
try {
|
||||||
String link = getUploaderLink().attr("href");
|
String link = getUploaderLink().attr("abs:href");
|
||||||
if (link.isEmpty()) {
|
if (link.isEmpty()) {
|
||||||
throw new IllegalArgumentException("is empty");
|
throw new IllegalArgumentException("is empty");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package org.schabi.newpipe.extractor;
|
package org.schabi.newpipe.extractor;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class ExtractorAsserts {
|
public class ExtractorAsserts {
|
||||||
public static void assertEmptyErrors(String message, List<Throwable> errors) {
|
public static void assertEmptyErrors(String message, List<Throwable> errors) {
|
||||||
if(!errors.isEmpty()) {
|
if(!errors.isEmpty()) {
|
||||||
|
@ -14,11 +17,21 @@ public class ExtractorAsserts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertIsValidUrl(String url) {
|
@Nonnull
|
||||||
|
private static URL urlFromString(String url) {
|
||||||
try {
|
try {
|
||||||
new URL(url);
|
return new URL(url);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
throw new AssertionError("Invalid url: " + url, e);
|
throw new AssertionError("Invalid url: " + url, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void assertIsValidUrl(String url) {
|
||||||
|
urlFromString(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertIsSecureUrl(String urlToCheck) {
|
||||||
|
URL url = urlFromString(urlToCheck);
|
||||||
|
assertEquals("Protocol of URL is not secure", "https", url.getProtocol());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||||
|
|
||||||
|
public abstract class BaseSoundcloudSearchTest {
|
||||||
|
|
||||||
|
protected static SearchResult result;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResultList() {
|
||||||
|
assertFalse("Got empty result list", result.resultList.isEmpty());
|
||||||
|
for(InfoItem infoItem: result.resultList) {
|
||||||
|
assertIsSecureUrl(infoItem.getUrl());
|
||||||
|
assertIsSecureUrl(infoItem.getThumbnailUrl());
|
||||||
|
assertFalse(infoItem.getName().isEmpty());
|
||||||
|
assertFalse("Name is probably a URI: " + infoItem.getName(),
|
||||||
|
infoItem.getName().contains("://"));
|
||||||
|
if(infoItem instanceof StreamInfoItem) {
|
||||||
|
// test stream item
|
||||||
|
StreamInfoItem streamInfoItem = (StreamInfoItem) infoItem;
|
||||||
|
assertIsSecureUrl(streamInfoItem.getUploaderUrl());
|
||||||
|
assertFalse(streamInfoItem.getUploadDate().isEmpty());
|
||||||
|
assertFalse(streamInfoItem.getUploaderName().isEmpty());
|
||||||
|
assertEquals(StreamType.AUDIO_STREAM, streamInfoItem.getStreamType());
|
||||||
|
} else if(infoItem instanceof ChannelInfoItem) {
|
||||||
|
// Nothing special to check?
|
||||||
|
} else if(infoItem instanceof PlaylistInfoItem) {
|
||||||
|
// test playlist item
|
||||||
|
assertTrue(infoItem.getUrl().contains("/sets/"));
|
||||||
|
long streamCount = ((PlaylistInfoItem) infoItem).getStreamCount();
|
||||||
|
assertTrue(streamCount > 0);
|
||||||
|
} else {
|
||||||
|
fail("Unknown infoItem type: " + infoItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResultErrors() {
|
||||||
|
assertNotNull(result.errors);
|
||||||
|
if (!result.errors.isEmpty()) {
|
||||||
|
for (Throwable error : result.errors) {
|
||||||
|
error.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(result.errors.isEmpty());
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +44,7 @@ public class SoundcloudChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAvatarUrl() throws Exception {
|
public void testGetAvatarUrl() throws Exception {
|
||||||
assertTrue(extractor.getAvatarUrl().contains("https://"));
|
assertIsSecureUrl(extractor.getAvatarUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,12 +43,13 @@ public class SoundcloudPlaylistExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetThumbnailUrl() throws Exception {
|
public void testGetThumbnailUrl() throws Exception {
|
||||||
assertTrue(extractor.getThumbnailUrl(), extractor.getThumbnailUrl().contains("https://"));
|
assertIsSecureUrl(extractor.getThumbnailUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUploaderUrl() throws Exception {
|
public void testGetUploaderUrl() throws Exception {
|
||||||
assertEquals(extractor.getUploaderUrl(), "http://soundcloud.com/liluzivert");
|
assertIsSecureUrl(extractor.getUploaderUrl());
|
||||||
|
assertEquals(extractor.getUploaderUrl(), "https://soundcloud.com/liluzivert");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -57,7 +59,7 @@ public class SoundcloudPlaylistExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUploaderAvatarUrl() throws Exception {
|
public void testGetUploaderAvatarUrl() throws Exception {
|
||||||
assertTrue(extractor.getUploaderAvatarUrl(), extractor.getUploaderAvatarUrl().contains("https://"));
|
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -6,9 +6,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.search.SearchEngine;
|
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
|
@ -16,8 +14,7 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
/**
|
/**
|
||||||
* Test for {@link SearchEngine}
|
* Test for {@link SearchEngine}
|
||||||
*/
|
*/
|
||||||
public class SoundcloudSearchEngineAllTest {
|
public class SoundcloudSearchEngineAllTest extends BaseSoundcloudSearchTest {
|
||||||
private static SearchResult result;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
@ -30,18 +27,6 @@ public class SoundcloudSearchEngineAllTest {
|
||||||
.getSearchResult();
|
.getSearchResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultList() {
|
|
||||||
assertFalse(result.resultList.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultErrors() {
|
|
||||||
assertNotNull(result.errors);
|
|
||||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
|
||||||
assertTrue(result.errors.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestion() {
|
public void testSuggestion() {
|
||||||
|
|
|
@ -15,8 +15,7 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
/**
|
/**
|
||||||
* Test for {@link SearchEngine}
|
* Test for {@link SearchEngine}
|
||||||
*/
|
*/
|
||||||
public class SoundcloudSearchEngineChannelTest {
|
public class SoundcloudSearchEngineChannelTest extends BaseSoundcloudSearchTest {
|
||||||
private static SearchResult result;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
@ -29,11 +28,6 @@ public class SoundcloudSearchEngineChannelTest {
|
||||||
.getSearchResult();
|
.getSearchResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultList() {
|
|
||||||
assertFalse(result.resultList.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResultsItemType() {
|
public void testResultsItemType() {
|
||||||
for (InfoItem infoItem : result.resultList) {
|
for (InfoItem infoItem : result.resultList) {
|
||||||
|
@ -41,13 +35,6 @@ public class SoundcloudSearchEngineChannelTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultErrors() {
|
|
||||||
assertNotNull(result.errors);
|
|
||||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
|
||||||
assertTrue(result.errors.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestion() {
|
public void testSuggestion() {
|
||||||
|
|
|
@ -36,8 +36,7 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
/**
|
/**
|
||||||
* Test for {@link SearchEngine}
|
* Test for {@link SearchEngine}
|
||||||
*/
|
*/
|
||||||
public class SoundcloudSearchEnginePlaylistTest {
|
public class SoundcloudSearchEnginePlaylistTest extends BaseSoundcloudSearchTest {
|
||||||
private static SearchResult result;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
@ -49,11 +48,6 @@ public class SoundcloudSearchEnginePlaylistTest {
|
||||||
.getSearchResult();
|
.getSearchResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultList() {
|
|
||||||
assertFalse(result.resultList.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserItemType() {
|
public void testUserItemType() {
|
||||||
for (InfoItem infoItem : result.resultList) {
|
for (InfoItem infoItem : result.resultList) {
|
||||||
|
@ -61,13 +55,6 @@ public class SoundcloudSearchEnginePlaylistTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultErrors() {
|
|
||||||
assertNotNull(result.errors);
|
|
||||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
|
||||||
assertTrue(result.errors.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestion() {
|
public void testSuggestion() {
|
||||||
|
|
|
@ -15,25 +15,19 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
/**
|
/**
|
||||||
* Test for {@link SearchEngine}
|
* Test for {@link SearchEngine}
|
||||||
*/
|
*/
|
||||||
public class SoundcloudSearchEngineStreamTest {
|
public class SoundcloudSearchEngineStreamTest extends BaseSoundcloudSearchTest {
|
||||||
private static SearchResult result;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
NewPipe.init(Downloader.getInstance());
|
NewPipe.init(Downloader.getInstance());
|
||||||
SearchEngine engine = SoundCloud.getService().getSearchEngine();
|
SearchEngine engine = SoundCloud.getService().getSearchEngine();
|
||||||
|
|
||||||
// SoundCloud will suggest "lil uzi vert" instead of "lil uzi vert",
|
// SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert",
|
||||||
// keep in mind that the suggestions can NOT change by country (the parameter "de")
|
// keep in mind that the suggestions can NOT change by country (the parameter "de")
|
||||||
result = engine.search("lill uzi vert", 0, "de", SearchEngine.Filter.STREAM)
|
result = engine.search("lill uzi vert", 0, "de", SearchEngine.Filter.STREAM)
|
||||||
.getSearchResult();
|
.getSearchResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultList() {
|
|
||||||
assertFalse(result.resultList.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResultsItemType() {
|
public void testResultsItemType() {
|
||||||
for (InfoItem infoItem : result.resultList) {
|
for (InfoItem infoItem : result.resultList) {
|
||||||
|
@ -41,13 +35,6 @@ public class SoundcloudSearchEngineStreamTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultErrors() {
|
|
||||||
assertNotNull(result.errors);
|
|
||||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
|
||||||
assertTrue(result.errors.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestion() {
|
public void testSuggestion() {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.schabi.newpipe.extractor.stream.SubtitlesFormat;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,22 +70,23 @@ public class SoundcloudStreamExtractorDefaultTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUploadDate() throws ParsingException {
|
public void testGetUploadDate() throws ParsingException {
|
||||||
assertEquals(extractor.getUploadDate(), "2016-07-31");
|
assertEquals("2016-07-31", extractor.getUploadDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUploaderUrl() throws ParsingException {
|
public void testGetUploaderUrl() throws ParsingException {
|
||||||
assertEquals(extractor.getUploaderUrl(), "http://soundcloud.com/liluzivert");
|
assertIsSecureUrl(extractor.getUploaderUrl());
|
||||||
|
assertEquals("https://soundcloud.com/liluzivert", extractor.getUploaderUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetThumbnailUrl() throws ParsingException {
|
public void testGetThumbnailUrl() throws ParsingException {
|
||||||
assertTrue(extractor.getThumbnailUrl(), extractor.getThumbnailUrl().contains("https://"));
|
assertIsSecureUrl(extractor.getThumbnailUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUploaderAvatarUrl() throws ParsingException {
|
public void testGetUploaderAvatarUrl() throws ParsingException {
|
||||||
assertTrue(extractor.getUploaderAvatarUrl(), extractor.getUploaderAvatarUrl().contains("https://"));
|
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package org.schabi.newpipe.extractor.services.youtube;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||||
|
|
||||||
|
public abstract class BaseYoutubeSearchTest {
|
||||||
|
|
||||||
|
protected static SearchResult result;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResultList() {
|
||||||
|
assertFalse("Got empty result list", result.resultList.isEmpty());
|
||||||
|
for(InfoItem infoItem: result.resultList) {
|
||||||
|
assertIsSecureUrl(infoItem.getUrl());
|
||||||
|
assertIsSecureUrl(infoItem.getThumbnailUrl());
|
||||||
|
assertFalse(infoItem.getName().isEmpty());
|
||||||
|
assertFalse("Name is probably a URI: " + infoItem.getName(),
|
||||||
|
infoItem.getName().contains("://"));
|
||||||
|
if(infoItem instanceof StreamInfoItem) {
|
||||||
|
// test stream item
|
||||||
|
StreamInfoItem streamInfoItem = (StreamInfoItem) infoItem;
|
||||||
|
assertIsSecureUrl(streamInfoItem.getUploaderUrl());
|
||||||
|
assertFalse(streamInfoItem.getUploadDate().isEmpty());
|
||||||
|
assertFalse(streamInfoItem.getUploaderName().isEmpty());
|
||||||
|
} else if(infoItem instanceof ChannelInfoItem) {
|
||||||
|
// Nothing special to check?
|
||||||
|
} else if(infoItem instanceof PlaylistInfoItem) {
|
||||||
|
// test playlist item
|
||||||
|
long streamCount = ((PlaylistInfoItem) infoItem).getStreamCount();
|
||||||
|
assertTrue(streamCount > 0);
|
||||||
|
} else {
|
||||||
|
fail("Unknown infoItem type: " + infoItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResultErrors() {
|
||||||
|
assertNotNull(result.errors);
|
||||||
|
if (!result.errors.isEmpty()) {
|
||||||
|
for (Throwable error : result.errors) {
|
||||||
|
error.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(result.errors.isEmpty());
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,8 +40,7 @@ import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
|
||||||
/**
|
/**
|
||||||
* Test for {@link SearchEngine}
|
* Test for {@link SearchEngine}
|
||||||
*/
|
*/
|
||||||
public class YoutubeSearchEngineAllTest {
|
public class YoutubeSearchEngineAllTest extends BaseYoutubeSearchTest {
|
||||||
private static SearchResult result;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpClass() throws Exception {
|
public static void setUpClass() throws Exception {
|
||||||
|
@ -53,29 +52,13 @@ public class YoutubeSearchEngineAllTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResultList() {
|
public void testResultList_FirstElement() {
|
||||||
final List<InfoItem> results = result.getResults();
|
InfoItem firstInfoItem = result.getResults().get(0);
|
||||||
assertFalse("Results are empty: " + results, results.isEmpty());
|
|
||||||
|
|
||||||
InfoItem firstInfoItem = results.get(0);
|
|
||||||
|
|
||||||
// THe channel should be the first item
|
// THe channel should be the first item
|
||||||
assertTrue(firstInfoItem instanceof ChannelInfoItem);
|
assertTrue(firstInfoItem instanceof ChannelInfoItem);
|
||||||
assertEquals("name", "PewDiePie", firstInfoItem.name);
|
assertEquals("name", "PewDiePie", firstInfoItem.name);
|
||||||
assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.url);
|
assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.url);
|
||||||
|
|
||||||
for(InfoItem item: results) {
|
|
||||||
assertIsValidUrl(item.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultErrors() {
|
|
||||||
for (Throwable error : result.getErrors()) {
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
assertTrue(result.getErrors().isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
|
|
|
@ -37,8 +37,7 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
/**
|
/**
|
||||||
* Test for {@link SearchEngine}
|
* Test for {@link SearchEngine}
|
||||||
*/
|
*/
|
||||||
public class YoutubeSearchEngineChannelTest {
|
public class YoutubeSearchEngineChannelTest extends BaseYoutubeSearchTest {
|
||||||
private static SearchResult result;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
@ -51,14 +50,6 @@ public class YoutubeSearchEngineChannelTest {
|
||||||
.getSearchResult();
|
.getSearchResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultList() {
|
|
||||||
assertFalse(result.resultList.isEmpty());
|
|
||||||
for(InfoItem item: result.getResults()) {
|
|
||||||
assertIsValidUrl(item.url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResultsItemType() {
|
public void testResultsItemType() {
|
||||||
for (InfoItem infoItem : result.resultList) {
|
for (InfoItem infoItem : result.resultList) {
|
||||||
|
@ -66,13 +57,6 @@ public class YoutubeSearchEngineChannelTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultErrors() {
|
|
||||||
assertNotNull(result.errors);
|
|
||||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
|
||||||
assertTrue(result.errors.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestion() {
|
public void testSuggestion() {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.junit.Test;
|
||||||
import org.schabi.newpipe.Downloader;
|
import org.schabi.newpipe.Downloader;
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
||||||
import org.schabi.newpipe.extractor.search.SearchEngine;
|
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||||
|
|
||||||
|
@ -37,8 +38,7 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
/**
|
/**
|
||||||
* Test for {@link SearchEngine}
|
* Test for {@link SearchEngine}
|
||||||
*/
|
*/
|
||||||
public class YoutubeSearchEnginePlaylistTest {
|
public class YoutubeSearchEnginePlaylistTest extends BaseYoutubeSearchTest {
|
||||||
private static SearchResult result;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
@ -52,27 +52,13 @@ public class YoutubeSearchEnginePlaylistTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResultList() {
|
public void testInfoItemType() {
|
||||||
assertFalse(result.resultList.isEmpty());
|
|
||||||
for(InfoItem item: result.getResults()) {
|
|
||||||
assertIsValidUrl(item.url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUserItemType() {
|
|
||||||
for (InfoItem infoItem : result.resultList) {
|
for (InfoItem infoItem : result.resultList) {
|
||||||
|
assertTrue(infoItem instanceof PlaylistInfoItem);
|
||||||
assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.info_type);
|
assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.info_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultErrors() {
|
|
||||||
assertNotNull(result.errors);
|
|
||||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
|
||||||
assertTrue(result.errors.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestion() {
|
public void testSuggestion() {
|
||||||
|
|
|
@ -37,8 +37,7 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
/**
|
/**
|
||||||
* Test for {@link SearchEngine}
|
* Test for {@link SearchEngine}
|
||||||
*/
|
*/
|
||||||
public class YoutubeSearchEngineStreamTest {
|
public class YoutubeSearchEngineStreamTest extends BaseYoutubeSearchTest {
|
||||||
private static SearchResult result;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
@ -51,14 +50,6 @@ public class YoutubeSearchEngineStreamTest {
|
||||||
.getSearchResult();
|
.getSearchResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultList() {
|
|
||||||
assertFalse(result.resultList.isEmpty());
|
|
||||||
for(InfoItem item: result.getResults()) {
|
|
||||||
assertIsValidUrl(item.url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResultsItemType() {
|
public void testResultsItemType() {
|
||||||
for (InfoItem infoItem : result.resultList) {
|
for (InfoItem infoItem : result.resultList) {
|
||||||
|
@ -66,13 +57,6 @@ public class YoutubeSearchEngineStreamTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResultErrors() {
|
|
||||||
assertNotNull(result.errors);
|
|
||||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
|
||||||
assertTrue(result.errors.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestion() {
|
public void testSuggestion() {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.schabi.newpipe.Downloader;
|
import org.schabi.newpipe.Downloader;
|
||||||
|
import org.schabi.newpipe.extractor.ExtractorAsserts;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
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;
|
||||||
|
@ -12,6 +13,7 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -38,7 +40,6 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
* Test for {@link StreamExtractor}
|
* Test for {@link StreamExtractor}
|
||||||
*/
|
*/
|
||||||
public class YoutubeStreamExtractorDefaultTest {
|
public class YoutubeStreamExtractorDefaultTest {
|
||||||
public static final String HTTPS = "https://";
|
|
||||||
private static YoutubeStreamExtractor extractor;
|
private static YoutubeStreamExtractor extractor;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
@ -102,14 +103,12 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetThumbnailUrl() throws ParsingException {
|
public void testGetThumbnailUrl() throws ParsingException {
|
||||||
assertTrue(extractor.getThumbnailUrl(),
|
assertIsSecureUrl(extractor.getThumbnailUrl());
|
||||||
extractor.getThumbnailUrl().contains(HTTPS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUploaderAvatarUrl() throws ParsingException {
|
public void testGetUploaderAvatarUrl() throws ParsingException {
|
||||||
assertTrue(extractor.getUploaderAvatarUrl(),
|
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
|
||||||
extractor.getUploaderAvatarUrl().contains(HTTPS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -120,8 +119,7 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetVideoStreams() throws IOException, ExtractionException {
|
public void testGetVideoStreams() throws IOException, ExtractionException {
|
||||||
for (VideoStream s : extractor.getVideoStreams()) {
|
for (VideoStream s : extractor.getVideoStreams()) {
|
||||||
assertTrue(s.url,
|
assertIsSecureUrl(s.url);
|
||||||
s.url.contains(HTTPS));
|
|
||||||
assertTrue(s.resolution.length() > 0);
|
assertTrue(s.resolution.length() > 0);
|
||||||
assertTrue(Integer.toString(s.getFormatId()),
|
assertTrue(Integer.toString(s.getFormatId()),
|
||||||
0 <= s.getFormatId() && s.getFormatId() <= 4);
|
0 <= s.getFormatId() && s.getFormatId() <= 4);
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,14 +86,12 @@ public class YoutubeStreamExtractorRestrictedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetThumbnailUrl() throws ParsingException {
|
public void testGetThumbnailUrl() throws ParsingException {
|
||||||
assertTrue(extractor.getThumbnailUrl(),
|
assertIsSecureUrl(extractor.getThumbnailUrl());
|
||||||
extractor.getThumbnailUrl().contains(HTTPS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUploaderAvatarUrl() throws ParsingException {
|
public void testGetUploaderAvatarUrl() throws ParsingException {
|
||||||
assertTrue(extractor.getUploaderAvatarUrl(),
|
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
|
||||||
extractor.getUploaderAvatarUrl().contains(HTTPS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: 25.11.17 Are there no streams or are they not listed?
|
// FIXME: 25.11.17 Are there no streams or are they not listed?
|
||||||
|
|
Loading…
Reference in New Issue