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 547a0356e..970cddc9e 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 @@ -7,20 +7,15 @@ import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParserException; import com.grack.nanojson.JsonWriter; import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.localization.DateWrapper; -import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; import java.time.DateTimeException; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.Locale; public class BandcampExtractorHelper { @@ -95,12 +90,18 @@ public class BandcampExtractorHelper { if (url.toLowerCase().matches("https?://.+\\.bandcamp\\.com(/.*)?")) return true; try { - // Accept all other URLs if they contain a tag that says they are generated by bandcamp + // Test other URLs for whether they contain a footer that links to bandcamp return Jsoup.parse( NewPipe.getDownloader().get(url).responseBody() ) - .getElementsByAttributeValue("name", "generator") - .attr("content").equals("Bandcamp"); + .getElementById("pgFt") + .getElementById("pgFt-inner") + .getElementById("footer-logo-wrapper") + .getElementById("footer-logo") + .getElementsByClass("hiddenAccess") + .text().equals("Bandcamp"); + } catch (NullPointerException e) { + return false; } catch (IOException | ReCaptchaException e) { throw new ParsingException("Could not determine whether URL is custom domain " + "(not available? network error?)"); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampChannelLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampChannelLinkHandlerFactory.java index 727aec404..05caf1141 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampChannelLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampChannelLinkHandlerFactory.java @@ -55,7 +55,9 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory { * Accepts only pages that lead to the root of an artist profile. Supports external pages. */ @Override - public boolean onAcceptUrl(final String url) throws ParsingException { + public boolean onAcceptUrl(String url) throws ParsingException { + + url = url.toLowerCase(); // https: | | artist.bandcamp.com | releases // 0 1 2 3 @@ -64,8 +66,10 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory { // URL is too short if (splitUrl.length < 3) return false; - // Must have "releases" as segment after url or none at all - if (splitUrl.length > 3 && !splitUrl[3].equals("releases")) { + // Must have "releases" or "music" as segment after url or none at all + if (splitUrl.length > 3 && !( + splitUrl[3].equals("releases") || splitUrl[3].equals("music") + )) { return false; 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 fcadb25f2..85c182734 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 @@ -29,17 +29,24 @@ public class BandcampChannelLinkHandlerFactoryTest { assertTrue(linkHandler.acceptUrl("http://zachbenson.bandcamp.com")); assertTrue(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/")); assertTrue(linkHandler.acceptUrl("https://billwurtz.bandcamp.com/releases")); + assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/releases")); + assertTrue(linkHandler.acceptUrl("https://interovgm.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")); assertFalse(linkHandler.acceptUrl("https://daily.bandcamp.com/")); + assertFalse(linkHandler.acceptUrl("https://DAILY.BANDCAMP.COM")); assertFalse(linkHandler.acceptUrl("https://daily.bandcamp.com/best-of-2020/bandcamp-daily-staffers-on-their-favorite-albums-of-2020")); // External URLs - assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/releases")); - assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/releases/")); + assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com")); + assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com/music")); + assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com/music/")); + assertTrue(linkHandler.acceptUrl("https://diskak.usopop.com/")); + assertTrue(linkHandler.acceptUrl("https://diskak.usopop.com/releases")); + assertTrue(linkHandler.acceptUrl("https://diskak.usopop.com/RELEASES")); assertFalse(linkHandler.acceptUrl("https://example.com/releases")); } @@ -51,6 +58,10 @@ public class BandcampChannelLinkHandlerFactoryTest { assertEquals("1581461772", linkHandler.getId("https://interovgm.bandcamp.com/releases")); assertEquals("3321800855", linkHandler.getId("https://infiniteammo.bandcamp.com/")); assertEquals("3775652329", linkHandler.getId("https://npet.bandcamp.com/")); + + assertEquals("2735462545", linkHandler.getId("http://lobstertheremin.com/")); + assertEquals("2735462545", linkHandler.getId("https://lobstertheremin.com/music/")); + assertEquals("3826445168", linkHandler.getId("https://diskak.usopop.com/releases")); } @Test @@ -58,6 +69,8 @@ public class BandcampChannelLinkHandlerFactoryTest { assertEquals("https://macbenson.bandcamp.com", linkHandler.getUrl("1196681540")); assertEquals("https://interovgm.bandcamp.com", linkHandler.getUrl("1581461772")); assertEquals("https://infiniteammo.bandcamp.com", linkHandler.getUrl("3321800855")); + + assertEquals("https://lobstertheremin.com", linkHandler.getUrl("2735462545")); } @Test(expected = ParsingException.class) diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamLinkHandlerFactoryTest.java index 52512ac40..cb48ddbbf 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamLinkHandlerFactoryTest.java @@ -49,5 +49,6 @@ public class BandcampStreamLinkHandlerFactoryTest { assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/track/title")); assertTrue(linkHandler.acceptUrl("http://bandcamP.com/?show=38")); assertTrue(linkHandler.acceptUrl("https://goodgoodblood-tl.bandcamp.com/track/when-it-all-wakes-up")); + assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com/track/unfinished")); } }