mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-13 22:00:32 +05:30
Add support for on.soundcloud.com urls (#1179)
Add support for on.soundcloud.com urls Fixes #1178 Co-authored-by: TobiGr <tobigr@users.noreply.github.com>
This commit is contained in:
parent
0e15f9ac1b
commit
02e14b8931
@ -45,6 +45,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class SoundcloudParsingHelper {
|
public final class SoundcloudParsingHelper {
|
||||||
// CHECKSTYLE:OFF
|
// CHECKSTYLE:OFF
|
||||||
@ -88,6 +89,10 @@ public final class SoundcloudParsingHelper {
|
|||||||
private static String clientId;
|
private static String clientId;
|
||||||
public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/";
|
public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/";
|
||||||
|
|
||||||
|
private static final Pattern ON_URL_PATTERN = Pattern.compile(
|
||||||
|
"^https?://on.soundcloud.com/[0-9a-zA-Z]+$"
|
||||||
|
);
|
||||||
|
|
||||||
private SoundcloudParsingHelper() {
|
private SoundcloudParsingHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,8 +190,21 @@ public final class SoundcloudParsingHelper {
|
|||||||
*/
|
*/
|
||||||
public static String resolveIdWithWidgetApi(final String urlString) throws IOException,
|
public static String resolveIdWithWidgetApi(final String urlString) throws IOException,
|
||||||
ParsingException {
|
ParsingException {
|
||||||
// Remove the tailing slash from URLs due to issues with the SoundCloud API
|
|
||||||
String fixedUrl = urlString;
|
String fixedUrl = urlString;
|
||||||
|
|
||||||
|
// if URL is an on.soundcloud link, do a request to resolve the redirect
|
||||||
|
|
||||||
|
if (ON_URL_PATTERN.matcher(fixedUrl).find()) {
|
||||||
|
try {
|
||||||
|
fixedUrl = NewPipe.getDownloader().head(fixedUrl).latestUrl();
|
||||||
|
// remove tracking params which are in the query string
|
||||||
|
fixedUrl = fixedUrl.split("\\?")[0];
|
||||||
|
} catch (final ExtractionException e) {
|
||||||
|
throw new ParsingException("Could not follow on.soundcloud.com redirect", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the tailing slash from URLs due to issues with the SoundCloud API
|
||||||
if (fixedUrl.charAt(fixedUrl.length() - 1) == '/') {
|
if (fixedUrl.charAt(fixedUrl.length() - 1) == '/') {
|
||||||
fixedUrl = fixedUrl.substring(0, fixedUrl.length() - 1);
|
fixedUrl = fixedUrl.substring(0, fixedUrl.length() - 1);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
|||||||
public final class SoundcloudStreamLinkHandlerFactory extends LinkHandlerFactory {
|
public final class SoundcloudStreamLinkHandlerFactory extends LinkHandlerFactory {
|
||||||
private static final SoundcloudStreamLinkHandlerFactory INSTANCE
|
private static final SoundcloudStreamLinkHandlerFactory INSTANCE
|
||||||
= new SoundcloudStreamLinkHandlerFactory();
|
= new SoundcloudStreamLinkHandlerFactory();
|
||||||
private static final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+"
|
private static final String URL_PATTERN = "^https?://(www\\.|m\\.|on\\.)?"
|
||||||
|
+ "soundcloud.com/[0-9a-z_-]+"
|
||||||
+ "/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
|
+ "/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
|
||||||
private static final String API_URL_PATTERN = "^https?://api-v2\\.soundcloud.com"
|
private static final String API_URL_PATTERN = "^https?://api-v2\\.soundcloud.com"
|
||||||
+ "/(tracks|albums|sets|reposts|followers|following)/([0-9a-z_-]+)/";
|
+ "/(tracks|albums|sets|reposts|followers|following)/([0-9a-z_-]+)/";
|
||||||
|
@ -25,6 +25,10 @@ class SoundcloudParsingHelperTest {
|
|||||||
void resolveIdWithWidgetApiTest() throws Exception {
|
void resolveIdWithWidgetApiTest() throws Exception {
|
||||||
assertEquals("26057743", SoundcloudParsingHelper.resolveIdWithWidgetApi("https://soundcloud.com/trapcity"));
|
assertEquals("26057743", SoundcloudParsingHelper.resolveIdWithWidgetApi("https://soundcloud.com/trapcity"));
|
||||||
assertEquals("16069159", SoundcloudParsingHelper.resolveIdWithWidgetApi("https://soundcloud.com/nocopyrightsounds"));
|
assertEquals("16069159", SoundcloudParsingHelper.resolveIdWithWidgetApi("https://soundcloud.com/nocopyrightsounds"));
|
||||||
|
|
||||||
|
assertEquals("26057743", SoundcloudParsingHelper.resolveIdWithWidgetApi("https://on.soundcloud.com/Rr2JyfFcYwbawpw49"));
|
||||||
|
assertEquals("1818813498", SoundcloudParsingHelper.resolveIdWithWidgetApi("https://on.soundcloud.com/a8QmYdMnmxnsSTEp9"));
|
||||||
|
assertEquals("1468401502", SoundcloudParsingHelper.resolveIdWithWidgetApi("https://on.soundcloud.com/rdt7e"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user