From c9e9953bb085a1231817b9d29675587d10d92470 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Tue, 22 Dec 2020 20:02:53 +0100 Subject: [PATCH] [Bandcamp] Fix channel link handler factory --- .../BandcampChannelLinkHandlerFactory.java | 26 +++++++++++++++---- ...BandcampChannelLinkHandlerFactoryTest.java | 2 ++ 2 files changed, 23 insertions(+), 5 deletions(-) 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 762c5d9b..2cf956cc 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 @@ -51,15 +51,31 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory { } /** - * Accepts only pages that do not lead to an album or track. Supports external pages. + * Accepts only pages that lead to the root of an artist profile. Supports external pages. */ @Override public boolean onAcceptUrl(final String url) throws ParsingException { - // Exclude URLs that lead to a track or album - if (url.matches(".*/(album|track)/.*")) return false; + // https: | | artist.bandcamp.com | releases + // 0 1 2 3 + String[] splitUrl = url.split("/"); - // Test whether domain is supported - return BandcampExtractorHelper.isSupportedDomain(url); + // 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")) { + + return false; + + } else { + if (splitUrl[2].equals("daily.bandcamp.com")) { + // Refuse links to daily.bandcamp.com as that is not an artist + return false; + } + + // Test whether domain is supported + return BandcampExtractorHelper.isSupportedDomain(url); + } } } 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 499704b9..6052a254 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 @@ -35,6 +35,8 @@ public class BandcampChannelLinkHandlerFactoryTest { 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/best-of-2020/bandcamp-daily-staffers-on-their-favorite-albums-of-2020")); // External URLs assertTrue(linkHandler.acceptUrl("http://interovgm.com/releases/"));