Merge pull request #22 from wb9688/soundcloud-test
Add tests for SoundCloud
This commit is contained in:
commit
1a2a6df7ec
|
@ -29,7 +29,7 @@ import org.schabi.newpipe.extractor.user.UserInfoItemExtractor;
|
|||
*/
|
||||
|
||||
public class InfoItemSearchCollector extends InfoItemCollector {
|
||||
private String suggestion;
|
||||
private String suggestion = "";
|
||||
private StreamInfoItemCollector streamCollector;
|
||||
private UserInfoItemCollector userCollector;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
|
|||
|
||||
@Override
|
||||
public String getAvatarUrl() {
|
||||
return playlist.getString("artwork_url");
|
||||
return playlist.optString("artwork_url");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,10 +6,13 @@ import org.schabi.newpipe.extractor.NewPipe;
|
|||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.utils.Parser;
|
||||
import org.schabi.newpipe.extractor.utils.Utils;
|
||||
|
||||
public class SoundcloudPlaylistUrlIdHandler implements UrlIdHandler {
|
||||
|
||||
private static final SoundcloudPlaylistUrlIdHandler instance = new SoundcloudPlaylistUrlIdHandler();
|
||||
private final String URL_PATTERN = "^https?://(www\\.)?soundcloud.com/[0-9a-z_-]+" +
|
||||
"/sets/[0-9a-z_-]+/?([#?].*)?$";
|
||||
|
||||
public static SoundcloudPlaylistUrlIdHandler getInstance() {
|
||||
return instance;
|
||||
|
@ -26,6 +29,8 @@ public class SoundcloudPlaylistUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
Utils.checkUrl(URL_PATTERN, url);
|
||||
|
||||
try {
|
||||
return SoundcloudParsingHelper.resolveIdWithEmbedPlayer(url);
|
||||
} catch (Exception e) {
|
||||
|
@ -35,6 +40,8 @@ public class SoundcloudPlaylistUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public String cleanUrl(String complexUrl) throws ParsingException {
|
||||
Utils.checkUrl(URL_PATTERN, complexUrl);
|
||||
|
||||
try {
|
||||
Element ogElement = Jsoup.parse(NewPipe.getDownloader().download(complexUrl))
|
||||
.select("meta[property=og:url]").first();
|
||||
|
@ -47,7 +54,6 @@ public class SoundcloudPlaylistUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public boolean acceptUrl(String url) {
|
||||
String regex = "^https?://(www\\.)?soundcloud.com/[0-9a-z_-]+/sets/[0-9a-z_-]+/?([#?].*)?$";
|
||||
return Parser.isMatch(regex, url.toLowerCase());
|
||||
return Parser.isMatch(URL_PATTERN, url.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,12 +9,7 @@ import org.schabi.newpipe.extractor.StreamingService;
|
|||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||
import org.schabi.newpipe.extractor.stream.*;
|
||||
import org.schabi.newpipe.extractor.utils.Parser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -83,7 +78,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
|
|||
|
||||
@Override
|
||||
public String getThumbnailUrl() {
|
||||
return track.getString("artwork_url");
|
||||
return track.optString("artwork_url");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -45,7 +45,7 @@ public class SoundcloudStreamInfoItemExtractor implements StreamInfoItemExtracto
|
|||
|
||||
@Override
|
||||
public String getThumbnailUrl() {
|
||||
return searchResult.getString("artwork_url");
|
||||
return searchResult.optString("artwork_url");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,10 +6,13 @@ import org.schabi.newpipe.extractor.NewPipe;
|
|||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.utils.Parser;
|
||||
import org.schabi.newpipe.extractor.utils.Utils;
|
||||
|
||||
public class SoundcloudStreamUrlIdHandler implements UrlIdHandler {
|
||||
|
||||
private static final SoundcloudStreamUrlIdHandler instance = new SoundcloudStreamUrlIdHandler();
|
||||
private final String URL_PATTERN = "^https?://(www\\.)?soundcloud.com/[0-9a-z_-]+" +
|
||||
"/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
|
||||
|
||||
private SoundcloudStreamUrlIdHandler() {
|
||||
}
|
||||
|
@ -29,6 +32,8 @@ public class SoundcloudStreamUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
Utils.checkUrl(URL_PATTERN, url);
|
||||
|
||||
try {
|
||||
return SoundcloudParsingHelper.resolveIdWithEmbedPlayer(url);
|
||||
} catch (Exception e) {
|
||||
|
@ -38,6 +43,8 @@ public class SoundcloudStreamUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public String cleanUrl(String complexUrl) throws ParsingException {
|
||||
Utils.checkUrl(URL_PATTERN, complexUrl);
|
||||
|
||||
try {
|
||||
Element ogElement = Jsoup.parse(NewPipe.getDownloader().download(complexUrl))
|
||||
.select("meta[property=og:url]").first();
|
||||
|
@ -50,7 +57,6 @@ public class SoundcloudStreamUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public boolean acceptUrl(String url) {
|
||||
String regex = "^https?://(www\\.)?soundcloud.com/[0-9a-z_-]+/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
|
||||
return Parser.isMatch(regex, url.toLowerCase());
|
||||
return Parser.isMatch(URL_PATTERN, url.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class SoundcloudUserInfoItemExtractor implements UserInfoItemExtractor {
|
|||
|
||||
@Override
|
||||
public String getThumbnailUrl() {
|
||||
return searchResult.getString("avatar_url");
|
||||
return searchResult.optString("avatar_url");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,6 +37,6 @@ public class SoundcloudUserInfoItemExtractor implements UserInfoItemExtractor {
|
|||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return searchResult.getString("description");
|
||||
return searchResult.optString("description");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,13 @@ import org.schabi.newpipe.extractor.NewPipe;
|
|||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.utils.Parser;
|
||||
import org.schabi.newpipe.extractor.utils.Utils;
|
||||
|
||||
public class SoundcloudUserUrlIdHandler implements UrlIdHandler {
|
||||
|
||||
private static final SoundcloudUserUrlIdHandler instance = new SoundcloudUserUrlIdHandler();
|
||||
private final String URL_PATTERN = "^https?://(www\\.)?soundcloud.com/[0-9a-z_-]+" +
|
||||
"(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$";
|
||||
|
||||
public static SoundcloudUserUrlIdHandler getInstance() {
|
||||
return instance;
|
||||
|
@ -26,6 +29,8 @@ public class SoundcloudUserUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
Utils.checkUrl(URL_PATTERN, url);
|
||||
|
||||
try {
|
||||
return SoundcloudParsingHelper.resolveIdWithEmbedPlayer(url);
|
||||
} catch (Exception e) {
|
||||
|
@ -35,6 +40,8 @@ public class SoundcloudUserUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public String cleanUrl(String complexUrl) throws ParsingException {
|
||||
Utils.checkUrl(URL_PATTERN, complexUrl);
|
||||
|
||||
try {
|
||||
Element ogElement = Jsoup.parse(NewPipe.getDownloader().download(complexUrl))
|
||||
.select("meta[property=og:url]").first();
|
||||
|
@ -47,7 +54,6 @@ public class SoundcloudUserUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public boolean acceptUrl(String url) {
|
||||
String regex = "^https?://(www\\.)?soundcloud.com/[0-9a-z_-]+(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$";
|
||||
return Parser.isMatch(regex, url.toLowerCase());
|
||||
return Parser.isMatch(URL_PATTERN, url.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,7 @@ public class YoutubeUserUrlIdHandler implements UrlIdHandler {
|
|||
|
||||
@Override
|
||||
public boolean acceptUrl(String url) {
|
||||
return (url.contains("youtube") ||
|
||||
url.contains("youtu.be")) &&
|
||||
(url.contains("/user/") ||
|
||||
url.contains("/channel/"));
|
||||
return (url.contains("youtube") || url.contains("youtu.be"))
|
||||
&& (url.contains("/user/") || url.contains("/channel/"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.schabi.newpipe.extractor.utils;
|
||||
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
|
||||
public class Utils {
|
||||
private Utils() {
|
||||
//no instance
|
||||
|
@ -42,4 +44,20 @@ public class Utils {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the url matches the pattern.
|
||||
*
|
||||
* @param pattern the pattern that will be used to check the url
|
||||
* @param url the url to be tested
|
||||
*/
|
||||
public static void checkUrl(String pattern, String url) throws ParsingException {
|
||||
if (url == null || url.isEmpty()) {
|
||||
throw new IllegalArgumentException("Url can't be null or empty");
|
||||
}
|
||||
|
||||
if (!Parser.isMatch(pattern, url.toLowerCase())) {
|
||||
throw new ParsingException("Url not suitable for this url handler");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
||||
/**
|
||||
* Test for {@link PlaylistExtractor}
|
||||
*/
|
||||
|
||||
public class SoundcloudPlaylistExtractorTest {
|
||||
private PlaylistExtractor extractor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
extractor = SoundCloud.getService()
|
||||
.getPlaylistExtractor("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDownloader() throws Exception {
|
||||
assertNotNull(NewPipe.getDownloader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetId() throws Exception {
|
||||
assertEquals(extractor.getPlaylistId(), "246349810");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
assertEquals(extractor.getPlaylistName(), "THE PERFECT LUV TAPE®️");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAvatarUrl() throws Exception {
|
||||
assertEquals(extractor.getAvatarUrl(), "https://i1.sndcdn.com/artworks-000174203688-bweu12-large.jpg");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploaderUrl() throws Exception {
|
||||
assertEquals(extractor.getUploaderUrl(), "http://soundcloud.com/liluzivert");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploaderName() throws Exception {
|
||||
assertEquals(extractor.getUploaderName(), "LIL UZI VERT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploaderAvatarUrl() throws Exception {
|
||||
assertEquals(extractor.getUploaderAvatarUrl(), "https://a1.sndcdn.com/images/default_avatar_large.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStreamsCount() throws Exception {
|
||||
assertEquals(extractor.getStreamCount(), 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStreams() throws Exception {
|
||||
assertTrue("no streams are received", !extractor.getStreams().getItemList().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStreamsErrors() throws Exception {
|
||||
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasMoreStreams() throws Exception {
|
||||
// Setup the streams
|
||||
extractor.getStreams();
|
||||
assertTrue("extractor didn't have more streams", !extractor.hasMoreStreams());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
||||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class SoundcloudSearchEngineAllTest {
|
||||
private SearchResult result;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
SearchEngine engine = SoundCloud.getService().getSearchEngine();
|
||||
|
||||
// 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")
|
||||
result = engine.search("lill uzi vert", 0, "de",
|
||||
EnumSet.of(SearchEngine.Filter.USER,
|
||||
SearchEngine.Filter.STREAM)).getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
||||
assertTrue(result.errors == null || result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
//todo write a real test
|
||||
assertTrue(result.suggestion != null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.InfoItem;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
||||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class SoundcloudSearchEngineStreamTest {
|
||||
private SearchResult result;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
SearchEngine engine = SoundCloud.getService().getSearchEngine();
|
||||
|
||||
// SoundCloud will suggest "lil uzi vert" instead of "lil uzi vert",
|
||||
// keep in mind that the suggestions can NOT change by country (the parameter "de")
|
||||
result = engine.search("lill uzi vert", 0, "de",
|
||||
EnumSet.of(SearchEngine.Filter.STREAM)).getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamItemType() {
|
||||
for (InfoItem infoItem : result.resultList) {
|
||||
assertEquals(InfoItem.InfoType.STREAM, infoItem.info_type);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
||||
assertTrue(result.errors == null || result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
//todo write a real test
|
||||
assertTrue(result.suggestion != null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.InfoItem;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
||||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class SoundcloudSearchEngineUserTest {
|
||||
private SearchResult result;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
SearchEngine engine = SoundCloud.getService().getSearchEngine();
|
||||
|
||||
// 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")
|
||||
result = engine.search("lill uzi vert", 0, "de",
|
||||
EnumSet.of(SearchEngine.Filter.USER)).getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserItemType() {
|
||||
for (InfoItem infoItem : result.resultList) {
|
||||
assertEquals(InfoItem.InfoType.USER, infoItem.info_type);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
||||
assertTrue(result.errors == null || result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
//todo write a real test
|
||||
assertTrue(result.suggestion != null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
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.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
||||
/**
|
||||
* Test for {@link StreamExtractor}
|
||||
*/
|
||||
public class SoundcloudStreamExtractorDefaultTest {
|
||||
private StreamExtractor extractor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
extractor = SoundCloud.getService().getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInvalidTimeStamp() throws ParsingException {
|
||||
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
||||
extractor.getTimeStamp() <= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValidTimeStamp() throws IOException, ExtractionException {
|
||||
StreamExtractor extractor = SoundCloud.getService().getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon#t=69");
|
||||
assertEquals(Integer.toString(extractor.getTimeStamp()), "69");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTitle() throws ParsingException {
|
||||
assertEquals(extractor.getTitle(), "Do What I Want [Produced By Maaly Raw + Don Cannon]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDescription() throws ParsingException {
|
||||
assertEquals(extractor.getDescription(), "The Perfect LUV Tape®️");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploader() throws ParsingException {
|
||||
assertEquals(extractor.getUploader(), "LIL UZI VERT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLength() throws ParsingException {
|
||||
assertEquals(extractor.getLength(), 175);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetViewCount() throws ParsingException {
|
||||
assertTrue(Long.toString(extractor.getViewCount()),
|
||||
extractor.getViewCount() > 44227978);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploadDate() throws ParsingException {
|
||||
assertEquals(extractor.getUploadDate(), "2016-07-31");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserUrl() throws ParsingException {
|
||||
assertEquals(extractor.getUserUrl(), "http://soundcloud.com/liluzivert");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThumbnailUrl() throws ParsingException {
|
||||
assertEquals(extractor.getThumbnailUrl(), "https://i1.sndcdn.com/artworks-000174195399-iw6seg-large.jpg");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploaderThumbnailUrl() throws ParsingException {
|
||||
assertEquals(extractor.getUploaderThumbnailUrl(), "https://a1.sndcdn.com/images/default_avatar_large.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAudioStreams() throws IOException, ExtractionException {
|
||||
assertTrue(!extractor.getAudioStreams().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamType() throws ParsingException {
|
||||
assertTrue(extractor.getStreamType() == StreamType.AUDIO_STREAM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRelatedVideos() throws ExtractionException, IOException {
|
||||
StreamInfoItemCollector relatedVideos = extractor.getRelatedVideos();
|
||||
assertFalse(relatedVideos.getItemList().isEmpty());
|
||||
assertTrue(relatedVideos.getErrors().isEmpty());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test for {@link SoundcloudStreamUrlIdHandler}
|
||||
*/
|
||||
public class SoundcloudStreamUrlIdHandlerTest {
|
||||
private SoundcloudStreamUrlIdHandler urlIdHandler;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
urlIdHandler = SoundcloudStreamUrlIdHandler.getInstance();
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getIdWithNullAsUrl() throws ParsingException {
|
||||
urlIdHandler.getId(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIdForInvalidUrls() {
|
||||
List<String> invalidUrls = new ArrayList<>(50);
|
||||
invalidUrls.add("https://soundcloud.com/liluzivert/t.e.s.t");
|
||||
invalidUrls.add("https://soundcloud.com/liluzivert/tracks");
|
||||
invalidUrls.add("https://soundcloud.com/");
|
||||
for (String invalidUrl : invalidUrls) {
|
||||
Throwable exception = null;
|
||||
try {
|
||||
urlIdHandler.getId(invalidUrl);
|
||||
} catch (ParsingException e) {
|
||||
exception = e;
|
||||
}
|
||||
if (exception == null) {
|
||||
fail("Expected ParsingException for url: " + invalidUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getId() throws Exception {
|
||||
assertEquals("309689103", urlIdHandler.getId("https://soundcloud.com/liluzivert/15-ysl"));
|
||||
assertEquals("309689082", urlIdHandler.getId("https://www.soundcloud.com/liluzivert/15-luv-scars-ko"));
|
||||
assertEquals("309689035", urlIdHandler.getId("http://soundcloud.com/liluzivert/15-boring-shit"));
|
||||
assertEquals("294488599", urlIdHandler.getId("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats"));
|
||||
assertEquals("294488438", urlIdHandler.getId("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz"));
|
||||
assertEquals("294488147", urlIdHandler.getId("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69"));
|
||||
assertEquals("294487876", urlIdHandler.getId("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09"));
|
||||
assertEquals("294487684", urlIdHandler.getId("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9"));
|
||||
assertEquals("294487428", urlIdHandler.getId("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s"));
|
||||
assertEquals("294487157", urlIdHandler.getId("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAcceptUrl() {
|
||||
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/15-ysl"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko"));
|
||||
assertTrue(urlIdHandler.acceptUrl("http://soundcloud.com/liluzivert/15-boring-shit"));
|
||||
assertTrue(urlIdHandler.acceptUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats"));
|
||||
assertTrue(urlIdHandler.acceptUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.SuggestionExtractor;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
||||
/**
|
||||
* Test for {@link SuggestionExtractor}
|
||||
*/
|
||||
public class SoundcloudSuggestionExtractorTest {
|
||||
private SuggestionExtractor suggestionExtractor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
suggestionExtractor = SoundCloud.getService().getSuggestionExtractor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfSuggestions() throws IOException, ExtractionException {
|
||||
assertFalse(suggestionExtractor.suggestionList("lil uzi vert", "de").isEmpty());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.user.UserExtractor;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
||||
/**
|
||||
* Test for {@link UserExtractor}
|
||||
*/
|
||||
|
||||
public class SoundcloudUserExtractorTest {
|
||||
|
||||
UserExtractor extractor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
extractor = SoundCloud.getService()
|
||||
.getUserExtractor("https://soundcloud.com/liluzivert");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDownloader() throws Exception {
|
||||
assertNotNull(NewPipe.getDownloader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserName() throws Exception {
|
||||
assertEquals(extractor.getUserName(), "LIL UZI VERT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDescription() throws Exception {
|
||||
assertEquals(extractor.getDescription(), "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAvatarUrl() throws Exception {
|
||||
assertEquals(extractor.getAvatarUrl(), "https://a1.sndcdn.com/images/default_avatar_large.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStreams() throws Exception {
|
||||
assertTrue("no streams are received", !extractor.getStreams().getItemList().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStreamsErrors() throws Exception {
|
||||
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasMoreStreams() throws Exception {
|
||||
// Setup the streams
|
||||
extractor.getStreams();
|
||||
assertTrue("don't have more streams", extractor.hasMoreStreams());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubscriberCount() throws Exception {
|
||||
assertTrue("wrong subscriber count", extractor.getSubscriberCount() >= 1224324);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextStreams() throws Exception {
|
||||
// Setup the streams
|
||||
extractor.getStreams();
|
||||
assertTrue("extractor didn't have next streams", !extractor.getNextStreams().nextItemsList.isEmpty());
|
||||
assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams());
|
||||
}
|
||||
|
||||
}
|
|
@ -6,9 +6,7 @@ import org.schabi.newpipe.Downloader;
|
|||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
|
||||
/**
|
||||
|
@ -26,7 +24,7 @@ public class YoutubePlaylistExtractorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetDownloader() throws Exception {
|
||||
public void testGetDownloader() throws Exception {
|
||||
assertNotNull(NewPipe.getDownloader());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.schabi.newpipe.extractor.services.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
|
@ -63,6 +64,7 @@ public class YoutubeSearchEngineAllTest {
|
|||
assertTrue(result.errors == null || result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
//todo write a real test
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package org.schabi.newpipe.extractor.services.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.InfoItem;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
|
@ -11,9 +11,7 @@ import org.schabi.newpipe.extractor.search.SearchResult;
|
|||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
|
||||
|
||||
|
@ -72,6 +70,7 @@ public class YoutubeSearchEngineStreamTest {
|
|||
assertTrue(result.errors == null || result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
//todo write a real test
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.schabi.newpipe.extractor.services.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.InfoItem;
|
||||
|
@ -10,9 +11,7 @@ import org.schabi.newpipe.extractor.search.SearchResult;
|
|||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
|
||||
|
||||
|
@ -71,6 +70,7 @@ public class YoutubeSearchEngineUserTest {
|
|||
assertTrue(result.errors == null || result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
//todo write a real test
|
||||
|
|
|
@ -118,7 +118,7 @@ public class YoutubeStreamExtractorDefaultTest {
|
|||
|
||||
@Test
|
||||
public void testGetVideoStreams() throws IOException, ExtractionException {
|
||||
for(VideoStream s : extractor.getVideoStreams()) {
|
||||
for (VideoStream s : extractor.getVideoStreams()) {
|
||||
assertTrue(s.url,
|
||||
s.url.contains(HTTPS));
|
||||
assertTrue(s.resolution.length() > 0);
|
||||
|
|
|
@ -33,7 +33,7 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
|||
|
||||
/**
|
||||
* This exception is only thrown in Germany.
|
||||
*
|
||||
* <p>
|
||||
* WARNING: Deactivate this Test Case before uploading it to Github, otherwise CI will fail.
|
||||
*/
|
||||
@Ignore
|
||||
|
|
|
@ -36,7 +36,7 @@ public class YoutubeStreamExtractorRestrictedTest {
|
|||
|
||||
@Test
|
||||
public void testGetValidTimeStamp() throws IOException, ExtractionException {
|
||||
StreamExtractor extractor= YouTube.getService()
|
||||
StreamExtractor extractor = YouTube.getService()
|
||||
.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
|
||||
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
||||
extractor.getTimeStamp() == 174);
|
||||
|
@ -97,7 +97,7 @@ public class YoutubeStreamExtractorRestrictedTest {
|
|||
|
||||
@Test
|
||||
public void testGetVideoStreams() throws IOException, ExtractionException {
|
||||
for(VideoStream s : extractor.getVideoStreams()) {
|
||||
for (VideoStream s : extractor.getVideoStreams()) {
|
||||
assertTrue(s.url,
|
||||
s.url.contains(HTTPS));
|
||||
assertTrue(s.resolution.length() > 0);
|
||||
|
|
|
@ -10,9 +10,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test for {@link YoutubeStreamUrlIdHandler}
|
||||
|
@ -43,18 +41,19 @@ public class YoutubeStreamUrlIdHandlerTest {
|
|||
invalidUrls.add("https://www.youtube.com/watch?v=jZViOEv90d");
|
||||
invalidUrls.add("https://www.youtube.com/watchjZViOEv90d");
|
||||
invalidUrls.add("https://www.youtube.com/");
|
||||
for(String invalidUrl: invalidUrls) {
|
||||
for (String invalidUrl : invalidUrls) {
|
||||
Throwable exception = null;
|
||||
try {
|
||||
urlIdHandler.getId(invalidUrl);
|
||||
} catch (ParsingException e) {
|
||||
exception = e;
|
||||
}
|
||||
if(exception == null) {
|
||||
if (exception == null) {
|
||||
fail("Expected ParsingException for url: " + invalidUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getId() throws Exception {
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("https://www.youtube.com/watch?v=jZViOEv90dI"));
|
||||
|
@ -84,7 +83,7 @@ public class YoutubeStreamUrlIdHandlerTest {
|
|||
String sharedId = "7JIArTByb3E";
|
||||
String realId = "Q7JsK50NGaA";
|
||||
assertEquals(realId, urlIdHandler.getId("vnd.youtube://www.YouTube.com/shared?ci=" + sharedId + "&feature=twitter-deep-link"));
|
||||
assertEquals(realId, urlIdHandler.getId("vnd.youtube://www.youtube.com/shared?ci=" + sharedId ));
|
||||
assertEquals(realId, urlIdHandler.getId("vnd.youtube://www.youtube.com/shared?ci=" + sharedId));
|
||||
assertEquals(realId, urlIdHandler.getId("https://www.youtube.com/shared?ci=" + sharedId));
|
||||
}
|
||||
|
||||
|
@ -111,7 +110,7 @@ public class YoutubeStreamUrlIdHandlerTest {
|
|||
|
||||
String sharedId = "8A940MXKFmQ";
|
||||
assertTrue(urlIdHandler.acceptUrl("vnd.youtube://www.youtube.com/shared?ci=" + sharedId + "&feature=twitter-deep-link"));
|
||||
assertTrue(urlIdHandler.acceptUrl("vnd.youtube://www.youtube.com/shared?ci=" + sharedId ));
|
||||
assertTrue(urlIdHandler.acceptUrl("vnd.youtube://www.youtube.com/shared?ci=" + sharedId));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/shared?ci=" + sharedId));
|
||||
}
|
||||
}
|
|
@ -6,9 +6,7 @@ import org.schabi.newpipe.Downloader;
|
|||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.user.UserExtractor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
|
||||
/*
|
||||
|
@ -35,7 +33,7 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
|||
* Test for {@link UserExtractor}
|
||||
*/
|
||||
|
||||
public class YoutubeUserExtractorTest {
|
||||
public class YoutubeUserExtractorTest {
|
||||
|
||||
UserExtractor extractor;
|
||||
|
||||
|
@ -47,7 +45,7 @@ public class YoutubeUserExtractorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetDownloader() throws Exception {
|
||||
public void testGetDownloader() throws Exception {
|
||||
assertNotNull(NewPipe.getDownloader());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue