46 lines
1.7 KiB
Java
46 lines
1.7 KiB
Java
package org.schabi.newpipe.extractor.services.soundcloud.linkHandler;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
|
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
|
|
import org.schabi.newpipe.extractor.utils.Parser;
|
|
import org.schabi.newpipe.extractor.utils.Utils;
|
|
|
|
public class SoundcloudStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|
private static final SoundcloudStreamLinkHandlerFactory instance = new SoundcloudStreamLinkHandlerFactory();
|
|
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
|
|
"/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
|
|
|
|
private SoundcloudStreamLinkHandlerFactory() {
|
|
}
|
|
|
|
public static SoundcloudStreamLinkHandlerFactory getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
@Override
|
|
public String getUrl(String id) throws ParsingException {
|
|
try {
|
|
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/tracks/" + id);
|
|
} catch (Exception e) {
|
|
throw new ParsingException(e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getId(String url) throws ParsingException {
|
|
Utils.checkUrl(URL_PATTERN, url);
|
|
|
|
try {
|
|
return SoundcloudParsingHelper.resolveIdWithEmbedPlayer(url);
|
|
} catch (Exception e) {
|
|
throw new ParsingException(e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean onAcceptUrl(final String url) throws ParsingException {
|
|
return Parser.isMatch(URL_PATTERN, url.toLowerCase());
|
|
}
|
|
}
|