From 50903730b13e1b60e297f11047cfbd3dc13fd9c7 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Tue, 22 Dec 2020 08:53:10 +0100 Subject: [PATCH] [Bandcamp] Fix accepting HTTP URLs --- .../BandcampFeaturedLinkHandlerFactory.java | 11 +++++++---- .../BandcampChannelLinkHandlerFactoryTest.java | 3 +++ .../BandcampFeaturedLinkHandlerFactoryTest.java | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) 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 7aac3684b..6286e31da 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.utils.Utils; import java.util.List; @@ -25,8 +26,9 @@ public class BandcampFeaturedLinkHandlerFactory extends ListLinkHandlerFactory { } @Override - public String getId(final String url) { - if (url.matches("https?://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL)) { + public String getId(String url) { + url = Utils.replaceHttpWithHttps(url); + if (url.matches("https://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL)) { return KIOSK_RADIO; } else if (url.equals(FEATURED_API_URL)) { return KIOSK_FEATURED; @@ -36,8 +38,9 @@ public class BandcampFeaturedLinkHandlerFactory extends ListLinkHandlerFactory { } @Override - public boolean onAcceptUrl(final String url) { + 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+")); + || url.matches("https://bandcamp\\.com/\\?show=\\d+")); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelLinkHandlerFactoryTest.java index 8886f649f..499704b99 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelLinkHandlerFactoryTest.java @@ -31,6 +31,8 @@ public class BandcampChannelLinkHandlerFactoryTest { assertTrue(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/")); assertTrue(linkHandler.acceptUrl("https://billwurtz.bandcamp.com/releases")); + assertTrue(linkHandler.acceptUrl("http://zachbenson.bandcamp.com/")); + assertFalse(linkHandler.acceptUrl("https://bandcamp.com")); assertFalse(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/track/kitchen")); @@ -44,6 +46,7 @@ public class BandcampChannelLinkHandlerFactoryTest { @Test public void testGetId() throws ParsingException { assertEquals("1196681540", linkHandler.getId("https://macbenson.bandcamp.com/")); + assertEquals("1196681540", linkHandler.getId("http://macbenson.bandcamp.com/")); assertEquals("1581461772", linkHandler.getId("https://interovgm.com/releases")); assertEquals("3321800855", linkHandler.getId("https://infiniteammo.bandcamp.com/")); assertEquals("3775652329", linkHandler.getId("https://npet.bandcamp.com/")); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampFeaturedLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampFeaturedLinkHandlerFactoryTest.java index 38559782b..b337ded7d 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampFeaturedLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampFeaturedLinkHandlerFactoryTest.java @@ -24,6 +24,7 @@ public class BandcampFeaturedLinkHandlerFactoryTest { @Test public void testAcceptUrl() throws ParsingException { + assertTrue(linkHandler.acceptUrl("http://bandcamp.com/?show=1")); assertTrue(linkHandler.acceptUrl("https://bandcamp.com/?show=1")); assertTrue(linkHandler.acceptUrl("http://bandcamp.com/?show=2")); assertTrue(linkHandler.acceptUrl("https://bandcamp.com/api/mobile/24/bootstrap_data")); @@ -42,6 +43,7 @@ public class BandcampFeaturedLinkHandlerFactoryTest { @Test public void testGetId() { + assertEquals("Featured", linkHandler.getId("http://bandcamp.com/api/mobile/24/bootstrap_data")); assertEquals("Featured", linkHandler.getId("https://bandcamp.com/api/mobile/24/bootstrap_data")); assertEquals("Radio", linkHandler.getId("http://bandcamp.com/?show=1")); assertEquals("Radio", linkHandler.getId("https://bandcamp.com/api/bcweekly/1/list"));