2019-12-22 00:42:26 +01:00
|
|
|
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
|
|
|
|
|
|
|
|
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
|
|
|
|
2023-04-13 11:03:37 +02:00
|
|
|
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
|
|
|
|
|
2020-11-24 09:41:40 +01:00
|
|
|
import com.grack.nanojson.JsonArray;
|
|
|
|
import com.grack.nanojson.JsonObject;
|
2023-04-13 11:03:37 +02:00
|
|
|
|
2019-12-22 01:05:34 +01:00
|
|
|
import org.jsoup.Jsoup;
|
2019-12-22 00:42:26 +01:00
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
|
|
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
2023-04-13 11:03:37 +02:00
|
|
|
import org.schabi.newpipe.extractor.channel.ChannelTabExtractor;
|
2019-12-22 00:42:26 +01:00
|
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
2022-11-04 23:47:44 +01:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
|
2019-12-22 00:42:26 +01:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
2023-04-13 11:03:37 +02:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ReadyChannelTabListLinkHandler;
|
2019-12-22 00:42:26 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2023-04-13 11:03:37 +02:00
|
|
|
import java.util.ArrayList;
|
2022-10-25 10:38:23 +02:00
|
|
|
import java.util.List;
|
2022-03-17 17:13:25 +01:00
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.stream.Stream;
|
2019-12-22 00:42:26 +01:00
|
|
|
|
2023-04-13 11:03:37 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2022-03-18 17:50:25 +01:00
|
|
|
|
2019-12-22 00:42:26 +01:00
|
|
|
public class BandcampChannelExtractor extends ChannelExtractor {
|
|
|
|
|
2020-03-19 11:18:29 +01:00
|
|
|
private JsonObject channelInfo;
|
2019-12-22 00:42:26 +01:00
|
|
|
|
2022-03-18 17:50:25 +01:00
|
|
|
public BandcampChannelExtractor(final StreamingService service,
|
|
|
|
final ListLinkHandler linkHandler) {
|
2019-12-22 00:42:26 +01:00
|
|
|
super(service, linkHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getAvatarUrl() {
|
2022-03-18 17:50:25 +01:00
|
|
|
if (channelInfo.getLong("bio_image_id") == 0) {
|
|
|
|
return "";
|
|
|
|
}
|
2020-03-19 11:18:29 +01:00
|
|
|
|
2020-04-26 23:05:56 +02:00
|
|
|
return BandcampExtractorHelper.getImageUrl(channelInfo.getLong("bio_image_id"), false);
|
2019-12-22 00:42:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBannerUrl() throws ParsingException {
|
2020-11-24 09:41:40 +01:00
|
|
|
/*
|
2021-04-13 21:10:59 +02:00
|
|
|
* Mobile API does not return the header or not the correct header.
|
|
|
|
* Therefore, we need to query the website
|
2020-11-24 09:41:40 +01:00
|
|
|
*/
|
2019-12-22 00:42:26 +01:00
|
|
|
try {
|
2020-11-24 09:41:40 +01:00
|
|
|
final String html = getDownloader()
|
2022-10-25 10:38:23 +02:00
|
|
|
.get(replaceHttpWithHttps(channelInfo.getString("bandcamp_url")))
|
|
|
|
.responseBody();
|
2019-12-22 00:42:26 +01:00
|
|
|
|
2022-03-17 17:13:25 +01:00
|
|
|
return Stream.of(Jsoup.parse(html).getElementById("customHeader"))
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
.flatMap(element -> element.getElementsByTag("img").stream())
|
|
|
|
.map(element -> element.attr("src"))
|
|
|
|
.findFirst()
|
|
|
|
.orElse(""); // no banner available
|
2019-12-22 00:42:26 +01:00
|
|
|
|
2020-11-24 09:41:40 +01:00
|
|
|
} catch (final IOException | ReCaptchaException e) {
|
2019-12-22 00:42:26 +01:00
|
|
|
throw new ParsingException("Could not download artist web site", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-13 21:10:59 +02:00
|
|
|
* Bandcamp discontinued their RSS feeds because it hadn't been used enough.
|
2019-12-22 00:42:26 +01:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String getFeedUrl() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getSubscriberCount() {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDescription() {
|
|
|
|
return channelInfo.getString("bio");
|
|
|
|
}
|
|
|
|
|
2020-06-03 21:35:11 +02:00
|
|
|
@Override
|
|
|
|
public String getParentChannelName() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getParentChannelUrl() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getParentChannelAvatarUrl() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-02-19 15:51:02 +01:00
|
|
|
@Override
|
|
|
|
public boolean isVerified() throws ParsingException {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-25 10:38:23 +02:00
|
|
|
@Nonnull
|
|
|
|
@Override
|
2022-11-04 23:47:44 +01:00
|
|
|
public List<ListLinkHandler> getTabs() throws ParsingException {
|
2022-10-25 10:38:23 +02:00
|
|
|
final JsonArray discography = channelInfo.getArray("discography");
|
2023-04-16 15:24:19 +02:00
|
|
|
final TabExtractorBuilder builder = new TabExtractorBuilder(discography);
|
2022-10-25 10:38:23 +02:00
|
|
|
|
2023-04-13 11:03:37 +02:00
|
|
|
final List<ListLinkHandler> tabs = new ArrayList<>();
|
2023-04-16 15:24:19 +02:00
|
|
|
|
|
|
|
if (discography.stream().anyMatch(o -> (
|
|
|
|
(JsonObject) o).getString("item_type").equals("track"))) {
|
|
|
|
tabs.add(new ReadyChannelTabListLinkHandler(getUrl(), getId(),
|
|
|
|
ChannelTabs.TRACKS, builder));
|
|
|
|
}
|
2023-04-13 11:03:37 +02:00
|
|
|
|
2022-10-25 10:38:23 +02:00
|
|
|
if (discography.stream().anyMatch(o -> (
|
|
|
|
(JsonObject) o).getString("item_type").equals("album"))) {
|
2023-04-25 15:43:47 +02:00
|
|
|
tabs.add(new ReadyChannelTabListLinkHandler(getUrl(), getId(),
|
|
|
|
ChannelTabs.ALBUMS, builder));
|
2022-10-25 10:38:23 +02:00
|
|
|
}
|
2019-12-22 00:42:26 +01:00
|
|
|
|
2023-04-13 11:03:37 +02:00
|
|
|
return tabs;
|
2019-12-22 00:42:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-03-18 17:50:25 +01:00
|
|
|
public void onFetchPage(@Nonnull final Downloader downloader)
|
|
|
|
throws IOException, ExtractionException {
|
2020-04-26 23:05:56 +02:00
|
|
|
channelInfo = BandcampExtractorHelper.getArtistDetails(getId());
|
2019-12-22 00:42:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return channelInfo.getString("name");
|
|
|
|
}
|
2023-04-13 11:03:37 +02:00
|
|
|
|
2023-04-16 15:24:19 +02:00
|
|
|
private static class TabExtractorBuilder
|
|
|
|
implements ReadyChannelTabListLinkHandler.ChannelTabExtractorBuilder {
|
|
|
|
private final JsonArray discography;
|
|
|
|
|
|
|
|
TabExtractorBuilder(final JsonArray discography) {
|
|
|
|
this.discography = discography;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelTabExtractor build(final StreamingService service,
|
|
|
|
final ListLinkHandler linkHandler) {
|
|
|
|
return BandcampChannelTabExtractor.fromDiscography(service, linkHandler, discography);
|
|
|
|
}
|
2023-04-13 11:03:37 +02:00
|
|
|
}
|
2019-12-22 00:42:26 +01:00
|
|
|
}
|