From 98268e351c06d30009965bd2698246cff6a2a405 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Fri, 19 Feb 2021 13:35:44 +0100 Subject: [PATCH] Move radio URL check into a function --- .../bandcamp/extractors/BandcampExtractorHelper.java | 9 +++++++++ .../linkHandler/BandcampFeaturedLinkHandlerFactory.java | 6 +++--- .../linkHandler/BandcampStreamLinkHandlerFactory.java | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java index 1d76c4612..b19c41dd1 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java @@ -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 https://bandcamp.com/?show=SHOW_ID + */ + 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( diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampFeaturedLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampFeaturedLinkHandlerFactory.java index 6286e31da..ea6254979 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampFeaturedLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampFeaturedLinkHandlerFactory.java @@ -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)); } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampStreamLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampStreamLinkHandlerFactory.java index fa0435daa..37ff29c0c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampStreamLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampStreamLinkHandlerFactory.java @@ -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;