From 71cda03c4c048209842177983a628d391bf35ac3 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sat, 30 Jul 2022 17:14:15 +0200 Subject: [PATCH] [Bandcamp] Apply changes in Extractors --- .../extractors/BandcampChannelExtractor.java | 33 ++++++++++++------- .../extractors/BandcampPlaylistExtractor.java | 21 +++++++----- .../BandcampRadioStreamExtractor.java | 13 +++++--- .../extractors/BandcampStreamExtractor.java | 23 ++++++++----- 4 files changed, 57 insertions(+), 33 deletions(-) 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 dc2f98407..ac44cbb8d 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 @@ -2,12 +2,18 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors; +import static org.schabi.newpipe.extractor.Image.HEIGHT_UNKNOWN; +import static org.schabi.newpipe.extractor.Image.WIDTH_UNKNOWN; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getArtistDetails; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImagesFromImageId; import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; import org.jsoup.Jsoup; +import org.schabi.newpipe.extractor.Image; +import org.schabi.newpipe.extractor.Image.ResolutionLevel; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor; @@ -25,6 +31,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nonnull; @@ -38,17 +45,15 @@ public class BandcampChannelExtractor extends ChannelExtractor { super(service, linkHandler); } + @Nonnull @Override - public String getAvatarUrl() { - if (channelInfo.getLong("bio_image_id") == 0) { - return ""; - } - - return BandcampExtractorHelper.getImageUrl(channelInfo.getLong("bio_image_id"), false); + public List getAvatars() { + return getImagesFromImageId(channelInfo.getLong("bio_image_id"), false); } + @Nonnull @Override - public String getBannerUrl() throws ParsingException { + public List getBanners() throws ParsingException { /* * Mobile API does not return the header or not the correct header. * Therefore, we need to query the website @@ -62,8 +67,11 @@ public class BandcampChannelExtractor extends ChannelExtractor { .filter(Objects::nonNull) .flatMap(element -> element.getElementsByTag("img").stream()) .map(element -> element.attr("src")) - .findFirst() - .orElse(""); // no banner available + .filter(url -> !url.isEmpty()) + .map(url -> new Image( + replaceHttpWithHttps(url), HEIGHT_UNKNOWN, WIDTH_UNKNOWN, + ResolutionLevel.UNKNOWN)) + .collect(Collectors.toUnmodifiableList()); } catch (final IOException | ReCaptchaException e) { throw new ParsingException("Could not download artist web site", e); @@ -98,9 +106,10 @@ public class BandcampChannelExtractor extends ChannelExtractor { return null; } + @Nonnull @Override - public String getParentChannelAvatarUrl() { - return null; + public List getParentChannelAvatars() { + return List.of(); } @Override @@ -156,7 +165,7 @@ public class BandcampChannelExtractor extends ChannelExtractor { @Override public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException { - channelInfo = BandcampExtractorHelper.getArtistDetails(getId()); + channelInfo = getArtistDetails(getId()); } @Nonnull 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 aa6dd7968..ee5dc9213 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 @@ -1,6 +1,7 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors; -import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImagesFromImageId; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImagesFromImageUrl; import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor.getAlbumInfoJson; import static org.schabi.newpipe.extractor.utils.JsonUtils.getJsonData; import static org.schabi.newpipe.extractor.utils.Utils.HTTPS; @@ -13,6 +14,7 @@ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; +import org.schabi.newpipe.extractor.Image; import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.downloader.Downloader; @@ -28,6 +30,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import java.io.IOException; import java.util.Objects; +import java.util.List; import javax.annotation.Nonnull; @@ -74,11 +77,11 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor { @Nonnull @Override - public String getThumbnailUrl() throws ParsingException { + public List getThumbnails() throws ParsingException { if (albumJson.isNull("art_id")) { - return ""; + return List.of(); } else { - return getImageUrl(albumJson.getLong("art_id"), true); + return getImagesFromImageId(albumJson.getLong("art_id"), true); } } @@ -94,12 +97,14 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor { return albumJson.getString("artist"); } + @Nonnull @Override - public String getUploaderAvatarUrl() { - return document.getElementsByClass("band-photo").stream() + public List getUploaderAvatars() { + return getImagesFromImageUrl(document.getElementsByClass("band-photo") + .stream() .map(element -> element.attr("src")) .findFirst() - .orElse(""); + .orElse("")); } @Override @@ -154,7 +159,7 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor { } else { // Pretend every track has the same cover art as the album collector.commit(new BandcampPlaylistStreamInfoItemExtractor( - track, getUploaderUrl(), getThumbnailUrl())); + track, getUploaderUrl(), getThumbnails())); } } 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 03a9c2222..2b28f03a7 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 @@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors; import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_API_URL; import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_URL; import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImagesFromImageId; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; @@ -11,6 +12,8 @@ import com.grack.nanojson.JsonParserException; import org.jsoup.Jsoup; import org.jsoup.nodes.Element; +import org.schabi.newpipe.extractor.Image; +import org.schabi.newpipe.extractor.Image.ResolutionLevel; import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; @@ -97,14 +100,16 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor { @Nonnull @Override - public String getThumbnailUrl() throws ParsingException { - return getImageUrl(showInfo.getLong("show_image_id"), false); + public List getThumbnails() throws ParsingException { + return getImagesFromImageId(showInfo.getLong("show_image_id"), false); } @Nonnull @Override - public String getUploaderAvatarUrl() { - return BASE_URL + "/img/buttons/bandcamp-button-circle-whitecolor-512.png"; + public List getUploaderAvatars() { + return Collections.singletonList( + new Image(BASE_URL + "/img/buttons/bandcamp-button-circle-whitecolor-512.png", + 512, 512, ResolutionLevel.MEDIUM)); } @Nonnull 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 b4e6098ae..dfdbb5696 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 @@ -2,8 +2,11 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors; -import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImagesFromImageId; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImagesFromImageUrl; +import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.parseDate; import static org.schabi.newpipe.extractor.utils.Utils.HTTPS; +import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonParserException; @@ -11,6 +14,7 @@ import com.grack.nanojson.JsonParserException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import org.schabi.newpipe.extractor.Image; import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.downloader.Downloader; @@ -98,7 +102,7 @@ public class BandcampStreamExtractor extends StreamExtractor { @Nonnull @Override public String getUrl() throws ParsingException { - return albumJson.getString("url").replace("http://", "https://"); + return replaceHttpWithHttps(albumJson.getString("url")); } @Nonnull @@ -116,26 +120,27 @@ public class BandcampStreamExtractor extends StreamExtractor { @Nullable @Override public DateWrapper getUploadDate() throws ParsingException { - return BandcampExtractorHelper.parseDate(getTextualUploadDate()); + return parseDate(getTextualUploadDate()); } @Nonnull @Override - public String getThumbnailUrl() throws ParsingException { + public List getThumbnails() throws ParsingException { if (albumJson.isNull("art_id")) { - return ""; + return List.of(); } - return getImageUrl(albumJson.getLong("art_id"), true); + return getImagesFromImageId(albumJson.getLong("art_id"), true); } @Nonnull @Override - public String getUploaderAvatarUrl() { - return document.getElementsByClass("band-photo").stream() + public List getUploaderAvatars() { + return getImagesFromImageUrl(document.getElementsByClass("band-photo") + .stream() .map(element -> element.attr("src")) .findFirst() - .orElse(""); + .orElse("")); } @Nonnull