Skip to content

Commit 13f7900

Browse files
committed
[YouTube] Add test for genre mix
1 parent 279f3a2 commit 13f7900

File tree

7 files changed

+1820
-0
lines changed

7 files changed

+1820
-0
lines changed

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,94 @@ void getPlaylistType() throws ParsingException {
403403
assertEquals(PlaylistInfo.PlaylistType.MIX_CHANNEL, extractor.getPlaylistType());
404404
}
405405
}
406+
407+
public static class GenreMix {
408+
private static final String VIDEO_ID = "kINJeTNFbpg";
409+
private static final String MIX_TITLE = "Mix – Electronic music";
410+
411+
@BeforeAll
412+
public static void setUp() throws Exception {
413+
YoutubeParsingHelper.resetClientVersionAndKey();
414+
YoutubeParsingHelper.setNumberGenerator(new Random(1));
415+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "genreMix"));
416+
dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
417+
extractor = (YoutubeMixPlaylistExtractor) YouTube
418+
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID
419+
+ "&list=RDGMEMYH9CUrFO7CfLJpaD7UR85w");
420+
extractor.fetchPage();
421+
}
422+
423+
@Test
424+
void getServiceId() {
425+
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
426+
}
427+
428+
@Test
429+
void getName() throws Exception {
430+
assertEquals(MIX_TITLE, extractor.getName());
431+
}
432+
433+
@Test
434+
void getThumbnailUrl() throws Exception {
435+
final String thumbnailUrl = extractor.getThumbnailUrl();
436+
assertIsSecureUrl(thumbnailUrl);
437+
ExtractorAsserts.assertContains("yt", thumbnailUrl);
438+
ExtractorAsserts.assertContains(VIDEO_ID, thumbnailUrl);
439+
}
440+
441+
@Test
442+
void getInitialPage() throws Exception {
443+
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
444+
assertFalse(streams.getItems().isEmpty());
445+
assertTrue(streams.hasNextPage());
446+
}
447+
448+
@Test
449+
void getPage() throws Exception {
450+
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
451+
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
452+
.value("videoId", VIDEO_ID)
453+
.value("playlistId", "RD" + VIDEO_ID)
454+
.value("params", "OAE%3D")
455+
.done())
456+
.getBytes(StandardCharsets.UTF_8);
457+
458+
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
459+
YOUTUBEI_V1_URL + "next?key=" + getKey(), null, null, dummyCookie, body));
460+
assertFalse(streams.getItems().isEmpty());
461+
assertTrue(streams.hasNextPage());
462+
}
463+
464+
@Test
465+
void getContinuations() throws Exception {
466+
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
467+
final Set<String> urls = new HashSet<>();
468+
469+
// Should work infinitely, but for testing purposes only 3 times
470+
for (int i = 0; i < 3; i++) {
471+
assertTrue(streams.hasNextPage());
472+
assertFalse(streams.getItems().isEmpty());
473+
474+
for (final StreamInfoItem item : streams.getItems()) {
475+
// TODO Duplicates are appearing
476+
// assertFalse(urls.contains(item.getUrl()));
477+
urls.add(item.getUrl());
478+
}
479+
480+
streams = extractor.getPage(streams.getNextPage());
481+
}
482+
assertTrue(streams.hasNextPage());
483+
assertFalse(streams.getItems().isEmpty());
484+
}
485+
486+
@Test
487+
void getStreamCount() {
488+
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
489+
}
490+
491+
@Test
492+
void getPlaylistType() throws ParsingException {
493+
assertEquals(PlaylistInfo.PlaylistType.MIX_GENRE, extractor.getPlaylistType());
494+
}
495+
}
406496
}

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/mix/genreMix/generated_mock_0.json

Lines changed: 226 additions & 0 deletions
Large diffs are not rendered by default.

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/mix/genreMix/generated_mock_1.json

Lines changed: 278 additions & 0 deletions
Large diffs are not rendered by default.

extractor/src/test/resources/org/schabi/newpipe/extractor/services/youtube/extractor/mix/genreMix/generated_mock_2.json

Lines changed: 281 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)