diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java new file mode 100644 index 000000000..ef56da31d --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListUrlIdHandler.java @@ -0,0 +1,31 @@ +package org.schabi.newpipe.extractor; + +import org.schabi.newpipe.extractor.exceptions.ParsingException; + +public abstract class ListUrlIdHandler extends UrlIdHandler { + + public abstract String getUrl(String id, String[] contentFilter, String sortFilter) throws ParsingException; + + @Override + public String getUrl(String id) throws ParsingException { + return getUrl(id, new String[0], null); + } + + /** + * 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]; + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java index 6fe43ec8a..9e327c5fc 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java @@ -22,16 +22,16 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; * along with NewPipe. If not, see . */ -public interface UrlIdHandler { +public abstract class UrlIdHandler { - String getUrl(String id) throws ParsingException; - String getId(String url) throws ParsingException; - String cleanUrl(String complexUrl) throws ParsingException; + public abstract String getUrl(String id) throws ParsingException; + public abstract String getId(String url) throws ParsingException; + public abstract String cleanUrl(String complexUrl) throws ParsingException; /** * When a VIEW_ACTION is caught this function will test if the url delivered within the calling * Intent was meant to be watched with this Service. * Return false if this service shall not allow to be called through ACTIONs. */ - boolean acceptUrl(String url); + public abstract boolean acceptUrl(String url); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUrlIdHandler.java index 04902eb3a..9498671ab 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUrlIdHandler.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.services.soundcloud; import org.jsoup.Jsoup; import org.jsoup.nodes.Element; +import org.schabi.newpipe.extractor.ListUrlIdHandler; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -10,7 +11,7 @@ import org.schabi.newpipe.extractor.utils.Utils; import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; -public class SoundcloudChannelUrlIdHandler implements UrlIdHandler { +public class SoundcloudChannelUrlIdHandler extends ListUrlIdHandler { private static final SoundcloudChannelUrlIdHandler instance = new SoundcloudChannelUrlIdHandler(); private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + "(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$"; @@ -20,7 +21,7 @@ public class SoundcloudChannelUrlIdHandler implements UrlIdHandler { } @Override - public String getUrl(String id) throws ParsingException { + public String getUrl(String id, String[] contentFilter, String sortFilter) throws ParsingException { try { return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/" + id); } catch (Exception e) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandler.java index b26f0deb0..bc8a16190 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandler.java @@ -1,13 +1,14 @@ package org.schabi.newpipe.extractor.services.soundcloud; +import org.schabi.newpipe.extractor.ListUrlIdHandler; import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.utils.Parser; -public class SoundcloudChartsUrlIdHandler implements UrlIdHandler { +public class SoundcloudChartsUrlIdHandler extends ListUrlIdHandler { private final String TOP_URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top)?/?([#?].*)?$"; private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top|/new)?/?([#?].*)?$"; - public String getUrl(String id) { + public String getUrl(String id, String[] contentFilter, String sortFilter) { if (id.equals("Top 50")) { return "https://soundcloud.com/charts/top"; } else { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUrlIdHandler.java index 9518f1f9a..ccad52787 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUrlIdHandler.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.services.soundcloud; import org.jsoup.Jsoup; import org.jsoup.nodes.Element; +import org.schabi.newpipe.extractor.ListUrlIdHandler; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -10,7 +11,7 @@ import org.schabi.newpipe.extractor.utils.Utils; import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; -public class SoundcloudPlaylistUrlIdHandler implements UrlIdHandler { +public class SoundcloudPlaylistUrlIdHandler extends ListUrlIdHandler { private static final SoundcloudPlaylistUrlIdHandler instance = new SoundcloudPlaylistUrlIdHandler(); private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + "/sets/[0-9a-z_-]+/?([#?].*)?$"; @@ -20,7 +21,7 @@ public class SoundcloudPlaylistUrlIdHandler implements UrlIdHandler { } @Override - public String getUrl(String id) throws ParsingException { + public String getUrl(String id, String[] contentFilter, String sortFilter) throws ParsingException { try { return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/playlists/" + id); } catch (Exception e) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandler.java index b38dac032..0b9dd0286 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandler.java @@ -10,7 +10,7 @@ import org.schabi.newpipe.extractor.utils.Utils; import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; -public class SoundcloudStreamUrlIdHandler implements UrlIdHandler { +public class SoundcloudStreamUrlIdHandler extends UrlIdHandler { private static final SoundcloudStreamUrlIdHandler instance = new SoundcloudStreamUrlIdHandler(); private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + "/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$"; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandler.java index bc9ce6811..259a5bf30 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandler.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.extractor.services.youtube; +import org.schabi.newpipe.extractor.ListUrlIdHandler; import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; @@ -24,7 +25,7 @@ import org.schabi.newpipe.extractor.utils.Parser; * along with NewPipe. If not, see . */ -public class YoutubeChannelUrlIdHandler implements UrlIdHandler { +public class YoutubeChannelUrlIdHandler extends ListUrlIdHandler { private static final YoutubeChannelUrlIdHandler instance = new YoutubeChannelUrlIdHandler(); private static final String ID_PATTERN = "/(user/[A-Za-z0-9_-]*|channel/[A-Za-z0-9_-]*)"; @@ -34,7 +35,7 @@ public class YoutubeChannelUrlIdHandler implements UrlIdHandler { } @Override - public String getUrl(String id) { + public String getUrl(String id, String[] contentFilter, String sortFilter) { return "https://www.youtube.com/" + id; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistUrlIdHandler.java index 0c24f993c..e6032803c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistUrlIdHandler.java @@ -1,11 +1,12 @@ package org.schabi.newpipe.extractor.services.youtube; +import org.schabi.newpipe.extractor.ListUrlIdHandler; import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; -public class YoutubePlaylistUrlIdHandler implements UrlIdHandler { +public class YoutubePlaylistUrlIdHandler extends ListUrlIdHandler { private static final YoutubePlaylistUrlIdHandler instance = new YoutubePlaylistUrlIdHandler(); private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{10,})"; @@ -15,7 +16,7 @@ public class YoutubePlaylistUrlIdHandler implements UrlIdHandler { } @Override - public String getUrl(String id) { + public String getUrl(String id, String[] contentFilter, String sortFilter) { return "https://www.youtube.com/playlist?list=" + id; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java index 9addec48f..25afe98a4 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java @@ -37,7 +37,7 @@ import java.net.URLDecoder; * along with NewPipe. If not, see . */ -public class YoutubeStreamUrlIdHandler implements UrlIdHandler { +public class YoutubeStreamUrlIdHandler extends UrlIdHandler { private static final YoutubeStreamUrlIdHandler instance = new YoutubeStreamUrlIdHandler(); private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{11})"; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java index 63a35181e..f6110484f 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java @@ -20,12 +20,14 @@ package org.schabi.newpipe.extractor.services.youtube; * along with NewPipe. If not, see . */ +import org.schabi.newpipe.extractor.ListUrlIdHandler; import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.Parser; -public class YoutubeTrendingUrlIdHandler implements UrlIdHandler { +public class YoutubeTrendingUrlIdHandler extends ListUrlIdHandler { - public String getUrl(String id) { + public String getUrl(String id, String[] contentFilter, String sortFilter) { return "https://www.youtube.com/feed/trending"; } @@ -35,7 +37,7 @@ public class YoutubeTrendingUrlIdHandler implements UrlIdHandler { } @Override - public String cleanUrl(String url) { + public String cleanUrl(String url) throws ParsingException { return getUrl(""); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java index e805b297f..76e52cd78 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandlerTest.java @@ -22,7 +22,7 @@ public class SoundcloudChartsUrlIdHandlerTest { } @Test - public void getUrl() { + public void getUrl() throws Exception { assertEquals(urlIdHandler.getUrl("Top 50"), "https://soundcloud.com/charts/top"); assertEquals(urlIdHandler.getUrl("New & hot"), "https://soundcloud.com/charts/new"); }