diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelExtractor.java index 8b3cabfdb..4da4a44ef 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelExtractor.java @@ -4,7 +4,6 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors; import com.grack.nanojson.*; import org.jsoup.Jsoup; -import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.downloader.Downloader; @@ -26,46 +25,11 @@ public class BandcampChannelExtractor extends ChannelExtractor { super(service, linkHandler); } - /** - * Fetch artist details from mobile endpoint. - * - * I once took a moment to note down how it works. - */ - public static JsonObject getArtistDetails(String id) throws ParsingException { - try { - return - JsonParser.object().from( - NewPipe.getDownloader().post( - "https://bandcamp.com/api/mobile/22/band_details", - null, - JsonWriter.string() - .object() - .value("band_id", id) - .end() - .done() - .getBytes() - ).responseBody() - ); - } catch (IOException | ReCaptchaException | JsonParserException e) { - throw new ParsingException("Could not download band details", e); - } - } - - /** - * @param id The image ID - * @param album Whether this is the cover of an album - * @return Url of image with this ID in size 10 which is 1200x1200 (we could also choose size 0 - * but we don't want something as large as 3460x3460 here, do we?) - */ - static String getImageUrl(long id, boolean album) { - return "https://f4.bcbits.com/img/" + (album ? 'a' : "") + id + "_10.jpg"; - } - @Override public String getAvatarUrl() { if (channelInfo.getLong("bio_image_id") == 0) return ""; - return getImageUrl(channelInfo.getLong("bio_image_id"), false); + return BandcampExtractorHelper.getImageUrl(channelInfo.getLong("bio_image_id"), false); } /** @@ -132,7 +96,7 @@ public class BandcampChannelExtractor extends ChannelExtractor { discograph.getLong("item_id"), discograph.getString("item_type") ), - getImageUrl( + BandcampExtractorHelper.getImageUrl( discograph.getLong("art_id"), true ), discograph.getString("band_name") @@ -154,7 +118,7 @@ public class BandcampChannelExtractor extends ChannelExtractor { @Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { - channelInfo = getArtistDetails(getId()); + channelInfo = BandcampExtractorHelper.getArtistDetails(getId()); } @Nonnull diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java index a9f4ec746..5371681a4 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java @@ -5,6 +5,7 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors; import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParserException; +import com.grack.nanojson.JsonWriter; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; @@ -105,4 +106,39 @@ public class BandcampExtractorHelper { return String.valueOf(result); } + + /** + * Fetch artist details from mobile endpoint. + * + * I once took a moment to note down how it works. + */ + public static JsonObject getArtistDetails(String id) throws ParsingException { + try { + return + JsonParser.object().from( + NewPipe.getDownloader().post( + "https://bandcamp.com/api/mobile/22/band_details", + null, + JsonWriter.string() + .object() + .value("band_id", id) + .end() + .done() + .getBytes() + ).responseBody() + ); + } catch (IOException | ReCaptchaException | JsonParserException e) { + throw new ParsingException("Could not download band details", e); + } + } + + /** + * @param id The image ID + * @param album Whether this is the cover of an album + * @return Url of image with this ID in size 10 which is 1200x1200 (we could also choose size 0 + * but we don't want something as large as 3460x3460 here, do we?) + */ + static String getImageUrl(long id, boolean album) { + return "https://f4.bcbits.com/img/" + (album ? 'a' : "") + id + "_10.jpg"; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampFeaturedExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampFeaturedExtractor.java index 0456b4c2e..d5d3c412d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampFeaturedExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampFeaturedExtractor.java @@ -19,8 +19,6 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector; import javax.annotation.Nonnull; import java.io.IOException; -import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl; - public class BandcampFeaturedExtractor extends KioskExtractor { public static final String KIOSK_FEATURED = "Featured"; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java index ddb78d3fa..ddc2b6b40 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java @@ -18,7 +18,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import javax.annotation.Nonnull; import java.io.IOException; -import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl; import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getJSONFromJavaScriptVariables; import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor.getAlbumInfoJson; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java index 75d841723..668dcddd7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java @@ -4,7 +4,7 @@ import com.grack.nanojson.JsonObject; import org.jsoup.nodes.Element; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor; -import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl; public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioInfoItemExtractor.java index adae3e557..808c1afd3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioInfoItemExtractor.java @@ -10,7 +10,7 @@ import org.schabi.newpipe.extractor.stream.StreamType; import javax.annotation.Nullable; -import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl; public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java index 98518b442..3780671ac 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl; public class BandcampRadioStreamExtractor extends BandcampStreamExtractor { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java index e38315af6..8353959fc 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java @@ -24,7 +24,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl; public class BandcampStreamExtractor extends StreamExtractor { 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 94b45771e..370057dde 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 @@ -8,7 +8,6 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; -import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor; import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper; import java.io.IOException; @@ -41,7 +40,7 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory { @Override public String getUrl(String id, List contentFilter, String sortFilter) throws ParsingException { try { - return BandcampChannelExtractor.getArtistDetails(id) + return BandcampExtractorHelper.getArtistDetails(id) .getString("bandcamp_url") .replace("http://", "https://"); } catch (NullPointerException e) {