[Bandcamp] Fix accepting HTTP URLs

This commit is contained in:
TobiGr 2020-12-22 08:53:10 +01:00
parent 74b46fed2d
commit 50903730b1
3 changed files with 12 additions and 4 deletions

View File

@ -3,6 +3,7 @@
package org.schabi.newpipe.extractor.services.bandcamp.linkHandler; package org.schabi.newpipe.extractor.services.bandcamp.linkHandler;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Utils;
import java.util.List; import java.util.List;
@ -25,8 +26,9 @@ public class BandcampFeaturedLinkHandlerFactory extends ListLinkHandlerFactory {
} }
@Override @Override
public String getId(final String url) { public String getId(String url) {
if (url.matches("https?://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL)) { url = Utils.replaceHttpWithHttps(url);
if (url.matches("https://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL)) {
return KIOSK_RADIO; return KIOSK_RADIO;
} else if (url.equals(FEATURED_API_URL)) { } else if (url.equals(FEATURED_API_URL)) {
return KIOSK_FEATURED; return KIOSK_FEATURED;
@ -36,8 +38,9 @@ public class BandcampFeaturedLinkHandlerFactory extends ListLinkHandlerFactory {
} }
@Override @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) 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+"));
} }
} }

View File

@ -31,6 +31,8 @@ public class BandcampChannelLinkHandlerFactoryTest {
assertTrue(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/")); assertTrue(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/"));
assertTrue(linkHandler.acceptUrl("https://billwurtz.bandcamp.com/releases")); 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://bandcamp.com"));
assertFalse(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/track/kitchen")); assertFalse(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/track/kitchen"));
@ -44,6 +46,7 @@ public class BandcampChannelLinkHandlerFactoryTest {
@Test @Test
public void testGetId() throws ParsingException { public void testGetId() throws ParsingException {
assertEquals("1196681540", linkHandler.getId("https://macbenson.bandcamp.com/")); 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("1581461772", linkHandler.getId("https://interovgm.com/releases"));
assertEquals("3321800855", linkHandler.getId("https://infiniteammo.bandcamp.com/")); assertEquals("3321800855", linkHandler.getId("https://infiniteammo.bandcamp.com/"));
assertEquals("3775652329", linkHandler.getId("https://npet.bandcamp.com/")); assertEquals("3775652329", linkHandler.getId("https://npet.bandcamp.com/"));

View File

@ -24,6 +24,7 @@ public class BandcampFeaturedLinkHandlerFactoryTest {
@Test @Test
public void testAcceptUrl() throws ParsingException { public void testAcceptUrl() throws ParsingException {
assertTrue(linkHandler.acceptUrl("http://bandcamp.com/?show=1"));
assertTrue(linkHandler.acceptUrl("https://bandcamp.com/?show=1")); assertTrue(linkHandler.acceptUrl("https://bandcamp.com/?show=1"));
assertTrue(linkHandler.acceptUrl("http://bandcamp.com/?show=2")); assertTrue(linkHandler.acceptUrl("http://bandcamp.com/?show=2"));
assertTrue(linkHandler.acceptUrl("https://bandcamp.com/api/mobile/24/bootstrap_data")); assertTrue(linkHandler.acceptUrl("https://bandcamp.com/api/mobile/24/bootstrap_data"));
@ -42,6 +43,7 @@ public class BandcampFeaturedLinkHandlerFactoryTest {
@Test @Test
public void testGetId() { 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("Featured", linkHandler.getId("https://bandcamp.com/api/mobile/24/bootstrap_data"));
assertEquals("Radio", linkHandler.getId("http://bandcamp.com/?show=1")); assertEquals("Radio", linkHandler.getId("http://bandcamp.com/?show=1"));
assertEquals("Radio", linkHandler.getId("https://bandcamp.com/api/bcweekly/1/list")); assertEquals("Radio", linkHandler.getId("https://bandcamp.com/api/bcweekly/1/list"));