2017-03-12 15:15:51 +00:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube;
|
|
|
|
|
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.UrlIdHandler;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2017-06-29 18:12:55 +00:00
|
|
|
import org.schabi.newpipe.extractor.utils.Parser;
|
2017-03-12 15:15:51 +00:00
|
|
|
|
2017-06-29 18:12:55 +00:00
|
|
|
public class YoutubePlaylistUrlIdHandler implements UrlIdHandler {
|
2017-03-12 15:15:51 +00:00
|
|
|
|
2017-07-11 03:08:03 +00:00
|
|
|
private static final YoutubePlaylistUrlIdHandler instance = new YoutubePlaylistUrlIdHandler();
|
2017-03-12 15:15:51 +00:00
|
|
|
private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{34})";
|
|
|
|
|
2017-07-11 03:08:03 +00:00
|
|
|
public static YoutubePlaylistUrlIdHandler getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-03-12 15:15:51 +00:00
|
|
|
@Override
|
|
|
|
public String getUrl(String listId) {
|
|
|
|
return "https://www.youtube.com/playlist?list=" + listId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
public boolean acceptUrl(String videoUrl) {
|
|
|
|
final boolean hasNotEmptyUrl = videoUrl != null && !videoUrl.isEmpty();
|
|
|
|
final boolean isYoutubeDomain = hasNotEmptyUrl && (videoUrl.contains("youtube") || videoUrl.contains("youtu.be"));
|
|
|
|
return isYoutubeDomain && videoUrl.contains("list=");
|
|
|
|
}
|
|
|
|
}
|