From bb97de7e3d2fd37fb1469a8680824c0781a68591 Mon Sep 17 00:00:00 2001 From: evermind Date: Wed, 2 Nov 2022 00:09:12 +0100 Subject: [PATCH] searchfilters: convert to using LibraryStringIds to identify strings --- .../extractor/search/filter/FilterGroup.java | 26 +-- .../extractor/search/filter/FilterItem.java | 20 ++- .../search/filter/BandcampFilters.java | 23 ++- .../search/filter/MediaCCCFilters.java | 14 +- .../search/filter/PeertubeFilters.java | 126 ++++++++----- .../search/filter/SoundcloudFilters.java | 76 +++++--- .../YoutubeMusicSearchExtractor.java | 32 ++-- .../YoutubeSearchQueryHandlerFactory.java | 10 -- .../youtube/search/filter/YoutubeFilters.java | 170 ++++++++++-------- .../services/DefaultFiltersTest.java | 4 +- 10 files changed, 289 insertions(+), 212 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterGroup.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterGroup.java index 001a92d679..148e7f17e3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterGroup.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterGroup.java @@ -19,9 +19,11 @@ public final class FilterGroup { private final int identifier; /** - * The name of the filter group that the user will see + * The name id of the filter group. + *

+ * The id has to be translated to an actual string that the user will see in the UI. */ - private final String groupName; + private final LibraryStringIds groupNameId; /** * Specify whether only one item can be selected in this group at a time. @@ -47,13 +49,13 @@ public final class FilterGroup { private final FilterContainer allSortFilters; private FilterGroup(final int identifier, - final String groupName, + final LibraryStringIds groupNameId, final boolean onlyOneCheckable, final int defaultSelectedFilterId, final FilterItem[] filterItems, final FilterContainer allSortFilters) { this.identifier = identifier; - this.groupName = groupName; + this.groupNameId = groupNameId; this.onlyOneCheckable = onlyOneCheckable; this.defaultSelectedFilterId = defaultSelectedFilterId; this.filterItems = filterItems; @@ -79,10 +81,10 @@ public int getIdentifier() { } /** - * {@link #groupName} + * {@link #groupNameId} */ - public String getName() { - return groupName; + public LibraryStringIds getNameId() { + return groupNameId; } /** @@ -132,14 +134,14 @@ void uniqueIdChecker(final Map filterItems, && !(item instanceof FilterItem.DividerItem)) { throw new InvalidFilterIdException("Filter ID " + item.getIdentifier() + " aka FilterContainer.ITEM_IDENTIFIER_UNKNOWN" - + " for \"" + item.getName() + "\" not allowed"); + + " for \"" + item.getNameId() + "\" not allowed"); } if (filterItems.containsKey(item.getIdentifier())) { final FilterItem storedItem = filterItems.get(item.getIdentifier()); throw new InvalidFilterIdException("Filter ID " - + item.getIdentifier() + " for \"" + item.getName() - + "\" already taken from \"" + storedItem.getName() + "\""); + + item.getIdentifier() + " for \"" + item.getNameId() + + "\" already taken from \"" + storedItem.getNameId() + "\""); } } @@ -158,12 +160,12 @@ public int addFilterItem(final FilterItem filter) { } public FilterGroup createFilterGroup(final int identifier, - final String groupName, + final LibraryStringIds groupNameId, final boolean onlyOneCheckable, final int defaultSelectedFilterId, final FilterItem[] filterItems, final FilterContainer allSortFilters) { - return new FilterGroup(identifier, groupName, onlyOneCheckable, + return new FilterGroup(identifier, groupNameId, onlyOneCheckable, defaultSelectedFilterId, filterItems, allSortFilters); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterItem.java b/extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterItem.java index 2bddde1e7e..e06106eb92 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterItem.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterItem.java @@ -13,9 +13,11 @@ public class FilterItem { /** - * The name of the filter option, that will be visible to the user. + * The name id of the filter group. + * + * The id has to be translated to an actual string that the user will see in the UI. */ - private final String name; + private final LibraryStringIds nameId; /** * A sequential unique number identifier. @@ -28,9 +30,9 @@ public class FilterItem { */ private final int identifier; - public FilterItem(final int identifier, final String name) { + public FilterItem(final int identifier, final LibraryStringIds nameId) { this.identifier = identifier; - this.name = name; + this.nameId = nameId; } /** @@ -41,10 +43,10 @@ public int getIdentifier() { } /** - * @return {@link #name} + * @return {@link #nameId} */ - public String getName() { - return this.name; + public LibraryStringIds getNameId() { + return this.nameId; } /** @@ -52,8 +54,8 @@ public String getName() { */ public static class DividerItem extends FilterItem { - public DividerItem(final String name) { - super(FilterContainer.ITEM_IDENTIFIER_UNKNOWN, name); + public DividerItem(final LibraryStringIds nameId) { + super(FilterContainer.ITEM_IDENTIFIER_UNKNOWN, nameId); } } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/search/filter/BandcampFilters.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/search/filter/BandcampFilters.java index eba8fd278a..0b61319020 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/search/filter/BandcampFilters.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/search/filter/BandcampFilters.java @@ -4,6 +4,7 @@ import org.schabi.newpipe.extractor.search.filter.BaseSearchFilters; import org.schabi.newpipe.extractor.search.filter.FilterItem; +import org.schabi.newpipe.extractor.search.filter.LibraryStringIds; public final class BandcampFilters extends BaseSearchFilters { @@ -14,12 +15,6 @@ public final class BandcampFilters extends BaseSearchFilters { public static final int ID_CF_MAIN_TRACKS = 4; // public static final int ID_CF_MAIN_FANS = 5; - private static final String ALL = "all"; - private static final String ARTISTS = "artists & labels"; - private static final String ALBUMS = "albums"; - private static final String TRACKS = "tracks"; - // private static final String FANS = "fans"; - @Override public String evaluateSelectedContentFilters() { if (selectedSortFilter != null) { @@ -42,13 +37,17 @@ public String evaluateSelectedContentFilters() { protected void init() { /* content filters */ groupsFactory.addFilterItem(new BandcampContentFilterItem( - ID_CF_MAIN_ALL, ALL, "")); + ID_CF_MAIN_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, "")); groupsFactory.addFilterItem(new BandcampContentFilterItem( - ID_CF_MAIN_ARTISTS, ARTISTS, "item_type=b")); + ID_CF_MAIN_ARTISTS, + LibraryStringIds.SEARCH_FILTERS_ARTISTS_AND_LABELS, "item_type=b")); groupsFactory.addFilterItem(new BandcampContentFilterItem( - ID_CF_MAIN_ALBUMS, ALBUMS, "item_type=a")); + ID_CF_MAIN_ALBUMS, + LibraryStringIds.SEARCH_FILTERS_ALBUMS, "item_type=a")); groupsFactory.addFilterItem(new BandcampContentFilterItem( - ID_CF_MAIN_TRACKS, TRACKS, "item_type=t")); + ID_CF_MAIN_TRACKS, + LibraryStringIds.SEARCH_FILTERS_TRACKS, "item_type=t")); // FIXME no FANS extractor in BandcampSearchExtractor -> no content filter here // groupsFactory.addFilterItem(new BandcampContentFilterItem( // ID_CF_MAIN_FANS, FANS, "item_type=f")); @@ -66,9 +65,9 @@ protected void init() { public static class BandcampContentFilterItem extends FilterItem { private final String query; - public BandcampContentFilterItem(final int identifier, final String name, + public BandcampContentFilterItem(final int identifier, final LibraryStringIds nameId, final String query) { - super(identifier, name); + super(identifier, nameId); this.query = query; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/search/filter/MediaCCCFilters.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/search/filter/MediaCCCFilters.java index 15d9fd5b1d..4ab820ce64 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/search/filter/MediaCCCFilters.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/search/filter/MediaCCCFilters.java @@ -4,6 +4,7 @@ import org.schabi.newpipe.extractor.search.filter.BaseSearchFilters; import org.schabi.newpipe.extractor.search.filter.FilterItem; +import org.schabi.newpipe.extractor.search.filter.LibraryStringIds; public final class MediaCCCFilters extends BaseSearchFilters { @@ -12,19 +13,18 @@ public final class MediaCCCFilters extends BaseSearchFilters { public static final int ID_CF_MAIN_CONFERENCES = 2; public static final int ID_CF_MAIN_EVENTS = 3; - public static final String ALL = "all"; - public static final String CONFERENCES = "conferences"; - public static final String EVENTS = "events"; - @Override protected void init() { /* content filters */ groupsFactory.addFilterItem(new FilterItem( - ID_CF_MAIN_ALL, ALL)); + ID_CF_MAIN_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL)); groupsFactory.addFilterItem(new FilterItem( - ID_CF_MAIN_CONFERENCES, CONFERENCES)); + ID_CF_MAIN_CONFERENCES, + LibraryStringIds.SEARCH_FILTERS_CONFERENCES)); groupsFactory.addFilterItem(new FilterItem( - ID_CF_MAIN_EVENTS, EVENTS)); + ID_CF_MAIN_EVENTS, + LibraryStringIds.SEARCH_FILTERS_EVENTS)); addContentFilterGroup(groupsFactory.createFilterGroup(ID_CF_MAIN_GRP, null, true, ID_CF_MAIN_ALL, new FilterItem[]{ diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/search/filter/PeertubeFilters.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/search/filter/PeertubeFilters.java index 714610b857..d6d50f4e24 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/search/filter/PeertubeFilters.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/search/filter/PeertubeFilters.java @@ -7,6 +7,7 @@ import org.schabi.newpipe.extractor.search.filter.FilterContainer; import org.schabi.newpipe.extractor.search.filter.FilterGroup; import org.schabi.newpipe.extractor.search.filter.FilterItem; +import org.schabi.newpipe.extractor.search.filter.LibraryStringIds; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -85,70 +86,96 @@ protected void init() { /* sort filters */ /* 'Sort order' filter item */ groupsFactory.addFilterItem(new PeertubeSortOrderFilterItem( - ID_SF_SORT_ORDER_ASCENDING, "Ascending")); + ID_SF_SORT_ORDER_ASCENDING, + LibraryStringIds.SEARCH_FILTERS_ASCENDING)); /* 'Sort by' filter items */ groupsFactory.addFilterItem(new PeertubeSortFilterItem( - ID_SF_SORT_BY_RELEVANCE, "Relevance", "sort=match")); + ID_SF_SORT_BY_RELEVANCE, + LibraryStringIds.SEARCH_FILTERS_RELEVANCE, "sort=match")); groupsFactory.addFilterItem(new PeertubeSortFilterItem( - ID_SF_SORT_BY_NAME, "Name", "sort=name")); + ID_SF_SORT_BY_NAME, + LibraryStringIds.SEARCH_FILTERS_NAME, "sort=name")); groupsFactory.addFilterItem(new PeertubeSortFilterItem( - ID_SF_SORT_BY_DURATION, "Duration", "sort=duration")); + ID_SF_SORT_BY_DURATION, + LibraryStringIds.SEARCH_FILTERS_DURATION, "sort=duration")); groupsFactory.addFilterItem(new PeertubeSortFilterItem( - ID_SF_SORT_BY_PUBLISH_DATE, "Publish date", "sort=publishedAt")); + ID_SF_SORT_BY_PUBLISH_DATE, + LibraryStringIds.SEARCH_FILTERS_PUBLISH_DATE, "sort=publishedAt")); groupsFactory.addFilterItem(new PeertubeSortFilterItem( - ID_SF_SORT_BY_CREATION_DATE, "Creation date", "sort=createdAt")); + ID_SF_SORT_BY_CREATION_DATE, + LibraryStringIds.SEARCH_FILTERS_CREATION_DATE, "sort=createdAt")); groupsFactory.addFilterItem(new PeertubeSortFilterItem( - ID_SF_SORT_BY_VIEWS, "Views", "sort=views")); + ID_SF_SORT_BY_VIEWS, + LibraryStringIds.SEARCH_FILTERS_VIEWS, "sort=views")); groupsFactory.addFilterItem(new PeertubeSortFilterItem( - ID_SF_SORT_BY_LIKES, "Likes", "sort=likes")); + ID_SF_SORT_BY_LIKES, + LibraryStringIds.SEARCH_FILTERS_LIKES, "sort=likes")); /* stream kind filter items */ groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_KIND_ALL, "All", "")); + ID_SF_KIND_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, "")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_KIND_LIVE, "Live", "isLive=true")); + ID_SF_KIND_LIVE, + LibraryStringIds.SEARCH_FILTERS_LIVE, "isLive=true")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_KIND_VOD_VIDEOS, "VOD videos", "isLive=false")); + ID_SF_KIND_VOD_VIDEOS, + LibraryStringIds.SEARCH_FILTERS_VOD_VIDEOS, "isLive=false")); /* sensitive filter items */ groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_SENSITIVE_ALL, "All", "")); + ID_SF_SENSITIVE_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, "")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_SENSITIVE_YES, "Yes", "nsfw=true")); + ID_SF_SENSITIVE_YES, + LibraryStringIds.SEARCH_FILTERS_YES, "nsfw=true")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_SENSITIVE_NO, "No", "nsfw=false")); + ID_SF_SENSITIVE_NO, + LibraryStringIds.SEARCH_FILTERS_NO, "nsfw=false")); /* 'Date' filter items */ // here query is set to null as the value is generated dynamically groupsFactory.addFilterItem(new PeertubePublishedDateFilterItem( - ID_SF_PUBLISHED_ALL, "All", null, + ID_SF_PUBLISHED_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, null, PeertubePublishedDateFilterItem.NO_DAYS_SET)); groupsFactory.addFilterItem(new PeertubePublishedDateFilterItem( - ID_SF_PUBLISHED_TODAY, "Today", null, 1)); + ID_SF_PUBLISHED_TODAY, + LibraryStringIds.SEARCH_FILTERS_TODAY, null, 1)); groupsFactory.addFilterItem(new PeertubePublishedDateFilterItem( - ID_SF_PUBLISHED_LAST_7_DAYS, "last 7 days", null, 7)); + ID_SF_PUBLISHED_LAST_7_DAYS, + LibraryStringIds.SEARCH_FILTERS_LAST_7_DAYS, null, 7)); groupsFactory.addFilterItem(new PeertubePublishedDateFilterItem( - ID_SF_PUBLISHED_LAST_30_DAYS, "last 30 days", null, 30)); + ID_SF_PUBLISHED_LAST_30_DAYS, + LibraryStringIds.SEARCH_FILTERS_LAST_30_DAYS, null, 30)); groupsFactory.addFilterItem(new PeertubePublishedDateFilterItem( - ID_SF_PUBLISHED_LAST_YEAR, "last year", null, 365)); + ID_SF_PUBLISHED_LAST_YEAR, + LibraryStringIds.SEARCH_FILTERS_LAST_YEAR, null, 365)); /* 'Duration' filter items */ groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_DURATION_ALL, "All", "")); + ID_SF_DURATION_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, "")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_DURATION_SHORT, "Short (< 4 min)", "durationMax=240")); + ID_SF_DURATION_SHORT, + LibraryStringIds.SEARCH_FILTERS_SHORT_LESS_4_MIN, "durationMax=240")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_DURATION_MEDIUM, "Medium (4-10 min)", "durationMin=240&durationMax=600")); + ID_SF_DURATION_MEDIUM, + LibraryStringIds.SEARCH_FILTERS_MEDIUM_4_10_MIN, + "durationMin=240&durationMax=600")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_SF_DURATION_LONG, "Long (> 10 min)", "durationMin=600")); + ID_SF_DURATION_LONG, + LibraryStringIds.SEARCH_FILTERS_LONG_GREATER_10_MIN, "durationMin=600")); final FilterContainer allSortFilters = new FilterContainer(new FilterGroup[]{ - groupsFactory.createFilterGroup(ID_SF_SORT_ORDER_GRP, "Sort order", false, + groupsFactory.createFilterGroup(ID_SF_SORT_ORDER_GRP, + LibraryStringIds.SEARCH_FILTERS_SORT_ORDER, false, ITEM_IDENTIFIER_UNKNOWN, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_SORT_ORDER_ASCENDING), }, null), - groupsFactory.createFilterGroup(ID_SF_SORT_BY_GRP, "Sort by", true, + groupsFactory.createFilterGroup(ID_SF_SORT_BY_GRP, + LibraryStringIds.SEARCH_FILTERS_SORT_BY, true, ID_SF_SORT_BY_RELEVANCE, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_SORT_BY_RELEVANCE), groupsFactory.getFilterForId(ID_SF_SORT_BY_NAME), @@ -158,19 +185,22 @@ protected void init() { groupsFactory.getFilterForId(ID_SF_SORT_BY_VIEWS), groupsFactory.getFilterForId(ID_SF_SORT_BY_LIKES), }, null), - groupsFactory.createFilterGroup(ID_SF_KIND_GRP, "Kind", true, + groupsFactory.createFilterGroup(ID_SF_KIND_GRP, + LibraryStringIds.SEARCH_FILTERS_KIND, true, ID_SF_KIND_ALL, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_KIND_ALL), groupsFactory.getFilterForId(ID_SF_KIND_LIVE), groupsFactory.getFilterForId(ID_SF_KIND_VOD_VIDEOS), }, null), - groupsFactory.createFilterGroup(ID_SF_SENSITIVE_GRP, "Sensitive", true, + groupsFactory.createFilterGroup(ID_SF_SENSITIVE_GRP, + LibraryStringIds.SEARCH_FILTERS_SENSITIVE, true, ID_SF_SENSITIVE_ALL, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_SENSITIVE_ALL), groupsFactory.getFilterForId(ID_SF_SENSITIVE_YES), groupsFactory.getFilterForId(ID_SF_SENSITIVE_NO), }, null), - groupsFactory.createFilterGroup(ID_SF_PUBLISHED_GRP, "Published", true, + groupsFactory.createFilterGroup(ID_SF_PUBLISHED_GRP, + LibraryStringIds.SEARCH_FILTERS_PUBLISHED, true, ID_SF_PUBLISHED_ALL, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_PUBLISHED_ALL), groupsFactory.getFilterForId(ID_SF_PUBLISHED_TODAY), @@ -178,7 +208,8 @@ protected void init() { groupsFactory.getFilterForId(ID_SF_PUBLISHED_LAST_30_DAYS), groupsFactory.getFilterForId(ID_SF_PUBLISHED_LAST_YEAR), }, null), - groupsFactory.createFilterGroup(ID_SF_DURATION_GRP, "Duration", true, + groupsFactory.createFilterGroup(ID_SF_DURATION_GRP, + LibraryStringIds.SEARCH_FILTERS_DURATION, true, ID_SF_DURATION_ALL, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_DURATION_ALL), groupsFactory.getFilterForId(ID_SF_DURATION_SHORT), @@ -190,13 +221,17 @@ protected void init() { /* content filters */ groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_CF_MAIN_ALL, "All", "")); + ID_CF_MAIN_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, "")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_CF_MAIN_VIDEOS, "Videos", "resultType=videos")); + ID_CF_MAIN_VIDEOS, + LibraryStringIds.SEARCH_FILTERS_VIDEOS, "resultType=videos")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_CF_MAIN_CHANNELS, "Channels", "resultType=channels")); + ID_CF_MAIN_CHANNELS, + LibraryStringIds.SEARCH_FILTERS_CHANNELS, "resultType=channels")); groupsFactory.addFilterItem(new PeertubeFilterItem( - ID_CF_MAIN_PLAYLISTS, "Playlists", "resultType=playlists")); + ID_CF_MAIN_PLAYLISTS, + LibraryStringIds.SEARCH_FILTERS_PLAYLISTS, "resultType=playlists")); /* content filter groups */ @@ -209,7 +244,8 @@ protected void init() { }, allSortFilters)); groupsFactory.addFilterItem(new PeertubeSepiaFilterItem( - ID_CF_SEPIA_SEPIASEARCH, "SepiaSearch")); + ID_CF_SEPIA_SEPIASEARCH, + LibraryStringIds.SEARCH_FILTERS_SEPIASEARCH)); addContentFilterGroup(groupsFactory.createFilterGroup(ID_CF_SEPIA_GRP, null, false, ITEM_IDENTIFIER_UNKNOWN, new FilterItem[]{ @@ -234,8 +270,9 @@ private void appendFilterToQueryString(final FilterItem item, private static class PeertubeFilterItem extends FilterItem { protected final String query; - PeertubeFilterItem(final int identifier, final String name, final String query) { - super(identifier, name); + PeertubeFilterItem(final int identifier, final LibraryStringIds nameId, + final String query) { + super(identifier, nameId); this.query = query; } @@ -248,9 +285,9 @@ static class PeertubePublishedDateFilterItem extends PeertubeFilterItem { static final int NO_DAYS_SET = -1; private final int days; - PeertubePublishedDateFilterItem(final int identifier, final String name, + PeertubePublishedDateFilterItem(final int identifier, final LibraryStringIds nameId, final String query, final int days) { - super(identifier, name, query); + super(identifier, nameId, query); this.days = days; } @@ -269,20 +306,21 @@ public String getQueryData() { } public static class PeertubeSepiaFilterItem extends FilterItem { - public PeertubeSepiaFilterItem(final int identifier, final String name) { - super(identifier, name); + public PeertubeSepiaFilterItem(final int identifier, final LibraryStringIds nameId) { + super(identifier, nameId); } } private static class PeertubeSortOrderFilterItem extends FilterItem { - PeertubeSortOrderFilterItem(final int identifier, final String name) { - super(identifier, name); + PeertubeSortOrderFilterItem(final int identifier, final LibraryStringIds nameId) { + super(identifier, nameId); } } private class PeertubeSortFilterItem extends PeertubeFilterItem { - PeertubeSortFilterItem(final int identifier, final String name, final String query) { - super(identifier, name, query); + PeertubeSortFilterItem(final int identifier, final LibraryStringIds nameId, + final String query) { + super(identifier, nameId, query); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/search/filter/SoundcloudFilters.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/search/filter/SoundcloudFilters.java index 1e1733856c..a872906c78 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/search/filter/SoundcloudFilters.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/search/filter/SoundcloudFilters.java @@ -6,6 +6,7 @@ import org.schabi.newpipe.extractor.search.filter.FilterContainer; import org.schabi.newpipe.extractor.search.filter.FilterGroup; import org.schabi.newpipe.extractor.search.filter.FilterItem; +import org.schabi.newpipe.extractor.search.filter.LibraryStringIds; public final class SoundcloudFilters extends BaseSearchFilters { @@ -31,11 +32,6 @@ public final class SoundcloudFilters extends BaseSearchFilters { public static final int ID_SF_LICENSE_ALL = 19; public static final int ID_SF_LICENSE_COMMERCE = 20; - public static final String TRACKS = "tracks"; - public static final String USERS = "users"; - public static final String PLAYLISTS = "playlists"; - public static final String ALL = "all"; - @Override public String evaluateSelectedContentFilters() { if (selectedContentFilter != null && !selectedContentFilter.isEmpty()) { @@ -53,51 +49,69 @@ public String evaluateSelectedContentFilters() { protected void init() { /* content filters */ groupsFactory.addFilterItem(new SoundcloudContentFilterItem( - ID_CF_MAIN_ALL, ALL, "")); + ID_CF_MAIN_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, "")); groupsFactory.addFilterItem(new SoundcloudContentFilterItem( - ID_CF_MAIN_TRACKS, TRACKS, "/tracks")); + ID_CF_MAIN_TRACKS, + LibraryStringIds.SEARCH_FILTERS_TRACKS, "/tracks")); groupsFactory.addFilterItem(new SoundcloudContentFilterItem( - ID_CF_MAIN_USERS, USERS, "/users")); + ID_CF_MAIN_USERS, + LibraryStringIds.SEARCH_FILTERS_USERS, "/users")); groupsFactory.addFilterItem(new SoundcloudContentFilterItem( - ID_CF_MAIN_PLAYLISTS, PLAYLISTS, "/playlists")); + ID_CF_MAIN_PLAYLISTS, + LibraryStringIds.SEARCH_FILTERS_PLAYLISTS, "/playlists")); /* Sort filters */ /* 'Date' filter items */ groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DATE_ALL, "all", "")); + ID_SF_DATE_ALL, + LibraryStringIds.SEARCH_FILTERS_ANY_TIME, "")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DATE_LAST_HOUR, "Past hour", "filter.created_at=last_hour")); + ID_SF_DATE_LAST_HOUR, + LibraryStringIds.SEARCH_FILTERS_PAST_HOUR, "filter.created_at=last_hour")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DATE_LAST_DAY, "Past day", "filter.created_at=last_day")); + ID_SF_DATE_LAST_DAY, + LibraryStringIds.SEARCH_FILTERS_PAST_DAY, "filter.created_at=last_day")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DATE_LAST_WEEK, "Past week", "filter.created_at=last_week")); + ID_SF_DATE_LAST_WEEK, + LibraryStringIds.SEARCH_FILTERS_PAST_WEEK, "filter.created_at=last_week")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DATE_LAST_MONTH, "Past month", "filter.created_at=last_month")); + ID_SF_DATE_LAST_MONTH, + LibraryStringIds.SEARCH_FILTERS_PAST_MONTH, "filter.created_at=last_month")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DATE_LAST_YEAR, "Past year", "filter.created_at=last_year")); + ID_SF_DATE_LAST_YEAR, + LibraryStringIds.SEARCH_FILTERS_PAST_YEAR, "filter.created_at=last_year")); /* duration' filter items */ groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DURATION_ALL, "all", "")); + ID_SF_DURATION_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, "")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DURATION_SHORT, "< 2 min", "filter.duration=short")); + ID_SF_DURATION_SHORT, + LibraryStringIds.SEARCH_FILTERS_LESS_2_MIN, "filter.duration=short")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DURATION_MEDIUM, "2-10 min", "filter.duration=medium")); + ID_SF_DURATION_MEDIUM, + LibraryStringIds.SEARCH_FILTERS_2_10_MIN, "filter.duration=medium")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DURATION_LONG, "10-30 min", "filter.duration=long")); + ID_SF_DURATION_LONG, + LibraryStringIds.SEARCH_FILTERS_10_30_MIN, "filter.duration=long")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_DURATION_EPIC, "> 30 min", "filter.duration=epic")); + ID_SF_DURATION_EPIC, + LibraryStringIds.SEARCH_FILTERS_GREATER_30_MIN, "filter.duration=epic")); /* license */ groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_LICENSE_ALL, "all", "")); + ID_SF_LICENSE_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, "")); groupsFactory.addFilterItem(new SoundcloudSortFilterItem( - ID_SF_LICENSE_COMMERCE, "To modify commercially", + ID_SF_LICENSE_COMMERCE, + LibraryStringIds.SEARCH_FILTERS_TO_MODIFY_COMMERCIALLY, "filter.license=to_modify_commercially")); final FilterContainer allMainCFGrpSortFilters = new FilterContainer(new FilterGroup[]{ - groupsFactory.createFilterGroup(ID_SF_DATE_GRP, "Sort by", true, + groupsFactory.createFilterGroup(ID_SF_DATE_GRP, + LibraryStringIds.SEARCH_FILTERS_ADDED, true, ID_SF_DATE_ALL, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_DATE_ALL), groupsFactory.getFilterForId(ID_SF_DATE_LAST_HOUR), @@ -106,7 +120,8 @@ protected void init() { groupsFactory.getFilterForId(ID_SF_DATE_LAST_MONTH), groupsFactory.getFilterForId(ID_SF_DATE_LAST_YEAR), }, null), - groupsFactory.createFilterGroup(ID_SF_DURATION_GRP, "Length", true, + groupsFactory.createFilterGroup(ID_SF_DURATION_GRP, + LibraryStringIds.SEARCH_FILTERS_LENGTH, true, ID_SF_DURATION_ALL, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_DURATION_ALL), groupsFactory.getFilterForId(ID_SF_DURATION_SHORT), @@ -114,7 +129,8 @@ protected void init() { groupsFactory.getFilterForId(ID_SF_DURATION_LONG), groupsFactory.getFilterForId(ID_SF_DURATION_EPIC), }, null), - groupsFactory.createFilterGroup(ID_SF_LICENSE_GRP, "License", true, + groupsFactory.createFilterGroup(ID_SF_LICENSE_GRP, + LibraryStringIds.SEARCH_FILTERS_LICENSE, true, ID_SF_LICENSE_ALL, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_LICENSE_ALL), groupsFactory.getFilterForId(ID_SF_LICENSE_COMMERCE), @@ -152,8 +168,10 @@ public String evaluateSelectedSortFilters() { private static class SoundcloudSortFilterItem extends FilterItem { private final String query; - SoundcloudSortFilterItem(final int identifier, final String name, final String query) { - super(identifier, name); + SoundcloudSortFilterItem(final int identifier, + final LibraryStringIds nameId, + final String query) { + super(identifier, nameId); this.query = query; } } @@ -161,9 +179,9 @@ private static class SoundcloudSortFilterItem extends FilterItem { private static final class SoundcloudContentFilterItem extends FilterItem { private final String urlEndpoint; - private SoundcloudContentFilterItem(final int identifier, final String name, + private SoundcloudContentFilterItem(final int identifier, final LibraryStringIds nameId, final String urlEndpoint) { - super(identifier, name); + super(identifier, nameId); this.urlEndpoint = urlEndpoint; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java index ec3d60630f..1357bd3cef 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java @@ -5,15 +5,11 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getValidJsonResponseBody; -import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_ALBUMS; -import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_ARTISTS; -import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_PLAYLISTS; -import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_SONGS; -import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_VIDEOS; import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import org.schabi.newpipe.extractor.search.SearchExtractor; +import org.schabi.newpipe.extractor.search.filter.FilterContainer; import org.schabi.newpipe.extractor.services.youtube.search.filter.YoutubeFilters; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; @@ -56,13 +52,13 @@ public YoutubeMusicSearchExtractor(final StreamingService service, super(service, linkHandler); } - private String getSearchType() { + private int getSearchTypeId() { final YoutubeFilters.MusicYoutubeContentFilterItem contentFilterItem = Utils.getFirstContentFilterItem(getLinkHandler()); - if (contentFilterItem != null && contentFilterItem.getName() != null) { - return contentFilterItem.getName(); + if (contentFilterItem != null) { + return contentFilterItem.getIdentifier(); } - return ""; + return FilterContainer.ITEM_IDENTIFIER_UNKNOWN; } @Override @@ -291,8 +287,9 @@ private void collectMusicStreamsFrom(final MultiInfoItemsCollector collector, .getObject("musicResponsiveListItemFlexColumnRenderer"); final JsonArray descriptionElements = flexColumnRenderer.getObject("text") .getArray("runs"); - final String searchType = getSearchType(); - if (searchType.equals(MUSIC_SONGS) || searchType.equals(MUSIC_VIDEOS)) { + final int searchTypeId = getSearchTypeId(); + if (searchTypeId == YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_SONGS + || searchTypeId == YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_VIDEOS) { collector.commit(new YoutubeStreamInfoItemExtractor(info, timeAgoParser) { @Override public String getUrl() throws ParsingException { @@ -338,7 +335,7 @@ public String getUploaderName() throws ParsingException { @Override public String getUploaderUrl() throws ParsingException { - if (searchType.equals(MUSIC_VIDEOS)) { + if (searchTypeId == YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_VIDEOS) { final JsonArray items = info.getObject("menu") .getObject("menuRenderer") .getArray("items"); @@ -390,7 +387,7 @@ public DateWrapper getUploadDate() { @Override public long getViewCount() throws ParsingException { - if (searchType.equals(MUSIC_SONGS)) { + if (searchTypeId == YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_SONGS) { return -1; } final String viewCount = descriptionElements @@ -423,7 +420,7 @@ public String getThumbnailUrl() throws ParsingException { } } }); - } else if (searchType.equals(MUSIC_ARTISTS)) { + } else if (searchTypeId == YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_ARTISTS) { collector.commit(new YoutubeChannelInfoItemExtractor(info) { @Override public String getThumbnailUrl() throws ParsingException { @@ -490,7 +487,8 @@ public String getDescription() { return null; } }); - } else if (searchType.equals(MUSIC_ALBUMS) || searchType.equals(MUSIC_PLAYLISTS)) { + } else if (searchTypeId == YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_ALBUMS + || searchTypeId == YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_PLAYLISTS) { collector.commit(new YoutubePlaylistInfoItemExtractor(info) { @Override public String getThumbnailUrl() throws ParsingException { @@ -550,7 +548,7 @@ public String getUrl() throws ParsingException { @Override public String getUploaderName() throws ParsingException { final String name; - if (searchType.equals(MUSIC_ALBUMS)) { + if (searchTypeId == YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_ALBUMS) { name = descriptionElements.getObject(2).getString("text"); } else { name = descriptionElements.getObject(0).getString("text"); @@ -563,7 +561,7 @@ public String getUploaderName() throws ParsingException { @Override public long getStreamCount() throws ParsingException { - if (searchType.equals(MUSIC_ALBUMS)) { + if (searchTypeId == YoutubeFilters.ID_CF_MAIN_YOUTUBE_MUSIC_ALBUMS) { return ITEM_COUNT_UNKNOWN; } final String count = descriptionElements.getObject(2) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java index 2c40a39f5e..6ac367d720 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeSearchQueryHandlerFactory.java @@ -11,16 +11,6 @@ public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory { - public static final String ALL = "all"; - public static final String VIDEOS = "videos"; - public static final String CHANNELS = "channels"; - public static final String PLAYLISTS = "playlists"; - - public static final String MUSIC_SONGS = "music_songs"; - public static final String MUSIC_VIDEOS = "music_videos"; - public static final String MUSIC_ALBUMS = "music_albums"; - public static final String MUSIC_PLAYLISTS = "music_playlists"; - public static final String MUSIC_ARTISTS = "music_artists"; private static YoutubeSearchQueryHandlerFactory instance = null; private YoutubeSearchQueryHandlerFactory() { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/search/filter/YoutubeFilters.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/search/filter/YoutubeFilters.java index 0f14e58ded..d976781c1d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/search/filter/YoutubeFilters.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/search/filter/YoutubeFilters.java @@ -6,6 +6,7 @@ import org.schabi.newpipe.extractor.search.filter.FilterContainer; import org.schabi.newpipe.extractor.search.filter.FilterGroup; import org.schabi.newpipe.extractor.search.filter.FilterItem; +import org.schabi.newpipe.extractor.search.filter.LibraryStringIds; import org.schabi.newpipe.extractor.services.youtube.search.filter.protobuf.DateFilter; import org.schabi.newpipe.extractor.services.youtube.search.filter.protobuf.Features; import org.schabi.newpipe.extractor.services.youtube.search.filter.protobuf.LengthFilter; @@ -21,15 +22,9 @@ public class YoutubeFilters extends BaseSearchFilters { public static final String UTF_8 = "UTF-8"; /** - * 'ALL' this is the default search content filter. + * 'ID_CF_MAIN_ALL' this is the default search content filter. * It has all sort filters that are available. */ - public static final String ALL = "all"; - public static final String VIDEOS = "videos"; - public static final String CHANNELS = "channels"; - public static final String PLAYLISTS = "playlists"; - // public static final String MOVIES = "movies"; - public static final int ID_CF_MAIN_GRP = 0; public static final int ID_CF_MAIN_ALL = 1; public static final int ID_CF_MAIN_VIDEOS = 2; @@ -71,12 +66,6 @@ public class YoutubeFilters extends BaseSearchFilters { public static final int ID_SF_FEATURES_LOCATION = 38; public static final int ID_SF_FEATURES_PURCHASED = 39; - public static final String MUSIC_SONGS = "music_songs"; - public static final String MUSIC_VIDEOS = "music_videos"; - public static final String MUSIC_ALBUMS = "music_albums"; - public static final String MUSIC_PLAYLISTS = "music_playlists"; - public static final String MUSIC_ARTISTS = "music_artists"; - private static final String SEARCH_URL = "https://www.youtube.com/results?search_query="; private static final String MUSIC_SEARCH_URL = "https://music.youtube.com/search?q="; @@ -197,64 +186,90 @@ protected void init() { /* 'Sort order' filter items */ groupsFactory.addFilterItem(new YoutubeSortOrderSortFilterItem( - ID_SF_SORT_BY_RELEVANCE, "Relevance", SortOrder.relevance)); + ID_SF_SORT_BY_RELEVANCE, + LibraryStringIds.SEARCH_FILTERS_RELEVANCE, SortOrder.relevance)); groupsFactory.addFilterItem(new YoutubeSortOrderSortFilterItem( - ID_SF_SORT_BY_RATING, "Rating", SortOrder.rating)); + ID_SF_SORT_BY_RATING, + LibraryStringIds.SEARCH_FILTERS_RATING, SortOrder.rating)); groupsFactory.addFilterItem(new YoutubeSortOrderSortFilterItem( - ID_SF_SORT_BY_DATE, "Date", SortOrder.date)); + ID_SF_SORT_BY_DATE, + LibraryStringIds.SEARCH_FILTERS_DATE, SortOrder.date)); groupsFactory.addFilterItem(new YoutubeSortOrderSortFilterItem( - ID_SF_SORT_BY_VIEWS, "Views", SortOrder.views)); + ID_SF_SORT_BY_VIEWS, + LibraryStringIds.SEARCH_FILTERS_VIEWS, SortOrder.views)); /* 'Date' filter items */ groupsFactory.addFilterItem(new YoutubeDateSortFilterItem( - ID_SF_UPLOAD_DATE_ALL, "All", null)); + ID_SF_UPLOAD_DATE_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, null)); groupsFactory.addFilterItem(new YoutubeDateSortFilterItem( - ID_SF_UPLOAD_DATE_HOUR, "Hour", DateFilter.hour)); + ID_SF_UPLOAD_DATE_HOUR, + LibraryStringIds.SEARCH_FILTERS_LAST_HOUR, DateFilter.hour)); groupsFactory.addFilterItem(new YoutubeDateSortFilterItem( - ID_SF_UPLOAD_DATE_DAY, "Day", DateFilter.day)); + ID_SF_UPLOAD_DATE_DAY, + LibraryStringIds.SEARCH_FILTERS_TODAY, DateFilter.day)); groupsFactory.addFilterItem(new YoutubeDateSortFilterItem( - ID_SF_UPLOAD_DATE_WEEK, "Week", DateFilter.week)); + ID_SF_UPLOAD_DATE_WEEK, + LibraryStringIds.SEARCH_FILTERS_THIS_WEEK, DateFilter.week)); groupsFactory.addFilterItem(new YoutubeDateSortFilterItem( - ID_SF_UPLOAD_DATE_MONTH, "Month", DateFilter.month)); + ID_SF_UPLOAD_DATE_MONTH, + LibraryStringIds.SEARCH_FILTERS_THIS_MONTH, DateFilter.month)); groupsFactory.addFilterItem(new YoutubeDateSortFilterItem( - ID_SF_UPLOAD_DATE_YEAR, "Year", DateFilter.year)); + ID_SF_UPLOAD_DATE_YEAR, + LibraryStringIds.SEARCH_FILTERS_THIS_YEAR, DateFilter.year)); /* 'Duration' filter items */ groupsFactory.addFilterItem(new YoutubeLenSortFilterItem( - ID_SF_DURATION_ALL, "All", null)); + ID_SF_DURATION_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, null)); groupsFactory.addFilterItem(new YoutubeLenSortFilterItem( - ID_SF_DURATION_SHORT, "Under 4 min", LengthFilter.duration_short)); + ID_SF_DURATION_SHORT, + LibraryStringIds.SEARCH_FILTERS_UNDER_4_MIN, LengthFilter.duration_short)); groupsFactory.addFilterItem(new YoutubeLenSortFilterItem( - ID_SF_DURATION_MEDIUM, "4-20 min", LengthFilter.duration_medium)); + ID_SF_DURATION_MEDIUM, + LibraryStringIds.SEARCH_FILTERS_4_20_MIN, LengthFilter.duration_medium)); groupsFactory.addFilterItem(new YoutubeLenSortFilterItem( - ID_SF_DURATION_LONG, "Over 20 min", LengthFilter.duration_long)); + ID_SF_DURATION_LONG, + LibraryStringIds.SEARCH_FILTERS_OVER_20_MIN, LengthFilter.duration_long)); /* 'features' filter items */ groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_LIVE, "Live", Features.live)); + ID_SF_FEATURES_LIVE, + LibraryStringIds.SEARCH_FILTERS_LIVE, Features.live)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_4K, "4k", Features.is_4k)); + ID_SF_FEATURES_4K, + LibraryStringIds.SEARCH_FILTERS_4K, Features.is_4k)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_HD, "HD", Features.is_hd)); + ID_SF_FEATURES_HD, + LibraryStringIds.SEARCH_FILTERS_HD, Features.is_hd)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_SUBTITLES, "Subtitles", Features.subtitles)); + ID_SF_FEATURES_SUBTITLES, + LibraryStringIds.SEARCH_FILTERS_SUBTITLES, Features.subtitles)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_CCOMMONS, "Ccommons", Features.ccommons)); + ID_SF_FEATURES_CCOMMONS, + LibraryStringIds.SEARCH_FILTERS_CCOMMONS, Features.ccommons)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_360, "360°", Features.is_360)); + ID_SF_FEATURES_360, + LibraryStringIds.SEARCH_FILTERS_360, Features.is_360)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_VR180, "VR180", Features.is_vr180)); + ID_SF_FEATURES_VR180, + LibraryStringIds.SEARCH_FILTERS_VR180, Features.is_vr180)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_3D, "3d", Features.is_3d)); + ID_SF_FEATURES_3D, + LibraryStringIds.SEARCH_FILTERS_3D, Features.is_3d)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_HDR, "Hdr", Features.is_hdr)); + ID_SF_FEATURES_HDR, + LibraryStringIds.SEARCH_FILTERS_HDR, Features.is_hdr)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_LOCATION, "Location", Features.location)); + ID_SF_FEATURES_LOCATION, + LibraryStringIds.SEARCH_FILTERS_LOCATION, Features.location)); groupsFactory.addFilterItem(new YoutubeFeatureSortFilterItem( - ID_SF_FEATURES_PURCHASED, "Purchased", Features.purchased)); + ID_SF_FEATURES_PURCHASED, + LibraryStringIds.SEARCH_FILTERS_PURCHASED, Features.purchased)); final FilterGroup sortByGroup = - groupsFactory.createFilterGroup(ID_SF_SORT_BY_GRP, "Sort by", true, + groupsFactory.createFilterGroup(ID_SF_SORT_BY_GRP, + LibraryStringIds.SEARCH_FILTERS_SORT_BY, true, ID_SF_SORT_BY_RELEVANCE, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_SORT_BY_RELEVANCE), groupsFactory.getFilterForId(ID_SF_SORT_BY_RATING), @@ -263,7 +278,8 @@ protected void init() { }, null); final FilterGroup uploadDateGroup = - groupsFactory.createFilterGroup(ID_SF_UPLOAD_DATE_GRP, "Upload Date", true, + groupsFactory.createFilterGroup(ID_SF_UPLOAD_DATE_GRP, + LibraryStringIds.SEARCH_FILTERS_UPLOAD_DATE, true, ID_SF_UPLOAD_DATE_ALL, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_UPLOAD_DATE_ALL), groupsFactory.getFilterForId(ID_SF_UPLOAD_DATE_HOUR), @@ -274,7 +290,8 @@ protected void init() { }, null); final FilterGroup durationGroup = - groupsFactory.createFilterGroup(ID_SF_DURATION_GRP, "Duration", true, + groupsFactory.createFilterGroup(ID_SF_DURATION_GRP, + LibraryStringIds.SEARCH_FILTERS_DURATION, true, ID_SF_DURATION_ALL, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_DURATION_ALL), groupsFactory.getFilterForId(ID_SF_DURATION_SHORT), @@ -283,7 +300,8 @@ protected void init() { }, null); final FilterGroup featureGroup = - groupsFactory.createFilterGroup(ID_SF_FEATURES_GRP, "Features", false, + groupsFactory.createFilterGroup(ID_SF_FEATURES_GRP, + LibraryStringIds.SEARCH_FILTERS_FEATURES, false, FilterContainer.ITEM_IDENTIFIER_UNKNOWN, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_FEATURES_LIVE), groupsFactory.getFilterForId(ID_SF_FEATURES_4K), @@ -324,7 +342,8 @@ protected void init() { sortByGroup, uploadDateGroup, durationGroup, - groupsFactory.createSortGroup(ID_SF_FEATURES_GRP, "Features", false, + groupsFactory.createSortGroup(ID_SF_FEATURES_GRP, + CommonStrings.SEARCH_FILTERS_FEATURES, false, Filter.ITEM_IDENTIFIER_UNKNOWN, new FilterItem[]{ groupsFactory.getFilterForId(ID_SF_FEATURES_4K), groupsFactory.getFilterForId(ID_SF_FEATURES_HD), @@ -343,38 +362,48 @@ protected void init() { /* content filters with sort filters */ groupsFactory.addFilterItem(new YoutubeContentFilterItem( - ID_CF_MAIN_ALL, ALL, null)); + ID_CF_MAIN_ALL, + LibraryStringIds.SEARCH_FILTERS_ALL, null)); groupsFactory.addFilterItem(new YoutubeContentFilterItem( - ID_CF_MAIN_VIDEOS, VIDEOS, TypeFilter.video)); + ID_CF_MAIN_VIDEOS, + LibraryStringIds.SEARCH_FILTERS_VIDEOS, TypeFilter.video)); groupsFactory.addFilterItem(new YoutubeContentFilterItem( - ID_CF_MAIN_CHANNELS, CHANNELS, TypeFilter.channel)); + ID_CF_MAIN_CHANNELS, + LibraryStringIds.SEARCH_FILTERS_CHANNELS, TypeFilter.channel)); groupsFactory.addFilterItem(new YoutubeContentFilterItem( - ID_CF_MAIN_PLAYLISTS, PLAYLISTS, TypeFilter.playlist)); + ID_CF_MAIN_PLAYLISTS, + LibraryStringIds.SEARCH_FILTERS_PLAYLISTS, TypeFilter.playlist)); /* // movies are only available for logged in users builder.addFilterItem(new YoutubeContentFilterItem( - ID_CF_MAIN_MOVIES, MOVIES, TypeFilter.movie)); + ID_CF_MAIN_MOVIES, + CommonStrings.SEARACH_FILTERS_MOVIES, TypeFilter.movie)); */ /* Youtube Music content filters */ groupsFactory.addFilterItem(new MusicYoutubeContentFilterItem( - ID_CF_MAIN_YOUTUBE_MUSIC_SONGS, MUSIC_SONGS, + ID_CF_MAIN_YOUTUBE_MUSIC_SONGS, + LibraryStringIds.SEARCH_FILTERS_SONGS, "Eg-KAQwIARAAGAAgACgAMABqChAEEAUQAxAKEAk%3D" )); groupsFactory.addFilterItem(new MusicYoutubeContentFilterItem( - ID_CF_MAIN_YOUTUBE_MUSIC_VIDEOS, MUSIC_VIDEOS, + ID_CF_MAIN_YOUTUBE_MUSIC_VIDEOS, + LibraryStringIds.SEARCH_FILTERS_VIDEOS, "Eg-KAQwIABABGAAgACgAMABqChAEEAUQAxAKEAk%3D" )); groupsFactory.addFilterItem(new MusicYoutubeContentFilterItem( - ID_CF_MAIN_YOUTUBE_MUSIC_ALBUMS, MUSIC_ALBUMS, + ID_CF_MAIN_YOUTUBE_MUSIC_ALBUMS, + LibraryStringIds.SEARCH_FILTERS_ALBUMS, "Eg-KAQwIABAAGAEgACgAMABqChAEEAUQAxAKEAk%3D" )); groupsFactory.addFilterItem(new MusicYoutubeContentFilterItem( - ID_CF_MAIN_YOUTUBE_MUSIC_PLAYLISTS, MUSIC_PLAYLISTS, + ID_CF_MAIN_YOUTUBE_MUSIC_PLAYLISTS, + LibraryStringIds.SEARCH_FILTERS_PLAYLISTS, "Eg-KAQwIABAAGAAgACgBMABqChAEEAUQAxAKEAk%3D" )); groupsFactory.addFilterItem(new MusicYoutubeContentFilterItem( - ID_CF_MAIN_YOUTUBE_MUSIC_ARTISTS, MUSIC_ARTISTS, + ID_CF_MAIN_YOUTUBE_MUSIC_ARTISTS, + LibraryStringIds.SEARCH_FILTERS_ARTISTS, "Eg-KAQwIABAAGAAgASgAMABqChAEEAUQAxAKEAk%3D" )); @@ -387,7 +416,8 @@ protected void init() { groupsFactory.getFilterForId(ID_CF_MAIN_PLAYLISTS), // groupsFactory.getFilterForId(ID_CF_MAIN_MOVIES), groupsFactory.getFilterForId(groupsFactory.addFilterItem( - new FilterItem.DividerItem("YouTube Music"))), + new FilterItem.DividerItem( + LibraryStringIds.SEARCH_FILTERS_YOUTUBE_MUSIC))), groupsFactory.getFilterForId(ID_CF_MAIN_YOUTUBE_MUSIC_SONGS), groupsFactory.getFilterForId(ID_CF_MAIN_YOUTUBE_MUSIC_VIDEOS), groupsFactory.getFilterForId(ID_CF_MAIN_YOUTUBE_MUSIC_ALBUMS), @@ -405,9 +435,9 @@ private void addContentFilterTypeAndSortVariant(final int contentFilterId, private static class YoutubeSortOrderSortFilterItem extends YoutubeSortFilterItem { private final SortOrder sortOrder; - YoutubeSortOrderSortFilterItem(final int identifier, final String name, + YoutubeSortOrderSortFilterItem(final int identifier, final LibraryStringIds nameId, final SortOrder sortOrder) { - super(identifier, name); + super(identifier, nameId); this.sortOrder = sortOrder; } @@ -419,9 +449,9 @@ public SortOrder get() { private static class YoutubeDateSortFilterItem extends YoutubeSortFilterItem { private final DateFilter dateFilter; - YoutubeDateSortFilterItem(final int identifier, final String name, + YoutubeDateSortFilterItem(final int identifier, final LibraryStringIds nameId, final DateFilter dateFilter) { - super(identifier, name); + super(identifier, nameId); this.dateFilter = dateFilter; } @@ -433,9 +463,9 @@ public DateFilter get() { private static class YoutubeLenSortFilterItem extends YoutubeSortFilterItem { private final LengthFilter lengthFilter; - YoutubeLenSortFilterItem(final int identifier, final String name, + YoutubeLenSortFilterItem(final int identifier, final LibraryStringIds nameId, final LengthFilter lengthFilter) { - super(identifier, name); + super(identifier, nameId); this.lengthFilter = lengthFilter; } @@ -447,9 +477,9 @@ public LengthFilter get() { private static class YoutubeFeatureSortFilterItem extends YoutubeSortFilterItem { private final Features feature; - YoutubeFeatureSortFilterItem(final int identifier, final String name, + YoutubeFeatureSortFilterItem(final int identifier, final LibraryStringIds nameId, final Features feature) { - super(identifier, name); + super(identifier, nameId); this.feature = feature; } @@ -460,8 +490,8 @@ public Features get() { public static class YoutubeSortFilterItem extends FilterItem { - public YoutubeSortFilterItem(final int identifier, final String name) { - super(identifier, name); + public YoutubeSortFilterItem(final int identifier, final LibraryStringIds nameId) { + super(identifier, nameId); } } @@ -469,13 +499,13 @@ public static class YoutubeContentFilterItem extends YoutubeSortFilterItem { protected String params; private TypeFilter contentType = null; - public YoutubeContentFilterItem(final int identifier, final String name) { - super(identifier, name); + public YoutubeContentFilterItem(final int identifier, final LibraryStringIds nameId) { + super(identifier, nameId); } - public YoutubeContentFilterItem(final int identifier, final String name, + public YoutubeContentFilterItem(final int identifier, final LibraryStringIds nameId, final TypeFilter contentType) { - super(identifier, name); + super(identifier, nameId); this.params = ""; this.contentType = contentType; } @@ -494,9 +524,9 @@ private TypeFilter getContentType() { } public static class MusicYoutubeContentFilterItem extends YoutubeContentFilterItem { - public MusicYoutubeContentFilterItem(final int identifier, final String name, + public MusicYoutubeContentFilterItem(final int identifier, final LibraryStringIds nameId, final String params) { - super(identifier, name); + super(identifier, nameId); this.params = params; } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultFiltersTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultFiltersTest.java index 29654f09e3..1f80258d01 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultFiltersTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultFiltersTest.java @@ -81,7 +81,7 @@ void noSortFilterItemShouldBeNull() { final List sortFilters = getAllSortFiltersList(); for (final FilterItem item : sortFilters) { assertNotNull(item); - assertNotNull(item.getName()); + assertNotNull(item.getNameId()); } } @@ -206,7 +206,7 @@ protected abstract void contentFiltersThatHaveCorrespondingSortFiltersTestSetup( private void checkThatNoFilterItemAndItsNameIsNull(final List filterItems) { for (final FilterItem item : filterItems) { assertNotNull(item); - assertNotNull(item.getName()); + assertNotNull(item.getNameId()); } }