|
16 | 16 | import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; |
17 | 17 | import org.schabi.newpipe.extractor.localization.DateWrapper; |
18 | 18 | import org.schabi.newpipe.extractor.utils.ImageSuffix; |
| 19 | +import org.schabi.newpipe.extractor.utils.Utils; |
19 | 20 |
|
20 | 21 | import java.io.IOException; |
21 | 22 | import java.nio.charset.StandardCharsets; |
@@ -155,25 +156,34 @@ public static String getImageUrl(final long id, final boolean isAlbum) { |
155 | 156 |
|
156 | 157 | /** |
157 | 158 | * @return <code>true</code> if the given URL looks like it comes from a bandcamp custom domain |
158 | | - * or if it comes from <code>bandcamp.com</code> itself |
| 159 | + * or a <code>*.bandcamp.com</code> subdomain |
159 | 160 | */ |
160 | | - public static boolean isSupportedDomain(final String url) throws ParsingException { |
| 161 | + public static boolean isArtistDomain(final String url) throws ParsingException { |
161 | 162 |
|
162 | 163 | // Accept all bandcamp.com URLs |
163 | 164 | if (url.toLowerCase().matches("https?://.+\\.bandcamp\\.com(/.*)?")) { |
164 | 165 | return true; |
165 | 166 | } |
166 | 167 |
|
| 168 | + // Reject non-artist bandcamp.com URLs |
| 169 | + if (url.toLowerCase().matches("https?://bandcamp\\.com(/.*)?")) { |
| 170 | + return false; |
| 171 | + } |
| 172 | + |
167 | 173 | try { |
168 | 174 | // Test other URLs for whether they contain a footer that links to bandcamp |
169 | | - return Jsoup.parse(NewPipe.getDownloader().get(url).responseBody()) |
170 | | - .getElementById("pgFt") |
171 | | - .getElementById("pgFt-inner") |
172 | | - .getElementById("footer-logo-wrapper") |
173 | | - .getElementById("footer-logo") |
174 | | - .getElementsByClass("hiddenAccess") |
175 | | - .text().equals("Bandcamp"); |
176 | | - } catch (final NullPointerException e) { |
| 175 | + return Jsoup.parse( |
| 176 | + NewPipe.getDownloader() |
| 177 | + .get(Utils.replaceHttpWithHttps(url)) |
| 178 | + .responseBody() |
| 179 | + ) |
| 180 | + .getElementsByClass("cart-wrapper") |
| 181 | + .get(0) |
| 182 | + .getElementsByTag("a") |
| 183 | + .get(0) |
| 184 | + .attr("href") |
| 185 | + .equals("https://bandcamp.com/cart"); |
| 186 | + } catch (final NullPointerException | IndexOutOfBoundsException e) { |
177 | 187 | return false; |
178 | 188 | } catch (final IOException | ReCaptchaException e) { |
179 | 189 | throw new ParsingException("Could not determine whether URL is custom domain " |
|
0 commit comments