Skip to content

Commit ca44c04

Browse files
[SoundCloud] Use Pattern in SoundcloudStreamLinkHandlerFactory instead of String
1 parent 649641a commit ca44c04

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudStreamLinkHandlerFactory.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.schabi.newpipe.extractor.services.soundcloud.linkHandler;
22

3+
import java.util.regex.Pattern;
4+
35
import org.schabi.newpipe.extractor.exceptions.ParsingException;
46
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
57
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
@@ -9,11 +11,18 @@
911
public final class SoundcloudStreamLinkHandlerFactory extends LinkHandlerFactory {
1012
private static final SoundcloudStreamLinkHandlerFactory INSTANCE
1113
= new SoundcloudStreamLinkHandlerFactory();
12-
private static final String URL_PATTERN = "^https?://(www\\.|m\\.|on\\.)?"
13-
+ "soundcloud.com/[0-9a-z_-]+"
14-
+ "/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
15-
private static final String API_URL_PATTERN = "^https?://api-v2\\.soundcloud.com"
16-
+ "/(tracks|albums|sets|reposts|followers|following)/([0-9a-z_-]+)/";
14+
15+
private static final Pattern URL_PATTERN = Pattern.compile(
16+
"^https?://(?:www\\.|m\\.|on\\.)?"
17+
+ "soundcloud.com/[0-9a-z_-]+"
18+
+ "/(?!(?:tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?(?:[#?].*)?$"
19+
);
20+
21+
private static final Pattern API_URL_PATTERN = Pattern.compile(
22+
"^https?://api-v2\\.soundcloud.com"
23+
+ "/(tracks|albums|sets|reposts|followers|following)/([0-9a-z_-]+)/"
24+
);
25+
1726
private SoundcloudStreamLinkHandlerFactory() {
1827
}
1928

extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,22 @@ public static long mixedNumberWordToLong(final String numberWord)
110110
* @param url the url to be tested
111111
*/
112112
public static void checkUrl(final String pattern, final String url) throws ParsingException {
113+
checkUrl(Pattern.compile(pattern), url);
114+
}
115+
116+
/**
117+
* Check if the url matches the pattern.
118+
*
119+
* @param pattern the pattern that will be used to check the url
120+
* @param url the url to be tested
121+
*/
122+
public static void checkUrl(final Pattern pattern, final String url) throws ParsingException {
113123
if (isNullOrEmpty(url)) {
114124
throw new IllegalArgumentException("Url can't be null or empty");
115125
}
116126

117127
if (!Parser.isMatch(pattern, url.toLowerCase())) {
118-
throw new ParsingException("Url don't match the pattern");
128+
throw new ParsingException("Url doesn't match the pattern");
119129
}
120130
}
121131

0 commit comments

Comments
 (0)