[Bandcamp] Fix channel link handler factory

This commit is contained in:
Fynn Godau 2020-12-22 20:02:53 +01:00
parent 50903730b1
commit c9e9953bb0
2 changed files with 23 additions and 5 deletions

View File

@ -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);
}
}
}

View File

@ -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/"));