2018-10-11 21:10:22 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.peertube.linkHandler;
|
|
|
|
|
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.ServiceList;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
|
|
|
import org.schabi.newpipe.extractor.utils.Parser;
|
|
|
|
|
2020-02-08 23:58:46 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2022-03-18 10:25:16 +01:00
|
|
|
public final class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
|
2018-10-11 21:10:22 +02:00
|
|
|
|
2022-03-18 10:25:16 +01:00
|
|
|
private static final PeertubePlaylistLinkHandlerFactory INSTANCE
|
|
|
|
= new PeertubePlaylistLinkHandlerFactory();
|
2021-11-03 13:35:30 +01:00
|
|
|
private static final String ID_PATTERN = "(/videos/watch/playlist/|/w/p/)([^/?&#]*)";
|
2022-12-04 19:15:44 +01:00
|
|
|
private static final String API_ID_PATTERN = "/video-playlists/([^/?&#]*)";
|
2018-10-11 21:10:22 +02:00
|
|
|
|
2022-03-18 10:25:16 +01:00
|
|
|
private PeertubePlaylistLinkHandlerFactory() {
|
|
|
|
}
|
|
|
|
|
2018-10-11 21:10:22 +02:00
|
|
|
public static PeertubePlaylistLinkHandlerFactory getInstance() {
|
2022-03-18 10:25:16 +01:00
|
|
|
return INSTANCE;
|
2018-10-11 21:10:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-03-18 10:25:16 +01:00
|
|
|
public String getUrl(final String id,
|
|
|
|
final List<String> contentFilters,
|
|
|
|
final String sortFilter) {
|
|
|
|
return getUrl(id, contentFilters, sortFilter, ServiceList.PeerTube.getBaseUrl());
|
2019-11-21 00:30:09 +01:00
|
|
|
}
|
2020-02-08 23:58:46 +01:00
|
|
|
|
2019-11-21 00:30:09 +01:00
|
|
|
@Override
|
2022-03-18 10:25:16 +01:00
|
|
|
public String getUrl(final String id,
|
|
|
|
final List<String> contentFilters,
|
|
|
|
final String sortFilter,
|
|
|
|
final String baseUrl) {
|
2020-04-09 17:51:51 +02:00
|
|
|
return baseUrl + "/api/v1/video-playlists/" + id;
|
2018-10-11 21:10:22 +02:00
|
|
|
}
|
2020-02-08 23:58:46 +01:00
|
|
|
|
2018-10-11 21:10:22 +02:00
|
|
|
@Override
|
2022-03-18 10:25:16 +01:00
|
|
|
public String getId(final String url) throws ParsingException {
|
2022-12-04 19:15:44 +01:00
|
|
|
try {
|
|
|
|
return Parser.matchGroup(ID_PATTERN, url, 2);
|
|
|
|
} catch (final ParsingException ignored) {
|
|
|
|
// might also be an API url, no reason to throw an exception here
|
|
|
|
}
|
|
|
|
return Parser.matchGroup1(API_ID_PATTERN, url);
|
2018-10-11 21:10:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onAcceptUrl(final String url) {
|
2020-04-09 17:51:51 +02:00
|
|
|
try {
|
|
|
|
getId(url);
|
|
|
|
return true;
|
2022-03-18 10:25:16 +01:00
|
|
|
} catch (final ParsingException e) {
|
2020-04-09 17:51:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-11 21:10:22 +02:00
|
|
|
}
|
|
|
|
}
|