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;
|
|
|
|
|
2020-11-24 09:41:40 +01:00
|
|
|
import com.grack.nanojson.JsonArray;
|
|
|
|
import com.grack.nanojson.JsonObject;
|
2019-12-22 01:05:34 +01:00
|
|
|
import org.jsoup.Jsoup;
|
2020-08-02 16:23:53 +02:00
|
|
|
import org.schabi.newpipe.extractor.Page;
|
2019-12-22 00:42:26 +01:00
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
|
|
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
|
|
|
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;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
2020-05-25 18:51:31 +02:00
|
|
|
import org.schabi.newpipe.extractor.services.bandcamp.extractors.streaminfoitem.BandcampDiscographStreamInfoItemExtractor;
|
2019-12-22 00:42:26 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class BandcampChannelExtractor extends ChannelExtractor {
|
|
|
|
|
2020-03-19 11:18:29 +01:00
|
|
|
private JsonObject channelInfo;
|
2019-12-22 00:42:26 +01:00
|
|
|
|
2020-11-24 09:41:40 +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() {
|
2020-03-19 11:18:29 +01:00
|
|
|
if (channelInfo.getLong("bio_image_id") == 0) return "";
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Why does the mobile endpoint not contain the header?? Or at least not the same one?
|
|
|
|
* Anyway we're back to querying websites
|
|
|
|
*/
|
2019-12-22 00:42:26 +01:00
|
|
|
try {
|
2020-11-24 09:41:40 +01:00
|
|
|
final String html = getDownloader()
|
|
|
|
.get(channelInfo.getString("bandcamp_url").replace("http://", "https://"))
|
|
|
|
.responseBody();
|
2019-12-22 00:42:26 +01:00
|
|
|
|
2019-12-22 01:05:34 +01:00
|
|
|
return Jsoup.parse(html)
|
|
|
|
.getElementById("customHeader")
|
2019-12-22 00:42:26 +01:00
|
|
|
.getElementsByTag("img")
|
2019-12-22 01:05:34 +01:00
|
|
|
.first()
|
2019-12-22 00:42:26 +01:00
|
|
|
.attr("src");
|
|
|
|
|
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);
|
2020-11-24 09:41:40 +01:00
|
|
|
} catch (final NullPointerException e) {
|
2019-12-22 01:38:48 +01:00
|
|
|
// No banner available
|
|
|
|
return "";
|
2019-12-22 00:42:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-24 09:41:40 +01:00
|
|
|
* bandcamp stopped providing RSS feeds when appending /feed to any URL
|
|
|
|
* because too few people used it.
|
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;
|
|
|
|
}
|
|
|
|
|
2019-12-22 00:42:26 +01:00
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ParsingException {
|
|
|
|
|
2020-11-24 09:41:40 +01:00
|
|
|
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
2019-12-22 00:42:26 +01:00
|
|
|
|
2020-11-24 09:41:40 +01:00
|
|
|
final JsonArray discography = channelInfo.getArray("discography");
|
2019-12-22 00:42:26 +01:00
|
|
|
|
2020-03-19 11:18:29 +01:00
|
|
|
for (int i = 0; i < discography.size(); i++) {
|
2019-12-22 00:42:26 +01:00
|
|
|
// I define discograph as an item that can appear in a discography
|
2020-11-24 09:41:40 +01:00
|
|
|
final JsonObject discograph = discography.getObject(i);
|
2019-12-22 00:42:26 +01:00
|
|
|
|
|
|
|
if (!discograph.getString("item_type").equals("track")) continue;
|
|
|
|
|
2020-05-25 18:51:31 +02:00
|
|
|
collector.commit(new BandcampDiscographStreamInfoItemExtractor(discograph, getUrl()));
|
2019-12-22 00:42:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new InfoItemsPage<>(collector, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-02 16:23:53 +02:00
|
|
|
public InfoItemsPage<StreamInfoItem> getPage(Page page) {
|
2019-12-22 00:42:26 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFetchPage(@Nonnull 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");
|
|
|
|
}
|
|
|
|
}
|