Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework content and sort filter framework #904

Open
wants to merge 40 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3398a54
searchfilters: a framework to create sort and content filter objects
evermind-zz Aug 18, 2022
8409215
equals hashCode to FilterItem
Stypox Dec 29, 2023
3956e22
merge later ../extractor/src/main/java/org/schabi/newpipe/extractor/s…
evermind-zz Nov 13, 2022
b8eb121
searchfilters: convert core components to new framework
evermind-zz Aug 18, 2022
1dc746a
Changes due to channel tabs
Stypox Dec 29, 2023
9e75344
searchfilters: convert Peertube to new framework
evermind-zz Aug 18, 2022
c7ef8a9
[PeerTube]
Stypox Dec 29, 2023
f484f20
searchfilters: convert Soundcloud to use new framework
evermind-zz Aug 18, 2022
a043cbd
[SoundCloud]
Stypox Dec 29, 2023
17320ef
searchfilters: Soundcloud give empty page if no more results
evermind-zz Aug 19, 2022
d1bf446
searchfilters: Make SoundcloudSearchQueryHandlerFactory singleton
evermind-zz Aug 19, 2022
e084338
searchfilters: convert media_ccc to new framework
evermind-zz Aug 18, 2022
debb776
searchfilters: convert bandcamp to new framework
evermind-zz Aug 18, 2022
8568f19
[Bandcamp]
Stypox Dec 29, 2023
0a4b889
searchfilters: convert youtube to new framework
Stypox Dec 30, 2023
ec19719
[YouTube]
Stypox Dec 29, 2023
af1f1de
bandcamp: remove limit page.size as statement seems no longer true
evermind-zz Aug 18, 2022
d7b0430
searchfilters: added common helper methods for .*SearchExtractorTest's
evermind-zz Oct 11, 2022
49c3545
Fix base tests
Stypox Dec 30, 2023
e06fac6
searchfilters: Test: adjust PeerTube tests
evermind-zz Oct 11, 2022
c6b335c
Fix peertube tests
Stypox Dec 30, 2023
43479ab
searchfilters: Test: adjust SoundCloud tests
evermind-zz Oct 11, 2022
4a8b7f6
Fix soundcloud tests
Stypox Dec 30, 2023
1fc0fc7
searchfilters: Test: adjust MediaCCC tests
evermind-zz Oct 11, 2022
019ef62
searchfilters: Test: adjust Bandcamp tests
Stypox Dec 30, 2023
8280fd4
searchfilters: Test: adjust and extend YouTube tests
evermind-zz Oct 11, 2022
3e68e17
Fix yt tests
Stypox Dec 30, 2023
5a02063
searchfilters: unit tests for all derived BaseSearchFilters classes
evermind-zz Oct 20, 2022
1d552c4
searchfilters: an enum class which with strings ids that will be used…
evermind-zz Oct 28, 2022
78c8a60
searchfilters: convert to using LibraryStringIds to identify strings
evermind-zz Nov 1, 2022
11d268f
searchfilters: annotate methods and their parameters as Nullable or N…
evermind-zz Nov 13, 2022
4210592
searchfilters: annotate changed method signatures with Nullable or No…
evermind-zz Nov 13, 2022
0985afa
searchfilters: use base64 methods from okio to support <= Android Oreo
evermind-zz Nov 17, 2022
04f03ab
searchfilters: Moving DividerItem from NewPipeExtractor into NewPipe
evermind-zz Nov 22, 2022
e81796f
[Youtube] Update search mocks
Stypox Dec 30, 2023
23fe41d
searchfilters: Peertube: handle different endpoints for channel and p…
evermind-zz Feb 9, 2023
659deb0
searchfilters: Peertube: remove search option ID_CF_MAIN_ALL
evermind-zz Feb 11, 2023
dd252d3
searchfilters: bump squareup wire version to 4.5.2
evermind-zz Apr 4, 2023
70a2b63
searchfilters: Peertube restore different endpoints to fix peertube c…
evermind-zz Dec 30, 2023
67366ea
searchfilters: FilterItem now 'implements' Serializable to fix Parcel…
evermind-zz Jan 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions extractor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'checkstyle'
id 'com.squareup.wire' version '4.5.2'
}

test {
Expand All @@ -18,6 +19,15 @@ checkstyle {
toolVersion checkstyleVersion
}

checkstyleMain
// exclude the wire generated youtube protobuf files
.exclude ('org/schabi/newpipe/extractor/services/youtube/search/filter/protobuf/')

wire {
java {
}
}

checkstyleTest {
enabled false // do not checkstyle test files
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package org.schabi.newpipe.extractor;

import org.schabi.newpipe.extractor.search.filter.FilterItem;

import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;

import java.util.List;

public abstract class ListInfo<T extends InfoItem> extends Info {
private List<T> relatedItems;
private Page nextPage = null;
private final List<String> contentFilters;
private final String sortFilter;
private final List<FilterItem> contentFilters;
private final List<FilterItem> sortFilter;

public ListInfo(final int serviceId,
final String id,
final String url,
final String originalUrl,
final String name,
final List<String> contentFilter,
final String sortFilter) {
final List<FilterItem> contentFilter,
final List<FilterItem> sortFilter) {
super(serviceId, id, url, originalUrl, name);
this.contentFilters = contentFilter;
this.sortFilter = sortFilter;
Expand Down Expand Up @@ -50,11 +52,11 @@ public void setNextPage(final Page page) {
this.nextPage = page;
}

public List<String> getContentFilters() {
public List<FilterItem> getContentFilters() {
return contentFilters;
}

public String getSortFilter() {
public List<FilterItem> getSortFilter() {
return sortFilter;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.schabi.newpipe.extractor;

import org.schabi.newpipe.extractor.search.filter.FilterItem;

import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor;
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
Expand Down Expand Up @@ -246,23 +248,24 @@ public abstract CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandl
//////////////////////////////////////////////////////////////////////////*/

public SearchExtractor getSearchExtractor(final String query,
final List<String> contentFilter,
final String sortFilter) throws ExtractionException {
final List<FilterItem> contentFilter,
final List<FilterItem> sortFilter)
throws ExtractionException {
return getSearchExtractor(getSearchQHFactory()
.fromQuery(query, contentFilter, sortFilter));
}

public ChannelExtractor getChannelExtractor(final String id,
final List<String> contentFilter,
final String sortFilter)
final List<FilterItem> contentFilter,
final List<FilterItem> sortFilter)
throws ExtractionException {
return getChannelExtractor(getChannelLHFactory()
.fromQuery(id, contentFilter, sortFilter));
}

public PlaylistExtractor getPlaylistExtractor(final String id,
final List<String> contentFilter,
final String sortFilter)
final List<FilterItem> contentFilter,
final List<FilterItem> sortFilter)
throws ExtractionException {
return getPlaylistExtractor(getPlaylistLHFactory()
.fromQuery(id, contentFilter, sortFilter));
Expand All @@ -280,18 +283,18 @@ public ChannelExtractor getChannelExtractor(final String url) throws ExtractionE
return getChannelExtractor(getChannelLHFactory().fromUrl(url));
}

public ChannelTabExtractor getChannelTabExtractorFromId(final String id, final String tab)
public ChannelTabExtractor getChannelTabExtractorFromId(final String id, final FilterItem tab)
throws ExtractionException {
return getChannelTabExtractor(getChannelTabLHFactory().fromQuery(
id, Collections.singletonList(tab), ""));
id, List.of(tab), List.of()));
}

public ChannelTabExtractor getChannelTabExtractorFromIdAndBaseUrl(final String id,
final String tab,
final FilterItem tab,
final String baseUrl)
throws ExtractionException {
return getChannelTabExtractor(getChannelTabLHFactory().fromQuery(
id, Collections.singletonList(tab), "", baseUrl));
id, List.of(tab), List.of(), baseUrl));
}

public PlaylistExtractor getPlaylistExtractor(final String url) throws ExtractionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.search.filter.FilterItem;

import javax.annotation.Nonnull;

Expand All @@ -17,9 +18,14 @@ protected ChannelTabExtractor(@Nonnull final StreamingService service,
super(service, linkHandler);
}

@Nonnull
public FilterItem getChannelTabType() {
return getLinkHandler().getContentFilters().get(0);
}

@Nonnull
@Override
public String getName() {
return getLinkHandler().getContentFilters().get(0);
return getChannelTabType().getNameId().name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ChannelTabInfo extends ListInfo<InfoItem> {

public ChannelTabInfo(final int serviceId,
@Nonnull final ListLinkHandler linkHandler) {
super(serviceId, linkHandler, linkHandler.getContentFilters().get(0));
super(serviceId, linkHandler, linkHandler.getContentFilters().get(0).getNameId().name());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
package org.schabi.newpipe.extractor.channel.tabs;

import static org.schabi.newpipe.extractor.search.filter.LibraryStringIds.CHANNEL_TAB_ALBUMS;
import static org.schabi.newpipe.extractor.search.filter.LibraryStringIds.CHANNEL_TAB_CHANNELS;
import static org.schabi.newpipe.extractor.search.filter.LibraryStringIds.CHANNEL_TAB_LIVESTREAMS;
import static org.schabi.newpipe.extractor.search.filter.LibraryStringIds.CHANNEL_TAB_PLAYLISTS;
import static org.schabi.newpipe.extractor.search.filter.LibraryStringIds.CHANNEL_TAB_SHORTS;
import static org.schabi.newpipe.extractor.search.filter.LibraryStringIds.CHANNEL_TAB_TRACKS;
import static org.schabi.newpipe.extractor.search.filter.LibraryStringIds.CHANNEL_TAB_VIDEOS;

import org.schabi.newpipe.extractor.search.filter.FilterItem;

/**
* Constants of channel tabs supported by the extractor.
*/
public final class ChannelTabs {
public static final String VIDEOS = "videos";
public static final String TRACKS = "tracks";
public static final String SHORTS = "shorts";
public static final String LIVESTREAMS = "livestreams";
public static final String CHANNELS = "channels";
public static final String PLAYLISTS = "playlists";
public static final String ALBUMS = "albums";
public static final int ID_VIDEOS = 0;
public static final int ID_TRACKS = 1;
public static final int ID_SHORTS = 2;
public static final int ID_LIVESTREAMS = 3;
public static final int ID_CHANNELS = 4;
public static final int ID_PLAYLISTS = 5;
public static final int ID_ALBUMS = 6;

public static final FilterItem VIDEOS = new FilterItem(ID_VIDEOS, CHANNEL_TAB_VIDEOS);
public static final FilterItem TRACKS = new FilterItem(ID_TRACKS, CHANNEL_TAB_TRACKS);
public static final FilterItem SHORTS = new FilterItem(ID_SHORTS, CHANNEL_TAB_SHORTS);
public static final FilterItem LIVESTREAMS =
new FilterItem(ID_LIVESTREAMS, CHANNEL_TAB_LIVESTREAMS);
public static final FilterItem CHANNELS = new FilterItem(ID_CHANNELS, CHANNEL_TAB_CHANNELS);
public static final FilterItem PLAYLISTS = new FilterItem(ID_PLAYLISTS, CHANNEL_TAB_PLAYLISTS);
public static final FilterItem ALBUMS = new FilterItem(ID_ALBUMS, CHANNEL_TAB_ALBUMS);

private ChannelTabs() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.schabi.newpipe.extractor.exceptions;

import org.schabi.newpipe.extractor.search.filter.FilterItem;

public final class UnsupportedTabException extends UnsupportedOperationException {
public UnsupportedTabException(final String unsupportedTab) {
public UnsupportedTabException(final FilterItem unsupportedTab) {
super("Unsupported tab " + unsupportedTab);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.schabi.newpipe.extractor.feed;

import org.schabi.newpipe.extractor.search.filter.FilterItem;

import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe;
Expand All @@ -8,6 +10,7 @@
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.utils.ExtractorHelper;


import java.io.IOException;
import java.util.List;

Expand All @@ -18,8 +21,8 @@ public FeedInfo(final int serviceId,
final String url,
final String originalUrl,
final String name,
final List<String> contentFilter,
final String sortFilter) {
final List<FilterItem> contentFilter,
final List<FilterItem> sortFilter) {
super(serviceId, id, url, originalUrl, name, contentFilter, sortFilter);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package org.schabi.newpipe.extractor.linkhandler;

import org.schabi.newpipe.extractor.search.filter.FilterItem;

import java.util.Collections;
import java.util.List;

public class ListLinkHandler extends LinkHandler {
protected final List<String> contentFilters;
protected final String sortFilter;
protected final List<FilterItem> contentFilters;
protected final List<FilterItem> sortFilter;

public ListLinkHandler(final String originalUrl,
final String url,
final String id,
final List<String> contentFilters,
final String sortFilter) {
final List<FilterItem> selectedContentFilters,
final List<FilterItem> selectedSortFilter) {
super(originalUrl, url, id);
this.contentFilters = Collections.unmodifiableList(contentFilters);
this.sortFilter = sortFilter;
this.contentFilters = Collections.unmodifiableList(selectedContentFilters);
this.sortFilter = selectedSortFilter;
}

public ListLinkHandler(final ListLinkHandler handler) {
Expand All @@ -30,14 +32,14 @@ public ListLinkHandler(final LinkHandler handler) {
handler.url,
handler.id,
Collections.emptyList(),
"");
Collections.emptyList());
}

public List<String> getContentFilters() {
public List<FilterItem> getContentFilters() {
return contentFilters;
}

public String getSortFilter() {
public List<FilterItem> getSortFilter() {
return sortFilter;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package org.schabi.newpipe.extractor.linkhandler;

import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
import org.schabi.newpipe.extractor.utils.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {

///////////////////////////////////
// To Override
///////////////////////////////////

public abstract String getUrl(String id, List<String> contentFilter, String sortFilter)
public abstract String getUrl(String id,
@Nonnull List<FilterItem> contentFilter,
@Nullable List<FilterItem> sortFilter)
Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why @Nonnull content filter but @Nullable sort filter?

Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we just use one array with FilterItem and stop making the distinction between content and sort filters? What is the advantage of having two separate arrays?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a content filter might have a different set of sort filters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there can already be content filters from various available filter groups, so why can't sort filters be just another filter group? Maybe I'm missing something

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to review my code again. I think I thought about that.

throws ParsingException, UnsupportedOperationException;

public String getUrl(final String id,
final List<String> contentFilter,
final String sortFilter,
final List<FilterItem> contentFilter,
final List<FilterItem> sortFilter,
Comment on lines +25 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other @Nonnull and @Nullable annotations are missing in this file (and all derivate classes)

final String baseUrl)
throws ParsingException, UnsupportedOperationException {
return getUrl(id, contentFilter, sortFilter);
Expand Down Expand Up @@ -51,16 +56,16 @@ public ListLinkHandler fromId(final String id, final String baseUrl) throws Pars
return new ListLinkHandler(super.fromId(id, baseUrl));
}

public ListLinkHandler fromQuery(final String id,
final List<String> contentFilters,
final String sortFilter) throws ParsingException {
final String url = getUrl(id, contentFilters, sortFilter);
return new ListLinkHandler(url, url, id, contentFilters, sortFilter);
public ListLinkHandler fromQuery(final String query,
final List<FilterItem> contentFilter,
final List<FilterItem> sortFilter) throws ParsingException {
final String url = getUrl(query, contentFilter, sortFilter);
return new ListLinkHandler(url, url, query, contentFilter, sortFilter);
}

public ListLinkHandler fromQuery(final String id,
final List<String> contentFilters,
final String sortFilter,
final List<FilterItem> contentFilters,
final List<FilterItem> sortFilter,
final String baseUrl) throws ParsingException {
final String url = getUrl(id, contentFilters, sortFilter, baseUrl);
return new ListLinkHandler(url, url, id, contentFilters, sortFilter);
Expand All @@ -74,31 +79,12 @@ public ListLinkHandler fromQuery(final String id,
* @return the url corresponding to id without any filters applied
*/
public String getUrl(final String id) throws ParsingException, UnsupportedOperationException {
return getUrl(id, new ArrayList<>(0), "");
return getUrl(id, List.of(), List.of());
}

@Override
public String getUrl(final String id, final String baseUrl) throws ParsingException {
return getUrl(id, new ArrayList<>(0), "", baseUrl);
}

/**
* Will returns content filter the corresponding extractor can handle like "channels", "videos",
* "music", etc.
*
* @return filter that can be applied when building a query for getting a list
*/
public String[] getAvailableContentFilter() {
return new String[0];
}

/**
* Will returns sort filter the corresponding extractor can handle like "A-Z", "oldest first",
* "size", etc.
*
* @return filter that can be applied when building a query for getting a list
*/
public String[] getAvailableSortFilter() {
return new String[0];
public String getUrl(final String id, final String baseUrl)
throws ParsingException, UnsupportedOperationException {
return getUrl(id, List.of(), List.of(), baseUrl);
}
}
Loading