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

920 lines
35 KiB
Java
Raw Normal View History

package org.schabi.newpipe.extractor.services.youtube;
2017-08-05 10:03:56 +02:00
2021-12-27 21:08:08 +01:00
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
2021-12-27 21:08:08 +01:00
import org.schabi.newpipe.extractor.ExtractorAsserts;
2017-08-05 10:03:56 +02:00
import org.schabi.newpipe.extractor.NewPipe;
2017-08-11 03:23:09 +02:00
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
2023-04-14 14:10:26 +02:00
import org.schabi.newpipe.extractor.channel.ChannelTabExtractor;
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2022-11-04 23:47:44 +01:00
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
2018-03-04 21:26:13 +01:00
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
2018-05-08 21:19:03 +02:00
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelExtractor;
2017-08-05 10:03:56 +02:00
import java.io.IOException;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
2017-08-05 10:03:56 +02:00
/**
2017-08-11 03:23:09 +02:00
* Test for {@link ChannelExtractor}
2017-08-05 10:03:56 +02:00
*/
2017-08-11 03:23:09 +02:00
public class YoutubeChannelExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/channel/";
public static class NotAvailable {
2021-12-27 21:08:08 +01:00
@BeforeAll
public static void setUp() throws IOException {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable"));
}
2021-12-27 21:08:08 +01:00
@Test
public void deletedFetch() throws Exception {
final ChannelExtractor extractor =
YouTube.getChannelExtractor("https://www.youtube.com/channel/UCAUc4iz6edWerIjlnL8OSSw");
2021-12-27 21:08:08 +01:00
assertThrows(ContentNotAvailableException.class, extractor::fetchPage);
}
2021-12-27 21:08:08 +01:00
@Test
public void nonExistentFetch() throws Exception {
final ChannelExtractor extractor =
YouTube.getChannelExtractor("https://www.youtube.com/channel/DOESNT-EXIST");
2021-12-27 21:08:08 +01:00
assertThrows(ContentNotAvailableException.class, extractor::fetchPage);
}
2021-12-27 21:08:08 +01:00
@Test
public void accountTerminatedTOSFetch() throws Exception {
// "This account has been terminated for a violation of YouTube's Terms of Service."
final ChannelExtractor extractor =
YouTube.getChannelExtractor("https://www.youtube.com/channel/UCTGjY2I-ZUGnwVoWAGRd7XQ");
2021-12-27 21:08:08 +01:00
AccountTerminatedException ex =
assertThrows(AccountTerminatedException.class, extractor::fetchPage);
assertEquals(AccountTerminatedException.Reason.VIOLATION, ex.getReason());
}
2021-12-27 21:08:08 +01:00
@Test
public void accountTerminatedCommunityFetch() throws Exception {
// "This account has been terminated for violating YouTube's Community Guidelines."
final ChannelExtractor extractor =
YouTube.getChannelExtractor("https://www.youtube.com/channel/UC0AuOxCr9TZ0TtEgL1zpIgA");
2021-12-27 21:08:08 +01:00
AccountTerminatedException ex =
assertThrows(AccountTerminatedException.class, extractor::fetchPage);
assertEquals(AccountTerminatedException.Reason.VIOLATION, ex.getReason());
}
2021-12-27 21:08:08 +01:00
@Test
2021-03-30 10:14:33 +02:00
public void accountTerminatedHateFetch() throws Exception {
// "This account has been terminated due to multiple or severe violations
// of YouTube's policy prohibiting hate speech."
2021-03-30 10:14:33 +02:00
final ChannelExtractor extractor =
YouTube.getChannelExtractor("https://www.youtube.com/channel/UCPWXIOPK-9myzek6jHR5yrg");
2021-12-27 21:08:08 +01:00
AccountTerminatedException ex =
assertThrows(AccountTerminatedException.class, extractor::fetchPage);
assertEquals(AccountTerminatedException.Reason.VIOLATION, ex.getReason());
2021-03-30 10:14:33 +02:00
}
2021-12-27 21:08:08 +01:00
@Test
2021-03-30 10:14:33 +02:00
public void accountTerminatedBullyFetch() throws Exception {
// "This account has been terminated due to multiple or severe violations
// of YouTube's policy prohibiting content designed to harass, bully or threaten."
2021-03-30 10:14:33 +02:00
final ChannelExtractor extractor =
YouTube.getChannelExtractor("https://youtube.com/channel/UCB1o7_gbFp2PLsamWxFenBg");
2021-12-27 21:08:08 +01:00
AccountTerminatedException ex =
assertThrows(AccountTerminatedException.class, extractor::fetchPage);
assertEquals(AccountTerminatedException.Reason.VIOLATION, ex.getReason());
2021-03-30 10:14:33 +02:00
}
2021-12-27 21:08:08 +01:00
@Test
2021-03-30 10:14:33 +02:00
public void accountTerminatedSpamFetch() throws Exception {
// "This account has been terminated due to multiple or severe violations
// of YouTube's policy against spam, deceptive practices and misleading content
// or other Terms of Service violations."
2021-03-30 10:14:33 +02:00
final ChannelExtractor extractor =
YouTube.getChannelExtractor("https://www.youtube.com/channel/UCoaO4U_p7G7AwalqSbGCZOA");
2021-12-27 21:08:08 +01:00
AccountTerminatedException ex =
assertThrows(AccountTerminatedException.class, extractor::fetchPage);
assertEquals(AccountTerminatedException.Reason.VIOLATION, ex.getReason());
2021-03-30 10:14:33 +02:00
}
2021-12-27 21:08:08 +01:00
@Test
public void accountTerminatedCopyrightFetch() throws Exception {
// "This account has been terminated because we received multiple third-party claims
// of copyright infringement regarding material that the user posted."
final ChannelExtractor extractor =
YouTube.getChannelExtractor("https://www.youtube.com/channel/UCI4i4RgFT5ilfMpna4Z_Y8w");
2021-12-27 21:08:08 +01:00
AccountTerminatedException ex =
assertThrows(AccountTerminatedException.class, extractor::fetchPage);
assertEquals(AccountTerminatedException.Reason.VIOLATION, ex.getReason());
}
}
public static class NotSupported {
2021-12-27 21:08:08 +01:00
@BeforeAll
public static void setUp() throws IOException {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notSupported"));
}
2021-12-27 21:08:08 +01:00
@Test
void noVideoTab() throws Exception {
final ChannelExtractor extractor = YouTube.getChannelExtractor("https://invidio.us/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ");
extractor.fetchPage();
2023-04-14 14:10:26 +02:00
assertTrue(extractor.getTabs().isEmpty());
}
}
2018-03-04 21:26:13 +01:00
public static class Gronkh implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
2023-04-14 14:10:26 +02:00
private static ChannelTabExtractor tabExtractor;
2017-08-05 10:03:56 +02:00
2021-12-27 21:08:08 +01:00
@BeforeAll
2018-03-04 21:26:13 +01:00
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "gronkh"));
2018-03-04 21:26:13 +01:00
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("http://www.youtube.com/@Gronkh");
2018-03-04 21:26:13 +01:00
extractor.fetchPage();
2023-04-14 14:10:26 +02:00
tabExtractor = YouTube.getChannelTabExtractor(extractor.getTabs().get(0));
tabExtractor.fetchPage();
2018-03-04 21:26:13 +01:00
}
2017-08-05 10:03:56 +02:00
2018-03-04 21:26:13 +01:00
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
2017-08-05 10:03:56 +02:00
2018-03-04 21:26:13 +01:00
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
2023-04-27 12:31:39 +02:00
assertEquals(YouTube.getServiceId(), tabExtractor.getServiceId());
2018-03-04 21:26:13 +01:00
}
2017-08-05 10:03:56 +02:00
2018-03-04 21:26:13 +01:00
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testName() throws Exception {
assertEquals("Gronkh", extractor.getName());
}
2017-08-05 10:03:56 +02:00
2018-03-04 21:26:13 +01:00
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testId() throws Exception {
assertEquals("UCYJ61XIK64sp6ZFFS8sctxw", extractor.getId());
2023-04-27 12:31:39 +02:00
assertEquals("UCYJ61XIK64sp6ZFFS8sctxw", tabExtractor.getId());
2018-03-04 21:26:13 +01:00
}
2018-03-04 21:26:13 +01:00
@Test
@Override
public void testUrl() throws ParsingException {
assertEquals("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", extractor.getUrl());
2023-04-27 12:31:39 +02:00
assertEquals("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", tabExtractor.getUrl());
2018-03-04 21:26:13 +01:00
}
2018-03-04 21:26:13 +01:00
@Test
@Override
public void testOriginalUrl() throws ParsingException {
assertEquals("http://www.youtube.com/@Gronkh", extractor.getOriginalUrl());
2023-04-27 12:31:39 +02:00
assertEquals("/c/gronkh/videos", tabExtractor.getOriginalUrl());
2018-03-04 21:26:13 +01:00
}
2018-03-04 21:26:13 +01:00
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
2017-08-05 10:03:56 +02:00
2018-03-04 21:26:13 +01:00
@Test
public void testRelatedItems() throws Exception {
2023-04-14 14:10:26 +02:00
defaultTestRelatedItems(tabExtractor);
2018-03-04 21:26:13 +01:00
}
2017-08-05 10:03:56 +02:00
2018-03-04 21:26:13 +01:00
@Test
public void testMoreRelatedItems() throws Exception {
2023-04-14 14:10:26 +02:00
defaultTestMoreItems(tabExtractor);
2018-03-04 21:26:13 +01:00
}
2017-08-05 10:03:56 +02:00
2018-03-04 21:26:13 +01:00
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
2017-08-05 10:03:56 +02:00
2018-03-04 21:26:13 +01:00
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testDescription() throws Exception {
2021-12-27 21:08:08 +01:00
assertContains("Ungebremster Spieltrieb seit 1896.", extractor.getDescription());
2018-03-04 21:26:13 +01:00
}
2017-08-05 10:03:56 +02:00
2018-03-04 21:26:13 +01:00
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testFeedUrl() throws Exception {
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UCYJ61XIK64sp6ZFFS8sctxw", extractor.getFeedUrl());
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testSubscriberCount() throws Exception {
ExtractorAsserts.assertGreaterOrEqual(4_900_000, extractor.getSubscriberCount());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
@Test
@Override
public void testTabs() throws Exception {
2022-11-04 23:47:44 +01:00
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
2023-04-14 14:10:26 +02:00
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.LIVESTREAMS));
2022-11-04 23:47:44 +01:00
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
}
}
// Youtube RED/Premium ad blocking test
public static class VSauce implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
2023-04-14 14:10:26 +02:00
private static ChannelTabExtractor tabExtractor;
2021-12-27 21:08:08 +01:00
@BeforeAll
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "VSauce"));
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/user/Vsauce");
extractor.fetchPage();
2023-04-14 14:10:26 +02:00
tabExtractor = YouTube.getChannelTabExtractor(extractor.getTabs().get(0));
tabExtractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
2023-04-27 12:31:39 +02:00
assertEquals(YouTube.getServiceId(), tabExtractor.getServiceId());
}
@Test
@Override
public void testName() throws Exception {
assertEquals("Vsauce", extractor.getName());
}
@Test
@Override
public void testId() throws Exception {
assertEquals("UC6nSFpj9HTCZ5t-N3Rm3-HA", extractor.getId());
2023-04-27 12:31:39 +02:00
assertEquals("UC6nSFpj9HTCZ5t-N3Rm3-HA", tabExtractor.getId());
}
@Test
@Override
public void testUrl() throws ParsingException {
assertEquals("https://www.youtube.com/channel/UC6nSFpj9HTCZ5t-N3Rm3-HA", extractor.getUrl());
2023-04-27 12:31:39 +02:00
assertEquals("https://www.youtube.com/channel/UC6nSFpj9HTCZ5t-N3Rm3-HA", tabExtractor.getUrl());
}
@Test
@Override
public void testOriginalUrl() throws ParsingException {
assertEquals("https://www.youtube.com/user/Vsauce", extractor.getOriginalUrl());
2023-04-27 12:31:39 +02:00
assertEquals("/@Vsauce/videos", tabExtractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
2023-04-14 14:10:26 +02:00
defaultTestRelatedItems(tabExtractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
2023-04-14 14:10:26 +02:00
defaultTestMoreItems(tabExtractor);
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
public void testDescription() throws Exception {
2021-12-27 21:08:08 +01:00
assertContains("Our World is Amazing. \n\nQuestions? Ideas? Tweet me:", extractor.getDescription());
}
@Test
@Override
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
}
@Test
@Override
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
}
@Test
@Override
public void testFeedUrl() throws Exception {
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UC6nSFpj9HTCZ5t-N3Rm3-HA", extractor.getFeedUrl());
}
@Test
@Override
public void testSubscriberCount() throws Exception {
ExtractorAsserts.assertGreaterOrEqual(17_000_000, extractor.getSubscriberCount());
}
@Test
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
@Test
@Override
public void testTabs() throws Exception {
2022-11-04 23:47:44 +01:00
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
2023-04-14 14:10:26 +02:00
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.SHORTS));
assertTrue(tabs.contains(ChannelTabs.LIVESTREAMS));
2022-11-04 23:47:44 +01:00
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
}
2017-08-05 10:03:56 +02:00
}
2018-03-04 21:26:13 +01:00
public static class Kurzgesagt implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
2023-04-14 14:10:26 +02:00
private static ChannelTabExtractor tabExtractor;
2018-03-04 21:26:13 +01:00
2021-12-27 21:08:08 +01:00
@BeforeAll
2018-03-04 21:26:13 +01:00
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "kurzgesagt"));
2018-03-04 21:26:13 +01:00
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q");
extractor.fetchPage();
2023-04-14 14:10:26 +02:00
tabExtractor = YouTube.getChannelTabExtractor(extractor.getTabs().get(0));
tabExtractor.fetchPage();
2018-03-04 21:26:13 +01:00
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
2023-04-27 12:31:39 +02:00
assertEquals(YouTube.getServiceId(), tabExtractor.getServiceId());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testName() throws Exception {
2021-12-27 21:08:08 +01:00
assertTrue(extractor.getName().startsWith("Kurzgesagt"));
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testId() throws Exception {
assertEquals("UCsXVk37bltHxD1rDPwtNM8Q", extractor.getId());
2023-04-27 12:31:39 +02:00
assertEquals("UCsXVk37bltHxD1rDPwtNM8Q", tabExtractor.getId());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testUrl() throws ParsingException {
assertEquals("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q", extractor.getUrl());
2023-04-27 12:31:39 +02:00
assertEquals("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q", tabExtractor.getUrl());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testOriginalUrl() throws ParsingException {
2018-03-04 21:26:13 +01:00
assertEquals("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q", extractor.getOriginalUrl());
2023-04-27 12:31:39 +02:00
assertEquals("/@kurzgesagt/videos", tabExtractor.getOriginalUrl());
2018-03-04 21:26:13 +01:00
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
2023-04-14 14:10:26 +02:00
defaultTestRelatedItems(tabExtractor);
2018-03-04 21:26:13 +01:00
}
@Test
public void testMoreRelatedItems() throws Exception {
2023-04-14 14:10:26 +02:00
defaultTestMoreItems(tabExtractor);
2018-03-04 21:26:13 +01:00
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testDescription() throws Exception {
ExtractorAsserts.assertContains("science", extractor.getDescription());
ExtractorAsserts.assertContains("animators", extractor.getDescription());
2018-03-04 21:26:13 +01:00
//TODO: Description get cuts out, because the og:description is optimized and don't have all the content
//assertTrue(description, description.contains("Currently we make one animation video per month"));
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testFeedUrl() throws Exception {
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UCsXVk37bltHxD1rDPwtNM8Q", extractor.getFeedUrl());
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testSubscriberCount() throws Exception {
ExtractorAsserts.assertGreaterOrEqual(17_000_000, extractor.getSubscriberCount());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
@Test
@Override
public void testTabs() throws Exception {
2022-11-04 23:47:44 +01:00
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
2023-04-14 14:10:26 +02:00
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
2022-11-04 23:47:44 +01:00
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
}
2017-08-05 10:03:56 +02:00
}
public static class KurzgesagtAdditional {
2018-03-04 21:26:13 +01:00
private static YoutubeChannelExtractor extractor;
2023-04-14 14:10:26 +02:00
private static ChannelTabExtractor tabExtractor;
2018-03-04 21:26:13 +01:00
2021-12-27 21:08:08 +01:00
@BeforeAll
2018-03-04 21:26:13 +01:00
public static void setUp() throws Exception {
// Test is not deterministic, mocks can't be used
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q");
extractor.fetchPage();
2023-04-14 14:10:26 +02:00
tabExtractor = YouTube.getChannelTabExtractor(extractor.getTabs().get(0));
tabExtractor.fetchPage();
}
@Test
public void testGetPageInNewExtractor() throws Exception {
final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getUrl());
2023-04-14 14:10:26 +02:00
newExtractor.fetchPage();
final ChannelTabExtractor newTabExtractor = YouTube.getChannelTabExtractor(newExtractor.getTabs().get(0));
defaultTestGetPageInNewExtractor(tabExtractor, newTabExtractor);
}
}
public static class CaptainDisillusion implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
2023-04-14 14:10:26 +02:00
private static ChannelTabExtractor tabExtractor;
2021-12-27 21:08:08 +01:00
@BeforeAll
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "captainDisillusion"));
2018-03-04 21:26:13 +01:00
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/user/CaptainDisillusion/videos");
extractor.fetchPage();
2023-04-14 14:10:26 +02:00
tabExtractor = YouTube.getChannelTabExtractor(extractor.getTabs().get(0));
tabExtractor.fetchPage();
2018-03-04 21:26:13 +01:00
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
2023-04-27 12:31:39 +02:00
assertEquals(YouTube.getServiceId(), tabExtractor.getServiceId());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testName() throws Exception {
2019-03-23 14:40:34 +01:00
assertEquals("Captain Disillusion", extractor.getName());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testId() throws Exception {
assertEquals("UCEOXxzW2vU0P-0THehuIIeg", extractor.getId());
2023-04-27 12:31:39 +02:00
assertEquals("UCEOXxzW2vU0P-0THehuIIeg", tabExtractor.getId());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testUrl() throws ParsingException {
assertEquals("https://www.youtube.com/channel/UCEOXxzW2vU0P-0THehuIIeg", extractor.getUrl());
2023-04-27 12:31:39 +02:00
assertEquals("https://www.youtube.com/channel/UCEOXxzW2vU0P-0THehuIIeg", tabExtractor.getUrl());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testOriginalUrl() throws ParsingException {
2018-03-04 21:26:13 +01:00
assertEquals("https://www.youtube.com/user/CaptainDisillusion/videos", extractor.getOriginalUrl());
2023-04-27 12:31:39 +02:00
assertEquals("/@CaptainDisillusion/videos", tabExtractor.getOriginalUrl());
2018-03-04 21:26:13 +01:00
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
2023-04-14 14:10:26 +02:00
defaultTestRelatedItems(tabExtractor);
2018-03-04 21:26:13 +01:00
}
@Test
public void testMoreRelatedItems() throws Exception {
2023-04-14 14:10:26 +02:00
defaultTestMoreItems(tabExtractor);
2018-03-04 21:26:13 +01:00
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testDescription() throws Exception {
2021-12-27 21:08:08 +01:00
ExtractorAsserts.assertContains("In a world where", extractor.getDescription());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testFeedUrl() throws Exception {
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UCEOXxzW2vU0P-0THehuIIeg", extractor.getFeedUrl());
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testSubscriberCount() throws Exception {
ExtractorAsserts.assertGreaterOrEqual(2_000_000, extractor.getSubscriberCount());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
@Test
@Override
public void testTabs() throws Exception {
2022-11-04 23:47:44 +01:00
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
2023-04-14 14:10:26 +02:00
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
2022-11-04 23:47:44 +01:00
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
}
2018-02-26 16:49:15 +01:00
}
2018-03-04 21:26:13 +01:00
public static class RandomChannel implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
2023-04-14 14:10:26 +02:00
private static ChannelTabExtractor tabExtractor;
2018-03-04 21:26:13 +01:00
2021-12-27 21:08:08 +01:00
@BeforeAll
2018-03-04 21:26:13 +01:00
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "random"));
2018-03-04 21:26:13 +01:00
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w");
extractor.fetchPage();
2023-04-14 14:10:26 +02:00
tabExtractor = YouTube.getChannelTabExtractor(extractor.getTabs().get(0));
tabExtractor.fetchPage();
2018-03-04 21:26:13 +01:00
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
2023-04-27 12:31:39 +02:00
assertEquals(YouTube.getServiceId(), tabExtractor.getServiceId());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testName() throws Exception {
assertEquals("random channel", extractor.getName());
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testId() throws Exception {
assertEquals("UCUaQMQS9lY5lit3vurpXQ6w", extractor.getId());
2023-04-27 12:31:39 +02:00
assertEquals("UCUaQMQS9lY5lit3vurpXQ6w", tabExtractor.getId());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testUrl() throws ParsingException {
assertEquals("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w", extractor.getUrl());
2023-04-27 12:31:39 +02:00
assertEquals("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w", tabExtractor.getUrl());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testOriginalUrl() throws ParsingException {
2018-03-04 21:26:13 +01:00
assertEquals("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w", extractor.getOriginalUrl());
2023-04-27 12:31:39 +02:00
assertEquals("/channel/UCUaQMQS9lY5lit3vurpXQ6w/videos", tabExtractor.getOriginalUrl());
2018-03-04 21:26:13 +01:00
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
2023-04-14 14:10:26 +02:00
defaultTestRelatedItems(tabExtractor);
2018-03-04 21:26:13 +01:00
}
@Test
public void testMoreRelatedItems() {
try {
2023-04-14 14:10:26 +02:00
defaultTestMoreItems(tabExtractor);
} catch (final Throwable ignored) {
2018-03-04 21:26:13 +01:00
return;
}
fail("This channel doesn't have more items, it should throw an error");
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testDescription() throws Exception {
2021-12-27 21:08:08 +01:00
ExtractorAsserts.assertContains("Hey there iu will upoload a load of pranks onto this channel", extractor.getDescription());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
2018-03-04 21:26:13 +01:00
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testFeedUrl() throws Exception {
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UCUaQMQS9lY5lit3vurpXQ6w", extractor.getFeedUrl());
}
@Test
@Override
2018-03-04 21:26:13 +01:00
public void testSubscriberCount() throws Exception {
ExtractorAsserts.assertGreaterOrEqual(50, extractor.getSubscriberCount());
2018-03-04 21:26:13 +01:00
}
@Test
@Override
public void testVerified() throws Exception {
assertFalse(extractor.isVerified());
}
@Test
@Override
public void testTabs() throws Exception {
2022-11-04 23:47:44 +01:00
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
2023-04-14 14:10:26 +02:00
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
2022-11-04 23:47:44 +01:00
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
}
2017-08-05 10:03:56 +02:00
}
public static class CarouselHeader implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
2023-04-27 12:31:39 +02:00
private static ChannelTabExtractor tabExtractor;
@BeforeAll
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "carouselHeader"));
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/channel/UCHF66aWLOxBW4l6VkSrS3cQ");
extractor.fetchPage();
2023-04-27 12:31:39 +02:00
tabExtractor = YouTube.getChannelTabExtractor(extractor.getTabs().get(0));
tabExtractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
2023-04-27 12:31:39 +02:00
assertEquals(YouTube.getServiceId(), tabExtractor.getServiceId());
}
@Test
@Override
public void testName() throws Exception {
assertEquals(extractor.getName(), "Coachella");
}
@Test
@Override
public void testId() throws Exception {
assertEquals("UCHF66aWLOxBW4l6VkSrS3cQ", extractor.getId());
2023-04-27 12:31:39 +02:00
assertEquals("UCHF66aWLOxBW4l6VkSrS3cQ", tabExtractor.getId());
}
@Test
@Override
public void testUrl() throws ParsingException {
assertEquals("https://www.youtube.com/channel/UCHF66aWLOxBW4l6VkSrS3cQ", extractor.getUrl());
2023-04-27 12:31:39 +02:00
assertEquals("https://www.youtube.com/channel/UCHF66aWLOxBW4l6VkSrS3cQ", tabExtractor.getUrl());
}
@Test
@Override
public void testOriginalUrl() throws ParsingException {
assertEquals("https://www.youtube.com/channel/UCHF66aWLOxBW4l6VkSrS3cQ", extractor.getOriginalUrl());
2023-04-27 12:31:39 +02:00
assertEquals("/@Coachella/videos", tabExtractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
2023-04-27 12:31:39 +02:00
defaultTestRelatedItems(tabExtractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
2023-04-27 12:31:39 +02:00
defaultTestMoreItems(tabExtractor);
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Override
public void testDescription() {
}
@Test
@Override
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
}
@Test
@Override
public void testBannerUrl() throws Exception {
// CarouselHeaderRender does not contain a banner
}
@Test
@Override
public void testFeedUrl() throws Exception {
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UCHF66aWLOxBW4l6VkSrS3cQ", extractor.getFeedUrl());
}
@Test
@Override
public void testSubscriberCount() throws Exception {
ExtractorAsserts.assertGreaterOrEqual(2_900_000, extractor.getSubscriberCount());
}
@Test
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
2023-04-27 12:31:39 +02:00
@Test
@Override
2023-04-27 12:31:39 +02:00
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.SHORTS));
assertTrue(tabs.contains(ChannelTabs.LIVESTREAMS));
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
}
}
}