54 lines
2.0 KiB
Java
54 lines
2.0 KiB
Java
package org.schabi.newpipe.extractor.services.soundcloud.linkHandler;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
|
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
|
|
import org.schabi.newpipe.extractor.utils.Parser;
|
|
import org.schabi.newpipe.extractor.utils.Utils;
|
|
|
|
import java.util.List;
|
|
|
|
public final class SoundcloudPlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
|
|
private static final SoundcloudPlaylistLinkHandlerFactory INSTANCE =
|
|
new SoundcloudPlaylistLinkHandlerFactory();
|
|
private static final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+"
|
|
+ "/sets/[0-9a-z_-]+/?([#?].*)?$";
|
|
|
|
private SoundcloudPlaylistLinkHandlerFactory() {
|
|
}
|
|
|
|
public static SoundcloudPlaylistLinkHandlerFactory getInstance() {
|
|
return INSTANCE;
|
|
}
|
|
|
|
@Override
|
|
public String getId(final String url) throws ParsingException, UnsupportedOperationException {
|
|
Utils.checkUrl(URL_PATTERN, url);
|
|
|
|
try {
|
|
return SoundcloudParsingHelper.resolveIdWithWidgetApi(url);
|
|
} catch (final Exception e) {
|
|
throw new ParsingException("Could not get id of url: " + url + " " + e.getMessage(),
|
|
e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getUrl(final String id,
|
|
final List<String> contentFilter,
|
|
final String sortFilter)
|
|
throws ParsingException, UnsupportedOperationException {
|
|
try {
|
|
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer(
|
|
"https://api.soundcloud.com/playlists/" + id);
|
|
} catch (final Exception e) {
|
|
throw new ParsingException(e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean onAcceptUrl(final String url) throws ParsingException {
|
|
return Parser.isMatch(URL_PATTERN, url.toLowerCase());
|
|
}
|
|
}
|