add filter to stream lists

This commit is contained in:
Christian Schabesberger 2018-05-05 20:07:47 +02:00
parent bf1c771662
commit b7c1f251d8
11 changed files with 59 additions and 21 deletions

View File

@ -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];
}
}

View File

@ -22,16 +22,16 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
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);
}

View File

@ -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) {

View File

@ -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 {

View File

@ -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) {

View File

@ -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_-]+/?([#?].*)?$";

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}

View File

@ -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;
}

View File

@ -37,7 +37,7 @@ import java.net.URLDecoder;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
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})";

View File

@ -20,12 +20,14 @@ package org.schabi.newpipe.extractor.services.youtube;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
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("");
}

View File

@ -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");
}