Skip to content

Commit 0c37c75

Browse files
committed
Make getDownloader static & extract getDownloaderType
1 parent e7aee0c commit 0c37c75

17 files changed

+65
-63
lines changed

extractor/src/test/java/org/schabi/newpipe/downloader/DownloaderFactory.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ public class DownloaderFactory {
1010

1111
private final static DownloaderType DEFAULT_DOWNLOADER = DownloaderType.REAL;
1212

13+
public static DownloaderType getDownloaderType() {
14+
try {
15+
return DownloaderType.valueOf(System.getProperty("downloader"));
16+
} catch (final Exception e) {
17+
return DEFAULT_DOWNLOADER;
18+
}
19+
}
20+
1321
/**
1422
* <p>
1523
* Returns a implementation of a {@link Downloader}.
@@ -28,14 +36,8 @@ public class DownloaderFactory {
2836
* @param path The path to the folder where mocks are saved/retrieved.
2937
* Preferably starting with {@link DownloaderFactory#RESOURCE_PATH}
3038
*/
31-
public Downloader getDownloader(String path) throws IOException {
32-
DownloaderType type;
33-
try {
34-
type = DownloaderType.valueOf(System.getProperty("downloader"));
35-
} catch (Exception e) {
36-
type = DEFAULT_DOWNLOADER;
37-
}
38-
39+
public static Downloader getDownloader(final String path) throws IOException {
40+
final DownloaderType type = getDownloaderType();
3941
switch (type) {
4042
case REAL:
4143
return DownloaderTestImpl.getInstance();
@@ -44,7 +46,7 @@ public Downloader getDownloader(String path) throws IOException {
4446
case RECORDING:
4547
return new RecordingDownloader(path);
4648
default:
47-
throw new UnsupportedOperationException("Unknown downloader type: " + type.toString());
49+
throw new UnsupportedOperationException("Unknown downloader type: " + type);
4850
}
4951
}
5052
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static class NotAvailable {
3535
public static void setUp() throws IOException {
3636
YoutubeParsingHelper.resetClientVersionAndKey();
3737
YoutubeParsingHelper.setNumberGenerator(new Random(1));
38-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable"));
38+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable"));
3939
}
4040

4141
@Test
@@ -132,7 +132,7 @@ public static class NotSupported {
132132
public static void setUp() throws IOException {
133133
YoutubeParsingHelper.resetClientVersionAndKey();
134134
YoutubeParsingHelper.setNumberGenerator(new Random(1));
135-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notSupported"));
135+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notSupported"));
136136
}
137137

138138
@Test
@@ -151,7 +151,7 @@ public static class Gronkh implements BaseChannelExtractorTest {
151151
public static void setUp() throws Exception {
152152
YoutubeParsingHelper.resetClientVersionAndKey();
153153
YoutubeParsingHelper.setNumberGenerator(new Random(1));
154-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "gronkh"));
154+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "gronkh"));
155155
extractor = (YoutubeChannelExtractor) YouTube
156156
.getChannelExtractor("http://www.youtube.com/user/Gronkh");
157157
extractor.fetchPage();
@@ -248,7 +248,7 @@ public static class VSauce implements BaseChannelExtractorTest {
248248
public static void setUp() throws Exception {
249249
YoutubeParsingHelper.resetClientVersionAndKey();
250250
YoutubeParsingHelper.setNumberGenerator(new Random(1));
251-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "VSauce"));
251+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "VSauce"));
252252
extractor = (YoutubeChannelExtractor) YouTube
253253
.getChannelExtractor("https://www.youtube.com/user/Vsauce");
254254
extractor.fetchPage();
@@ -344,7 +344,7 @@ public static class Kurzgesagt implements BaseChannelExtractorTest {
344344
public static void setUp() throws Exception {
345345
YoutubeParsingHelper.resetClientVersionAndKey();
346346
YoutubeParsingHelper.setNumberGenerator(new Random(1));
347-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "kurzgesagt"));
347+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "kurzgesagt"));
348348
extractor = (YoutubeChannelExtractor) YouTube
349349
.getChannelExtractor("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q");
350350
extractor.fetchPage();
@@ -461,7 +461,7 @@ public static class CaptainDisillusion implements BaseChannelExtractorTest {
461461
public static void setUp() throws Exception {
462462
YoutubeParsingHelper.resetClientVersionAndKey();
463463
YoutubeParsingHelper.setNumberGenerator(new Random(1));
464-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "captainDisillusion"));
464+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "captainDisillusion"));
465465
extractor = (YoutubeChannelExtractor) YouTube
466466
.getChannelExtractor("https://www.youtube.com/user/CaptainDisillusion/videos");
467467
extractor.fetchPage();
@@ -556,7 +556,7 @@ public static class RandomChannel implements BaseChannelExtractorTest {
556556
public static void setUp() throws Exception {
557557
YoutubeParsingHelper.resetClientVersionAndKey();
558558
YoutubeParsingHelper.setNumberGenerator(new Random(1));
559-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "random"));
559+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "random"));
560560
extractor = (YoutubeChannelExtractor) YouTube
561561
.getChannelExtractor("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w");
562562
extractor.fetchPage();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class YoutubeChannelLocalizationTest {
3232
public void testAllSupportedLocalizations() throws Exception {
3333
YoutubeParsingHelper.resetClientVersionAndKey();
3434
YoutubeParsingHelper.setNumberGenerator(new Random(1));
35-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "localization"));
35+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "localization"));
3636

3737
testLocalizationsFor("https://www.youtube.com/user/NBCNews");
3838
testLocalizationsFor("https://www.youtube.com/channel/UCcmpeVbSSQlZRvHfdC-CRwg/videos");

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static class Thomas {
4040
public static void setUp() throws Exception {
4141
YoutubeParsingHelper.resetClientVersionAndKey();
4242
YoutubeParsingHelper.setNumberGenerator(new Random(1));
43-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "thomas"));
43+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "thomas"));
4444
extractor = (YoutubeCommentsExtractor) YouTube
4545
.getCommentsExtractor(url);
4646
extractor.fetchPage();
@@ -129,7 +129,7 @@ public static class EmptyComment {
129129
public static void setUp() throws Exception {
130130
YoutubeParsingHelper.resetClientVersionAndKey();
131131
YoutubeParsingHelper.setNumberGenerator(new Random(1));
132-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "empty"));
132+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "empty"));
133133
extractor = (YoutubeCommentsExtractor) YouTube
134134
.getCommentsExtractor(url);
135135
extractor.fetchPage();
@@ -169,7 +169,7 @@ public static class HeartedByCreator {
169169
public static void setUp() throws Exception {
170170
YoutubeParsingHelper.resetClientVersionAndKey();
171171
YoutubeParsingHelper.setNumberGenerator(new Random(1));
172-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "hearted"));
172+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "hearted"));
173173
extractor = (YoutubeCommentsExtractor) YouTube
174174
.getCommentsExtractor(url);
175175
extractor.fetchPage();
@@ -212,7 +212,7 @@ public static class Pinned {
212212
public static void setUp() throws Exception {
213213
YoutubeParsingHelper.resetClientVersionAndKey();
214214
YoutubeParsingHelper.setNumberGenerator(new Random(1));
215-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "pinned"));
215+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "pinned"));
216216
extractor = (YoutubeCommentsExtractor) YouTube
217217
.getCommentsExtractor(url);
218218
extractor.fetchPage();
@@ -254,7 +254,7 @@ public static class LikesVotes {
254254
public static void setUp() throws Exception {
255255
YoutubeParsingHelper.resetClientVersionAndKey();
256256
YoutubeParsingHelper.setNumberGenerator(new Random(1));
257-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "likes"));
257+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "likes"));
258258
extractor = (YoutubeCommentsExtractor) YouTube
259259
.getCommentsExtractor(url);
260260
extractor.fetchPage();
@@ -286,7 +286,7 @@ public static class LocalizedVoteCount {
286286
public static void setUp() throws Exception {
287287
YoutubeParsingHelper.resetClientVersionAndKey();
288288
YoutubeParsingHelper.setNumberGenerator(new Random(1));
289-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "localized_vote_count"));
289+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "localized_vote_count"));
290290
extractor = (YoutubeCommentsExtractor) YouTube
291291
.getCommentsExtractor(url);
292292
// Force non english local here
@@ -315,7 +315,7 @@ public static class RepliesTest {
315315
public static void setUp() throws Exception {
316316
YoutubeParsingHelper.resetClientVersionAndKey();
317317
YoutubeParsingHelper.setNumberGenerator(new Random(1));
318-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "replies"));
318+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "replies"));
319319
extractor = (YoutubeCommentsExtractor) YouTube
320320
.getCommentsExtractor(url);
321321
extractor.fetchPage();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class Kurzgesagt implements BaseListExtractorTest {
3030
public static void setUp() throws Exception {
3131
YoutubeParsingHelper.resetClientVersionAndKey();
3232
YoutubeParsingHelper.setNumberGenerator(new Random(1));
33-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH));
33+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
3434
extractor = (YoutubeFeedExtractor) YouTube
3535
.getFeedExtractor("https://www.youtube.com/user/Kurzgesagt");
3636
extractor.fetchPage();
@@ -84,7 +84,7 @@ public static class NotAvailable {
8484

8585
@BeforeAll
8686
public static void setUp() throws IOException {
87-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable/"));
87+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable/"));
8888
}
8989

9090
@Test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static class Trending implements BaseListExtractorTest {
2626
public static void setUp() throws Exception {
2727
YoutubeParsingHelper.resetClientVersionAndKey();
2828
YoutubeParsingHelper.setNumberGenerator(new Random(1));
29-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "trending"));
29+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "trending"));
3030
extractor = (YoutubeTrendingExtractor) YouTube.getKioskList().getDefaultKioskExtractor();
3131
extractor.fetchPage();
3232
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static class Mix {
4141
public static void setUp() throws Exception {
4242
YoutubeParsingHelper.resetClientVersionAndKey();
4343
YoutubeParsingHelper.setNumberGenerator(new Random(1));
44-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "mix"));
44+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "mix"));
4545
dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
4646
extractor = (YoutubeMixPlaylistExtractor) YouTube
4747
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID
@@ -131,7 +131,7 @@ public static class MixWithIndex {
131131
public static void setUp() throws Exception {
132132
YoutubeParsingHelper.resetClientVersionAndKey();
133133
YoutubeParsingHelper.setNumberGenerator(new Random(1));
134-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "mixWithIndex"));
134+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "mixWithIndex"));
135135
dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
136136
extractor = (YoutubeMixPlaylistExtractor) YouTube
137137
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID_NUMBER_4
@@ -212,7 +212,7 @@ public static class MyMix {
212212
public static void setUp() throws Exception {
213213
YoutubeParsingHelper.resetClientVersionAndKey();
214214
YoutubeParsingHelper.setNumberGenerator(new Random(1));
215-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "myMix"));
215+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "myMix"));
216216
dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
217217
extractor = (YoutubeMixPlaylistExtractor) YouTube
218218
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID
@@ -297,7 +297,7 @@ public static class Invalid {
297297
public static void setUp() throws IOException {
298298
YoutubeParsingHelper.resetClientVersionAndKey();
299299
YoutubeParsingHelper.setNumberGenerator(new Random(1));
300-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "invalid"));
300+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "invalid"));
301301
dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
302302
}
303303

@@ -332,7 +332,7 @@ public static class ChannelMix {
332332
public static void setUp() throws Exception {
333333
YoutubeParsingHelper.resetClientVersionAndKey();
334334
YoutubeParsingHelper.setNumberGenerator(new Random(1));
335-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "channelMix"));
335+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "channelMix"));
336336
dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
337337
extractor = (YoutubeMixPlaylistExtractor) YouTube
338338
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID_OF_CHANNEL

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class YoutubeParsingHelperTest {
2121
public static void setUp() throws IOException {
2222
YoutubeParsingHelper.resetClientVersionAndKey();
2323
YoutubeParsingHelper.setNumberGenerator(new Random(1));
24-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "youtubeParsingHelper"));
24+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "youtubeParsingHelper"));
2525
}
2626

2727
@Test

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static class NotAvailable {
4242
public static void setUp() throws IOException {
4343
YoutubeParsingHelper.resetClientVersionAndKey();
4444
YoutubeParsingHelper.setNumberGenerator(new Random(1));
45-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable"));
45+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable"));
4646
}
4747

4848
@Test
@@ -67,7 +67,7 @@ public static class TimelessPopHits implements BasePlaylistExtractorTest {
6767
public static void setUp() throws Exception {
6868
YoutubeParsingHelper.resetClientVersionAndKey();
6969
YoutubeParsingHelper.setNumberGenerator(new Random(1));
70-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "TimelessPopHits"));
70+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "TimelessPopHits"));
7171
extractor = (YoutubePlaylistExtractor) YouTube
7272
.getPlaylistExtractor("http://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj");
7373
extractor.fetchPage();
@@ -170,7 +170,7 @@ public static class HugePlaylist implements BasePlaylistExtractorTest {
170170
public static void setUp() throws Exception {
171171
YoutubeParsingHelper.resetClientVersionAndKey();
172172
YoutubeParsingHelper.setNumberGenerator(new Random(1));
173-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "huge"));
173+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "huge"));
174174
extractor = (YoutubePlaylistExtractor) YouTube
175175
.getPlaylistExtractor("https://www.youtube.com/watch?v=8SbUC-UaAxE&list=PLWwAypAcFRgKAIIFqBr9oy-ZYZnixa_Fj");
176176
extractor.fetchPage();
@@ -289,7 +289,7 @@ public static class LearningPlaylist implements BasePlaylistExtractorTest {
289289
public static void setUp() throws Exception {
290290
YoutubeParsingHelper.resetClientVersionAndKey();
291291
YoutubeParsingHelper.setNumberGenerator(new Random(1));
292-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "learning"));
292+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "learning"));
293293
extractor = (YoutubePlaylistExtractor) YouTube
294294
.getPlaylistExtractor("https://www.youtube.com/playlist?list=PL8dPuuaLjXtOAKed_MxxWBNaPno5h3Zs8");
295295
extractor.fetchPage();
@@ -392,7 +392,7 @@ public static class ContinuationsTests {
392392
public static void setUp() throws IOException {
393393
YoutubeParsingHelper.resetClientVersionAndKey();
394394
YoutubeParsingHelper.setNumberGenerator(new Random(1));
395-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "continuations"));
395+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "continuations"));
396396
}
397397

398398
@Test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class YoutubeSuggestionExtractorTest {
4747
public static void setUp() throws Exception {
4848
YoutubeParsingHelper.resetClientVersionAndKey();
4949
YoutubeParsingHelper.setNumberGenerator(new Random(1));
50-
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + ""), new Localization("de", "DE"));
50+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + ""), new Localization("de", "DE"));
5151
suggestionExtractor = YouTube.getSuggestionExtractor();
5252
}
5353

0 commit comments

Comments
 (0)