2020-03-07 15:03:12 +00:00
|
|
|
|
package org.schabi.newpipe.extractor.services.youtube;
|
|
|
|
|
|
2022-08-07 11:44:30 +00:00
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
|
|
|
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
|
|
|
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.DISABLE_PRETTY_PRINT_PARAMETER;
|
|
|
|
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.YOUTUBEI_V1_URL;
|
|
|
|
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getKey;
|
|
|
|
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
|
|
|
|
|
2021-05-30 15:23:51 +00:00
|
|
|
|
import com.grack.nanojson.JsonWriter;
|
2022-08-07 11:44:30 +00:00
|
|
|
|
|
2021-12-27 20:08:08 +00:00
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
2020-12-15 14:19:42 +00:00
|
|
|
|
import org.schabi.newpipe.downloader.DownloaderFactory;
|
2021-12-27 20:08:08 +00:00
|
|
|
|
import org.schabi.newpipe.extractor.ExtractorAsserts;
|
2020-03-07 15:03:12 +00:00
|
|
|
|
import org.schabi.newpipe.extractor.ListExtractor;
|
|
|
|
|
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
|
|
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
2020-04-16 17:28:27 +00:00
|
|
|
|
import org.schabi.newpipe.extractor.Page;
|
2020-03-07 15:03:12 +00:00
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2022-02-17 17:01:30 +00:00
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2023-01-15 22:30:30 +00:00
|
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
2022-02-17 17:01:30 +00:00
|
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
2020-03-07 15:03:12 +00:00
|
|
|
|
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeMixPlaylistExtractor;
|
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
|
|
|
|
2021-01-17 17:55:37 +00:00
|
|
|
|
import java.io.IOException;
|
2022-01-04 16:28:31 +00:00
|
|
|
|
import java.nio.charset.StandardCharsets;
|
2022-03-14 19:45:27 +00:00
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
2020-09-26 09:22:24 +00:00
|
|
|
|
|
2023-01-15 22:30:30 +00:00
|
|
|
|
@SuppressWarnings({"MismatchedQueryAndUpdateOfCollection", "NewClassNamingConvention"})
|
2020-03-07 15:03:12 +00:00
|
|
|
|
public class YoutubeMixPlaylistExtractorTest {
|
|
|
|
|
|
2021-01-17 17:55:37 +00:00
|
|
|
|
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/mix/";
|
2023-01-15 22:30:30 +00:00
|
|
|
|
private static final Map<String, String> dummyCookie = Map.of(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
|
2020-03-07 15:03:12 +00:00
|
|
|
|
private static YoutubeMixPlaylistExtractor extractor;
|
|
|
|
|
|
|
|
|
|
public static class Mix {
|
2022-08-14 13:06:57 +00:00
|
|
|
|
private static final String VIDEO_ID = "FAqYW76GLPA";
|
2022-03-14 19:45:27 +00:00
|
|
|
|
private static final String VIDEO_TITLE = "Mix – ";
|
2020-03-07 15:03:12 +00:00
|
|
|
|
|
2021-12-27 20:08:08 +00:00
|
|
|
|
@BeforeAll
|
2020-03-07 15:03:12 +00:00
|
|
|
|
public static void setUp() throws Exception {
|
2022-02-07 20:23:38 +00:00
|
|
|
|
YoutubeTestsUtils.ensureStateless();
|
2022-07-30 14:05:52 +00:00
|
|
|
|
YoutubeParsingHelper.setConsentAccepted(true);
|
2022-03-16 16:22:42 +00:00
|
|
|
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "mix"));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
2021-05-30 15:23:51 +00:00
|
|
|
|
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID
|
|
|
|
|
+ "&list=RD" + VIDEO_ID);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
extractor.fetchPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getServiceId() {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getName() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
final String name = extractor.getName();
|
2021-12-27 20:08:08 +00:00
|
|
|
|
ExtractorAsserts.assertContains("Mix", name);
|
|
|
|
|
ExtractorAsserts.assertContains(VIDEO_TITLE, name);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getThumbnailUrl() throws Exception {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
final String thumbnailUrl = extractor.getThumbnailUrl();
|
|
|
|
|
assertIsSecureUrl(thumbnailUrl);
|
2021-12-27 20:08:08 +00:00
|
|
|
|
ExtractorAsserts.assertContains("yt", thumbnailUrl);
|
|
|
|
|
ExtractorAsserts.assertContains(VIDEO_ID, thumbnailUrl);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getInitialPage() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getPage() throws Exception {
|
Rebase + some code improvements + fix extraction of age-restricted videos + update clients version
Here is now the requests which will be made by the `onFetchPage` method of `YoutubeStreamExtractor`:
- the desktop API is fetched.
If there is no streaming data, the desktop player API with the embed client screen will be fetched (and also the player code), then the Android mobile API.
- if there is no streaming data, a `ContentNotAvailableException` will be thrown by using the message provided in playability status
If the video is age restricted, a request to the next endpoint of the desktop player with the embed client screen will be sent.
Otherwise, the next endpoint will be fetched normally, if the content is available.
If the video is not age-restricted, a request to the player endpoint of the Android mobile API will be made.
We can get more streams by using the Android mobile API but some streams may be not available on this API, so the streaming data of the Android mobile API will be first used to get itags and then the streaming data of the desktop internal API will be used.
If the parsing of the Android mobile API went wrong, only the streams of the desktop API will be used.
Other code changes:
- `prepareJsonBuilder` in `YoutubeParsingHelper` was renamed to `prepareDesktopJsonBuilder`
- `prepareMobileJsonBuilder` in `YoutubeParsingHelper` was renamed to `prepareAndroidMobileJsonBuilder`
- two new methods in `YoutubeParsingHelper` were added: `prepareDesktopEmbedVideoJsonBuilder` and `prepareAndroidMobileEmbedVideoJsonBuilder`
- `createPlayerBodyWithSts` is now public and was moved to `YoutubeParsingHelper`
- a new method in `YoutubeJavaScriptExtractor` was added: `resetJavaScriptCode`, which was needed for the method `resetDebofuscationCode` of `YoutubeStreamExtractor`
- `areHardcodedClientVersionAndKeyValid` in `YoutubeParsingHelper` returns now a `boolean` instead of an `Optional<Boolean>`
- the `fetchVideoInfoPage` method of `YoutubeStreamExtractor` was removed because YouTube returns now 404 for every client with the `get_video_info` page
- some unused objects and some warnings in `YoutubeStreamExtractor` were removed and fixed
Co-authored-by: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com>
2021-07-28 21:55:09 +00:00
|
|
|
|
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
2021-05-30 15:23:51 +00:00
|
|
|
|
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
|
|
|
|
|
.value("videoId", VIDEO_ID)
|
|
|
|
|
.value("playlistId", "RD" + VIDEO_ID)
|
|
|
|
|
.value("params", "OAE%3D")
|
|
|
|
|
.done())
|
2022-01-04 16:28:31 +00:00
|
|
|
|
.getBytes(StandardCharsets.UTF_8);
|
2021-05-30 15:23:51 +00:00
|
|
|
|
|
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
|
2022-03-15 10:46:12 +00:00
|
|
|
|
YOUTUBEI_V1_URL + "next?key=" + getKey() + DISABLE_PRETTY_PRINT_PARAMETER,
|
|
|
|
|
null, null, dummyCookie, body));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getContinuations() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
|
|
|
|
final Set<String> urls = new HashSet<>();
|
2020-03-07 15:03:12 +00:00
|
|
|
|
|
2021-04-19 17:07:04 +00:00
|
|
|
|
// Should work infinitely, but for testing purposes only 3 times
|
2020-03-07 15:03:12 +00:00
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
|
2020-04-16 17:28:27 +00:00
|
|
|
|
for (final StreamInfoItem item : streams.getItems()) {
|
2021-04-19 17:07:04 +00:00
|
|
|
|
// TODO Duplicates are appearing
|
|
|
|
|
// assertFalse(urls.contains(item.getUrl()));
|
2020-04-16 17:28:27 +00:00
|
|
|
|
urls.add(item.getUrl());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
streams = extractor.getPage(streams.getNextPage());
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getStreamCount() {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
|
|
|
|
|
}
|
2022-02-17 17:01:30 +00:00
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getPlaylistType() throws ParsingException {
|
|
|
|
|
assertEquals(PlaylistInfo.PlaylistType.MIX_STREAM, extractor.getPlaylistType());
|
|
|
|
|
}
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class MixWithIndex {
|
2022-08-14 13:06:57 +00:00
|
|
|
|
private static final String VIDEO_ID = "FAqYW76GLPA";
|
2022-03-14 19:45:27 +00:00
|
|
|
|
private static final String VIDEO_TITLE = "Mix – ";
|
|
|
|
|
private static final int INDEX = 7; // YT starts the index with 1...
|
2022-08-14 13:06:57 +00:00
|
|
|
|
private static final String VIDEO_ID_AT_INDEX = "F90Cw4l-8NY";
|
2020-03-07 15:03:12 +00:00
|
|
|
|
|
2021-12-27 20:08:08 +00:00
|
|
|
|
@BeforeAll
|
2020-03-07 15:03:12 +00:00
|
|
|
|
public static void setUp() throws Exception {
|
2022-02-07 20:23:38 +00:00
|
|
|
|
YoutubeTestsUtils.ensureStateless();
|
2022-07-30 14:05:52 +00:00
|
|
|
|
YoutubeParsingHelper.setConsentAccepted(true);
|
2022-03-16 16:22:42 +00:00
|
|
|
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "mixWithIndex"));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
2022-03-14 19:45:27 +00:00
|
|
|
|
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID_AT_INDEX
|
2021-05-30 15:23:51 +00:00
|
|
|
|
+ "&list=RD" + VIDEO_ID + "&index=" + INDEX);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
extractor.fetchPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getName() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
final String name = extractor.getName();
|
2021-12-27 20:08:08 +00:00
|
|
|
|
ExtractorAsserts.assertContains("Mix", name);
|
|
|
|
|
ExtractorAsserts.assertContains(VIDEO_TITLE, name);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getThumbnailUrl() throws Exception {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
final String thumbnailUrl = extractor.getThumbnailUrl();
|
|
|
|
|
assertIsSecureUrl(thumbnailUrl);
|
2021-12-27 20:08:08 +00:00
|
|
|
|
ExtractorAsserts.assertContains("yt", thumbnailUrl);
|
|
|
|
|
ExtractorAsserts.assertContains(VIDEO_ID, thumbnailUrl);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getInitialPage() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getPage() throws Exception {
|
Rebase + some code improvements + fix extraction of age-restricted videos + update clients version
Here is now the requests which will be made by the `onFetchPage` method of `YoutubeStreamExtractor`:
- the desktop API is fetched.
If there is no streaming data, the desktop player API with the embed client screen will be fetched (and also the player code), then the Android mobile API.
- if there is no streaming data, a `ContentNotAvailableException` will be thrown by using the message provided in playability status
If the video is age restricted, a request to the next endpoint of the desktop player with the embed client screen will be sent.
Otherwise, the next endpoint will be fetched normally, if the content is available.
If the video is not age-restricted, a request to the player endpoint of the Android mobile API will be made.
We can get more streams by using the Android mobile API but some streams may be not available on this API, so the streaming data of the Android mobile API will be first used to get itags and then the streaming data of the desktop internal API will be used.
If the parsing of the Android mobile API went wrong, only the streams of the desktop API will be used.
Other code changes:
- `prepareJsonBuilder` in `YoutubeParsingHelper` was renamed to `prepareDesktopJsonBuilder`
- `prepareMobileJsonBuilder` in `YoutubeParsingHelper` was renamed to `prepareAndroidMobileJsonBuilder`
- two new methods in `YoutubeParsingHelper` were added: `prepareDesktopEmbedVideoJsonBuilder` and `prepareAndroidMobileEmbedVideoJsonBuilder`
- `createPlayerBodyWithSts` is now public and was moved to `YoutubeParsingHelper`
- a new method in `YoutubeJavaScriptExtractor` was added: `resetJavaScriptCode`, which was needed for the method `resetDebofuscationCode` of `YoutubeStreamExtractor`
- `areHardcodedClientVersionAndKeyValid` in `YoutubeParsingHelper` returns now a `boolean` instead of an `Optional<Boolean>`
- the `fetchVideoInfoPage` method of `YoutubeStreamExtractor` was removed because YouTube returns now 404 for every client with the `get_video_info` page
- some unused objects and some warnings in `YoutubeStreamExtractor` were removed and fixed
Co-authored-by: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com>
2021-07-28 21:55:09 +00:00
|
|
|
|
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
2021-05-30 15:23:51 +00:00
|
|
|
|
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
|
|
|
|
|
.value("videoId", VIDEO_ID)
|
|
|
|
|
.value("playlistId", "RD" + VIDEO_ID)
|
|
|
|
|
.value("playlistIndex", INDEX)
|
|
|
|
|
.value("params", "OAE%3D")
|
|
|
|
|
.done())
|
2022-01-04 16:28:31 +00:00
|
|
|
|
.getBytes(StandardCharsets.UTF_8);
|
2021-05-30 15:23:51 +00:00
|
|
|
|
|
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
|
2022-03-15 10:46:12 +00:00
|
|
|
|
YOUTUBEI_V1_URL + "next?key=" + getKey() + DISABLE_PRETTY_PRINT_PARAMETER,
|
|
|
|
|
null, null, dummyCookie, body));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getContinuations() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
|
|
|
|
final Set<String> urls = new HashSet<>();
|
2020-03-07 15:03:12 +00:00
|
|
|
|
|
2021-04-19 17:07:04 +00:00
|
|
|
|
// Should work infinitely, but for testing purposes only 3 times
|
2020-03-07 15:03:12 +00:00
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
2020-04-16 17:28:27 +00:00
|
|
|
|
for (final StreamInfoItem item : streams.getItems()) {
|
2021-04-19 17:07:04 +00:00
|
|
|
|
// TODO Duplicates are appearing
|
|
|
|
|
// assertFalse(urls.contains(item.getUrl()));
|
2020-04-16 17:28:27 +00:00
|
|
|
|
urls.add(item.getUrl());
|
|
|
|
|
}
|
2020-03-07 15:03:12 +00:00
|
|
|
|
|
2020-04-16 17:28:27 +00:00
|
|
|
|
streams = extractor.getPage(streams.getNextPage());
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 13:04:46 +00:00
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getStreamCount() {
|
2020-03-17 13:04:46 +00:00
|
|
|
|
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
|
|
|
|
|
}
|
2022-02-17 17:01:30 +00:00
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getPlaylistType() throws ParsingException {
|
|
|
|
|
assertEquals(PlaylistInfo.PlaylistType.MIX_STREAM, extractor.getPlaylistType());
|
|
|
|
|
}
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class MyMix {
|
2022-07-30 14:05:52 +00:00
|
|
|
|
private static final String VIDEO_ID = "YVkUvmDQ3HY";
|
2020-03-07 15:03:12 +00:00
|
|
|
|
|
2021-12-27 20:08:08 +00:00
|
|
|
|
@BeforeAll
|
2020-03-07 15:03:12 +00:00
|
|
|
|
public static void setUp() throws Exception {
|
2022-02-07 20:23:38 +00:00
|
|
|
|
YoutubeTestsUtils.ensureStateless();
|
2022-07-30 14:05:52 +00:00
|
|
|
|
YoutubeParsingHelper.setConsentAccepted(true);
|
2022-03-16 16:22:42 +00:00
|
|
|
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "myMix"));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
2021-05-30 15:23:51 +00:00
|
|
|
|
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID
|
|
|
|
|
+ "&list=RDMM" + VIDEO_ID);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
extractor.fetchPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getServiceId() {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getName() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
final String name = extractor.getName();
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertEquals("My Mix", name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getThumbnailUrl() throws Exception {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
final String thumbnailUrl = extractor.getThumbnailUrl();
|
|
|
|
|
assertIsSecureUrl(thumbnailUrl);
|
2022-07-30 14:05:52 +00:00
|
|
|
|
assertTrue(thumbnailUrl.startsWith("https://i.ytimg.com/vi/" + VIDEO_ID));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getInitialPage() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getPage() throws Exception {
|
Rebase + some code improvements + fix extraction of age-restricted videos + update clients version
Here is now the requests which will be made by the `onFetchPage` method of `YoutubeStreamExtractor`:
- the desktop API is fetched.
If there is no streaming data, the desktop player API with the embed client screen will be fetched (and also the player code), then the Android mobile API.
- if there is no streaming data, a `ContentNotAvailableException` will be thrown by using the message provided in playability status
If the video is age restricted, a request to the next endpoint of the desktop player with the embed client screen will be sent.
Otherwise, the next endpoint will be fetched normally, if the content is available.
If the video is not age-restricted, a request to the player endpoint of the Android mobile API will be made.
We can get more streams by using the Android mobile API but some streams may be not available on this API, so the streaming data of the Android mobile API will be first used to get itags and then the streaming data of the desktop internal API will be used.
If the parsing of the Android mobile API went wrong, only the streams of the desktop API will be used.
Other code changes:
- `prepareJsonBuilder` in `YoutubeParsingHelper` was renamed to `prepareDesktopJsonBuilder`
- `prepareMobileJsonBuilder` in `YoutubeParsingHelper` was renamed to `prepareAndroidMobileJsonBuilder`
- two new methods in `YoutubeParsingHelper` were added: `prepareDesktopEmbedVideoJsonBuilder` and `prepareAndroidMobileEmbedVideoJsonBuilder`
- `createPlayerBodyWithSts` is now public and was moved to `YoutubeParsingHelper`
- a new method in `YoutubeJavaScriptExtractor` was added: `resetJavaScriptCode`, which was needed for the method `resetDebofuscationCode` of `YoutubeStreamExtractor`
- `areHardcodedClientVersionAndKeyValid` in `YoutubeParsingHelper` returns now a `boolean` instead of an `Optional<Boolean>`
- the `fetchVideoInfoPage` method of `YoutubeStreamExtractor` was removed because YouTube returns now 404 for every client with the `get_video_info` page
- some unused objects and some warnings in `YoutubeStreamExtractor` were removed and fixed
Co-authored-by: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com>
2021-07-28 21:55:09 +00:00
|
|
|
|
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
2021-05-30 15:23:51 +00:00
|
|
|
|
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
|
|
|
|
|
.value("videoId", VIDEO_ID)
|
|
|
|
|
.value("playlistId", "RDMM" + VIDEO_ID)
|
|
|
|
|
.value("params", "OAE%3D")
|
|
|
|
|
.done())
|
2022-01-04 16:28:31 +00:00
|
|
|
|
.getBytes(StandardCharsets.UTF_8);
|
2021-05-30 15:23:51 +00:00
|
|
|
|
|
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
|
2022-03-15 10:46:12 +00:00
|
|
|
|
YOUTUBEI_V1_URL + "next?key=" + getKey() + DISABLE_PRETTY_PRINT_PARAMETER,
|
|
|
|
|
null, null, dummyCookie, body));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
2021-01-17 17:55:37 +00:00
|
|
|
|
|
2020-03-07 15:03:12 +00:00
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getContinuations() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
|
|
|
|
final Set<String> urls = new HashSet<>();
|
2020-03-07 15:03:12 +00:00
|
|
|
|
|
2021-04-19 17:07:04 +00:00
|
|
|
|
// Should work infinitely, but for testing purposes only 3 times
|
2020-03-07 15:03:12 +00:00
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
|
2020-04-16 17:28:27 +00:00
|
|
|
|
for (final StreamInfoItem item : streams.getItems()) {
|
2021-04-08 14:36:55 +00:00
|
|
|
|
// TODO Duplicates are appearing
|
2021-04-19 17:07:04 +00:00
|
|
|
|
// assertFalse(urls.contains(item.getUrl()));
|
2020-04-16 17:28:27 +00:00
|
|
|
|
urls.add(item.getUrl());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
streams = extractor.getPage(streams.getNextPage());
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getStreamCount() {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
|
|
|
|
|
}
|
2022-02-17 17:01:30 +00:00
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getPlaylistType() throws ParsingException {
|
|
|
|
|
assertEquals(PlaylistInfo.PlaylistType.MIX_STREAM, extractor.getPlaylistType());
|
|
|
|
|
}
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class Invalid {
|
2022-01-04 16:39:14 +00:00
|
|
|
|
private static final String VIDEO_ID = "QMVCAPd5cwBcg";
|
|
|
|
|
|
2021-12-27 20:08:08 +00:00
|
|
|
|
@BeforeAll
|
2020-12-15 14:19:42 +00:00
|
|
|
|
public static void setUp() throws IOException {
|
2022-02-07 20:23:38 +00:00
|
|
|
|
YoutubeTestsUtils.ensureStateless();
|
2022-07-30 14:05:52 +00:00
|
|
|
|
YoutubeParsingHelper.setConsentAccepted(true);
|
2022-03-16 16:22:42 +00:00
|
|
|
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "invalid"));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-04 16:33:08 +00:00
|
|
|
|
@Test
|
|
|
|
|
void getPageEmptyUrl() throws Exception {
|
|
|
|
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
|
|
|
|
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID
|
|
|
|
|
+ "&list=RD" + VIDEO_ID);
|
|
|
|
|
|
|
|
|
|
extractor.fetchPage();
|
|
|
|
|
assertThrows(IllegalArgumentException.class, () -> extractor.getPage(new Page("")));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 20:08:08 +00:00
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void invalidVideoId() throws Exception {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
2021-05-30 15:23:51 +00:00
|
|
|
|
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + "abcde"
|
|
|
|
|
+ "&list=RD" + "abcde");
|
2021-12-27 20:08:08 +00:00
|
|
|
|
|
2022-01-04 16:28:31 +00:00
|
|
|
|
assertThrows(ExtractionException.class, extractor::fetchPage);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class ChannelMix {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
private static final String CHANNEL_ID = "UCXuqSBlHAE6Xw-yeJA0Tunw";
|
|
|
|
|
private static final String VIDEO_ID_OF_CHANNEL = "mnk6gnOBYIo";
|
|
|
|
|
private static final String CHANNEL_TITLE = "Linus Tech Tips";
|
2020-03-07 15:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
2021-12-27 20:08:08 +00:00
|
|
|
|
@BeforeAll
|
2020-03-07 15:03:12 +00:00
|
|
|
|
public static void setUp() throws Exception {
|
2022-02-07 20:23:38 +00:00
|
|
|
|
YoutubeTestsUtils.ensureStateless();
|
2022-07-30 14:05:52 +00:00
|
|
|
|
YoutubeParsingHelper.setConsentAccepted(true);
|
2022-03-16 16:22:42 +00:00
|
|
|
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "channelMix"));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
2021-05-30 15:23:51 +00:00
|
|
|
|
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID_OF_CHANNEL
|
|
|
|
|
+ "&list=RDCM" + CHANNEL_ID);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
extractor.fetchPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getName() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
final String name = extractor.getName();
|
2021-12-27 20:08:08 +00:00
|
|
|
|
ExtractorAsserts.assertContains("Mix", name);
|
|
|
|
|
ExtractorAsserts.assertContains(CHANNEL_TITLE, name);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getThumbnailUrl() throws Exception {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
final String thumbnailUrl = extractor.getThumbnailUrl();
|
|
|
|
|
assertIsSecureUrl(thumbnailUrl);
|
2021-12-27 20:08:08 +00:00
|
|
|
|
ExtractorAsserts.assertContains("yt", thumbnailUrl);
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getInitialPage() throws Exception {
|
2020-04-16 17:28:27 +00:00
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getPage() throws Exception {
|
Rebase + some code improvements + fix extraction of age-restricted videos + update clients version
Here is now the requests which will be made by the `onFetchPage` method of `YoutubeStreamExtractor`:
- the desktop API is fetched.
If there is no streaming data, the desktop player API with the embed client screen will be fetched (and also the player code), then the Android mobile API.
- if there is no streaming data, a `ContentNotAvailableException` will be thrown by using the message provided in playability status
If the video is age restricted, a request to the next endpoint of the desktop player with the embed client screen will be sent.
Otherwise, the next endpoint will be fetched normally, if the content is available.
If the video is not age-restricted, a request to the player endpoint of the Android mobile API will be made.
We can get more streams by using the Android mobile API but some streams may be not available on this API, so the streaming data of the Android mobile API will be first used to get itags and then the streaming data of the desktop internal API will be used.
If the parsing of the Android mobile API went wrong, only the streams of the desktop API will be used.
Other code changes:
- `prepareJsonBuilder` in `YoutubeParsingHelper` was renamed to `prepareDesktopJsonBuilder`
- `prepareMobileJsonBuilder` in `YoutubeParsingHelper` was renamed to `prepareAndroidMobileJsonBuilder`
- two new methods in `YoutubeParsingHelper` were added: `prepareDesktopEmbedVideoJsonBuilder` and `prepareAndroidMobileEmbedVideoJsonBuilder`
- `createPlayerBodyWithSts` is now public and was moved to `YoutubeParsingHelper`
- a new method in `YoutubeJavaScriptExtractor` was added: `resetJavaScriptCode`, which was needed for the method `resetDebofuscationCode` of `YoutubeStreamExtractor`
- `areHardcodedClientVersionAndKeyValid` in `YoutubeParsingHelper` returns now a `boolean` instead of an `Optional<Boolean>`
- the `fetchVideoInfoPage` method of `YoutubeStreamExtractor` was removed because YouTube returns now 404 for every client with the `get_video_info` page
- some unused objects and some warnings in `YoutubeStreamExtractor` were removed and fixed
Co-authored-by: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com>
2021-07-28 21:55:09 +00:00
|
|
|
|
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
2021-05-30 15:23:51 +00:00
|
|
|
|
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
|
|
|
|
|
.value("videoId", VIDEO_ID_OF_CHANNEL)
|
|
|
|
|
.value("playlistId", "RDCM" + CHANNEL_ID)
|
|
|
|
|
.value("params", "OAE%3D")
|
|
|
|
|
.done())
|
2022-01-04 16:28:31 +00:00
|
|
|
|
.getBytes(StandardCharsets.UTF_8);
|
2021-05-30 15:23:51 +00:00
|
|
|
|
|
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
|
2022-03-15 10:46:12 +00:00
|
|
|
|
YOUTUBEI_V1_URL + "next?key=" + getKey() + DISABLE_PRETTY_PRINT_PARAMETER,
|
|
|
|
|
null, null, dummyCookie, body));
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-01-04 16:28:31 +00:00
|
|
|
|
void getStreamCount() {
|
2020-03-07 15:03:12 +00:00
|
|
|
|
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
|
|
|
|
|
}
|
2022-02-17 17:01:30 +00:00
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getPlaylistType() throws ParsingException {
|
|
|
|
|
assertEquals(PlaylistInfo.PlaylistType.MIX_CHANNEL, extractor.getPlaylistType());
|
|
|
|
|
}
|
2020-03-07 15:03:12 +00:00
|
|
|
|
}
|
2022-02-17 17:25:38 +00:00
|
|
|
|
|
|
|
|
|
public static class GenreMix {
|
|
|
|
|
private static final String VIDEO_ID = "kINJeTNFbpg";
|
|
|
|
|
private static final String MIX_TITLE = "Mix – Electronic music";
|
|
|
|
|
|
|
|
|
|
@BeforeAll
|
|
|
|
|
public static void setUp() throws Exception {
|
2022-02-07 20:23:38 +00:00
|
|
|
|
YoutubeTestsUtils.ensureStateless();
|
2022-07-30 14:05:52 +00:00
|
|
|
|
YoutubeParsingHelper.setConsentAccepted(true);
|
2022-02-07 20:23:38 +00:00
|
|
|
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "genreMix"));
|
2022-02-17 17:25:38 +00:00
|
|
|
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
|
|
|
|
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID
|
|
|
|
|
+ "&list=RDGMEMYH9CUrFO7CfLJpaD7UR85w");
|
|
|
|
|
extractor.fetchPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getServiceId() {
|
|
|
|
|
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getName() throws Exception {
|
|
|
|
|
assertEquals(MIX_TITLE, extractor.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getThumbnailUrl() throws Exception {
|
|
|
|
|
final String thumbnailUrl = extractor.getThumbnailUrl();
|
|
|
|
|
assertIsSecureUrl(thumbnailUrl);
|
|
|
|
|
ExtractorAsserts.assertContains("yt", thumbnailUrl);
|
|
|
|
|
ExtractorAsserts.assertContains(VIDEO_ID, thumbnailUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getInitialPage() throws Exception {
|
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getPage() throws Exception {
|
|
|
|
|
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
|
|
|
|
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
|
|
|
|
|
.value("videoId", VIDEO_ID)
|
|
|
|
|
.value("playlistId", "RD" + VIDEO_ID)
|
|
|
|
|
.value("params", "OAE%3D")
|
|
|
|
|
.done())
|
|
|
|
|
.getBytes(StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
|
|
|
|
|
YOUTUBEI_V1_URL + "next?key=" + getKey(), null, null, dummyCookie, body));
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getContinuations() throws Exception {
|
|
|
|
|
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
|
|
|
|
final Set<String> urls = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
// Should work infinitely, but for testing purposes only 3 times
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
|
|
|
|
|
for (final StreamInfoItem item : streams.getItems()) {
|
|
|
|
|
// TODO Duplicates are appearing
|
|
|
|
|
// assertFalse(urls.contains(item.getUrl()));
|
|
|
|
|
urls.add(item.getUrl());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
streams = extractor.getPage(streams.getNextPage());
|
|
|
|
|
}
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getStreamCount() {
|
|
|
|
|
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getPlaylistType() throws ParsingException {
|
|
|
|
|
assertEquals(PlaylistInfo.PlaylistType.MIX_GENRE, extractor.getPlaylistType());
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-15 22:30:30 +00:00
|
|
|
|
|
|
|
|
|
public static class Music {
|
|
|
|
|
private static final String VIDEO_ID = "dQw4w9WgXcQ";
|
|
|
|
|
private static final String MIX_TITLE = "Mix – Rick Astley - Never Gonna Give You Up (Official Music Video)";
|
|
|
|
|
|
|
|
|
|
@BeforeAll
|
|
|
|
|
public static void setUp() throws Exception {
|
|
|
|
|
YoutubeTestsUtils.ensureStateless();
|
|
|
|
|
YoutubeParsingHelper.setConsentAccepted(true);
|
|
|
|
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "musicMix"));
|
|
|
|
|
extractor = (YoutubeMixPlaylistExtractor)
|
|
|
|
|
YouTube.getPlaylistExtractor("https://m.youtube.com/watch?v=" + VIDEO_ID
|
|
|
|
|
+ "&list=RDAMVM" + VIDEO_ID);
|
|
|
|
|
extractor.fetchPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getServiceId() {
|
|
|
|
|
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getName() throws Exception {
|
|
|
|
|
assertEquals(MIX_TITLE, extractor.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getThumbnailUrl() throws Exception {
|
|
|
|
|
final String thumbnailUrl = extractor.getThumbnailUrl();
|
|
|
|
|
assertIsSecureUrl(thumbnailUrl);
|
|
|
|
|
ExtractorAsserts.assertContains("yt", thumbnailUrl);
|
|
|
|
|
ExtractorAsserts.assertContains(VIDEO_ID, thumbnailUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getInitialPage() throws Exception {
|
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getPage() throws Exception {
|
|
|
|
|
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
|
|
|
|
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
|
|
|
|
|
.value("videoId", VIDEO_ID)
|
|
|
|
|
.value("playlistId", "RD" + VIDEO_ID)
|
|
|
|
|
.value("params", "OAE%3D")
|
|
|
|
|
.done())
|
|
|
|
|
.getBytes(StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
|
|
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
|
|
|
|
|
YOUTUBEI_V1_URL + "next?key=" + getKey(), null, null, dummyCookie, body));
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getContinuations() throws Exception {
|
|
|
|
|
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
|
|
|
|
|
final Set<String> urls = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
// Should work infinitely, but for testing purposes only 3 times
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
|
|
|
|
|
for (final StreamInfoItem item : streams.getItems()) {
|
|
|
|
|
// TODO Duplicates are appearing
|
|
|
|
|
// assertFalse(urls.contains(item.getUrl()));
|
|
|
|
|
urls.add(item.getUrl());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
streams = extractor.getPage(streams.getNextPage());
|
|
|
|
|
}
|
|
|
|
|
assertTrue(streams.hasNextPage());
|
|
|
|
|
assertFalse(streams.getItems().isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getStreamCount() throws ParsingException {
|
|
|
|
|
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getPlaylistType() throws ParsingException {
|
|
|
|
|
assertEquals(PlaylistInfo.PlaylistType.MIX_MUSIC, extractor.getPlaylistType());
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-16 17:28:27 +00:00
|
|
|
|
}
|