From de9fb7cb28067dbfded98706883f37dcb5605523 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Sun, 21 Jul 2024 15:36:12 +0200 Subject: [PATCH] [Bandcamp] Update artist page detection Bandcamp changed the way the footer is rendered. Therefore, we check for a link to the cart page instead. --- .../extractors/BandcampExtractorHelper.java | 23 +++++++++++-------- .../BandcampChannelLinkHandlerFactory.java | 2 +- .../BandcampCommentsLinkHandlerFactory.java | 2 +- .../BandcampPlaylistLinkHandlerFactory.java | 2 +- .../BandcampStreamLinkHandlerFactory.java | 2 +- ...andcampCommentsLinkHandlerFactoryTest.java | 1 - .../BandcampStreamLinkHandlerFactoryTest.java | 1 - 7 files changed, 18 insertions(+), 15 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 216c3b756..ade12b030 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 @@ -155,25 +155,30 @@ public final class BandcampExtractorHelper { /** * @return true if the given URL looks like it comes from a bandcamp custom domain - * or if it comes from bandcamp.com itself + * or a *.bandcamp.com subdomain */ - public static boolean isSupportedDomain(final String url) throws ParsingException { + public static boolean isArtistDomain(final String url) throws ParsingException { // Accept all bandcamp.com URLs if (url.toLowerCase().matches("https?://.+\\.bandcamp\\.com(/.*)?")) { return true; } + // Reject non-artist bandcamp.com URLs + if (url.toLowerCase().matches("https?://bandcamp\\.com(/.*)?")) { + return false; + } + try { // Test other URLs for whether they contain a footer that links to bandcamp return Jsoup.parse(NewPipe.getDownloader().get(url).responseBody()) - .getElementById("pgFt") - .getElementById("pgFt-inner") - .getElementById("footer-logo-wrapper") - .getElementById("footer-logo") - .getElementsByClass("hiddenAccess") - .text().equals("Bandcamp"); - } catch (final NullPointerException e) { + .getElementsByClass("cart-wrapper") + .get(0) + .getElementsByTag("a") + .get(0) + .attr("href") + .equals("https://bandcamp.com/cart"); + } catch (final NullPointerException | IndexOutOfBoundsException e) { return false; } catch (final IOException | ReCaptchaException e) { throw new ParsingException("Could not determine whether URL is custom domain " 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 618bfc313..440b75c92 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 @@ -90,7 +90,7 @@ public final class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFact } // Test whether domain is supported - return BandcampExtractorHelper.isSupportedDomain(lowercaseUrl); + return BandcampExtractorHelper.isArtistDomain(lowercaseUrl); } } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampCommentsLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampCommentsLinkHandlerFactory.java index 086efd8e1..2fae71515 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampCommentsLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampCommentsLinkHandlerFactory.java @@ -39,7 +39,7 @@ public final class BandcampCommentsLinkHandlerFactory extends ListLinkHandlerFac } // Test whether domain is supported - return BandcampExtractorHelper.isSupportedDomain(url); + return BandcampExtractorHelper.isArtistDomain(url); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampPlaylistLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampPlaylistLinkHandlerFactory.java index 68fac3e6f..76dd92c55 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampPlaylistLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampPlaylistLinkHandlerFactory.java @@ -48,6 +48,6 @@ public final class BandcampPlaylistLinkHandlerFactory extends ListLinkHandlerFac } // Test whether domain is supported - return BandcampExtractorHelper.isSupportedDomain(url); + return BandcampExtractorHelper.isArtistDomain(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 c686f3147..88d4dda15 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 @@ -71,6 +71,6 @@ public final class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory { } // Test whether domain is supported - return BandcampExtractorHelper.isSupportedDomain(url); + return BandcampExtractorHelper.isArtistDomain(url); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampCommentsLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampCommentsLinkHandlerFactoryTest.java index 94361bbf6..12bb5aead 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampCommentsLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampCommentsLinkHandlerFactoryTest.java @@ -39,6 +39,5 @@ public class BandcampCommentsLinkHandlerFactoryTest { assertTrue(linkHandler.acceptUrl("http://ZachBenson.Bandcamp.COM/Track/U-I-Tonite/")); assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/track/title")); assertTrue(linkHandler.acceptUrl("https://goodgoodblood-tl.bandcamp.com/track/when-it-all-wakes-up")); - assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com/track/unfinished")); } } 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 f895dd351..ef535c8be 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,6 +49,5 @@ 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")); } }