Skip to content

Commit 84eb4b3

Browse files
committed
Use DownloaderFactory in YouTube tests
1 parent b43f347 commit 84eb4b3

16 files changed

Lines changed: 246 additions & 104 deletions

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.junit.BeforeClass;
44
import org.junit.Ignore;
55
import org.junit.Test;
6-
import org.schabi.newpipe.downloader.DownloaderTestImpl;
6+
import org.schabi.newpipe.downloader.DownloaderFactory;
77
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
88
import org.schabi.newpipe.extractor.NewPipe;
99
import org.schabi.newpipe.extractor.Page;
@@ -17,10 +17,15 @@
1717
import java.io.IOException;
1818
import java.util.List;
1919

20-
import static org.junit.Assert.*;
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertNotNull;
23+
import static org.junit.Assert.assertTrue;
2124
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2225

2326
public class YoutubeCommentsExtractorTest {
27+
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/comments/";
28+
2429
/**
2530
* Test a "normal" YouTube
2631
*/
@@ -31,7 +36,8 @@ public static class Thomas {
3136

3237
@BeforeClass
3338
public static void setUp() throws Exception {
34-
NewPipe.init(DownloaderTestImpl.getInstance());
39+
YoutubeParsingHelper.resetClientVersionAndKey();
40+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "thomas"));
3541
extractor = (YoutubeCommentsExtractor) YouTube
3642
.getCommentsExtractor(url);
3743
extractor.fetchPage();
@@ -118,7 +124,8 @@ public static class EmptyComment {
118124

119125
@BeforeClass
120126
public static void setUp() throws Exception {
121-
NewPipe.init(DownloaderTestImpl.getInstance());
127+
YoutubeParsingHelper.resetClientVersionAndKey();
128+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "empty"));
122129
extractor = (YoutubeCommentsExtractor) YouTube
123130
.getCommentsExtractor(url);
124131
extractor.fetchPage();
@@ -157,7 +164,8 @@ public static class HeartedByCreator {
157164

158165
@BeforeClass
159166
public static void setUp() throws Exception {
160-
NewPipe.init(DownloaderTestImpl.getInstance());
167+
YoutubeParsingHelper.resetClientVersionAndKey();
168+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "hearted"));
161169
extractor = (YoutubeCommentsExtractor) YouTube
162170
.getCommentsExtractor(url);
163171
extractor.fetchPage();

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22

33
import org.junit.BeforeClass;
44
import org.junit.Test;
5-
import org.schabi.newpipe.downloader.DownloaderTestImpl;
5+
import org.schabi.newpipe.downloader.DownloaderFactory;
66
import org.schabi.newpipe.extractor.NewPipe;
77
import org.schabi.newpipe.extractor.exceptions.ParsingException;
88
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
99
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeFeedExtractor;
1010

11-
import static org.junit.Assert.*;
11+
import static org.junit.Assert.assertEquals;
12+
import static org.junit.Assert.assertTrue;
1213
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
1314
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems;
1415
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
1516

1617
public class YoutubeFeedExtractorTest {
18+
19+
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/feed/";
20+
1721
public static class Kurzgesagt implements BaseListExtractorTest {
1822
private static YoutubeFeedExtractor extractor;
1923

2024
@BeforeClass
2125
public static void setUp() throws Exception {
22-
NewPipe.init(DownloaderTestImpl.getInstance());
26+
YoutubeParsingHelper.resetClientVersionAndKey();
27+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH));
2328
extractor = (YoutubeFeedExtractor) YouTube
2429
.getFeedExtractor("https://www.youtube.com/user/Kurzgesagt");
2530
extractor.fetchPage();

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeKioskExtractorTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.junit.BeforeClass;
44
import org.junit.Test;
5-
import org.schabi.newpipe.downloader.DownloaderTestImpl;
5+
import org.schabi.newpipe.downloader.DownloaderFactory;
66
import org.schabi.newpipe.extractor.NewPipe;
77
import org.schabi.newpipe.extractor.exceptions.ParsingException;
88
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
@@ -14,12 +14,16 @@
1414
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
1515

1616
public class YoutubeKioskExtractorTest {
17+
18+
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/kiosk/";
19+
1720
public static class Trending implements BaseListExtractorTest {
1821
private static YoutubeTrendingExtractor extractor;
1922

2023
@BeforeClass
2124
public static void setUp() throws Exception {
22-
NewPipe.init(DownloaderTestImpl.getInstance());
25+
YoutubeParsingHelper.resetClientVersionAndKey();
26+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "trending"));
2327
extractor = (YoutubeTrendingExtractor) YouTube.getKioskList().getDefaultKioskExtractor();
2428
extractor.fetchPage();
2529
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package org.schabi.newpipe.extractor.services.youtube;
22

3-
import java.io.File;
4-
import java.io.IOException;
5-
import java.util.Collections;
6-
import java.util.HashSet;
7-
import java.util.Map;
8-
import java.util.Set;
93
import org.hamcrest.MatcherAssert;
104
import org.junit.BeforeClass;
115
import org.junit.Test;
@@ -26,6 +20,12 @@
2620
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeMixPlaylistExtractor;
2721
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
2822

23+
import java.io.IOException;
24+
import java.util.Collections;
25+
import java.util.HashSet;
26+
import java.util.Map;
27+
import java.util.Set;
28+
2929
import static org.hamcrest.CoreMatchers.containsString;
3030
import static org.hamcrest.CoreMatchers.startsWith;
3131
import static org.hamcrest.MatcherAssert.assertThat;
@@ -43,7 +43,7 @@ public class YoutubeMixPlaylistExtractorTest {
4343
private static final String VIDEO_ID = "_AzeUSL9lZc";
4444
private static final String VIDEO_TITLE =
4545
"Most Beautiful And Emotional Piano: Anime Music Shigatsu wa Kimi no Uso OST IMO";
46-
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/mix/";
46+
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/mix/";
4747
private static final Map<String, String> dummyCookie
4848
= Collections.singletonMap(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
4949

@@ -134,9 +134,9 @@ public static void setUp() throws Exception {
134134
YoutubeParsingHelper.resetClientVersionAndKey();
135135
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "mixWithIndex"));
136136
extractor = (YoutubeMixPlaylistExtractor) YouTube
137-
.getPlaylistExtractor(
138-
"https://www.youtube.com/watch?v=" + VIDEO_ID_NUMBER_13 + "&list=RD"
139-
+ VIDEO_ID + INDEX);
137+
.getPlaylistExtractor(
138+
"https://www.youtube.com/watch?v=" + VIDEO_ID_NUMBER_13 + "&list=RD"
139+
+ VIDEO_ID + INDEX);
140140
extractor.fetchPage();
141141
}
142142

@@ -165,8 +165,8 @@ public void getInitialPage() throws Exception {
165165
@Test
166166
public void getPage() throws Exception {
167167
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(
168-
new Page("https://www.youtube.com/watch?v=" + VIDEO_ID_NUMBER_13 + "&list=RD"
169-
+ VIDEO_ID + INDEX + PBJ, dummyCookie));
168+
new Page("https://www.youtube.com/watch?v=" + VIDEO_ID_NUMBER_13 + "&list=RD"
169+
+ VIDEO_ID + INDEX + PBJ, dummyCookie));
170170
assertFalse(streams.getItems().isEmpty());
171171
assertTrue(streams.hasNextPage());
172172
}
@@ -204,9 +204,9 @@ public static void setUp() throws Exception {
204204
YoutubeParsingHelper.resetClientVersionAndKey();
205205
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "myMix"));
206206
extractor = (YoutubeMixPlaylistExtractor) YouTube
207-
.getPlaylistExtractor(
208-
"https://www.youtube.com/watch?v=" + VIDEO_ID + "&list=RDMM"
209-
+ VIDEO_ID);
207+
.getPlaylistExtractor(
208+
"https://www.youtube.com/watch?v=" + VIDEO_ID + "&list=RDMM"
209+
+ VIDEO_ID);
210210
extractor.fetchPage();
211211
}
212212

@@ -238,11 +238,12 @@ public void getInitialPage() throws Exception {
238238
@Test
239239
public void getPage() throws Exception {
240240
final InfoItemsPage<StreamInfoItem> streams =
241-
extractor.getPage(new Page("https://www.youtube.com/watch?v=" + VIDEO_ID
242-
+ "&list=RDMM" + VIDEO_ID + PBJ, dummyCookie));
241+
extractor.getPage(new Page("https://www.youtube.com/watch?v=" + VIDEO_ID
242+
+ "&list=RDMM" + VIDEO_ID + PBJ, dummyCookie));
243243
assertFalse(streams.getItems().isEmpty());
244244
assertTrue(streams.hasNextPage());
245245
}
246+
246247
@Test
247248
public void getContinuations() throws Exception {
248249
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
@@ -290,8 +291,8 @@ public void getPageEmptyUrl() throws Exception {
290291
@Test(expected = ExtractionException.class)
291292
public void invalidVideoId() throws Exception {
292293
extractor = (YoutubeMixPlaylistExtractor) YouTube
293-
.getPlaylistExtractor(
294-
"https://www.youtube.com/watch?v=" + "abcde" + "&list=RD" + "abcde");
294+
.getPlaylistExtractor(
295+
"https://www.youtube.com/watch?v=" + "abcde" + "&list=RD" + "abcde");
295296
extractor.fetchPage();
296297
extractor.getName();
297298
}
@@ -309,9 +310,9 @@ public static void setUp() throws Exception {
309310
YoutubeParsingHelper.resetClientVersionAndKey();
310311
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "channelMix"));
311312
extractor = (YoutubeMixPlaylistExtractor) YouTube
312-
.getPlaylistExtractor(
313-
"https://www.youtube.com/watch?v=" + VIDEO_ID_OF_CHANNEL
314-
+ "&list=RDCM" + CHANNEL_ID);
313+
.getPlaylistExtractor(
314+
"https://www.youtube.com/watch?v=" + VIDEO_ID_OF_CHANNEL
315+
+ "&list=RDCM" + CHANNEL_ID);
315316
extractor.fetchPage();
316317
}
317318

@@ -339,8 +340,8 @@ public void getInitialPage() throws Exception {
339340
@Test
340341
public void getPage() throws Exception {
341342
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(
342-
new Page("https://www.youtube.com/watch?v=" + VIDEO_ID_OF_CHANNEL
343-
+ "&list=RDCM" + CHANNEL_ID + PBJ, dummyCookie));
343+
new Page("https://www.youtube.com/watch?v=" + VIDEO_ID_OF_CHANNEL
344+
+ "&list=RDCM" + CHANNEL_ID + PBJ, dummyCookie));
344345
assertFalse(streams.getItems().isEmpty());
345346
assertTrue(streams.hasNextPage());
346347
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.junit.BeforeClass;
44
import org.junit.Test;
5-
import org.schabi.newpipe.downloader.DownloaderTestImpl;
5+
import org.schabi.newpipe.downloader.DownloaderFactory;
66
import org.schabi.newpipe.extractor.NewPipe;
77
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
88
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -13,9 +13,13 @@
1313
import static org.junit.Assert.assertTrue;
1414

1515
public class YoutubeParsingHelperTest {
16+
17+
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/";
18+
1619
@BeforeClass
17-
public static void setUp() {
18-
NewPipe.init(DownloaderTestImpl.getInstance());
20+
public static void setUp() throws IOException {
21+
YoutubeParsingHelper.resetClientVersionAndKey();
22+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "youtubeParsingHelper"));
1923
}
2024

2125
@Test

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import org.junit.runner.RunWith;
77
import org.junit.runners.Suite;
88
import org.junit.runners.Suite.SuiteClasses;
9-
import org.schabi.newpipe.downloader.DownloaderTestImpl;
9+
import org.schabi.newpipe.downloader.DownloaderFactory;
1010
import org.schabi.newpipe.extractor.ListExtractor;
1111
import org.schabi.newpipe.extractor.NewPipe;
12-
1312
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
1413
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1514
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
@@ -22,13 +21,18 @@
2221
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubePlaylistExtractor;
2322
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
2423

24+
import java.io.IOException;
25+
2526
import static junit.framework.TestCase.assertFalse;
2627
import static org.junit.Assert.assertEquals;
27-
import static org.junit.Assert.assertNull;
2828
import static org.junit.Assert.assertTrue;
2929
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
3030
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
31-
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
31+
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems;
32+
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor;
33+
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestListOfItems;
34+
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems;
35+
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
3236

3337
/**
3438
* Test for {@link YoutubePlaylistExtractor}
@@ -38,10 +42,13 @@
3842
LearningPlaylist.class, ContinuationsTests.class})
3943
public class YoutubePlaylistExtractorTest {
4044

45+
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/playlist/";
46+
4147
public static class NotAvailable {
4248
@BeforeClass
43-
public static void setUp() {
44-
NewPipe.init(DownloaderTestImpl.getInstance());
49+
public static void setUp() throws IOException {
50+
YoutubeParsingHelper.resetClientVersionAndKey();
51+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable"));
4552
}
4653

4754
@Test(expected = ContentNotAvailableException.class)
@@ -65,7 +72,8 @@ public static class TimelessPopHits implements BasePlaylistExtractorTest {
6572

6673
@BeforeClass
6774
public static void setUp() throws Exception {
68-
NewPipe.init(DownloaderTestImpl.getInstance());
75+
YoutubeParsingHelper.resetClientVersionAndKey();
76+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "TimelessPopHits"));
6977
extractor = (YoutubePlaylistExtractor) YouTube
7078
.getPlaylistExtractor("http://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj");
7179
extractor.fetchPage();
@@ -162,7 +170,8 @@ public static class HugePlaylist implements BasePlaylistExtractorTest {
162170

163171
@BeforeClass
164172
public static void setUp() throws Exception {
165-
NewPipe.init(DownloaderTestImpl.getInstance());
173+
YoutubeParsingHelper.resetClientVersionAndKey();
174+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "huge"));
166175
extractor = (YoutubePlaylistExtractor) YouTube
167176
.getPlaylistExtractor("https://www.youtube.com/watch?v=8SbUC-UaAxE&list=PLWwAypAcFRgKAIIFqBr9oy-ZYZnixa_Fj");
168177
extractor.fetchPage();
@@ -274,7 +283,8 @@ public static class LearningPlaylist implements BasePlaylistExtractorTest {
274283

275284
@BeforeClass
276285
public static void setUp() throws Exception {
277-
NewPipe.init(DownloaderTestImpl.getInstance());
286+
YoutubeParsingHelper.resetClientVersionAndKey();
287+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "learning"));
278288
extractor = (YoutubePlaylistExtractor) YouTube
279289
.getPlaylistExtractor("https://www.youtube.com/playlist?list=PL8dPuuaLjXtOAKed_MxxWBNaPno5h3Zs8");
280290
extractor.fetchPage();
@@ -370,8 +380,9 @@ public void testStreamCount() throws Exception {
370380
public static class ContinuationsTests {
371381

372382
@BeforeClass
373-
public static void setUp() {
374-
NewPipe.init(DownloaderTestImpl.getInstance());
383+
public static void setUp() throws IOException {
384+
YoutubeParsingHelper.resetClientVersionAndKey();
385+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "continuations"));
375386
}
376387

377388
@Test

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.junit.BeforeClass;
44
import org.junit.Test;
5-
import org.schabi.newpipe.downloader.DownloaderTestImpl;
5+
import org.schabi.newpipe.downloader.DownloaderFactory;
66
import org.schabi.newpipe.extractor.NewPipe;
77
import org.schabi.newpipe.extractor.ServiceList;
88
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
@@ -12,6 +12,7 @@
1212

1313
import java.io.ByteArrayInputStream;
1414
import java.io.FileInputStream;
15+
import java.io.IOException;
1516
import java.nio.charset.StandardCharsets;
1617
import java.util.Arrays;
1718
import java.util.List;
@@ -26,12 +27,16 @@
2627
* Test for {@link YoutubeSubscriptionExtractor}
2728
*/
2829
public class YoutubeSubscriptionExtractorTest {
30+
31+
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/subscription/";
32+
2933
private static YoutubeSubscriptionExtractor subscriptionExtractor;
3034
private static LinkHandlerFactory urlHandler;
3135

3236
@BeforeClass
33-
public static void setupClass() {
34-
NewPipe.init(DownloaderTestImpl.getInstance());
37+
public static void setupClass() throws IOException {
38+
YoutubeParsingHelper.resetClientVersionAndKey();
39+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH));
3540
subscriptionExtractor = new YoutubeSubscriptionExtractor(ServiceList.YouTube);
3641
urlHandler = ServiceList.YouTube.getChannelLHFactory();
3742
}

0 commit comments

Comments
 (0)