Add BASE_URL and BASE_API_URL to BandcampExtractorHelper
This commit is contained in:
parent
adde4332d1
commit
c07db80ef0
|
@ -19,6 +19,7 @@ import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
|
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
|
||||||
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_URL;
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampFeaturedExtractor.FEATURED_API_URL;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampFeaturedExtractor.FEATURED_API_URL;
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampFeaturedExtractor.KIOSK_FEATURED;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampFeaturedExtractor.KIOSK_FEATURED;
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioExtractor.KIOSK_RADIO;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioExtractor.KIOSK_RADIO;
|
||||||
|
@ -32,7 +33,7 @@ public class BandcampService extends StreamingService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBaseUrl() {
|
public String getBaseUrl() {
|
||||||
return "https://bandcamp.com";
|
return BASE_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,7 +114,7 @@ public class BandcampService extends StreamingService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamExtractor getStreamExtractor(final LinkHandler linkHandler) {
|
public StreamExtractor getStreamExtractor(final LinkHandler linkHandler) {
|
||||||
if (linkHandler.getUrl().matches("https?://bandcamp\\.com/\\?show=\\d+"))
|
if (BandcampExtractorHelper.isRadioUrl(linkHandler.getUrl()))
|
||||||
return new BandcampRadioStreamExtractor(this, linkHandler);
|
return new BandcampRadioStreamExtractor(this, linkHandler);
|
||||||
else
|
else
|
||||||
return new BandcampStreamExtractor(this, linkHandler);
|
return new BandcampStreamExtractor(this, linkHandler);
|
||||||
|
|
|
@ -20,10 +20,14 @@ import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class BandcampExtractorHelper {
|
public class BandcampExtractorHelper {
|
||||||
|
|
||||||
|
public static final String BASE_URL = "https://bandcamp.com";
|
||||||
|
public static final String BASE_API_URL = BASE_URL + "/api";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Get an attribute of a web page as JSON
|
* <p>Get an attribute of a web page as JSON
|
||||||
*
|
*
|
||||||
|
@ -50,11 +54,12 @@ public class BandcampExtractorHelper {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String jsonString = NewPipe.getDownloader().get(
|
final String jsonString = NewPipe.getDownloader().get(
|
||||||
"https://bandcamp.com/api/mobile/22/tralbum_details?band_id=" + bandId
|
BASE_API_URL + "/mobile/22/tralbum_details?band_id=" + bandId
|
||||||
+ "&tralbum_id=" + itemId + "&tralbum_type=" + itemType.charAt(0))
|
+ "&tralbum_id=" + itemId + "&tralbum_type=" + itemType.charAt(0))
|
||||||
.responseBody();
|
.responseBody();
|
||||||
|
|
||||||
return JsonParser.object().from(jsonString).getString("bandcamp_url").replace("http://", "https://");
|
return JsonParser.object().from(jsonString)
|
||||||
|
.getString("bandcamp_url").replace("http://", "https://");
|
||||||
|
|
||||||
} catch (final JsonParserException | ReCaptchaException | IOException e) {
|
} catch (final JsonParserException | ReCaptchaException | IOException e) {
|
||||||
throw new ParsingException("Ids could not be translated to URL", e);
|
throw new ParsingException("Ids could not be translated to URL", e);
|
||||||
|
@ -70,7 +75,7 @@ public class BandcampExtractorHelper {
|
||||||
final StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
// Remove empty strings
|
// Remove empty strings
|
||||||
final ArrayList<String> list = new ArrayList<>(Arrays.asList(strings));
|
final List<String> list = new ArrayList<>(Arrays.asList(strings));
|
||||||
for (int i = list.size() - 1; i >= 0; i--) {
|
for (int i = list.size() - 1; i >= 0; i--) {
|
||||||
if (Utils.isNullOrEmpty(list.get(i)) || list.get(i).equals("null")) {
|
if (Utils.isNullOrEmpty(list.get(i)) || list.get(i).equals("null")) {
|
||||||
list.remove(i);
|
list.remove(i);
|
||||||
|
@ -101,7 +106,7 @@ public class BandcampExtractorHelper {
|
||||||
return
|
return
|
||||||
JsonParser.object().from(
|
JsonParser.object().from(
|
||||||
NewPipe.getDownloader().post(
|
NewPipe.getDownloader().post(
|
||||||
"https://bandcamp.com/api/mobile/22/band_details",
|
BASE_API_URL + "/mobile/22/band_details",
|
||||||
null,
|
null,
|
||||||
JsonWriter.string()
|
JsonWriter.string()
|
||||||
.object()
|
.object()
|
||||||
|
@ -165,6 +170,5 @@ public class BandcampExtractorHelper {
|
||||||
} catch (final DateTimeException e) {
|
} catch (final DateTimeException e) {
|
||||||
throw new ParsingException("Could not parse date '" + textDate + "'", e);
|
throw new ParsingException("Could not parse date '" + textDate + "'", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,12 @@ 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.BandcampExtractorHelper.BASE_API_URL;
|
||||||
|
|
||||||
public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem> {
|
public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem> {
|
||||||
|
|
||||||
public static final String KIOSK_FEATURED = "Featured";
|
public static final String KIOSK_FEATURED = "Featured";
|
||||||
public static final String FEATURED_API_URL = "https://bandcamp.com/api/mobile/24/bootstrap_data";
|
public static final String FEATURED_API_URL = BASE_API_URL + "/mobile/24/bootstrap_data";
|
||||||
|
|
||||||
private JsonObject json;
|
private JsonObject json;
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,12 @@ 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.BandcampExtractorHelper.BASE_API_URL;
|
||||||
|
|
||||||
public class BandcampRadioExtractor extends KioskExtractor<StreamInfoItem> {
|
public class BandcampRadioExtractor extends KioskExtractor<StreamInfoItem> {
|
||||||
|
|
||||||
public static final String KIOSK_RADIO = "Radio";
|
public static final String KIOSK_RADIO = "Radio";
|
||||||
public static final String RADIO_API_URL = "https://bandcamp.com/api/bcweekly/1/list";
|
public static final String RADIO_API_URL = BASE_API_URL + "/bcweekly/1/list";
|
||||||
|
|
||||||
private JsonObject json = null;
|
private JsonObject json = null;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +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.BandcampExtractorHelper.BASE_URL;
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl;
|
||||||
|
|
||||||
public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
|
public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
|
@ -49,7 +50,7 @@ public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return "https://bandcamp.com/?show=" + show.getInt("id");
|
return BASE_URL + "/?show=" + show.getInt("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.*;
|
||||||
|
|
||||||
public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
|
public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
|
||||||
static JsonObject query(final int id) throws ParsingException {
|
static JsonObject query(final int id) throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return JsonParser.object().from(
|
return JsonParser.object().from(
|
||||||
NewPipe.getDownloader().get("https://bandcamp.com/api/bcweekly/1/get?id=" + id).responseBody()
|
NewPipe.getDownloader().get(BASE_API_URL + "/bcweekly/1/get?id=" + id).responseBody()
|
||||||
);
|
);
|
||||||
} catch (final IOException | ReCaptchaException | JsonParserException e) {
|
} catch (final IOException | ReCaptchaException | JsonParserException e) {
|
||||||
throw new ParsingException("could not get show data", e);
|
throw new ParsingException("could not get show data", e);
|
||||||
|
@ -88,7 +88,7 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderAvatarUrl() {
|
public String getUploaderAvatarUrl() {
|
||||||
return "https://bandcamp.com/img/buttons/bandcamp-button-circle-whitecolor-512.png";
|
return BASE_URL + "/img/buttons/bandcamp-button-circle-whitecolor-512.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
|
@ -18,9 +18,11 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_API_URL;
|
||||||
|
|
||||||
public class BandcampSuggestionExtractor extends SuggestionExtractor {
|
public class BandcampSuggestionExtractor extends SuggestionExtractor {
|
||||||
|
|
||||||
private static final String AUTOCOMPLETE_URL = "https://bandcamp.com/api/fuzzysearch/1/autocomplete?q=";
|
private static final String AUTOCOMPLETE_URL = BASE_API_URL + "/fuzzysearch/1/autocomplete?q=";
|
||||||
public BandcampSuggestionExtractor(final StreamingService service) {
|
public BandcampSuggestionExtractor(final StreamingService service) {
|
||||||
super(service);
|
super(service);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_URL;
|
||||||
|
|
||||||
public class BandcampSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
public class BandcampSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +19,7 @@ public class BandcampSearchQueryHandlerFactory extends SearchQueryHandlerFactory
|
||||||
throws ParsingException {
|
throws ParsingException {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return "https://bandcamp.com/search?q=" +
|
return BASE_URL + "/search?q=" +
|
||||||
URLEncoder.encode(query, "UTF-8")
|
URLEncoder.encode(query, "UTF-8")
|
||||||
+ "&page=1";
|
+ "&page=1";
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
|
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Tracks don't have standalone ids, they are always in combination with the band id.
|
* <p>Tracks don't have standalone ids, they are always in combination with the band id.
|
||||||
* That's why id = url.</p>
|
* That's why id = url.</p>
|
||||||
|
@ -34,7 +36,7 @@ public class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
|
||||||
@Override
|
@Override
|
||||||
public String getUrl(final String input) {
|
public String getUrl(final String input) {
|
||||||
if (input.matches("\\d+")) {
|
if (input.matches("\\d+")) {
|
||||||
return "https://bandcamp.com/?show=" + input;
|
return BASE_URL + "/?show=" + input;
|
||||||
} else {
|
} else {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue