Skip to content

Commit

Permalink
searchfilters: Test: adjust and extend YouTube tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evermind-zz committed Oct 20, 2022
1 parent 1707f5b commit 4c11830
Show file tree
Hide file tree
Showing 4 changed files with 375 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
import org.schabi.newpipe.extractor.services.youtube.search.filter.YoutubeFilters;

import java.net.URLEncoder;

Expand All @@ -26,7 +28,9 @@ public static class MusicSongs extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = YouTube.getSearchExtractor(QUERY, singletonList(YoutubeSearchQueryHandlerFactory.MUSIC_SONGS), "");
final FilterItem item =
getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_SONGS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -48,7 +52,9 @@ public static class MusicVideos extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = YouTube.getSearchExtractor(QUERY, singletonList(YoutubeSearchQueryHandlerFactory.MUSIC_VIDEOS), "");
final FilterItem item =
getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_VIDEOS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -70,7 +76,9 @@ public static class MusicAlbums extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = YouTube.getSearchExtractor(QUERY, singletonList(YoutubeSearchQueryHandlerFactory.MUSIC_ALBUMS), "");
final FilterItem item =
getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_ALBUMS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -92,7 +100,9 @@ public static class MusicPlaylists extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = YouTube.getSearchExtractor(QUERY, singletonList(YoutubeSearchQueryHandlerFactory.MUSIC_PLAYLISTS), "");
final FilterItem item =
getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_PLAYLISTS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -115,7 +125,9 @@ public static class MusicArtists extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = YouTube.getSearchExtractor(QUERY, singletonList(YoutubeSearchQueryHandlerFactory.MUSIC_ARTISTS), "");
final FilterItem item =
getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_ARTISTS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -139,7 +151,9 @@ public static class Suggestion extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = YouTube.getSearchExtractor(QUERY, singletonList(YoutubeSearchQueryHandlerFactory.MUSIC_SONGS), "");
final FilterItem item =
getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_SONGS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -163,7 +177,9 @@ public static class CorrectedSearch extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = YouTube.getSearchExtractor(QUERY, singletonList(YoutubeSearchQueryHandlerFactory.MUSIC_SONGS), "");
final FilterItem item =
getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_SONGS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems;
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.CHANNELS;
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.PLAYLISTS;
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.VIDEOS;
import static java.util.Collections.singletonList;

import org.junit.jupiter.api.BeforeAll;
Expand All @@ -24,8 +21,10 @@
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest;
import org.schabi.newpipe.extractor.services.youtube.YoutubeTestsUtils;
import org.schabi.newpipe.extractor.services.youtube.search.filter.YoutubeFilters;
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;

Expand Down Expand Up @@ -72,7 +71,8 @@ public static class Channel extends DefaultSearchExtractorTest {
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "channel"));
extractor = YouTube.getSearchExtractor(QUERY, singletonList(CHANNELS), "");
final FilterItem item = getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_CHANNELS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -96,7 +96,8 @@ public static class Playlists extends DefaultSearchExtractorTest {
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "playlist"));
extractor = YouTube.getSearchExtractor(QUERY, singletonList(PLAYLISTS), "");
final FilterItem item = getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_PLAYLISTS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -120,7 +121,8 @@ public static class Videos extends DefaultSearchExtractorTest {
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "videos"));
extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), "");
final FilterItem item = getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_VIDEOS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand Down Expand Up @@ -152,7 +154,8 @@ public static class Suggestion extends DefaultSearchExtractorTest {
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "suggestions"));
extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), "");
final FilterItem item = getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_VIDEOS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -179,7 +182,8 @@ public static class CorrectedSearch extends DefaultSearchExtractorTest {
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "corrected"));
extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), "");
final FilterItem item = getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_VIDEOS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand Down Expand Up @@ -238,7 +242,10 @@ public static class PagingTest {
public void duplicatedItemsCheck() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "paging"));
final SearchExtractor extractor = YouTube.getSearchExtractor("cirque du soleil", singletonList(VIDEOS), "");

final FilterItem item = DefaultSearchExtractorTest.getFilterItem(
YouTube, YoutubeFilters.ID_CF_MAIN_VIDEOS);
final SearchExtractor extractor = YouTube.getSearchExtractor("cirque du soleil", singletonList(item), null);
extractor.fetchPage();

final ListExtractor.InfoItemsPage<InfoItem> page1 = extractor.getInitialPage();
Expand All @@ -256,7 +263,8 @@ public static class MetaInfoTest extends DefaultSearchExtractorTest {
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "metaInfo"));
extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), "");
final FilterItem item = getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_VIDEOS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand Down Expand Up @@ -291,7 +299,9 @@ public static class ChannelVerified extends DefaultSearchExtractorTest {
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "verified"));
extractor = YouTube.getSearchExtractor(QUERY, singletonList(CHANNELS), "");

final FilterItem item = getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_CHANNELS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand Down Expand Up @@ -328,7 +338,8 @@ public static class VideoUploaderAvatar extends DefaultSearchExtractorTest {
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "video_uploader_avatar"));
extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), "");
final FilterItem item = getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_VIDEOS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand Down Expand Up @@ -359,7 +370,8 @@ public static class VideoDescription extends DefaultSearchExtractorTest {
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "video_description"));
extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), "");
final FilterItem item = getFilterItem(YouTube, YoutubeFilters.ID_CF_MAIN_VIDEOS);
extractor = YouTube.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand Down
Loading

0 comments on commit 4c11830

Please sign in to comment.