Skip to content

Commit 98268e3

Browse files
committed
Move radio URL check into a function
1 parent 54aa5b3 commit 98268e3

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ public static boolean isSupportedDomain(final String url) throws ParsingExceptio
148148
}
149149
}
150150

151+
/**
152+
* Whether the URL points to a radio kiosk.
153+
* @param url the URL to check
154+
* @return true if the URL is <code>https://bandcamp.com/?show=SHOW_ID</code>
155+
*/
156+
public static boolean isRadioUrl(final String url) {
157+
return url.toLowerCase().matches("https?://bandcamp\\.com/\\?show=\\d+");
158+
}
159+
151160
static DateWrapper parseDate(final String textDate) throws ParsingException {
152161
try {
153162
final ZonedDateTime zonedDateTime = ZonedDateTime.parse(

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampFeaturedLinkHandlerFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package org.schabi.newpipe.extractor.services.bandcamp.linkHandler;
44

55
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
6+
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
67
import org.schabi.newpipe.extractor.utils.Utils;
78

89
import java.util.List;
@@ -28,7 +29,7 @@ public String getUrl(final String id, final List<String> contentFilter, final St
2829
@Override
2930
public String getId(String url) {
3031
url = Utils.replaceHttpWithHttps(url);
31-
if (url.matches("https://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL)) {
32+
if (BandcampExtractorHelper.isRadioUrl(url) || url.equals(RADIO_API_URL)) {
3233
return KIOSK_RADIO;
3334
} else if (url.equals(FEATURED_API_URL)) {
3435
return KIOSK_FEATURED;
@@ -40,7 +41,6 @@ public String getId(String url) {
4041
@Override
4142
public boolean onAcceptUrl(String url) {
4243
url = Utils.replaceHttpWithHttps(url);
43-
return url.equals(FEATURED_API_URL) || (url.equals(RADIO_API_URL)
44-
|| url.matches("https://bandcamp\\.com/\\?show=\\d+"));
44+
return url.equals(FEATURED_API_URL) || (url.equals(RADIO_API_URL) || BandcampExtractorHelper.isRadioUrl(url));
4545
}
4646
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampStreamLinkHandlerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
2020
*/
2121
@Override
2222
public String getId(final String url) throws ParsingException {
23-
if (url.matches("https?://bandcamp\\.com/\\?show=\\d+")) {
23+
if (BandcampExtractorHelper.isRadioUrl(url)) {
2424
return url.split("bandcamp.com/\\?show=")[1];
2525
} else {
2626
return getUrl(url);
@@ -48,7 +48,7 @@ public String getUrl(final String input) {
4848
public boolean onAcceptUrl(final String url) throws ParsingException {
4949

5050
// Accept Bandcamp radio
51-
if (url.toLowerCase().matches("https?://bandcamp\\.com/\\?show=\\d+")) return true;
51+
if (BandcampExtractorHelper.isRadioUrl(url)) return true;
5252

5353
// Don't accept URLs that don't point to a track
5454
if (!url.toLowerCase().matches("https?://.+\\..+/track/.+")) return false;

0 commit comments

Comments
 (0)