From 2d88c34e00cbf3ebe39c6e52cb107364eb03d60c Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sat, 8 Mar 2025 14:52:38 +0100 Subject: [PATCH] [YouTube] add test for membersOnly playlist --- .../youtube/YoutubePlaylistExtractorTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index e568175d9..148e65a01 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -30,6 +30,8 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; /** * Test for {@link YoutubePlaylistExtractor} @@ -576,4 +578,34 @@ public class YoutubePlaylistExtractorTest { assertFalse(page.hasNextPage(), "More items available when it shouldn't"); } } + + public static class MembersOnlyTests { + + @BeforeAll + public static void setUp() { + YoutubeTestsUtils.ensureStateless(); + NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "membersOnlyVideos")); + } + + @Test + void testOnlyMembersOnlyVideos() throws Exception { + final YoutubePlaylistExtractor extractor = (YoutubePlaylistExtractor) YouTube + .getPlaylistExtractor( + // auto-generated playlist with only membersOnly videos + "https://www.youtube.com/playlist?list=UUMOQuLXlFNAeDJMSmuzHU5axw"); + extractor.fetchPage(); + + final List allItems = extractor.getInitialPage().getItems() + .stream() + .filter(StreamInfoItem.class::isInstance) + .map(StreamInfoItem.class::cast) + .collect(Collectors.toUnmodifiableList()); + final List membershipVideos = allItems.stream() + .filter(item -> !item.requiresMembership()) + .collect(Collectors.toUnmodifiableList()); + + assertFalse(allItems.isEmpty()); + assertTrue(membershipVideos.isEmpty()); + } + } }