Add BASE_URL and BASE_API_URL to BandcampExtractorHelper

This commit is contained in:
TobiGr 2021-02-21 12:15:45 +01:00
parent adde4332d1
commit c07db80ef0
9 changed files with 32 additions and 16 deletions

View File

@ -19,6 +19,7 @@ import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
import java.util.Collections;
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.KIOSK_FEATURED;
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioExtractor.KIOSK_RADIO;
@ -32,7 +33,7 @@ public class BandcampService extends StreamingService {
@Override
public String getBaseUrl() {
return "https://bandcamp.com";
return BASE_URL;
}
@Override
@ -113,7 +114,7 @@ public class BandcampService extends StreamingService {
@Override
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);
else
return new BandcampStreamExtractor(this, linkHandler);

View File

@ -20,10 +20,14 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
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
*
@ -50,11 +54,12 @@ public class BandcampExtractorHelper {
try {
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))
.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) {
throw new ParsingException("Ids could not be translated to URL", e);
@ -70,7 +75,7 @@ public class BandcampExtractorHelper {
final StringBuilder result = new StringBuilder();
// 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--) {
if (Utils.isNullOrEmpty(list.get(i)) || list.get(i).equals("null")) {
list.remove(i);
@ -101,7 +106,7 @@ public class BandcampExtractorHelper {
return
JsonParser.object().from(
NewPipe.getDownloader().post(
"https://bandcamp.com/api/mobile/22/band_details",
BASE_API_URL + "/mobile/22/band_details",
null,
JsonWriter.string()
.object()
@ -165,6 +170,5 @@ public class BandcampExtractorHelper {
} catch (final DateTimeException e) {
throw new ParsingException("Could not parse date '" + textDate + "'", e);
}
}
}

View File

@ -19,10 +19,12 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector;
import javax.annotation.Nonnull;
import java.io.IOException;
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_API_URL;
public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem> {
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;

View File

@ -19,10 +19,12 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import javax.annotation.Nonnull;
import java.io.IOException;
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_API_URL;
public class BandcampRadioExtractor extends KioskExtractor<StreamInfoItem> {
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;

View File

@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.stream.StreamType;
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;
public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
@ -49,7 +50,7 @@ public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
@Override
public String getUrl() {
return "https://bandcamp.com/?show=" + show.getInt("id");
return BASE_URL + "/?show=" + show.getInt("id");
}
@Override

View File

@ -23,7 +23,7 @@ import java.util.ArrayList;
import java.util.Collections;
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 {
@ -36,7 +36,7 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
static JsonObject query(final int id) throws ParsingException {
try {
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) {
throw new ParsingException("could not get show data", e);
@ -88,7 +88,7 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
@Nonnull
@Override
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

View File

@ -18,9 +18,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_API_URL;
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) {
super(service);
}

View File

@ -9,6 +9,8 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_URL;
public class BandcampSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
@ -17,7 +19,7 @@ public class BandcampSearchQueryHandlerFactory extends SearchQueryHandlerFactory
throws ParsingException {
try {
return "https://bandcamp.com/search?q=" +
return BASE_URL + "/search?q=" +
URLEncoder.encode(query, "UTF-8")
+ "&page=1";

View File

@ -6,6 +6,8 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
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.
* That's why id = url.</p>
@ -34,7 +36,7 @@ public class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
@Override
public String getUrl(final String input) {
if (input.matches("\\d+")) {
return "https://bandcamp.com/?show=" + input;
return BASE_URL + "/?show=" + input;
} else {
return input;
}