2020-04-10 10:51:05 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.soundcloud.linkHandler;
|
2017-08-04 16:21:45 +02:00
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2020-02-08 23:58:46 +01:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
2020-04-10 10:51:05 +02:00
|
|
|
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
|
2017-08-04 16:21:45 +02:00
|
|
|
import org.schabi.newpipe.extractor.utils.Parser;
|
2017-08-08 17:01:50 +02:00
|
|
|
import org.schabi.newpipe.extractor.utils.Utils;
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2022-03-18 11:12:45 +01:00
|
|
|
public final class SoundcloudStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|
|
|
private static final SoundcloudStreamLinkHandlerFactory INSTANCE
|
|
|
|
= new SoundcloudStreamLinkHandlerFactory();
|
2021-05-15 17:51:43 +02:00
|
|
|
private static final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+"
|
|
|
|
+ "/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
|
2022-10-11 13:01:35 +02:00
|
|
|
private static final String API_URL_PATTERN = "^https?://api-v2\\.soundcloud.com"
|
|
|
|
+ "/(tracks|albums|sets|reposts|followers|following)/([0-9a-z_-]+)/";
|
2018-07-13 18:02:40 +02:00
|
|
|
private SoundcloudStreamLinkHandlerFactory() {
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:02:40 +02:00
|
|
|
public static SoundcloudStreamLinkHandlerFactory getInstance() {
|
2022-03-18 11:12:45 +01:00
|
|
|
return INSTANCE;
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-05-15 17:51:43 +02:00
|
|
|
public String getUrl(final String id) throws ParsingException {
|
2017-08-04 16:21:45 +02:00
|
|
|
try {
|
2021-05-15 17:51:43 +02:00
|
|
|
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer(
|
|
|
|
"https://api.soundcloud.com/tracks/" + id);
|
|
|
|
} catch (final Exception e) {
|
2017-08-04 16:21:45 +02:00
|
|
|
throw new ParsingException(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-05-15 17:51:43 +02:00
|
|
|
public String getId(final String url) throws ParsingException {
|
2022-10-11 13:01:35 +02:00
|
|
|
if (Parser.isMatch(API_URL_PATTERN, url)) {
|
2022-12-04 13:19:24 +01:00
|
|
|
return Parser.matchGroup(API_URL_PATTERN, url, 2);
|
2022-10-11 13:01:35 +02:00
|
|
|
}
|
2017-08-08 17:01:50 +02:00
|
|
|
Utils.checkUrl(URL_PATTERN, url);
|
|
|
|
|
2017-08-04 16:21:45 +02:00
|
|
|
try {
|
2021-04-26 17:58:30 +02:00
|
|
|
return SoundcloudParsingHelper.resolveIdWithWidgetApi(url);
|
2021-05-15 17:51:43 +02:00
|
|
|
} catch (final Exception e) {
|
2017-08-04 16:21:45 +02:00
|
|
|
throw new ParsingException(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-05-06 14:08:50 +02:00
|
|
|
public boolean onAcceptUrl(final String url) throws ParsingException {
|
2017-08-08 17:01:50 +02:00
|
|
|
return Parser.isMatch(URL_PATTERN, url.toLowerCase());
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
}
|