2018-07-13 18:02:40 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube.linkHandler;
|
2017-03-12 16:15:51 +01:00
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2019-01-13 12:52:07 +01:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
|
|
|
import org.schabi.newpipe.extractor.utils.Utils;
|
2017-03-12 16:15:51 +01:00
|
|
|
|
2019-01-13 12:52:07 +01:00
|
|
|
import java.net.URL;
|
2018-07-01 16:21:40 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-07-13 18:02:40 +02:00
|
|
|
public class YoutubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
|
2017-03-12 16:15:51 +01:00
|
|
|
|
2018-07-13 18:02:40 +02:00
|
|
|
private static final YoutubePlaylistLinkHandlerFactory instance = new YoutubePlaylistLinkHandlerFactory();
|
2017-03-12 16:15:51 +01:00
|
|
|
|
2018-07-13 18:02:40 +02:00
|
|
|
public static YoutubePlaylistLinkHandlerFactory getInstance() {
|
2017-07-11 05:08:03 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-03-12 16:15:51 +01:00
|
|
|
@Override
|
2018-07-01 16:21:40 +02:00
|
|
|
public String getUrl(String id, List<String> contentFilters, 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
|
2018-07-01 16:21:40 +02:00
|
|
|
public String getId(String url) throws ParsingException {
|
2017-03-12 16:15:51 +01:00
|
|
|
try {
|
2019-01-20 01:31:30 +01:00
|
|
|
URL urlObj = Utils.stringToURL(url);
|
2019-01-13 12:52:07 +01:00
|
|
|
|
2019-01-27 01:28:51 +01:00
|
|
|
if (!Utils.isHTTP(urlObj) || !YoutubeParsingHelper.isYoutubeURL(urlObj)) {
|
2019-01-13 12:52:07 +01:00
|
|
|
throw new ParsingException("the url given is not a Youtube-URL");
|
|
|
|
}
|
|
|
|
|
|
|
|
String listID = Utils.getQueryValue(urlObj, "list");
|
|
|
|
|
|
|
|
if (listID == null) {
|
|
|
|
throw new ParsingException("the url given does not include a playlist");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!listID.matches("[a-zA-Z0-9_-]{10,}")) {
|
|
|
|
throw new ParsingException("the list-ID given in the URL does not match the list pattern");
|
|
|
|
}
|
|
|
|
|
|
|
|
return listID;
|
2017-03-12 16:15:51 +01:00
|
|
|
} catch (final Exception exception) {
|
|
|
|
throw new ParsingException("Error could not parse url :" + exception.getMessage(), exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-05-06 14:08:50 +02:00
|
|
|
public boolean onAcceptUrl(final String url) {
|
2019-01-13 12:52:07 +01:00
|
|
|
try {
|
|
|
|
getId(url);
|
|
|
|
} catch (ParsingException e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2017-03-12 16:15:51 +01:00
|
|
|
}
|
|
|
|
}
|