2017-03-12 16:15:51 +01:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube;
|
|
|
|
|
|
|
|
|
2018-05-05 20:07:47 +02:00
|
|
|
import org.schabi.newpipe.extractor.ListUrlIdHandler;
|
2017-03-12 16:15:51 +01:00
|
|
|
import org.schabi.newpipe.extractor.UrlIdHandler;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2017-06-29 20:12:55 +02:00
|
|
|
import org.schabi.newpipe.extractor.utils.Parser;
|
2017-03-12 16:15:51 +01:00
|
|
|
|
2018-05-05 20:07:47 +02:00
|
|
|
public class YoutubePlaylistUrlIdHandler extends ListUrlIdHandler {
|
2017-03-12 16:15:51 +01:00
|
|
|
|
2017-07-11 05:08:03 +02:00
|
|
|
private static final YoutubePlaylistUrlIdHandler instance = new YoutubePlaylistUrlIdHandler();
|
2017-09-08 16:22:49 +02:00
|
|
|
private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{10,})";
|
2017-03-12 16:15:51 +01:00
|
|
|
|
2017-07-11 05:08:03 +02:00
|
|
|
public static YoutubePlaylistUrlIdHandler getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-03-12 16:15:51 +01:00
|
|
|
@Override
|
2018-05-05 20:07:47 +02:00
|
|
|
public String getUrl(String id, String[] contentFilter, String sortFilter) {
|
2017-08-07 18:12:51 +02:00
|
|
|
return "https://www.youtube.com/playlist?list=" + id;
|
2017-03-12 16:15:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getId(String url) throws ParsingException {
|
|
|
|
try {
|
|
|
|
return Parser.matchGroup1("list=" + ID_PATTERN, url);
|
|
|
|
} catch (final Exception exception) {
|
|
|
|
throw new ParsingException("Error could not parse url :" + exception.getMessage(), exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String cleanUrl(String complexUrl) throws ParsingException {
|
|
|
|
return getUrl(getId(complexUrl));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-07 18:12:51 +02:00
|
|
|
public boolean acceptUrl(String url) {
|
|
|
|
final boolean hasNotEmptyUrl = url != null && !url.isEmpty();
|
|
|
|
final boolean isYoutubeDomain = hasNotEmptyUrl && (url.contains("youtube") || url.contains("youtu.be"));
|
|
|
|
return isYoutubeDomain && url.contains("list=");
|
2017-03-12 16:15:51 +01:00
|
|
|
}
|
|
|
|
}
|