add test for soundcloud search extractor

This commit is contained in:
Christian Schabesberger 2018-06-17 21:23:13 +02:00
parent ef2ce6854c
commit 9bda761103
15 changed files with 1289 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudService;
import org.schabi.newpipe.extractor.services.youtube.YoutubeService;
import java.util.List;
@ -15,10 +16,14 @@ public final class ServiceList {
//no instance
}
public static final YoutubeService YouTube = new YoutubeService(0);
public static final YoutubeService YouTube;
public static final SoundcloudService SoundCloud;
private static final List<StreamingService> SERVICES = unmodifiableList(
asList((StreamingService) YouTube));
asList(
YouTube = new YoutubeService(0),
SoundCloud = new SoundcloudService(1)
));
/**
* Get all the supported services.

View File

@ -0,0 +1,198 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
/**
* Test for {@link SoundcloudChannelExtractor}
*/
public class SoundcloudChannelExtractorTest {
public static class LilUzi implements BaseChannelExtractorTest {
private static SoundcloudChannelExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudChannelExtractor) SoundCloud
.getChannelExtractor("http://soundcloud.com/liluzivert/sets");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() {
assertEquals("LIL UZI VERT", extractor.getName());
}
@Test
public void testId() {
assertEquals("10494998", extractor.getId());
}
@Test
public void testUrl() throws ParsingException {
assertEquals("https://soundcloud.com/liluzivert", extractor.getUrl());
}
@Test
public void testOriginalUrl() throws ParsingException {
assertEquals("http://soundcloud.com/liluzivert/sets", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testDescription() {
assertNotNull(extractor.getDescription());
}
@Test
public void testAvatarUrl() {
assertIsSecureUrl(extractor.getAvatarUrl());
}
@Test
public void testBannerUrl() {
assertIsSecureUrl(extractor.getBannerUrl());
}
@Test
public void testFeedUrl() {
assertEmpty(extractor.getFeedUrl());
}
@Test
public void testSubscriberCount() {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 1e6);
}
}
public static class DubMatix implements BaseChannelExtractorTest {
private static SoundcloudChannelExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudChannelExtractor) SoundCloud
.getChannelExtractor("https://soundcloud.com/dubmatix");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Additional Testing
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testGetPageInNewExtractor() throws Exception {
final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getUrl());
defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() {
assertEquals("dubmatix", extractor.getName());
}
@Test
public void testId() {
assertEquals("542134", extractor.getId());
}
@Test
public void testUrl() throws ParsingException {
assertEquals("https://soundcloud.com/dubmatix", extractor.getUrl());
}
@Test
public void testOriginalUrl() throws ParsingException {
assertEquals("https://soundcloud.com/dubmatix", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testDescription() {
assertNotNull(extractor.getDescription());
}
@Test
public void testAvatarUrl() {
assertIsSecureUrl(extractor.getAvatarUrl());
}
@Test
public void testBannerUrl() {
assertIsSecureUrl(extractor.getBannerUrl());
}
@Test
public void testFeedUrl() {
assertEmpty(extractor.getFeedUrl());
}
@Test
public void testSubscriberCount() {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 2e6);
}
}
}

View File

@ -0,0 +1,93 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.util.List;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/**
* Test for {@link SoundcloudChartsUrlIdHandler}
*/
public class SoundcloudChartsExtractorTest {
static KioskExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = SoundCloud
.getKioskList()
.getExtractorById("Top 50", null);
extractor.fetchPage();
}
@Test
public void testGetDownloader() throws Exception {
assertNotNull(NewPipe.getDownloader());
}
@Ignore
@Test
public void testGetName() throws Exception {
assertEquals(extractor.getName(), "Top 50");
}
@Test
public void testId() {
assertEquals(extractor.getId(), "Top 50");
}
@Test
public void testGetStreams() throws Exception {
ListExtractor.InfoItemsPage<StreamInfoItem> page = extractor.getInitialPage();
if(!page.getErrors().isEmpty()) {
System.err.println("----------");
List<Throwable> errors = page.getErrors();
for(Throwable e: errors) {
e.printStackTrace();
System.err.println("----------");
}
}
assertTrue("no streams are received",
!page.getItems().isEmpty()
&& page.getErrors().isEmpty());
}
@Test
public void testGetStreamsErrors() throws Exception {
assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty());
}
@Test
public void testHasMoreStreams() throws Exception {
// Setup the streams
extractor.getInitialPage();
assertTrue("has more streams", extractor.hasNextPage());
}
@Test
public void testGetNextPageUrl() throws Exception {
assertTrue(extractor.hasNextPage());
}
@Test
public void testGetNextPage() throws Exception {
extractor.getInitialPage().getItems();
assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
|| extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
}
@Test
public void testGetCleanUrl() throws Exception {
assertEquals(extractor.getUrl(), "https://soundcloud.com/charts/top");
}
}

View File

@ -0,0 +1,50 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Test for {@link SoundcloudChartsUrlIdHandler}
*/
public class SoundcloudChartsUrlIdHandlerTest {
private static SoundcloudChartsUrlIdHandler urlIdHandler;
@BeforeClass
public static void setUp() throws Exception {
urlIdHandler = new SoundcloudChartsUrlIdHandler();
NewPipe.init(Downloader.getInstance());
}
@Test
public void getUrl() throws Exception {
assertEquals(urlIdHandler.setId("Top 50").getUrl(), "https://soundcloud.com/charts/top");
assertEquals(urlIdHandler.setId("New & hot").getUrl(), "https://soundcloud.com/charts/new");
}
@Test
public void getId() throws ParsingException {
assertEquals(urlIdHandler.setUrl("http://soundcloud.com/charts/top?genre=all-music").getId(), "Top 50");
assertEquals(urlIdHandler.setUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries").getId(), "New & hot");
}
@Test
public void acceptUrl() throws ParsingException {
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts"));
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts/"));
assertTrue(urlIdHandler.acceptUrl("https://www.soundcloud.com/charts/new"));
assertTrue(urlIdHandler.acceptUrl("http://soundcloud.com/charts/top?genre=all-music"));
assertTrue(urlIdHandler.acceptUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries"));
assertFalse(urlIdHandler.acceptUrl("kdskjfiiejfia"));
assertFalse(urlIdHandler.acceptUrl("soundcloud.com/charts askjkf"));
assertFalse(urlIdHandler.acceptUrl(" soundcloud.com/charts"));
assertFalse(urlIdHandler.acceptUrl(""));
}
}

View File

@ -0,0 +1,28 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
public class SoundcloudParsingHelperTest {
@BeforeClass
public static void setUp() {
NewPipe.init(Downloader.getInstance());
}
@Test
public void resolveUrlWithEmbedPlayerTest() throws Exception {
Assert.assertEquals("https://soundcloud.com/trapcity", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/26057743"));
Assert.assertEquals("https://soundcloud.com/nocopyrightsounds", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/16069159"));
}
@Test
public void resolveIdWithEmbedPlayerTest() throws Exception {
Assert.assertEquals("26057743", SoundcloudParsingHelper.resolveIdWithEmbedPlayer("https://soundcloud.com/trapcity"));
Assert.assertEquals("16069159", SoundcloudParsingHelper.resolveIdWithEmbedPlayer("https://soundcloud.com/nocopyrightsounds"));
}
}

View File

@ -0,0 +1,319 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
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.services.DefaultTests.*;
/**
* Test for {@link PlaylistExtractor}
*/
public class SoundcloudPlaylistExtractorTest {
public static class LuvTape implements BasePlaylistExtractorTest {
private static SoundcloudPlaylistExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudPlaylistExtractor) SoundCloud
.getPlaylistExtractor("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r?test=123");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() {
assertEquals("THE PERFECT LUV TAPE®", extractor.getName());
}
@Test
public void testId() {
assertEquals("246349810", extractor.getId());
}
@Test
public void testUrl() throws Exception {
assertEquals("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r", extractor.getUrl());
}
@Test
public void testOriginalUrl() throws Exception {
assertEquals("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r?test=123", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() {
try {
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
} catch (Throwable ignored) {
return;
}
fail("This playlist doesn't have more items, it should throw an error");
}
/*//////////////////////////////////////////////////////////////////////////
// PlaylistExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testThumbnailUrl() {
assertIsSecureUrl(extractor.getThumbnailUrl());
}
@Ignore
@Test
public void testBannerUrl() {
assertIsSecureUrl(extractor.getBannerUrl());
}
@Test
public void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
assertTrue(uploaderUrl, uploaderUrl.contains("liluzivert"));
}
@Test
public void testUploaderName() {
assertTrue(extractor.getUploaderName().contains("LIL UZI VERT"));
}
@Test
public void testUploaderAvatarUrl() {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test
public void testStreamCount() {
assertTrue("Error in the streams count", extractor.getStreamCount() >= 10);
}
}
public static class RandomHouseDanceMusic implements BasePlaylistExtractorTest {
private static SoundcloudPlaylistExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudPlaylistExtractor) SoundCloud
.getPlaylistExtractor("https://soundcloud.com/hunter-leader/sets/house-electro-dance-music-2");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() {
assertEquals("House, Electro , Dance Music 2", extractor.getName());
}
@Test
public void testId() {
assertEquals("310980722", extractor.getId());
}
@Test
public void testUrl() throws Exception {
assertEquals("https://soundcloud.com/hunter-leader/sets/house-electro-dance-music-2", extractor.getUrl());
}
@Test
public void testOriginalUrl() throws Exception {
assertEquals("https://soundcloud.com/hunter-leader/sets/house-electro-dance-music-2", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// PlaylistExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testThumbnailUrl() {
assertIsSecureUrl(extractor.getThumbnailUrl());
}
@Ignore
@Test
public void testBannerUrl() {
assertIsSecureUrl(extractor.getBannerUrl());
}
@Test
public void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
assertTrue(uploaderUrl, uploaderUrl.contains("hunter-leader"));
}
@Test
public void testUploaderName() {
assertEquals("Gosu", extractor.getUploaderName());
}
@Test
public void testUploaderAvatarUrl() {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test
public void testStreamCount() {
assertTrue("Error in the streams count", extractor.getStreamCount() >= 10);
}
}
public static class EDMxxx implements BasePlaylistExtractorTest {
private static SoundcloudPlaylistExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudPlaylistExtractor) SoundCloud
.getPlaylistExtractor("https://soundcloud.com/user350509423/sets/edm-xxx");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Additional Testing
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testGetPageInNewExtractor() throws Exception {
final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl());
defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() {
assertEquals("EDM xXx", extractor.getName());
}
@Test
public void testId() {
assertEquals("136000376", extractor.getId());
}
@Test
public void testUrl() throws Exception {
assertEquals("https://soundcloud.com/user350509423/sets/edm-xxx", extractor.getUrl());
}
@Test
public void testOriginalUrl() throws Exception {
assertEquals("https://soundcloud.com/user350509423/sets/edm-xxx", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
ListExtractor.InfoItemsPage<StreamInfoItem> currentPage = defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId());
// Test for 2 more levels
for (int i = 0; i < 2; i++) {
currentPage = extractor.getPage(currentPage.getNextPageUrl());
defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItems(), currentPage.getErrors());
}
}
/*//////////////////////////////////////////////////////////////////////////
// PlaylistExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testThumbnailUrl() {
assertIsSecureUrl(extractor.getThumbnailUrl());
}
@Ignore
@Test
public void testBannerUrl() {
assertIsSecureUrl(extractor.getBannerUrl());
}
@Test
public void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
assertTrue(uploaderUrl, uploaderUrl.contains("user350509423"));
}
@Test
public void testUploaderName() {
assertEquals("user350509423", extractor.getUploaderName());
}
@Test
public void testUploaderAvatarUrl() {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test
public void testStreamCount() {
assertTrue("Error in the streams count", extractor.getStreamCount() >= 3900);
}
}
}

View File

@ -0,0 +1,119 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass;
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.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.stream.StreamType;
import java.io.IOException;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/**
* Test for {@link StreamExtractor}
*/
public class SoundcloudStreamExtractorDefaultTest {
private static SoundcloudStreamExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudStreamExtractor) SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon");
extractor.fetchPage();
}
@Test
public void testGetInvalidTimeStamp() throws ParsingException {
assertTrue(extractor.getTimeStamp() + "",
extractor.getTimeStamp() <= 0);
}
@Test
public void testGetValidTimeStamp() throws IOException, ExtractionException {
StreamExtractor extractor = SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon#t=69");
assertEquals(extractor.getTimeStamp() + "", "69");
}
@Test
public void testGetTitle() throws ParsingException {
assertEquals(extractor.getName(), "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 testGetUploaderName() throws ParsingException {
assertEquals(extractor.getUploaderName(), "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("2016-07-31", extractor.getUploadDate());
}
@Test
public void testGetUploaderUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderUrl());
assertEquals("https://soundcloud.com/liluzivert", extractor.getUploaderUrl());
}
@Test
public void testGetThumbnailUrl() throws ParsingException {
assertIsSecureUrl(extractor.getThumbnailUrl());
}
@Test
public void testGetUploaderAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test
public void testGetAudioStreams() throws IOException, ExtractionException {
assertFalse(extractor.getAudioStreams().isEmpty());
}
@Test
public void testStreamType() throws ParsingException {
assertTrue(extractor.getStreamType() == StreamType.AUDIO_STREAM);
}
@Test
public void testGetRelatedVideos() throws ExtractionException, IOException {
StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos();
assertFalse(relatedVideos.getItems().isEmpty());
assertTrue(relatedVideos.getErrors().isEmpty());
}
@Test
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(extractor.getSubtitlesDefault().isEmpty());
}
@Test
public void testGetSubtitlesList() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(extractor.getSubtitlesDefault().isEmpty());
}
}

View File

@ -0,0 +1,78 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass;
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 static SoundcloudStreamUrlIdHandler urlIdHandler;
@BeforeClass
public static void setUp() throws Exception {
urlIdHandler = SoundcloudStreamUrlIdHandler.getInstance();
NewPipe.init(Downloader.getInstance());
}
@Test(expected = IllegalArgumentException.class)
public void getIdWithNullAsUrl() throws ParsingException {
urlIdHandler.setUrl(null).getId();
}
@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.setUrl(invalidUrl).getId();
} catch (ParsingException e) {
exception = e;
}
if (exception == null) {
fail("Expected ParsingException for url: " + invalidUrl);
}
}
}
@Test
public void getId() throws Exception {
assertEquals("309689103", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/15-ysl").getId());
assertEquals("309689082", urlIdHandler.setUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko").getId());
assertEquals("309689035", urlIdHandler.setUrl("http://soundcloud.com/liluzivert/15-boring-shit").getId());
assertEquals("294488599", urlIdHandler.setUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats").getId());
assertEquals("294488438", urlIdHandler.setUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz").getId());
assertEquals("294488147", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69").getId());
assertEquals("294487876", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09").getId());
assertEquals("294487684", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9").getId());
assertEquals("294487428", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s").getId());
assertEquals("294487157", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s").getId());
}
@Test
public void testAcceptUrl() throws ParsingException {
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"));
}
}

View File

@ -0,0 +1,76 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionItem;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
/**
* Test for {@link SoundcloudSubscriptionExtractor}
*/
public class SoundcloudSubscriptionExtractorTest {
private static SoundcloudSubscriptionExtractor subscriptionExtractor;
private static UrlIdHandler urlHandler;
@BeforeClass
public static void setupClass() {
NewPipe.init(Downloader.getInstance());
subscriptionExtractor = new SoundcloudSubscriptionExtractor(ServiceList.SoundCloud);
urlHandler = ServiceList.SoundCloud.getChannelUrlIdHandler();
}
@Test
public void testFromChannelUrl() throws Exception {
testList(subscriptionExtractor.fromChannelUrl("https://soundcloud.com/monstercat"));
testList(subscriptionExtractor.fromChannelUrl("http://soundcloud.com/monstercat"));
testList(subscriptionExtractor.fromChannelUrl("soundcloud.com/monstercat"));
testList(subscriptionExtractor.fromChannelUrl("monstercat"));
//Empty followings user
testList(subscriptionExtractor.fromChannelUrl("some-random-user-184047028"));
}
@Test
public void testInvalidSourceException() {
List<String> invalidList = Arrays.asList(
"httttps://invalid.com/user",
".com/monstercat",
"ithinkthatthisuserdontexist",
"",
null
);
for (String invalidUser : invalidList) {
try {
subscriptionExtractor.fromChannelUrl(invalidUser);
fail("didn't throw exception");
} catch (IOException e) {
// Ignore it, could be an unstable network on the CI server
} catch (Exception e) {
boolean isExpectedException = e instanceof SubscriptionExtractor.InvalidSourceException;
assertTrue(e.getClass().getSimpleName() + " is not the expected exception", isExpectedException);
}
}
}
private void testList(List<SubscriptionItem> subscriptionItems) throws ParsingException {
for (SubscriptionItem item : subscriptionItems) {
assertNotNull(item.getName());
assertNotNull(item.getUrl());
assertTrue(urlHandler.acceptUrl(item.getUrl()));
assertFalse(item.getServiceId() == -1);
}
}
}

View File

@ -0,0 +1,31 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass;
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 static SuggestionExtractor suggestionExtractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
suggestionExtractor = SoundCloud.getSuggestionExtractor();
}
@Test
public void testIfSuggestions() throws IOException, ExtractionException {
assertFalse(suggestionExtractor.suggestionList("lil uzi vert", "de").isEmpty());
}
}

View File

@ -0,0 +1,50 @@
package org.schabi.newpipe.extractor.services.soundcloud.search;
import org.junit.Test;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor;
import static org.junit.Assert.assertTrue;
/*
* Created by Christian Schabesberger on 17.06.18
*
* Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
* SoundcloudSearchExtractorBaseTest.java is part of NewPipe.
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPipe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Test for {@link SoundcloudSearchExtractor}
*/
public abstract class SoundcloudSearchExtractorBaseTest {
protected static SoundcloudSearchExtractor extractor;
protected static ListExtractor.InfoItemsPage<InfoItem> itemsPage;
@Test
public void testResultListElementsLength() {
assertTrue(Integer.toString(itemsPage.getItems().size()),
itemsPage.getItems().size() >= 10);
}
@Test
public void testUrl() throws Exception {
assertTrue(extractor.getUrl(), extractor.getUrl().startsWith("https://api-v2.soundcloud.com/search"));
}
}

View File

@ -0,0 +1,64 @@
package org.schabi.newpipe.extractor.services.soundcloud.search;
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor;
import static java.util.Arrays.asList;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchExtractorBaseTest {
@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert",
asList(new String[]{"users"}), null, "de");
extractor.fetchPage();
itemsPage = extractor.getInitialPage();
}
@Test
public void testGetSecondPage() throws Exception {
SoundcloudSearchExtractor secondExtractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert",
asList(new String[]{"users"}), null, "de");
ListExtractor.InfoItemsPage<InfoItem> secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl());
assertTrue(Integer.toString(secondPage.getItems().size()),
secondPage.getItems().size() >= 7);
// check if its the same result
boolean equals = true;
for (int i = 0; i < secondPage.getItems().size()
&& i < itemsPage.getItems().size(); i++) {
if(!secondPage.getItems().get(i).getUrl().equals(
itemsPage.getItems().get(i).getUrl())) {
equals = false;
}
}
assertFalse("First and second page are equal", equals);
assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=20",
secondPage.getNextPageUrl());
}
@Test
public void testGetSecondPageUrl() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=10",
extractor.getNextPageUrl());
}
@Test
public void testOnlyContainChannels() {
for(InfoItem item : itemsPage.getItems()) {
if(!(item instanceof ChannelInfoItem)) {
fail("The following item is no channel item: " + item.toString());
}
}
}
}

View File

@ -0,0 +1,109 @@
package org.schabi.newpipe.extractor.services.soundcloud.search;
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
/*
* Created by Christian Schabesberger on 27.05.18
*
* Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
* YoutubeSearchExtractorStreamTest.java is part of NewPipe.
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPipe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Test for {@link YoutubeSearchExtractor}
*/
public class SoundcloudSearchExtractorDefaultTest extends SoundcloudSearchExtractorBaseTest {
@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert", "de");
extractor.fetchPage();
itemsPage = extractor.getInitialPage();
}
@Test
public void testGetSecondPageUrl() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=10",
extractor.getNextPageUrl());
}
@Test
public void testResultList_FirstElement() {
InfoItem firstInfoItem = itemsPage.getItems().get(0);
// THe channel should be the first item
assertEquals("name", "Bad and Boujee (Feat. Lil Uzi Vert) [Prod. By Metro Boomin]", firstInfoItem.getName());
assertEquals("url","https://soundcloud.com/migosatl/bad-and-boujee-feat-lil-uzi-vert-prod-by-metro-boomin", firstInfoItem.getUrl());
}
@Test
public void testResultListCheckIfContainsStreamItems() {
boolean hasStreams = false;
for(InfoItem item : itemsPage.getItems()) {
if(item instanceof StreamInfoItem) {
hasStreams = true;
}
}
assertTrue("Has no InfoItemStreams", hasStreams);
}
@Test
public void testGetSecondPage() throws Exception {
SoundcloudSearchExtractor secondExtractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert", "de");
ListExtractor.InfoItemsPage<InfoItem> secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl());
assertTrue(Integer.toString(secondPage.getItems().size()),
secondPage.getItems().size() >= 10);
// check if its the same result
boolean equals = true;
for (int i = 0; i < secondPage.getItems().size()
&& i < itemsPage.getItems().size(); i++) {
if(!secondPage.getItems().get(i).getUrl().equals(
itemsPage.getItems().get(i).getUrl())) {
equals = false;
}
}
assertFalse("First and second page are equal", equals);
assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=20",
secondPage.getNextPageUrl());
}
@Test
public void testId() throws Exception {
assertEquals("lill uzi vert", extractor.getId());
}
@Test
public void testName() {
assertEquals("lill uzi vert", extractor.getName());
}
}

View File

@ -0,0 +1,64 @@
package org.schabi.newpipe.extractor.services.soundcloud.search;
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
public class SoundcloudSearchQUHTest {
@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(Downloader.getInstance());
}
@Test
public void testRegularValues() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler().setQuery("asdf").getUrl());
assertEquals("https://api-v2.soundcloud.com/search?q=hans&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0",SoundCloud.getSearchQueryHandler().setQuery("hans").getUrl());
assertEquals("https://api-v2.soundcloud.com/search?q=Poifj%26jaijf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler().setQuery("Poifj&jaijf").getUrl());
assertEquals("https://api-v2.soundcloud.com/search?q=G%C3%BCl%C3%BCm&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler().setQuery("Gülüm").getUrl());
assertEquals("https://api-v2.soundcloud.com/search?q=%3Fj%24%29H%C2%A7B&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler().setQuery("?j$)H§B").getUrl());
}
@Test
public void testGetContentFilter() throws Exception {
assertEquals("tracks", SoundCloud.getSearchQueryHandler()
.setQuery("", asList(new String[]{"tracks"}), "").getContentFilter().get(0));
assertEquals("users", SoundCloud.getSearchQueryHandler()
.setQuery("asdf", asList(new String[]{"users"}), "").getContentFilter().get(0));
}
@Test
public void testWithContentfilter() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search/tracks?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler()
.setQuery("asdf", asList(new String[]{"tracks"}), "").getUrl());
assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler()
.setQuery("asdf", asList(new String[]{"users"}), "").getUrl());
assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler()
.setQuery("asdf", asList(new String[]{"playlist"}), "").getUrl());
assertEquals("https://api-v2.soundcloud.com/search?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQueryHandler()
.setQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl());
}
@Test
public void testGetAvailableContentFilter() {
final String[] contentFilter = SoundCloud.getSearchQueryHandler().getAvailableContentFilter();
assertEquals(4, contentFilter.length);
assertEquals("tracks", contentFilter[0]);
assertEquals("users", contentFilter[1]);
assertEquals("playlist", contentFilter[2]);
assertEquals("any", contentFilter[3]);
}
@Test
public void testGetAvailableSortFilter() {
final String[] contentFilter = SoundCloud.getSearchQueryHandler().getAvailableSortFilter();
assertEquals(0, contentFilter.length);
}
}

View File

@ -52,7 +52,7 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas
@Test
public void testGetSecondPageUrl() throws Exception {
assertEquals(extractor.getNextPageUrl(), "https://www.youtube.com/results?q=pewdiepie&page=2");
assertEquals("https://www.youtube.com/results?q=pewdiepie&page=2", extractor.getNextPageUrl());
}
@Test
@ -107,11 +107,11 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas
@Test
public void testId() throws Exception {
assertEquals(extractor.getId(), "pewdiepie");
assertEquals("pewdiepie", extractor.getId());
}
@Test
public void testName() {
assertEquals(extractor.getName(), "pewdiepie");
assertEquals("pewdiepie", extractor.getName());
}
}