Skip to content

Commit 9bda761

Browse files
committed
add test for soundcloud search extractor
1 parent ef2ce68 commit 9bda761

15 files changed

Lines changed: 1289 additions & 5 deletions

extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.schabi.newpipe.extractor;
22

3+
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudService;
34
import org.schabi.newpipe.extractor.services.youtube.YoutubeService;
45

56
import java.util.List;
@@ -15,10 +16,14 @@ private ServiceList() {
1516
//no instance
1617
}
1718

18-
public static final YoutubeService YouTube = new YoutubeService(0);
19+
public static final YoutubeService YouTube;
20+
public static final SoundcloudService SoundCloud;
1921

2022
private static final List<StreamingService> SERVICES = unmodifiableList(
21-
asList((StreamingService) YouTube));
23+
asList(
24+
YouTube = new YoutubeService(0),
25+
SoundCloud = new SoundcloudService(1)
26+
));
2227

2328
/**
2429
* Get all the supported services.
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.Test;
5+
import org.schabi.newpipe.Downloader;
6+
import org.schabi.newpipe.extractor.NewPipe;
7+
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
8+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
9+
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
10+
11+
import static org.junit.Assert.*;
12+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
13+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
14+
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
15+
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
16+
17+
/**
18+
* Test for {@link SoundcloudChannelExtractor}
19+
*/
20+
public class SoundcloudChannelExtractorTest {
21+
public static class LilUzi implements BaseChannelExtractorTest {
22+
private static SoundcloudChannelExtractor extractor;
23+
24+
@BeforeClass
25+
public static void setUp() throws Exception {
26+
NewPipe.init(Downloader.getInstance());
27+
extractor = (SoundcloudChannelExtractor) SoundCloud
28+
.getChannelExtractor("http://soundcloud.com/liluzivert/sets");
29+
extractor.fetchPage();
30+
}
31+
32+
/*//////////////////////////////////////////////////////////////////////////
33+
// Extractor
34+
//////////////////////////////////////////////////////////////////////////*/
35+
36+
@Test
37+
public void testServiceId() {
38+
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
39+
}
40+
41+
@Test
42+
public void testName() {
43+
assertEquals("LIL UZI VERT", extractor.getName());
44+
}
45+
46+
@Test
47+
public void testId() {
48+
assertEquals("10494998", extractor.getId());
49+
}
50+
51+
@Test
52+
public void testUrl() throws ParsingException {
53+
assertEquals("https://soundcloud.com/liluzivert", extractor.getUrl());
54+
}
55+
56+
@Test
57+
public void testOriginalUrl() throws ParsingException {
58+
assertEquals("http://soundcloud.com/liluzivert/sets", extractor.getOriginalUrl());
59+
}
60+
61+
/*//////////////////////////////////////////////////////////////////////////
62+
// ListExtractor
63+
//////////////////////////////////////////////////////////////////////////*/
64+
65+
@Test
66+
public void testRelatedItems() throws Exception {
67+
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
68+
}
69+
70+
@Test
71+
public void testMoreRelatedItems() throws Exception {
72+
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
73+
}
74+
75+
/*//////////////////////////////////////////////////////////////////////////
76+
// ChannelExtractor
77+
//////////////////////////////////////////////////////////////////////////*/
78+
79+
@Test
80+
public void testDescription() {
81+
assertNotNull(extractor.getDescription());
82+
}
83+
84+
@Test
85+
public void testAvatarUrl() {
86+
assertIsSecureUrl(extractor.getAvatarUrl());
87+
}
88+
89+
@Test
90+
public void testBannerUrl() {
91+
assertIsSecureUrl(extractor.getBannerUrl());
92+
}
93+
94+
@Test
95+
public void testFeedUrl() {
96+
assertEmpty(extractor.getFeedUrl());
97+
}
98+
99+
@Test
100+
public void testSubscriberCount() {
101+
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 1e6);
102+
}
103+
}
104+
105+
public static class DubMatix implements BaseChannelExtractorTest {
106+
private static SoundcloudChannelExtractor extractor;
107+
108+
@BeforeClass
109+
public static void setUp() throws Exception {
110+
NewPipe.init(Downloader.getInstance());
111+
extractor = (SoundcloudChannelExtractor) SoundCloud
112+
.getChannelExtractor("https://soundcloud.com/dubmatix");
113+
extractor.fetchPage();
114+
}
115+
116+
/*//////////////////////////////////////////////////////////////////////////
117+
// Additional Testing
118+
//////////////////////////////////////////////////////////////////////////*/
119+
120+
@Test
121+
public void testGetPageInNewExtractor() throws Exception {
122+
final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getUrl());
123+
defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
124+
}
125+
126+
/*//////////////////////////////////////////////////////////////////////////
127+
// Extractor
128+
//////////////////////////////////////////////////////////////////////////*/
129+
130+
@Test
131+
public void testServiceId() {
132+
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
133+
}
134+
135+
@Test
136+
public void testName() {
137+
assertEquals("dubmatix", extractor.getName());
138+
}
139+
140+
@Test
141+
public void testId() {
142+
assertEquals("542134", extractor.getId());
143+
}
144+
145+
@Test
146+
public void testUrl() throws ParsingException {
147+
assertEquals("https://soundcloud.com/dubmatix", extractor.getUrl());
148+
}
149+
150+
@Test
151+
public void testOriginalUrl() throws ParsingException {
152+
assertEquals("https://soundcloud.com/dubmatix", extractor.getOriginalUrl());
153+
}
154+
155+
/*//////////////////////////////////////////////////////////////////////////
156+
// ListExtractor
157+
//////////////////////////////////////////////////////////////////////////*/
158+
159+
@Test
160+
public void testRelatedItems() throws Exception {
161+
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
162+
}
163+
164+
@Test
165+
public void testMoreRelatedItems() throws Exception {
166+
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
167+
}
168+
169+
/*//////////////////////////////////////////////////////////////////////////
170+
// ChannelExtractor
171+
//////////////////////////////////////////////////////////////////////////*/
172+
173+
@Test
174+
public void testDescription() {
175+
assertNotNull(extractor.getDescription());
176+
}
177+
178+
@Test
179+
public void testAvatarUrl() {
180+
assertIsSecureUrl(extractor.getAvatarUrl());
181+
}
182+
183+
@Test
184+
public void testBannerUrl() {
185+
assertIsSecureUrl(extractor.getBannerUrl());
186+
}
187+
188+
@Test
189+
public void testFeedUrl() {
190+
assertEmpty(extractor.getFeedUrl());
191+
}
192+
193+
@Test
194+
public void testSubscriberCount() {
195+
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 2e6);
196+
}
197+
}
198+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.Ignore;
5+
import org.junit.Test;
6+
import org.schabi.newpipe.Downloader;
7+
import org.schabi.newpipe.extractor.ListExtractor;
8+
import org.schabi.newpipe.extractor.NewPipe;
9+
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
10+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
11+
12+
import java.util.List;
13+
14+
import static org.junit.Assert.*;
15+
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
16+
17+
/**
18+
* Test for {@link SoundcloudChartsUrlIdHandler}
19+
*/
20+
public class SoundcloudChartsExtractorTest {
21+
22+
static KioskExtractor extractor;
23+
24+
@BeforeClass
25+
public static void setUp() throws Exception {
26+
NewPipe.init(Downloader.getInstance());
27+
extractor = SoundCloud
28+
.getKioskList()
29+
.getExtractorById("Top 50", null);
30+
extractor.fetchPage();
31+
}
32+
33+
@Test
34+
public void testGetDownloader() throws Exception {
35+
assertNotNull(NewPipe.getDownloader());
36+
}
37+
38+
@Ignore
39+
@Test
40+
public void testGetName() throws Exception {
41+
assertEquals(extractor.getName(), "Top 50");
42+
}
43+
44+
@Test
45+
public void testId() {
46+
assertEquals(extractor.getId(), "Top 50");
47+
}
48+
49+
@Test
50+
public void testGetStreams() throws Exception {
51+
ListExtractor.InfoItemsPage<StreamInfoItem> page = extractor.getInitialPage();
52+
if(!page.getErrors().isEmpty()) {
53+
System.err.println("----------");
54+
List<Throwable> errors = page.getErrors();
55+
for(Throwable e: errors) {
56+
e.printStackTrace();
57+
System.err.println("----------");
58+
}
59+
}
60+
assertTrue("no streams are received",
61+
!page.getItems().isEmpty()
62+
&& page.getErrors().isEmpty());
63+
}
64+
65+
@Test
66+
public void testGetStreamsErrors() throws Exception {
67+
assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty());
68+
}
69+
70+
@Test
71+
public void testHasMoreStreams() throws Exception {
72+
// Setup the streams
73+
extractor.getInitialPage();
74+
assertTrue("has more streams", extractor.hasNextPage());
75+
}
76+
77+
@Test
78+
public void testGetNextPageUrl() throws Exception {
79+
assertTrue(extractor.hasNextPage());
80+
}
81+
82+
@Test
83+
public void testGetNextPage() throws Exception {
84+
extractor.getInitialPage().getItems();
85+
assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
86+
|| extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
87+
}
88+
89+
@Test
90+
public void testGetCleanUrl() throws Exception {
91+
assertEquals(extractor.getUrl(), "https://soundcloud.com/charts/top");
92+
}
93+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.Test;
5+
import org.schabi.newpipe.Downloader;
6+
import org.schabi.newpipe.extractor.NewPipe;
7+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
8+
9+
import static junit.framework.TestCase.assertFalse;
10+
import static org.junit.Assert.assertEquals;
11+
import static org.junit.Assert.assertTrue;
12+
13+
/**
14+
* Test for {@link SoundcloudChartsUrlIdHandler}
15+
*/
16+
public class SoundcloudChartsUrlIdHandlerTest {
17+
private static SoundcloudChartsUrlIdHandler urlIdHandler;
18+
19+
@BeforeClass
20+
public static void setUp() throws Exception {
21+
urlIdHandler = new SoundcloudChartsUrlIdHandler();
22+
NewPipe.init(Downloader.getInstance());
23+
}
24+
25+
@Test
26+
public void getUrl() throws Exception {
27+
assertEquals(urlIdHandler.setId("Top 50").getUrl(), "https://soundcloud.com/charts/top");
28+
assertEquals(urlIdHandler.setId("New & hot").getUrl(), "https://soundcloud.com/charts/new");
29+
}
30+
31+
@Test
32+
public void getId() throws ParsingException {
33+
assertEquals(urlIdHandler.setUrl("http://soundcloud.com/charts/top?genre=all-music").getId(), "Top 50");
34+
assertEquals(urlIdHandler.setUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries").getId(), "New & hot");
35+
}
36+
37+
@Test
38+
public void acceptUrl() throws ParsingException {
39+
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts"));
40+
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts/"));
41+
assertTrue(urlIdHandler.acceptUrl("https://www.soundcloud.com/charts/new"));
42+
assertTrue(urlIdHandler.acceptUrl("http://soundcloud.com/charts/top?genre=all-music"));
43+
assertTrue(urlIdHandler.acceptUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries"));
44+
45+
assertFalse(urlIdHandler.acceptUrl("kdskjfiiejfia"));
46+
assertFalse(urlIdHandler.acceptUrl("soundcloud.com/charts askjkf"));
47+
assertFalse(urlIdHandler.acceptUrl(" soundcloud.com/charts"));
48+
assertFalse(urlIdHandler.acceptUrl(""));
49+
}
50+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import org.junit.Assert;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
import org.schabi.newpipe.Downloader;
7+
import org.schabi.newpipe.extractor.NewPipe;
8+
9+
public class SoundcloudParsingHelperTest {
10+
@BeforeClass
11+
public static void setUp() {
12+
NewPipe.init(Downloader.getInstance());
13+
}
14+
15+
@Test
16+
public void resolveUrlWithEmbedPlayerTest() throws Exception {
17+
Assert.assertEquals("https://soundcloud.com/trapcity", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/26057743"));
18+
Assert.assertEquals("https://soundcloud.com/nocopyrightsounds", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/16069159"));
19+
}
20+
21+
@Test
22+
public void resolveIdWithEmbedPlayerTest() throws Exception {
23+
Assert.assertEquals("26057743", SoundcloudParsingHelper.resolveIdWithEmbedPlayer("https://soundcloud.com/trapcity"));
24+
Assert.assertEquals("16069159", SoundcloudParsingHelper.resolveIdWithEmbedPlayer("https://soundcloud.com/nocopyrightsounds"));
25+
26+
}
27+
28+
}

0 commit comments

Comments
 (0)