Bandcamp: move own methods to helper class
This commit is contained in:
parent
9bc7a470ab
commit
a3e8e1c70e
9 changed files with 45 additions and 48 deletions
|
@ -4,7 +4,6 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
||||||
|
|
||||||
import com.grack.nanojson.*;
|
import com.grack.nanojson.*;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
|
@ -26,46 +25,11 @@ public class BandcampChannelExtractor extends ChannelExtractor {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch artist details from mobile endpoint.
|
|
||||||
* <a href=https://notabug.org/fynngodau/bandcampDirect/wiki/rewindBandcamp+%E2%80%93+Fetching+artist+details>
|
|
||||||
* I once took a moment to note down how it works.</a>
|
|
||||||
*/
|
|
||||||
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
|
@Override
|
||||||
public String getAvatarUrl() {
|
public String getAvatarUrl() {
|
||||||
if (channelInfo.getLong("bio_image_id") == 0) return "";
|
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.getLong("item_id"),
|
||||||
discograph.getString("item_type")
|
discograph.getString("item_type")
|
||||||
),
|
),
|
||||||
getImageUrl(
|
BandcampExtractorHelper.getImageUrl(
|
||||||
discograph.getLong("art_id"), true
|
discograph.getLong("art_id"), true
|
||||||
),
|
),
|
||||||
discograph.getString("band_name")
|
discograph.getString("band_name")
|
||||||
|
@ -154,7 +118,7 @@ public class BandcampChannelExtractor extends ChannelExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||||
channelInfo = getArtistDetails(getId());
|
channelInfo = BandcampExtractorHelper.getArtistDetails(getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
|
@ -5,6 +5,7 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
|
import com.grack.nanojson.JsonWriter;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
|
@ -105,4 +106,39 @@ public class BandcampExtractorHelper {
|
||||||
|
|
||||||
return String.valueOf(result);
|
return String.valueOf(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch artist details from mobile endpoint.
|
||||||
|
* <a href=https://notabug.org/fynngodau/bandcampDirect/wiki/rewindBandcamp+%E2%80%93+Fetching+artist+details>
|
||||||
|
* I once took a moment to note down how it works.</a>
|
||||||
|
*/
|
||||||
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,6 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl;
|
|
||||||
|
|
||||||
public class BandcampFeaturedExtractor extends KioskExtractor<InfoItem> {
|
public class BandcampFeaturedExtractor extends KioskExtractor<InfoItem> {
|
||||||
|
|
||||||
public static final String KIOSK_FEATURED = "Featured";
|
public static final String KIOSK_FEATURED = "Featured";
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
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.BandcampExtractorHelper.getJSONFromJavaScriptVariables;
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor.getAlbumInfoJson;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor.getAlbumInfoJson;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import com.grack.nanojson.JsonObject;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
|
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 {
|
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
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 {
|
public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 {
|
public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
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 {
|
public class BandcampStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
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 org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -41,7 +40,7 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||||
@Override
|
@Override
|
||||||
public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
|
public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return BandcampChannelExtractor.getArtistDetails(id)
|
return BandcampExtractorHelper.getArtistDetails(id)
|
||||||
.getString("bandcamp_url")
|
.getString("bandcamp_url")
|
||||||
.replace("http://", "https://");
|
.replace("http://", "https://");
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
|
|
Loading…
Reference in a new issue