[Bandcamp] Apply small changes to code formatting and style
Make variables final when possible Remove unused imports Improve code formatting
This commit is contained in:
parent
8c369b0f79
commit
99e7ef013e
23 changed files with 187 additions and 166 deletions
|
@ -6,7 +6,6 @@ import org.schabi.newpipe.extractor.StreamingService;
|
|||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
||||
import org.schabi.newpipe.extractor.linkhandler.*;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||
|
@ -17,7 +16,6 @@ import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
|||
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
|
||||
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
|
||||
|
@ -28,7 +26,7 @@ import static org.schabi.newpipe.extractor.services.bandcamp.extractors.Bandcamp
|
|||
|
||||
public class BandcampService extends StreamingService {
|
||||
|
||||
public BandcampService(int id) {
|
||||
public BandcampService(final int id) {
|
||||
super(id, "Bandcamp", Collections.singletonList(AUDIO));
|
||||
}
|
||||
|
||||
|
@ -63,7 +61,7 @@ public class BandcampService extends StreamingService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler) {
|
||||
public SearchExtractor getSearchExtractor(final SearchQueryHandler queryHandler) {
|
||||
return new BandcampSearchExtractor(this, queryHandler);
|
||||
}
|
||||
|
||||
|
@ -83,24 +81,20 @@ public class BandcampService extends StreamingService {
|
|||
KioskList kioskList = new KioskList(this);
|
||||
|
||||
try {
|
||||
kioskList.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
||||
@Override
|
||||
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String kioskId) throws ExtractionException {
|
||||
return new BandcampFeaturedExtractor(BandcampService.this, new BandcampFeaturedLinkHandlerFactory().fromUrl(FEATURED_API_URL), kioskId);
|
||||
}
|
||||
}, new BandcampFeaturedLinkHandlerFactory(), KIOSK_FEATURED);
|
||||
kioskList.addKioskEntry((streamingService, url, kioskId) ->
|
||||
new BandcampFeaturedExtractor(
|
||||
BandcampService.this,
|
||||
new BandcampFeaturedLinkHandlerFactory().fromUrl(FEATURED_API_URL), kioskId),
|
||||
new BandcampFeaturedLinkHandlerFactory(), KIOSK_FEATURED);
|
||||
|
||||
|
||||
kioskList.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
||||
@Override
|
||||
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String kioskId) throws ExtractionException {
|
||||
return new BandcampRadioExtractor(BandcampService.this, new BandcampFeaturedLinkHandlerFactory().fromUrl(RADIO_API_URL), kioskId);
|
||||
}
|
||||
}, new BandcampFeaturedLinkHandlerFactory(), KIOSK_RADIO);
|
||||
kioskList.addKioskEntry((streamingService, url, kioskId) ->
|
||||
new BandcampRadioExtractor(BandcampService.this,
|
||||
new BandcampFeaturedLinkHandlerFactory().fromUrl(RADIO_API_URL), kioskId),
|
||||
new BandcampFeaturedLinkHandlerFactory(), KIOSK_RADIO);
|
||||
|
||||
kioskList.setDefaultKiosk(KIOSK_FEATURED);
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new ExtractionException(e);
|
||||
}
|
||||
|
||||
|
@ -108,17 +102,17 @@ public class BandcampService extends StreamingService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler) throws ExtractionException {
|
||||
public ChannelExtractor getChannelExtractor(final ListLinkHandler linkHandler) {
|
||||
return new BandcampChannelExtractor(this, linkHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler) {
|
||||
public PlaylistExtractor getPlaylistExtractor(final ListLinkHandler linkHandler) {
|
||||
return new BandcampPlaylistExtractor(this, linkHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamExtractor getStreamExtractor(LinkHandler linkHandler) {
|
||||
public StreamExtractor getStreamExtractor(final LinkHandler linkHandler) {
|
||||
if (linkHandler.getUrl().matches("https?://bandcamp\\.com/\\?show=\\d+"))
|
||||
return new BandcampRadioStreamExtractor(this, linkHandler);
|
||||
else
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
||||
|
||||
import com.grack.nanojson.*;
|
||||
import com.grack.nanojson.JsonArray;
|
||||
import com.grack.nanojson.JsonObject;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.schabi.newpipe.extractor.Page;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
|
@ -23,7 +24,7 @@ public class BandcampChannelExtractor extends ChannelExtractor {
|
|||
|
||||
private JsonObject channelInfo;
|
||||
|
||||
public BandcampChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
||||
public BandcampChannelExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
|
||||
super(service, linkHandler);
|
||||
}
|
||||
|
||||
|
@ -34,14 +35,15 @@ public class BandcampChannelExtractor extends ChannelExtractor {
|
|||
return BandcampExtractorHelper.getImageUrl(channelInfo.getLong("bio_image_id"), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@Override
|
||||
public String getBannerUrl() throws ParsingException {
|
||||
/*
|
||||
* Why does the mobile endpoint not contain the header?? Or at least not the same one?
|
||||
* Anyway we're back to querying websites
|
||||
*/
|
||||
@Override
|
||||
public String getBannerUrl() throws ParsingException {
|
||||
try {
|
||||
String html = getDownloader().get(channelInfo.getString("bandcamp_url").replace("http://", "https://"))
|
||||
final String html = getDownloader()
|
||||
.get(channelInfo.getString("bandcamp_url").replace("http://", "https://"))
|
||||
.responseBody();
|
||||
|
||||
return Jsoup.parse(html)
|
||||
|
@ -50,17 +52,17 @@ public class BandcampChannelExtractor extends ChannelExtractor {
|
|||
.first()
|
||||
.attr("src");
|
||||
|
||||
} catch (IOException | ReCaptchaException e) {
|
||||
} catch (final IOException | ReCaptchaException e) {
|
||||
throw new ParsingException("Could not download artist web site", e);
|
||||
} catch (NullPointerException e) {
|
||||
} catch (final NullPointerException e) {
|
||||
// No banner available
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* I had to learn bandcamp stopped providing RSS feeds when appending /feed to any URL
|
||||
* because too few people used it. Bummer!
|
||||
* bandcamp stopped providing RSS feeds when appending /feed to any URL
|
||||
* because too few people used it.
|
||||
*/
|
||||
@Override
|
||||
public String getFeedUrl() {
|
||||
|
@ -96,13 +98,13 @@ public class BandcampChannelExtractor extends ChannelExtractor {
|
|||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ParsingException {
|
||||
|
||||
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||
|
||||
JsonArray discography = channelInfo.getArray("discography");
|
||||
final JsonArray discography = channelInfo.getArray("discography");
|
||||
|
||||
for (int i = 0; i < discography.size(); i++) {
|
||||
// I define discograph as an item that can appear in a discography
|
||||
JsonObject discograph = discography.getObject(i);
|
||||
final JsonObject discograph = discography.getObject(i);
|
||||
|
||||
if (!discograph.getString("item_type").equals("track")) continue;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ public class BandcampChannelInfoItemExtractor implements ChannelInfoItemExtracto
|
|||
|
||||
private final Element resultInfo, searchResult;
|
||||
|
||||
public BandcampChannelInfoItemExtractor(Element searchResult) {
|
||||
public BandcampChannelInfoItemExtractor(final Element searchResult) {
|
||||
this.searchResult = searchResult;
|
||||
resultInfo = searchResult.getElementsByClass("result-info").first();
|
||||
}
|
||||
|
@ -27,11 +27,13 @@ public class BandcampChannelInfoItemExtractor implements ChannelInfoItemExtracto
|
|||
|
||||
@Override
|
||||
public String getThumbnailUrl() throws ParsingException {
|
||||
Element img = searchResult.getElementsByClass("art").first()
|
||||
final Element img = searchResult.getElementsByClass("art").first()
|
||||
.getElementsByTag("img").first();
|
||||
if (img != null) {
|
||||
return img.attr("src");
|
||||
} else return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,9 +31,10 @@ public class BandcampExtractorHelper {
|
|||
* @param variable Name of the variable
|
||||
* @return The JsonObject stored in the variable with this name
|
||||
*/
|
||||
public static JsonObject getJsonData(String html, String variable) throws JsonParserException, ArrayIndexOutOfBoundsException, ParsingException {
|
||||
Document document = Jsoup.parse(html);
|
||||
String json = document.getElementsByAttribute(variable).attr(variable);
|
||||
public static JsonObject getJsonData(final String html, final String variable)
|
||||
throws JsonParserException, ArrayIndexOutOfBoundsException {
|
||||
final Document document = Jsoup.parse(html);
|
||||
final String json = document.getElementsByAttribute(variable).attr(variable);
|
||||
return JsonParser.object().from(json);
|
||||
}
|
||||
|
||||
|
@ -41,17 +42,18 @@ public class BandcampExtractorHelper {
|
|||
* Translate all these parameters together to the URL of the corresponding album or track
|
||||
* using the mobile api
|
||||
*/
|
||||
public static String getStreamUrlFromIds(long bandId, long itemId, String itemType) throws ParsingException {
|
||||
public static String getStreamUrlFromIds(final long bandId, final long itemId, final String itemType)
|
||||
throws ParsingException {
|
||||
|
||||
try {
|
||||
String jsonString = NewPipe.getDownloader().get(
|
||||
final String jsonString = NewPipe.getDownloader().get(
|
||||
"https://bandcamp.com/api/mobile/22/tralbum_details?band_id=" + bandId
|
||||
+ "&tralbum_id=" + itemId + "&tralbum_type=" + itemType.substring(0, 1))
|
||||
.responseBody();
|
||||
|
||||
return JsonParser.object().from(jsonString).getString("bandcamp_url").replace("http://", "https://");
|
||||
|
||||
} catch (JsonParserException | ReCaptchaException | IOException e) {
|
||||
} catch (final JsonParserException | ReCaptchaException | IOException e) {
|
||||
throw new ParsingException("Ids could not be translated to URL", e);
|
||||
}
|
||||
|
||||
|
@ -61,11 +63,11 @@ public class BandcampExtractorHelper {
|
|||
* Concatenate all non-null and non-empty strings together while separating them using
|
||||
* the comma parameter
|
||||
*/
|
||||
public static String smartConcatenate(String[] strings, String comma) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
public static String smartConcatenate(final String[] strings, final String comma) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
// Remove empty strings
|
||||
ArrayList<String> list = new ArrayList<>(Arrays.asList(strings));
|
||||
final ArrayList<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);
|
||||
|
@ -74,8 +76,7 @@ public class BandcampExtractorHelper {
|
|||
|
||||
// Append remaining strings to result
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
String string = list.get(i);
|
||||
result.append(string);
|
||||
result.append(list.get(i));
|
||||
|
||||
if (i != list.size() - 1) {
|
||||
// This is not the last iteration yet
|
||||
|
@ -107,7 +108,7 @@ public class BandcampExtractorHelper {
|
|||
.getBytes()
|
||||
).responseBody()
|
||||
);
|
||||
} catch (IOException | ReCaptchaException | JsonParserException e) {
|
||||
} catch (final IOException | ReCaptchaException | JsonParserException e) {
|
||||
throw new ParsingException("Could not download band details", e);
|
||||
}
|
||||
}
|
||||
|
@ -118,17 +119,17 @@ public class BandcampExtractorHelper {
|
|||
* @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?)
|
||||
*/
|
||||
public static String getImageUrl(long id, boolean album) {
|
||||
public static String getImageUrl(final long id, final boolean album) {
|
||||
return "https://f4.bcbits.com/img/" + (album ? 'a' : "") + id + "_10.jpg";
|
||||
}
|
||||
|
||||
static DateWrapper parseDate(String textDate) throws ParsingException {
|
||||
static DateWrapper parseDate(final String textDate) throws ParsingException {
|
||||
try {
|
||||
Date date = new SimpleDateFormat("dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH).parse(textDate);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
final Date date = new SimpleDateFormat("dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH).parse(textDate);
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
return new DateWrapper(calendar, false);
|
||||
} catch (ParseException e) {
|
||||
} catch (final ParseException e) {
|
||||
throw new ParsingException("Could not extract date", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ 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 BandcampFeaturedExtractor(StreamingService streamingService, ListLinkHandler listLinkHandler, String kioskId) {
|
||||
public BandcampFeaturedExtractor(final StreamingService streamingService, final ListLinkHandler listLinkHandler,
|
||||
final String kioskId) {
|
||||
super(streamingService, listLinkHandler, kioskId);
|
||||
}
|
||||
|
||||
|
@ -43,23 +44,23 @@ public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem>
|
|||
@Override
|
||||
public InfoItemsPage<PlaylistInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
|
||||
PlaylistInfoItemsCollector c = new PlaylistInfoItemsCollector(getServiceId());
|
||||
final PlaylistInfoItemsCollector c = new PlaylistInfoItemsCollector(getServiceId());
|
||||
|
||||
try {
|
||||
|
||||
|
||||
JsonObject json = JsonParser.object().from(
|
||||
final JsonObject json = JsonParser.object().from(
|
||||
getDownloader().post(
|
||||
FEATURED_API_URL, null, "{\"platform\":\"\",\"version\":0}".getBytes()
|
||||
).responseBody()
|
||||
);
|
||||
|
||||
JsonArray featuredStories = json.getObject("feed_content")
|
||||
final JsonArray featuredStories = json.getObject("feed_content")
|
||||
.getObject("stories")
|
||||
.getArray("featured");
|
||||
|
||||
for (int i = 0; i < featuredStories.size(); i++) {
|
||||
JsonObject featuredStory = featuredStories.getObject(i);
|
||||
final JsonObject featuredStory = featuredStories.getObject(i);
|
||||
|
||||
if (featuredStory.isNull("album_title")) {
|
||||
// Is not an album, ignore
|
||||
|
@ -70,7 +71,7 @@ public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem>
|
|||
}
|
||||
|
||||
return new InfoItemsPage<>(c, null);
|
||||
} catch (JsonParserException e) {
|
||||
} catch (final JsonParserException e) {
|
||||
e.printStackTrace();
|
||||
throw new ParsingException("JSON error", e);
|
||||
}
|
||||
|
|
|
@ -38,22 +38,22 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
|||
private JsonArray trackInfo;
|
||||
private String name;
|
||||
|
||||
public BandcampPlaylistExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
||||
public BandcampPlaylistExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
|
||||
super(service, linkHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||
String html = downloader.get(getLinkHandler().getUrl()).responseBody();
|
||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
||||
final String html = downloader.get(getLinkHandler().getUrl()).responseBody();
|
||||
document = Jsoup.parse(html);
|
||||
albumJson = getAlbumInfoJson(html);
|
||||
trackInfo = albumJson.getArray("trackinfo");
|
||||
|
||||
try {
|
||||
name = getJsonData(html, "data-embed").getString("album_title");
|
||||
} catch (JsonParserException e) {
|
||||
} catch (final JsonParserException e) {
|
||||
throw new ParsingException("Faulty JSON; page likely does not contain album data", e);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
} catch (final ArrayIndexOutOfBoundsException e) {
|
||||
throw new ParsingException("JSON does not exist", e);
|
||||
}
|
||||
|
||||
|
@ -67,8 +67,11 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
|||
|
||||
@Override
|
||||
public String getThumbnailUrl() throws ParsingException {
|
||||
if (albumJson.isNull("art_id")) return "";
|
||||
else return getImageUrl(albumJson.getLong("art_id"), true);
|
||||
if (albumJson.isNull("art_id")) {
|
||||
return "";
|
||||
} else {
|
||||
return getImageUrl(albumJson.getLong("art_id"), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,7 +81,7 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
|||
|
||||
@Override
|
||||
public String getUploaderUrl() throws ParsingException {
|
||||
String[] parts = getUrl().split("/");
|
||||
final String[] parts = getUrl().split("/");
|
||||
// https: (/) (/) * .bandcamp.com (/) and leave out the rest
|
||||
return "https://" + parts[2] + "/";
|
||||
}
|
||||
|
@ -124,7 +127,7 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
|||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException {
|
||||
|
||||
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||
|
||||
for (int i = 0; i < trackInfo.size(); i++) {
|
||||
JsonObject track = trackInfo.getObject(i);
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
||||
|
||||
import com.grack.nanojson.JsonObject;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
||||
private final Element searchResult, resultInfo;
|
||||
|
||||
public BandcampPlaylistInfoItemExtractor(Element searchResult) {
|
||||
public BandcampPlaylistInfoItemExtractor(@Nonnull Element searchResult) {
|
||||
this.searchResult = searchResult;
|
||||
resultInfo = searchResult.getElementsByClass("result-info").first();
|
||||
}
|
||||
|
@ -20,7 +21,7 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
|
|||
|
||||
@Override
|
||||
public long getStreamCount() {
|
||||
String length = resultInfo.getElementsByClass("length").text();
|
||||
final String length = resultInfo.getElementsByClass("length").text();
|
||||
return Integer.parseInt(length.split(" track")[0]);
|
||||
}
|
||||
|
||||
|
@ -36,7 +37,7 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
|
|||
|
||||
@Override
|
||||
public String getThumbnailUrl() {
|
||||
Element img = searchResult.getElementsByClass("art").first()
|
||||
final Element img = searchResult.getElementsByClass("art").first()
|
||||
.getElementsByTag("img").first();
|
||||
if (img != null) {
|
||||
return img.attr("src");
|
||||
|
|
|
@ -9,7 +9,7 @@ public class BandcampPlaylistInfoItemFeaturedExtractor implements PlaylistInfoIt
|
|||
|
||||
private final JsonObject featuredStory;
|
||||
|
||||
public BandcampPlaylistInfoItemFeaturedExtractor(JsonObject featuredStory) {
|
||||
public BandcampPlaylistInfoItemFeaturedExtractor(final JsonObject featuredStory) {
|
||||
this.featuredStory = featuredStory;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -26,12 +25,13 @@ public class BandcampRadioExtractor extends KioskExtractor<InfoItem> {
|
|||
public static final String KIOSK_RADIO = "Radio";
|
||||
public static final String RADIO_API_URL = "https://bandcamp.com/api/bcweekly/1/list";
|
||||
|
||||
public BandcampRadioExtractor(StreamingService streamingService, ListLinkHandler linkHandler, String kioskId) {
|
||||
public BandcampRadioExtractor(final StreamingService streamingService, final ListLinkHandler linkHandler,
|
||||
final String kioskId) {
|
||||
super(streamingService, linkHandler, kioskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
||||
|
||||
}
|
||||
|
||||
|
@ -44,27 +44,27 @@ public class BandcampRadioExtractor extends KioskExtractor<InfoItem> {
|
|||
@Nonnull
|
||||
@Override
|
||||
public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
InfoItemsCollector c = new StreamInfoItemsCollector(getServiceId());
|
||||
final InfoItemsCollector c = new StreamInfoItemsCollector(getServiceId());
|
||||
|
||||
try {
|
||||
|
||||
JsonObject json = JsonParser.object().from(
|
||||
final JsonObject json = JsonParser.object().from(
|
||||
getDownloader().get(
|
||||
RADIO_API_URL
|
||||
).responseBody()
|
||||
);
|
||||
|
||||
JsonArray radioShows = json.getArray("results");
|
||||
final JsonArray radioShows = json.getArray("results");
|
||||
|
||||
for (int i = 0; i < radioShows.size(); i++) {
|
||||
JsonObject radioShow = radioShows.getObject(i);
|
||||
final JsonObject radioShow = radioShows.getObject(i);
|
||||
|
||||
c.commit(
|
||||
new BandcampRadioInfoItemExtractor(radioShow)
|
||||
);
|
||||
}
|
||||
|
||||
} catch (JsonParserException e) {
|
||||
} catch (final JsonParserException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class BandcampRadioExtractor extends KioskExtractor<InfoItem> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InfoItemsPage<InfoItem> getPage(Page page) {
|
||||
public InfoItemsPage<InfoItem> getPage(final Page page) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
|
|||
|
||||
private JsonObject show;
|
||||
|
||||
public BandcampRadioInfoItemExtractor(JsonObject radioShow) {
|
||||
public BandcampRadioInfoItemExtractor(final JsonObject radioShow) {
|
||||
show = radioShow;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,23 +29,23 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
|
|||
private JsonObject showInfo;
|
||||
private LinkHandler linkHandler;
|
||||
|
||||
public BandcampRadioStreamExtractor(StreamingService service, LinkHandler linkHandler) {
|
||||
public BandcampRadioStreamExtractor(final StreamingService service, final LinkHandler linkHandler) {
|
||||
super(service, linkHandler);
|
||||
this.linkHandler = linkHandler;
|
||||
}
|
||||
|
||||
static JsonObject query(int id) throws ParsingException {
|
||||
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()
|
||||
);
|
||||
} catch (IOException | ReCaptchaException | JsonParserException e) {
|
||||
} catch (final IOException | ReCaptchaException | JsonParserException e) {
|
||||
throw new ParsingException("could not get show data", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
||||
showInfo = query(Integer.parseInt(getId()));
|
||||
}
|
||||
|
||||
|
@ -105,8 +105,8 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
|
|||
|
||||
@Override
|
||||
public List<AudioStream> getAudioStreams() {
|
||||
ArrayList<AudioStream> list = new ArrayList<>();
|
||||
JsonObject streams = showInfo.getObject("audio_stream");
|
||||
final ArrayList<AudioStream> list = new ArrayList<>();
|
||||
final JsonObject streams = showInfo.getObject("audio_stream");
|
||||
|
||||
if (streams.has("opus-lo")) {
|
||||
list.add(new AudioStream(
|
||||
|
|
|
@ -37,21 +37,20 @@ public class BandcampSearchExtractor extends SearchExtractor {
|
|||
return false;
|
||||
}
|
||||
|
||||
public InfoItemsPage<InfoItem> getPage(Page page) throws IOException, ExtractionException {
|
||||
public InfoItemsPage<InfoItem> getPage(final Page page) throws IOException, ExtractionException {
|
||||
// okay apparently this is where we DOWNLOAD the page and then COMMIT its ENTRIES to an INFOITEMPAGE
|
||||
String html = getDownloader().get(page.getUrl()).responseBody();
|
||||
final String html = getDownloader().get(page.getUrl()).responseBody();
|
||||
|
||||
InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
|
||||
final InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
|
||||
|
||||
|
||||
Document d = Jsoup.parse(html);
|
||||
final Document d = Jsoup.parse(html);
|
||||
|
||||
Elements searchResultsElements = d.getElementsByClass("searchresult");
|
||||
final Elements searchResultsElements = d.getElementsByClass("searchresult");
|
||||
|
||||
for (Element searchResult :
|
||||
searchResultsElements) {
|
||||
for (final Element searchResult : searchResultsElements) {
|
||||
|
||||
String type = searchResult.getElementsByClass("result-info").first()
|
||||
final String type = searchResult.getElementsByClass("result-info").first()
|
||||
.getElementsByClass("itemtype").first().text();
|
||||
|
||||
switch (type) {
|
||||
|
@ -77,16 +76,16 @@ public class BandcampSearchExtractor extends SearchExtractor {
|
|||
}
|
||||
|
||||
// Count pages
|
||||
Elements pageLists = d.getElementsByClass("pagelist");
|
||||
final Elements pageLists = d.getElementsByClass("pagelist");
|
||||
if (pageLists.size() == 0)
|
||||
return new InfoItemsPage<>(collector, null);
|
||||
|
||||
Elements pages = pageLists.first().getElementsByTag("li");
|
||||
final Elements pages = pageLists.first().getElementsByTag("li");
|
||||
|
||||
// Find current page
|
||||
int currentPage = -1;
|
||||
for (int i = 0; i < pages.size(); i++) {
|
||||
Element pageElement = pages.get(i);
|
||||
final Element pageElement = pages.get(i);
|
||||
if (pageElement.getElementsByTag("span").size() > 0) {
|
||||
currentPage = i + 1;
|
||||
break;
|
||||
|
@ -112,7 +111,7 @@ public class BandcampSearchExtractor extends SearchExtractor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,14 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||
private JsonObject current;
|
||||
private Document document;
|
||||
|
||||
public BandcampStreamExtractor(StreamingService service, LinkHandler linkHandler) {
|
||||
public BandcampStreamExtractor(final StreamingService service, final LinkHandler linkHandler) {
|
||||
super(service, linkHandler);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||
String html = downloader.get(getLinkHandler().getUrl()).responseBody();
|
||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
||||
final String html = downloader.get(getLinkHandler().getUrl()).responseBody();
|
||||
document = Jsoup.parse(html);
|
||||
albumJson = getAlbumInfoJson(html);
|
||||
current = albumJson.getObject("current");
|
||||
|
@ -58,12 +58,12 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||
* @return Album metadata JSON
|
||||
* @throws ParsingException In case of a faulty website
|
||||
*/
|
||||
public static JsonObject getAlbumInfoJson(String html) throws ParsingException {
|
||||
public static JsonObject getAlbumInfoJson(final String html) throws ParsingException {
|
||||
try {
|
||||
return BandcampExtractorHelper.getJsonData(html, "data-tralbum");
|
||||
} catch (JsonParserException e) {
|
||||
} catch (final JsonParserException e) {
|
||||
throw new ParsingException("Faulty JSON; page likely does not contain album data", e);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
} catch (final ArrayIndexOutOfBoundsException e) {
|
||||
throw new ParsingException("JSON does not exist", e);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||
@Nonnull
|
||||
@Override
|
||||
public String getUploaderUrl() throws ParsingException {
|
||||
String[] parts = getUrl().split("/");
|
||||
final String[] parts = getUrl().split("/");
|
||||
// https: (/) (/) * .bandcamp.com (/) and leave out the rest
|
||||
return "https://" + parts[2] + "/";
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||
public String getUploaderAvatarUrl() {
|
||||
try {
|
||||
return document.getElementsByClass("band-photo").first().attr("src");
|
||||
} catch (NullPointerException e) {
|
||||
} catch (final NullPointerException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||
@Nonnull
|
||||
@Override
|
||||
public Description getDescription() {
|
||||
String s = BandcampExtractorHelper.smartConcatenate(
|
||||
final String s = BandcampExtractorHelper.smartConcatenate(
|
||||
new String[]{
|
||||
current.getString("about"),
|
||||
current.getString("lyrics"),
|
||||
|
@ -198,7 +198,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||
|
||||
@Override
|
||||
public List<AudioStream> getAudioStreams() {
|
||||
List<AudioStream> audioStreams = new ArrayList<>();
|
||||
final List<AudioStream> audioStreams = new ArrayList<>();
|
||||
|
||||
audioStreams.add(new AudioStream(
|
||||
albumJson.getArray("trackinfo").getObject(0)
|
||||
|
@ -303,11 +303,11 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||
@Nonnull
|
||||
@Override
|
||||
public List<String> getTags() {
|
||||
Elements tagElements = document.getElementsByAttributeValue("itemprop", "keywords");
|
||||
final Elements tagElements = document.getElementsByAttributeValue("itemprop", "keywords");
|
||||
|
||||
ArrayList<String> tags = new ArrayList<>();
|
||||
final ArrayList<String> tags = new ArrayList<>();
|
||||
|
||||
for (Element e : tagElements) {
|
||||
for (final Element e : tagElements) {
|
||||
tags.add(e.text());
|
||||
}
|
||||
|
||||
|
|
|
@ -20,32 +20,32 @@ import java.util.List;
|
|||
public class BandcampSuggestionExtractor extends SuggestionExtractor {
|
||||
|
||||
private static final String AUTOCOMPLETE_URL = "https://bandcamp.com/api/fuzzysearch/1/autocomplete?q=";
|
||||
public BandcampSuggestionExtractor(StreamingService service) {
|
||||
public BandcampSuggestionExtractor(final StreamingService service) {
|
||||
super(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggestionList(String query) throws IOException, ExtractionException {
|
||||
Downloader downloader = NewPipe.getDownloader();
|
||||
public List<String> suggestionList(final String query) throws IOException, ExtractionException {
|
||||
final Downloader downloader = NewPipe.getDownloader();
|
||||
|
||||
try {
|
||||
JsonObject fuzzyResults = JsonParser.object().from(
|
||||
final JsonObject fuzzyResults = JsonParser.object().from(
|
||||
downloader.get(AUTOCOMPLETE_URL + URLEncoder.encode(query, "UTF-8")).responseBody()
|
||||
);
|
||||
|
||||
JsonArray jsonArray = fuzzyResults.getObject("auto")
|
||||
final JsonArray jsonArray = fuzzyResults.getObject("auto")
|
||||
.getArray("results");
|
||||
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
final ArrayList<String> suggestions = new ArrayList<>();
|
||||
|
||||
for (Object fuzzyResult : jsonArray) {
|
||||
String res = ((JsonObject) fuzzyResult).getString("name");
|
||||
for (final Object fuzzyResult : jsonArray) {
|
||||
final String res = ((JsonObject) fuzzyResult).getString("name");
|
||||
|
||||
if (!suggestions.contains(res)) suggestions.add(res);
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
} catch (JsonParserException e) {
|
||||
} catch (final JsonParserException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
return new ArrayList<>();
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtract
|
|||
public class BandcampDiscographStreamInfoItemExtractor extends BandcampStreamInfoItemExtractor {
|
||||
|
||||
private final JsonObject discograph;
|
||||
public BandcampDiscographStreamInfoItemExtractor(JsonObject discograph, String uploaderUrl) {
|
||||
public BandcampDiscographStreamInfoItemExtractor(final JsonObject discograph, final String uploaderUrl) {
|
||||
super(uploaderUrl);
|
||||
|
||||
this.discograph = discograph;
|
||||
|
|
|
@ -17,13 +17,15 @@ public class BandcampPlaylistStreamInfoItemExtractor extends BandcampStreamInfoI
|
|||
private String substituteCoverUrl;
|
||||
private final StreamingService service;
|
||||
|
||||
public BandcampPlaylistStreamInfoItemExtractor(JsonObject track, String uploaderUrl, StreamingService service) {
|
||||
public BandcampPlaylistStreamInfoItemExtractor(final JsonObject track, final String uploaderUrl,
|
||||
final StreamingService service) {
|
||||
super(uploaderUrl);
|
||||
this.track = track;
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public BandcampPlaylistStreamInfoItemExtractor(JsonObject track, String uploaderUrl, String substituteCoverUrl) {
|
||||
public BandcampPlaylistStreamInfoItemExtractor(final JsonObject track, final String uploaderUrl,
|
||||
final String substituteCoverUrl) {
|
||||
this(track, uploaderUrl, (StreamingService) null);
|
||||
this.substituteCoverUrl = substituteCoverUrl;
|
||||
}
|
||||
|
@ -61,10 +63,10 @@ public class BandcampPlaylistStreamInfoItemExtractor extends BandcampStreamInfoI
|
|||
return substituteCoverUrl;
|
||||
} else {
|
||||
try {
|
||||
StreamExtractor extractor = service.getStreamExtractor(getUrl());
|
||||
final StreamExtractor extractor = service.getStreamExtractor(getUrl());
|
||||
extractor.fetchPage();
|
||||
return extractor.getThumbnailUrl();
|
||||
} catch (ExtractionException | IOException e) {
|
||||
} catch (final ExtractionException | IOException e) {
|
||||
throw new ParsingException("could not download cover art location", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ public class BandcampSearchStreamInfoItemExtractor extends BandcampStreamInfoIte
|
|||
|
||||
private final Element resultInfo, searchResult;
|
||||
|
||||
public BandcampSearchStreamInfoItemExtractor(Element searchResult, String uploaderUrl) {
|
||||
public BandcampSearchStreamInfoItemExtractor(final Element searchResult, final String uploaderUrl) {
|
||||
super(uploaderUrl);
|
||||
this.searchResult = searchResult;
|
||||
resultInfo = searchResult.getElementsByClass("result-info").first();
|
||||
|
@ -15,8 +15,8 @@ public class BandcampSearchStreamInfoItemExtractor extends BandcampStreamInfoIte
|
|||
|
||||
@Override
|
||||
public String getUploaderName() {
|
||||
String subhead = resultInfo.getElementsByClass("subhead").text();
|
||||
String[] splitBy = subhead.split("by ");
|
||||
final String subhead = resultInfo.getElementsByClass("subhead").text();
|
||||
final String[] splitBy = subhead.split("by ");
|
||||
if (splitBy.length > 1) {
|
||||
return splitBy[1];
|
||||
} else {
|
||||
|
@ -36,11 +36,13 @@ public class BandcampSearchStreamInfoItemExtractor extends BandcampStreamInfoIte
|
|||
|
||||
@Override
|
||||
public String getThumbnailUrl() throws ParsingException {
|
||||
Element img = searchResult.getElementsByClass("art").first()
|
||||
final Element img = searchResult.getElementsByClass("art").first()
|
||||
.getElementsByTag("img").first();
|
||||
if (img != null) {
|
||||
return img.attr("src");
|
||||
} else return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,7 @@ import javax.annotation.Nullable;
|
|||
public abstract class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||
private final String uploaderUrl;
|
||||
|
||||
public BandcampStreamInfoItemExtractor(String uploaderUrl) {
|
||||
public BandcampStreamInfoItemExtractor(final String uploaderUrl) {
|
||||
this.uploaderUrl = uploaderUrl;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,16 +20,16 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
|
||||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
public String getId(final String url) throws ParsingException {
|
||||
try {
|
||||
String response = NewPipe.getDownloader().get(url).responseBody();
|
||||
final String response = NewPipe.getDownloader().get(url).responseBody();
|
||||
|
||||
// This variable contains band data!
|
||||
JsonObject bandData = BandcampExtractorHelper.getJsonData(response, "data-band");
|
||||
final JsonObject bandData = BandcampExtractorHelper.getJsonData(response, "data-band");
|
||||
|
||||
return String.valueOf(bandData.getLong("id"));
|
||||
|
||||
} catch (IOException | ReCaptchaException | ArrayIndexOutOfBoundsException | JsonParserException e) {
|
||||
} catch (final IOException | ReCaptchaException | ArrayIndexOutOfBoundsException | JsonParserException e) {
|
||||
throw new ParsingException("Download failed", e);
|
||||
}
|
||||
}
|
||||
|
@ -38,12 +38,13 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
* Uses the mobile endpoint as a "translator" from id to url
|
||||
*/
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
|
||||
public String getUrl(final String id, final List<String> contentFilter, final String sortFilter)
|
||||
throws ParsingException {
|
||||
try {
|
||||
return BandcampExtractorHelper.getArtistDetails(id)
|
||||
.getString("bandcamp_url")
|
||||
.replace("http://", "https://");
|
||||
} catch (NullPointerException e) {
|
||||
} catch (final NullPointerException e) {
|
||||
throw new ParsingException("JSON does not contain URL (invalid id?) or is otherwise invalid", e);
|
||||
}
|
||||
|
||||
|
@ -54,7 +55,7 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
* where the profile is at <code>* . * /releases</code>
|
||||
*/
|
||||
@Override
|
||||
public boolean onAcceptUrl(String url) {
|
||||
public boolean onAcceptUrl(final String url) {
|
||||
|
||||
// Is a subdomain of bandcamp.com?
|
||||
boolean isBandcampComArtistPage = url.matches("https?://.+\\.bandcamp\\.com/?");
|
||||
|
|
|
@ -14,23 +14,30 @@ import static org.schabi.newpipe.extractor.services.bandcamp.extractors.Bandcamp
|
|||
public class BandcampFeaturedLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilter, String sortFilter) {
|
||||
if (id.equals(KIOSK_FEATURED)) return FEATURED_API_URL; // doesn't have a website
|
||||
else if (id.equals(KIOSK_RADIO)) return RADIO_API_URL; // doesn't have its own website
|
||||
else return null;
|
||||
public String getUrl(final String id, final List<String> contentFilter, final String sortFilter) {
|
||||
if (id.equals(KIOSK_FEATURED)) {
|
||||
return FEATURED_API_URL; // doesn't have a website
|
||||
} else if (id.equals(KIOSK_RADIO)) {
|
||||
return RADIO_API_URL; // doesn't have its own website
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(String url) {
|
||||
if (url.matches("https?://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL))
|
||||
public String getId(final String url) {
|
||||
if (url.matches("https?://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL)) {
|
||||
return KIOSK_RADIO;
|
||||
else if (url.equals(FEATURED_API_URL))
|
||||
} else if (url.equals(FEATURED_API_URL)) {
|
||||
return KIOSK_FEATURED;
|
||||
else return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onAcceptUrl(String url) {
|
||||
return url.equals(FEATURED_API_URL) || (url.equals(RADIO_API_URL) || url.matches("https?://bandcamp\\.com/\\?show=\\d+"));
|
||||
public boolean onAcceptUrl(final String url) {
|
||||
return url.equals(FEATURED_API_URL) || (url.equals(RADIO_API_URL)
|
||||
|| url.matches("https?://bandcamp\\.com/\\?show=\\d+"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,17 +12,18 @@ import java.util.List;
|
|||
*/
|
||||
public class BandcampPlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
public String getId(final String url) throws ParsingException {
|
||||
return getUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String url, List<String> contentFilter, String sortFilter) throws ParsingException {
|
||||
public String getUrl(final String url, final List<String> contentFilter, final String sortFilter)
|
||||
throws ParsingException {
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onAcceptUrl(String url) {
|
||||
public boolean onAcceptUrl(final String url) {
|
||||
return url.toLowerCase().matches("https?://.+\\..+/album/.+");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,14 +13,15 @@ public class BandcampSearchQueryHandlerFactory extends SearchQueryHandlerFactory
|
|||
|
||||
|
||||
@Override
|
||||
public String getUrl(String query, List<String> contentFilter, String sortFilter) throws ParsingException {
|
||||
public String getUrl(final String query, final List<String> contentFilter, final String sortFilter)
|
||||
throws ParsingException {
|
||||
try {
|
||||
|
||||
return "https://bandcamp.com/search?q=" +
|
||||
URLEncoder.encode(query, "UTF-8")
|
||||
+ "&page=1";
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
throw new ParsingException("query \"" + query + "\" could not be encoded", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,22 +18,25 @@ public class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|||
* @see BandcampStreamLinkHandlerFactory
|
||||
*/
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
public String getId(final String url) throws ParsingException {
|
||||
if (url.matches("https?://bandcamp\\.com/\\?show=\\d+")) {
|
||||
return url.split("bandcamp.com/\\?show=")[1];
|
||||
} else
|
||||
} else {
|
||||
return getUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up url
|
||||
* @see BandcampStreamLinkHandlerFactory
|
||||
*/
|
||||
@Override
|
||||
public String getUrl(String input) {
|
||||
if (input.matches("\\d+"))
|
||||
public String getUrl(final String input) {
|
||||
if (input.matches("\\d+")) {
|
||||
return "https://bandcamp.com/?show=" + input;
|
||||
else return input;
|
||||
} else {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +48,8 @@ public class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|||
* <code>https:// * . * /track/ *</code>
|
||||
*/
|
||||
@Override
|
||||
public boolean onAcceptUrl(String url) {
|
||||
return url.toLowerCase().matches("https?://.+\\..+/track/.+") || url.toLowerCase().matches("https?://bandcamp\\.com/\\?show=\\d+");
|
||||
public boolean onAcceptUrl(final String url) {
|
||||
return url.toLowerCase().matches("https?://.+\\..+/track/.+")
|
||||
|| url.toLowerCase().matches("https?://bandcamp\\.com/\\?show=\\d+");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue