Skip to content

Commit b7c1f25

Browse files
committed
add filter to stream lists
1 parent bf1c771 commit b7c1f25

11 files changed

Lines changed: 59 additions & 21 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
4+
5+
public abstract class ListUrlIdHandler extends UrlIdHandler {
6+
7+
public abstract String getUrl(String id, String[] contentFilter, String sortFilter) throws ParsingException;
8+
9+
@Override
10+
public String getUrl(String id) throws ParsingException {
11+
return getUrl(id, new String[0], null);
12+
}
13+
14+
/**
15+
* Will returns content filter the corresponding extractor can handle like "channels", "videos", "music", etc.
16+
*
17+
* @return filter that can be applied when building a query for getting a list
18+
*/
19+
public String[] getAvailableContentFilter() {
20+
return new String[0];
21+
}
22+
23+
/**
24+
* Will returns sort filter the corresponding extractor can handle like "A-Z", "oldest first", "size", etc.
25+
*
26+
* @return filter that can be applied when building a query for getting a list
27+
*/
28+
public String[] getAvailableSortFilter() {
29+
return new String[0];
30+
}
31+
}

extractor/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2323
*/
2424

25-
public interface UrlIdHandler {
25+
public abstract class UrlIdHandler {
2626

27-
String getUrl(String id) throws ParsingException;
28-
String getId(String url) throws ParsingException;
29-
String cleanUrl(String complexUrl) throws ParsingException;
27+
public abstract String getUrl(String id) throws ParsingException;
28+
public abstract String getId(String url) throws ParsingException;
29+
public abstract String cleanUrl(String complexUrl) throws ParsingException;
3030

3131
/**
3232
* When a VIEW_ACTION is caught this function will test if the url delivered within the calling
3333
* Intent was meant to be watched with this Service.
3434
* Return false if this service shall not allow to be called through ACTIONs.
3535
*/
36-
boolean acceptUrl(String url);
36+
public abstract boolean acceptUrl(String url);
3737
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelUrlIdHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.jsoup.Jsoup;
44
import org.jsoup.nodes.Element;
5+
import org.schabi.newpipe.extractor.ListUrlIdHandler;
56
import org.schabi.newpipe.extractor.NewPipe;
67
import org.schabi.newpipe.extractor.UrlIdHandler;
78
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -10,7 +11,7 @@
1011

1112
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
1213

13-
public class SoundcloudChannelUrlIdHandler implements UrlIdHandler {
14+
public class SoundcloudChannelUrlIdHandler extends ListUrlIdHandler {
1415
private static final SoundcloudChannelUrlIdHandler instance = new SoundcloudChannelUrlIdHandler();
1516
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
1617
"(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$";
@@ -20,7 +21,7 @@ public static SoundcloudChannelUrlIdHandler getInstance() {
2021
}
2122

2223
@Override
23-
public String getUrl(String id) throws ParsingException {
24+
public String getUrl(String id, String[] contentFilter, String sortFilter) throws ParsingException {
2425
try {
2526
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/" + id);
2627
} catch (Exception e) {

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsUrlIdHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.schabi.newpipe.extractor.services.soundcloud;
22

3+
import org.schabi.newpipe.extractor.ListUrlIdHandler;
34
import org.schabi.newpipe.extractor.UrlIdHandler;
45
import org.schabi.newpipe.extractor.utils.Parser;
56

6-
public class SoundcloudChartsUrlIdHandler implements UrlIdHandler {
7+
public class SoundcloudChartsUrlIdHandler extends ListUrlIdHandler {
78
private final String TOP_URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top)?/?([#?].*)?$";
89
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top|/new)?/?([#?].*)?$";
910

10-
public String getUrl(String id) {
11+
public String getUrl(String id, String[] contentFilter, String sortFilter) {
1112
if (id.equals("Top 50")) {
1213
return "https://soundcloud.com/charts/top";
1314
} else {

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistUrlIdHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.jsoup.Jsoup;
44
import org.jsoup.nodes.Element;
5+
import org.schabi.newpipe.extractor.ListUrlIdHandler;
56
import org.schabi.newpipe.extractor.NewPipe;
67
import org.schabi.newpipe.extractor.UrlIdHandler;
78
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -10,7 +11,7 @@
1011

1112
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
1213

13-
public class SoundcloudPlaylistUrlIdHandler implements UrlIdHandler {
14+
public class SoundcloudPlaylistUrlIdHandler extends ListUrlIdHandler {
1415
private static final SoundcloudPlaylistUrlIdHandler instance = new SoundcloudPlaylistUrlIdHandler();
1516
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
1617
"/sets/[0-9a-z_-]+/?([#?].*)?$";
@@ -20,7 +21,7 @@ public static SoundcloudPlaylistUrlIdHandler getInstance() {
2021
}
2122

2223
@Override
23-
public String getUrl(String id) throws ParsingException {
24+
public String getUrl(String id, String[] contentFilter, String sortFilter) throws ParsingException {
2425
try {
2526
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/playlists/" + id);
2627
} catch (Exception e) {

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamUrlIdHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
1212

13-
public class SoundcloudStreamUrlIdHandler implements UrlIdHandler {
13+
public class SoundcloudStreamUrlIdHandler extends UrlIdHandler {
1414
private static final SoundcloudStreamUrlIdHandler instance = new SoundcloudStreamUrlIdHandler();
1515
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
1616
"/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.schabi.newpipe.extractor.services.youtube;
22

3+
import org.schabi.newpipe.extractor.ListUrlIdHandler;
34
import org.schabi.newpipe.extractor.UrlIdHandler;
45
import org.schabi.newpipe.extractor.exceptions.ParsingException;
56
import org.schabi.newpipe.extractor.utils.Parser;
@@ -24,7 +25,7 @@
2425
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2526
*/
2627

27-
public class YoutubeChannelUrlIdHandler implements UrlIdHandler {
28+
public class YoutubeChannelUrlIdHandler extends ListUrlIdHandler {
2829

2930
private static final YoutubeChannelUrlIdHandler instance = new YoutubeChannelUrlIdHandler();
3031
private static final String ID_PATTERN = "/(user/[A-Za-z0-9_-]*|channel/[A-Za-z0-9_-]*)";
@@ -34,7 +35,7 @@ public static YoutubeChannelUrlIdHandler getInstance() {
3435
}
3536

3637
@Override
37-
public String getUrl(String id) {
38+
public String getUrl(String id, String[] contentFilter, String sortFilter) {
3839
return "https://www.youtube.com/" + id;
3940
}
4041

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistUrlIdHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package org.schabi.newpipe.extractor.services.youtube;
22

33

4+
import org.schabi.newpipe.extractor.ListUrlIdHandler;
45
import org.schabi.newpipe.extractor.UrlIdHandler;
56
import org.schabi.newpipe.extractor.exceptions.ParsingException;
67
import org.schabi.newpipe.extractor.utils.Parser;
78

8-
public class YoutubePlaylistUrlIdHandler implements UrlIdHandler {
9+
public class YoutubePlaylistUrlIdHandler extends ListUrlIdHandler {
910

1011
private static final YoutubePlaylistUrlIdHandler instance = new YoutubePlaylistUrlIdHandler();
1112
private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{10,})";
@@ -15,7 +16,7 @@ public static YoutubePlaylistUrlIdHandler getInstance() {
1516
}
1617

1718
@Override
18-
public String getUrl(String id) {
19+
public String getUrl(String id, String[] contentFilter, String sortFilter) {
1920
return "https://www.youtube.com/playlist?list=" + id;
2021
}
2122

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
3838
*/
3939

40-
public class YoutubeStreamUrlIdHandler implements UrlIdHandler {
40+
public class YoutubeStreamUrlIdHandler extends UrlIdHandler {
4141

4242
private static final YoutubeStreamUrlIdHandler instance = new YoutubeStreamUrlIdHandler();
4343
private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{11})";

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2121
*/
2222

23+
import org.schabi.newpipe.extractor.ListUrlIdHandler;
2324
import org.schabi.newpipe.extractor.UrlIdHandler;
25+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2426
import org.schabi.newpipe.extractor.utils.Parser;
2527

26-
public class YoutubeTrendingUrlIdHandler implements UrlIdHandler {
28+
public class YoutubeTrendingUrlIdHandler extends ListUrlIdHandler {
2729

28-
public String getUrl(String id) {
30+
public String getUrl(String id, String[] contentFilter, String sortFilter) {
2931
return "https://www.youtube.com/feed/trending";
3032
}
3133

@@ -35,7 +37,7 @@ public String getId(String url) {
3537
}
3638

3739
@Override
38-
public String cleanUrl(String url) {
40+
public String cleanUrl(String url) throws ParsingException {
3941
return getUrl("");
4042
}
4143

0 commit comments

Comments
 (0)