Skip to content

Commit 35e2997

Browse files
committed
Add method to allow resetting youtube client version and key
This is needed so that a request is made for each test class when running multiple at once. This way RecordingDownloader records all necessary requests. This works as long as tests are run sequentially and not in parallel.
1 parent f447a7a commit 35e2997

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ public static String getKey() throws IOException, ExtractionException {
353353
return key;
354354
}
355355

356+
static void resetClientVersionAndKey() {
357+
clientVersion = null;
358+
key = null;
359+
}
360+
356361
public static boolean areHardcodedYoutubeMusicKeysValid() throws IOException, ReCaptchaException {
357362
final String url = "https://music.youtube.com/youtubei/v1/search?alt=json&key=" + HARDCODED_YOUTUBE_MUSIC_KEYS[0];
358363

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ public MockDownloader(@Nonnull String path) throws IOException {
3131
reader.close();
3232
mocks.put(response.getRequest(), response.getResponse());
3333
}
34-
35-
//shared find proper solution
36-
File clientVersion = new File("src/test/resources/org/schabi/newpipe/extractor/services/youtube/client_version.json");
37-
final FileReader reader = new FileReader(clientVersion);
38-
final TestRequestResponse response = new GsonBuilder()
39-
.create()
40-
.fromJson(reader, TestRequestResponse.class);
41-
reader.close();
42-
mocks.put(response.getRequest(), response.getResponse());
4334
}
4435

4536
@Override

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static class Mix {
5353

5454
@BeforeClass
5555
public static void setUp() throws Exception {
56+
YoutubeParsingHelper.resetClientVersionAndKey();
5657
final File file = new File(RESOURCE_PATH + "mix");
5758
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
5859
extractor = (YoutubeMixPlaylistExtractor) YouTube
@@ -131,6 +132,7 @@ public static class MixWithIndex {
131132

132133
@BeforeClass
133134
public static void setUp() throws Exception {
135+
YoutubeParsingHelper.resetClientVersionAndKey();
134136
final File file = new File(RESOURCE_PATH + "mixWithIndex");
135137
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
136138
extractor = (YoutubeMixPlaylistExtractor) YouTube
@@ -201,6 +203,7 @@ public static class MyMix {
201203

202204
@BeforeClass
203205
public static void setUp() throws Exception {
206+
YoutubeParsingHelper.resetClientVersionAndKey();
204207
final File file = new File(RESOURCE_PATH + "myMix");
205208
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
206209
extractor = (YoutubeMixPlaylistExtractor) YouTube
@@ -274,6 +277,7 @@ public static class Invalid {
274277

275278
@BeforeClass
276279
public static void setUp() throws IOException {
280+
YoutubeParsingHelper.resetClientVersionAndKey();
277281
final File file = new File(RESOURCE_PATH + "invalid");
278282
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
279283
}
@@ -306,6 +310,7 @@ public static class ChannelMix {
306310

307311
@BeforeClass
308312
public static void setUp() throws Exception {
313+
YoutubeParsingHelper.resetClientVersionAndKey();
309314
final File file = new File(RESOURCE_PATH + "channelMix");
310315
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
311316
extractor = (YoutubeMixPlaylistExtractor) YouTube

0 commit comments

Comments
 (0)