Move radio URL check into a function

This commit is contained in:
TobiGr 2021-02-19 13:35:44 +01:00
parent 54aa5b3042
commit 98268e351c
3 changed files with 14 additions and 5 deletions

View File

@ -148,6 +148,15 @@ public class BandcampExtractorHelper {
}
}
/**
* Whether the URL points to a radio kiosk.
* @param url the URL to check
* @return true if the URL is <code>https://bandcamp.com/?show=SHOW_ID</code>
*/
public static boolean isRadioUrl(final String url) {
return url.toLowerCase().matches("https?://bandcamp\\.com/\\?show=\\d+");
}
static DateWrapper parseDate(final String textDate) throws ParsingException {
try {
final ZonedDateTime zonedDateTime = ZonedDateTime.parse(

View File

@ -3,6 +3,7 @@
package org.schabi.newpipe.extractor.services.bandcamp.linkHandler;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
import org.schabi.newpipe.extractor.utils.Utils;
import java.util.List;
@ -28,7 +29,7 @@ public class BandcampFeaturedLinkHandlerFactory extends ListLinkHandlerFactory {
@Override
public String getId(String url) {
url = Utils.replaceHttpWithHttps(url);
if (url.matches("https://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL)) {
if (BandcampExtractorHelper.isRadioUrl(url) || url.equals(RADIO_API_URL)) {
return KIOSK_RADIO;
} else if (url.equals(FEATURED_API_URL)) {
return KIOSK_FEATURED;
@ -40,7 +41,6 @@ public class BandcampFeaturedLinkHandlerFactory extends ListLinkHandlerFactory {
@Override
public boolean onAcceptUrl(String url) {
url = Utils.replaceHttpWithHttps(url);
return url.equals(FEATURED_API_URL) || (url.equals(RADIO_API_URL)
|| url.matches("https://bandcamp\\.com/\\?show=\\d+"));
return url.equals(FEATURED_API_URL) || (url.equals(RADIO_API_URL) || BandcampExtractorHelper.isRadioUrl(url));
}
}

View File

@ -20,7 +20,7 @@ public class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
*/
@Override
public String getId(final String url) throws ParsingException {
if (url.matches("https?://bandcamp\\.com/\\?show=\\d+")) {
if (BandcampExtractorHelper.isRadioUrl(url)) {
return url.split("bandcamp.com/\\?show=")[1];
} else {
return getUrl(url);
@ -48,7 +48,7 @@ public class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
public boolean onAcceptUrl(final String url) throws ParsingException {
// Accept Bandcamp radio
if (url.toLowerCase().matches("https?://bandcamp\\.com/\\?show=\\d+")) return true;
if (BandcampExtractorHelper.isRadioUrl(url)) return true;
// Don't accept URLs that don't point to a track
if (!url.toLowerCase().matches("https?://.+\\..+/track/.+")) return false;