mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-13 05:40:34 +05:30
add filter to stream lists
This commit is contained in:
parent
bf1c771662
commit
b7c1f251d8
@ -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];
|
||||||
|
}
|
||||||
|
}
|
@ -22,16 +22,16 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface UrlIdHandler {
|
public abstract class UrlIdHandler {
|
||||||
|
|
||||||
String getUrl(String id) throws ParsingException;
|
public abstract String getUrl(String id) throws ParsingException;
|
||||||
String getId(String url) throws ParsingException;
|
public abstract String getId(String url) throws ParsingException;
|
||||||
String cleanUrl(String complexUrl) 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
|
* 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.
|
* Intent was meant to be watched with this Service.
|
||||||
* Return false if this service shall not allow to be called through ACTIONs.
|
* Return false if this service shall not allow to be called through ACTIONs.
|
||||||
*/
|
*/
|
||||||
boolean acceptUrl(String url);
|
public abstract boolean acceptUrl(String url);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.services.soundcloud;
|
|||||||
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.schabi.newpipe.extractor.ListUrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
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;
|
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 static final SoundcloudChannelUrlIdHandler instance = new SoundcloudChannelUrlIdHandler();
|
||||||
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
|
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
|
||||||
"(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$";
|
"(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$";
|
||||||
@ -20,7 +21,7 @@ public class SoundcloudChannelUrlIdHandler implements UrlIdHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUrl(String id) throws ParsingException {
|
public String getUrl(String id, String[] contentFilter, String sortFilter) throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/" + id);
|
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/" + id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package org.schabi.newpipe.extractor.services.soundcloud;
|
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.ListUrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.utils.Parser;
|
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 TOP_URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top)?/?([#?].*)?$";
|
||||||
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top|/new)?/?([#?].*)?$";
|
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")) {
|
if (id.equals("Top 50")) {
|
||||||
return "https://soundcloud.com/charts/top";
|
return "https://soundcloud.com/charts/top";
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.services.soundcloud;
|
|||||||
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.schabi.newpipe.extractor.ListUrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
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;
|
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 static final SoundcloudPlaylistUrlIdHandler instance = new SoundcloudPlaylistUrlIdHandler();
|
||||||
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
|
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
|
||||||
"/sets/[0-9a-z_-]+/?([#?].*)?$";
|
"/sets/[0-9a-z_-]+/?([#?].*)?$";
|
||||||
@ -20,7 +21,7 @@ public class SoundcloudPlaylistUrlIdHandler implements UrlIdHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUrl(String id) throws ParsingException {
|
public String getUrl(String id, String[] contentFilter, String sortFilter) throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/playlists/" + id);
|
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/playlists/" + id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -10,7 +10,7 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
|||||||
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
|
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 static final SoundcloudStreamUrlIdHandler instance = new SoundcloudStreamUrlIdHandler();
|
||||||
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
|
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
|
||||||
"/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
|
"/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.schabi.newpipe.extractor.services.youtube;
|
package org.schabi.newpipe.extractor.services.youtube;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.ListUrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.utils.Parser;
|
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/>.
|
* 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 YoutubeChannelUrlIdHandler instance = new YoutubeChannelUrlIdHandler();
|
||||||
private static final String ID_PATTERN = "/(user/[A-Za-z0-9_-]*|channel/[A-Za-z0-9_-]*)";
|
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
|
@Override
|
||||||
public String getUrl(String id) {
|
public String getUrl(String id, String[] contentFilter, String sortFilter) {
|
||||||
return "https://www.youtube.com/" + id;
|
return "https://www.youtube.com/" + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package org.schabi.newpipe.extractor.services.youtube;
|
package org.schabi.newpipe.extractor.services.youtube;
|
||||||
|
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.ListUrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.utils.Parser;
|
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 YoutubePlaylistUrlIdHandler instance = new YoutubePlaylistUrlIdHandler();
|
||||||
private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{10,})";
|
private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{10,})";
|
||||||
@ -15,7 +16,7 @@ public class YoutubePlaylistUrlIdHandler implements UrlIdHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUrl(String id) {
|
public String getUrl(String id, String[] contentFilter, String sortFilter) {
|
||||||
return "https://www.youtube.com/playlist?list=" + id;
|
return "https://www.youtube.com/playlist?list=" + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ import java.net.URLDecoder;
|
|||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
* 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 YoutubeStreamUrlIdHandler instance = new YoutubeStreamUrlIdHandler();
|
||||||
private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{11})";
|
private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{11})";
|
||||||
|
@ -20,12 +20,14 @@ package org.schabi.newpipe.extractor.services.youtube;
|
|||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
* 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.UrlIdHandler;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.utils.Parser;
|
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";
|
return "https://www.youtube.com/feed/trending";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ public class YoutubeTrendingUrlIdHandler implements UrlIdHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String cleanUrl(String url) {
|
public String cleanUrl(String url) throws ParsingException {
|
||||||
return getUrl("");
|
return getUrl("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class SoundcloudChartsUrlIdHandlerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getUrl() {
|
public void getUrl() throws Exception {
|
||||||
assertEquals(urlIdHandler.getUrl("Top 50"), "https://soundcloud.com/charts/top");
|
assertEquals(urlIdHandler.getUrl("Top 50"), "https://soundcloud.com/charts/top");
|
||||||
assertEquals(urlIdHandler.getUrl("New & hot"), "https://soundcloud.com/charts/new");
|
assertEquals(urlIdHandler.getUrl("New & hot"), "https://soundcloud.com/charts/new");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user