Skip to content

Commit def745b

Browse files
authored
Merge pull request #579 from fynngodau/bandcamp-fix-linkhandler
[Bandcamp] Fix link handler acceptance behaviour
2 parents f9d0625 + 2e57a8f commit def745b

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@
77
import com.grack.nanojson.JsonParserException;
88
import com.grack.nanojson.JsonWriter;
99
import org.jsoup.Jsoup;
10-
import org.jsoup.nodes.Document;
1110
import org.schabi.newpipe.extractor.NewPipe;
1211
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1312
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
1413
import org.schabi.newpipe.extractor.localization.DateWrapper;
15-
import org.schabi.newpipe.extractor.utils.Utils;
1614

1715
import java.io.IOException;
1816
import java.time.DateTimeException;
1917
import java.time.ZonedDateTime;
2018
import java.time.format.DateTimeFormatter;
21-
import java.util.ArrayList;
22-
import java.util.Arrays;
23-
import java.util.List;
2419
import java.util.Locale;
2520

2621
public class BandcampExtractorHelper {
@@ -95,12 +90,18 @@ public static boolean isSupportedDomain(final String url) throws ParsingExceptio
9590
if (url.toLowerCase().matches("https?://.+\\.bandcamp\\.com(/.*)?")) return true;
9691

9792
try {
98-
// Accept all other URLs if they contain a <meta> tag that says they are generated by bandcamp
93+
// Test other URLs for whether they contain a footer that links to bandcamp
9994
return Jsoup.parse(
10095
NewPipe.getDownloader().get(url).responseBody()
10196
)
102-
.getElementsByAttributeValue("name", "generator")
103-
.attr("content").equals("Bandcamp");
97+
.getElementById("pgFt")
98+
.getElementById("pgFt-inner")
99+
.getElementById("footer-logo-wrapper")
100+
.getElementById("footer-logo")
101+
.getElementsByClass("hiddenAccess")
102+
.text().equals("Bandcamp");
103+
} catch (NullPointerException e) {
104+
return false;
104105
} catch (IOException | ReCaptchaException e) {
105106
throw new ParsingException("Could not determine whether URL is custom domain " +
106107
"(not available? network error?)");

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/linkHandler/BandcampChannelLinkHandlerFactory.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public String getUrl(final String id, final List<String> contentFilter, final St
5555
* Accepts only pages that lead to the root of an artist profile. Supports external pages.
5656
*/
5757
@Override
58-
public boolean onAcceptUrl(final String url) throws ParsingException {
58+
public boolean onAcceptUrl(String url) throws ParsingException {
59+
60+
url = url.toLowerCase();
5961

6062
// https: | | artist.bandcamp.com | releases
6163
// 0 1 2 3
@@ -64,8 +66,10 @@ public boolean onAcceptUrl(final String url) throws ParsingException {
6466
// URL is too short
6567
if (splitUrl.length < 3) return false;
6668

67-
// Must have "releases" as segment after url or none at all
68-
if (splitUrl.length > 3 && !splitUrl[3].equals("releases")) {
69+
// Must have "releases" or "music" as segment after url or none at all
70+
if (splitUrl.length > 3 && !(
71+
splitUrl[3].equals("releases") || splitUrl[3].equals("music")
72+
)) {
6973

7074
return false;
7175

extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelLinkHandlerFactoryTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,24 @@ public void testAcceptUrl() throws ParsingException {
2929
assertTrue(linkHandler.acceptUrl("http://zachbenson.bandcamp.com"));
3030
assertTrue(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/"));
3131
assertTrue(linkHandler.acceptUrl("https://billwurtz.bandcamp.com/releases"));
32+
assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/releases"));
33+
assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/releases/"));
3234

3335
assertTrue(linkHandler.acceptUrl("http://zachbenson.bandcamp.com/"));
3436

3537
assertFalse(linkHandler.acceptUrl("https://bandcamp.com"));
3638
assertFalse(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/track/kitchen"));
3739
assertFalse(linkHandler.acceptUrl("https://daily.bandcamp.com/"));
40+
assertFalse(linkHandler.acceptUrl("https://DAILY.BANDCAMP.COM"));
3841
assertFalse(linkHandler.acceptUrl("https://daily.bandcamp.com/best-of-2020/bandcamp-daily-staffers-on-their-favorite-albums-of-2020"));
3942

4043
// External URLs
41-
assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/releases"));
42-
assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/releases/"));
44+
assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com"));
45+
assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com/music"));
46+
assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com/music/"));
47+
assertTrue(linkHandler.acceptUrl("https://diskak.usopop.com/"));
48+
assertTrue(linkHandler.acceptUrl("https://diskak.usopop.com/releases"));
49+
assertTrue(linkHandler.acceptUrl("https://diskak.usopop.com/RELEASES"));
4350

4451
assertFalse(linkHandler.acceptUrl("https://example.com/releases"));
4552
}
@@ -51,13 +58,19 @@ public void testGetId() throws ParsingException {
5158
assertEquals("1581461772", linkHandler.getId("https://interovgm.bandcamp.com/releases"));
5259
assertEquals("3321800855", linkHandler.getId("https://infiniteammo.bandcamp.com/"));
5360
assertEquals("3775652329", linkHandler.getId("https://npet.bandcamp.com/"));
61+
62+
assertEquals("2735462545", linkHandler.getId("http://lobstertheremin.com/"));
63+
assertEquals("2735462545", linkHandler.getId("https://lobstertheremin.com/music/"));
64+
assertEquals("3826445168", linkHandler.getId("https://diskak.usopop.com/releases"));
5465
}
5566

5667
@Test
5768
public void testGetUrl() throws ParsingException {
5869
assertEquals("https://macbenson.bandcamp.com", linkHandler.getUrl("1196681540"));
5970
assertEquals("https://interovgm.bandcamp.com", linkHandler.getUrl("1581461772"));
6071
assertEquals("https://infiniteammo.bandcamp.com", linkHandler.getUrl("3321800855"));
72+
73+
assertEquals("https://lobstertheremin.com", linkHandler.getUrl("2735462545"));
6174
}
6275

6376
@Test(expected = ParsingException.class)

extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamLinkHandlerFactoryTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ public void testAcceptUrl() throws ParsingException {
4949
assertTrue(linkHandler.acceptUrl("https://interovgm.bandcamp.com/track/title"));
5050
assertTrue(linkHandler.acceptUrl("http://bandcamP.com/?show=38"));
5151
assertTrue(linkHandler.acceptUrl("https://goodgoodblood-tl.bandcamp.com/track/when-it-all-wakes-up"));
52+
assertTrue(linkHandler.acceptUrl("https://lobstertheremin.com/track/unfinished"));
5253
}
5354
}

0 commit comments

Comments
 (0)