[Bandcamp] Update artist page detection

Bandcamp changed the way the footer is rendered. Therefore, we check for
a link to the cart page instead.
This commit is contained in:
Fynn Godau 2024-07-21 15:36:12 +02:00
parent 592f1596e6
commit de9fb7cb28
7 changed files with 18 additions and 15 deletions

View File

@ -155,25 +155,30 @@ public final class BandcampExtractorHelper {
/** /**
* @return <code>true</code> if the given URL looks like it comes from a bandcamp custom domain * @return <code>true</code> if the given URL looks like it comes from a bandcamp custom domain
* or if it comes from <code>bandcamp.com</code> itself * or a <code>*.bandcamp.com</code> subdomain
*/ */
public static boolean isSupportedDomain(final String url) throws ParsingException { public static boolean isArtistDomain(final String url) throws ParsingException {
// Accept all bandcamp.com URLs // Accept all bandcamp.com URLs
if (url.toLowerCase().matches("https?://.+\\.bandcamp\\.com(/.*)?")) { if (url.toLowerCase().matches("https?://.+\\.bandcamp\\.com(/.*)?")) {
return true; return true;
} }
// Reject non-artist bandcamp.com URLs
if (url.toLowerCase().matches("https?://bandcamp\\.com(/.*)?")) {
return false;
}
try { try {
// Test other URLs for whether they contain a footer that links to bandcamp // Test other URLs for whether they contain a footer that links to bandcamp
return Jsoup.parse(NewPipe.getDownloader().get(url).responseBody()) return Jsoup.parse(NewPipe.getDownloader().get(url).responseBody())
.getElementById("pgFt") .getElementsByClass("cart-wrapper")
.getElementById("pgFt-inner") .get(0)
.getElementById("footer-logo-wrapper") .getElementsByTag("a")
.getElementById("footer-logo") .get(0)
.getElementsByClass("hiddenAccess") .attr("href")
.text().equals("Bandcamp"); .equals("https://bandcamp.com/cart");
} catch (final NullPointerException e) { } catch (final NullPointerException | IndexOutOfBoundsException e) {
return false; return false;
} catch (final IOException | ReCaptchaException e) { } catch (final IOException | ReCaptchaException e) {
throw new ParsingException("Could not determine whether URL is custom domain " throw new ParsingException("Could not determine whether URL is custom domain "

View File

@ -90,7 +90,7 @@ public final class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFact
} }
// Test whether domain is supported // Test whether domain is supported
return BandcampExtractorHelper.isSupportedDomain(lowercaseUrl); return BandcampExtractorHelper.isArtistDomain(lowercaseUrl);
} }
} }
} }

View File

@ -39,7 +39,7 @@ public final class BandcampCommentsLinkHandlerFactory extends ListLinkHandlerFac
} }
// Test whether domain is supported // Test whether domain is supported
return BandcampExtractorHelper.isSupportedDomain(url); return BandcampExtractorHelper.isArtistDomain(url);
} }
@Override @Override

View File

@ -48,6 +48,6 @@ public final class BandcampPlaylistLinkHandlerFactory extends ListLinkHandlerFac
} }
// Test whether domain is supported // Test whether domain is supported
return BandcampExtractorHelper.isSupportedDomain(url); return BandcampExtractorHelper.isArtistDomain(url);
} }
} }

View File

@ -71,6 +71,6 @@ public final class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
} }
// Test whether domain is supported // Test whether domain is supported
return BandcampExtractorHelper.isSupportedDomain(url); return BandcampExtractorHelper.isArtistDomain(url);
} }
} }

View File

@ -39,6 +39,5 @@ public class BandcampCommentsLinkHandlerFactoryTest {
assertTrue(linkHandler.acceptUrl("http://ZachBenson.Bandcamp.COM/Track/U-I-Tonite/")); assertTrue(linkHandler.acceptUrl("http://ZachBenson.Bandcamp.COM/Track/U-I-Tonite/"));
assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/track/title")); 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://goodgoodblood-tl.bandcamp.com/track/when-it-all-wakes-up"));
assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com/track/unfinished"));
} }
} }

View File

@ -49,6 +49,5 @@ public class BandcampStreamLinkHandlerFactoryTest {
assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/track/title")); assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/track/title"));
assertTrue(linkHandler.acceptUrl("http://bandcamP.com/?show=38")); 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://goodgoodblood-tl.bandcamp.com/track/when-it-all-wakes-up"));
assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com/track/unfinished"));
} }
} }