[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:
TobiGr 2020-11-24 09:41:40 +01:00
parent 8c369b0f79
commit 99e7ef013e
23 changed files with 187 additions and 166 deletions

View File

@ -6,7 +6,6 @@ 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.comments.CommentsExtractor; import org.schabi.newpipe.extractor.comments.CommentsExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; 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.kiosk.KioskList;
import org.schabi.newpipe.extractor.linkhandler.*; import org.schabi.newpipe.extractor.linkhandler.*;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; 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.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor; import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
import java.io.IOException;
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;
@ -28,7 +26,7 @@ import static org.schabi.newpipe.extractor.services.bandcamp.extractors.Bandcamp
public class BandcampService extends StreamingService { public class BandcampService extends StreamingService {
public BandcampService(int id) { public BandcampService(final int id) {
super(id, "Bandcamp", Collections.singletonList(AUDIO)); super(id, "Bandcamp", Collections.singletonList(AUDIO));
} }
@ -63,7 +61,7 @@ public class BandcampService extends StreamingService {
} }
@Override @Override
public SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler) { public SearchExtractor getSearchExtractor(final SearchQueryHandler queryHandler) {
return new BandcampSearchExtractor(this, queryHandler); return new BandcampSearchExtractor(this, queryHandler);
} }
@ -83,24 +81,20 @@ public class BandcampService extends StreamingService {
KioskList kioskList = new KioskList(this); KioskList kioskList = new KioskList(this);
try { try {
kioskList.addKioskEntry(new KioskList.KioskExtractorFactory() { kioskList.addKioskEntry((streamingService, url, kioskId) ->
@Override new BandcampFeaturedExtractor(
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String kioskId) throws ExtractionException { BandcampService.this,
return new BandcampFeaturedExtractor(BandcampService.this, new BandcampFeaturedLinkHandlerFactory().fromUrl(FEATURED_API_URL), kioskId); new BandcampFeaturedLinkHandlerFactory().fromUrl(FEATURED_API_URL), kioskId),
} new BandcampFeaturedLinkHandlerFactory(), KIOSK_FEATURED);
}, new BandcampFeaturedLinkHandlerFactory(), KIOSK_FEATURED);
kioskList.addKioskEntry((streamingService, url, kioskId) ->
kioskList.addKioskEntry(new KioskList.KioskExtractorFactory() { new BandcampRadioExtractor(BandcampService.this,
@Override new BandcampFeaturedLinkHandlerFactory().fromUrl(RADIO_API_URL), kioskId),
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String kioskId) throws ExtractionException { new BandcampFeaturedLinkHandlerFactory(), KIOSK_RADIO);
return new BandcampRadioExtractor(BandcampService.this, new BandcampFeaturedLinkHandlerFactory().fromUrl(RADIO_API_URL), kioskId);
}
}, new BandcampFeaturedLinkHandlerFactory(), KIOSK_RADIO);
kioskList.setDefaultKiosk(KIOSK_FEATURED); kioskList.setDefaultKiosk(KIOSK_FEATURED);
} catch (Exception e) { } catch (final Exception e) {
throw new ExtractionException(e); throw new ExtractionException(e);
} }
@ -108,17 +102,17 @@ public class BandcampService extends StreamingService {
} }
@Override @Override
public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler) throws ExtractionException { public ChannelExtractor getChannelExtractor(final ListLinkHandler linkHandler) {
return new BandcampChannelExtractor(this, linkHandler); return new BandcampChannelExtractor(this, linkHandler);
} }
@Override @Override
public PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler) { public PlaylistExtractor getPlaylistExtractor(final ListLinkHandler linkHandler) {
return new BandcampPlaylistExtractor(this, linkHandler); return new BandcampPlaylistExtractor(this, linkHandler);
} }
@Override @Override
public StreamExtractor getStreamExtractor(LinkHandler linkHandler) { public StreamExtractor getStreamExtractor(final LinkHandler linkHandler) {
if (linkHandler.getUrl().matches("https?://bandcamp\\.com/\\?show=\\d+")) if (linkHandler.getUrl().matches("https?://bandcamp\\.com/\\?show=\\d+"))
return new BandcampRadioStreamExtractor(this, linkHandler); return new BandcampRadioStreamExtractor(this, linkHandler);
else else

View File

@ -2,7 +2,8 @@
package org.schabi.newpipe.extractor.services.bandcamp.extractors; 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.jsoup.Jsoup;
import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
@ -23,7 +24,7 @@ public class BandcampChannelExtractor extends ChannelExtractor {
private JsonObject channelInfo; private JsonObject channelInfo;
public BandcampChannelExtractor(StreamingService service, ListLinkHandler linkHandler) { public BandcampChannelExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
super(service, linkHandler); super(service, linkHandler);
} }
@ -34,15 +35,16 @@ public class BandcampChannelExtractor extends ChannelExtractor {
return BandcampExtractorHelper.getImageUrl(channelInfo.getLong("bio_image_id"), false); return BandcampExtractorHelper.getImageUrl(channelInfo.getLong("bio_image_id"), false);
} }
/**
* Why does the mobile endpoint not contain the header?? Or at least not the same one?
* Anyway we're back to querying websites
*/
@Override @Override
public String getBannerUrl() throws ParsingException { 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
*/
try { try {
String html = getDownloader().get(channelInfo.getString("bandcamp_url").replace("http://", "https://")) final String html = getDownloader()
.responseBody(); .get(channelInfo.getString("bandcamp_url").replace("http://", "https://"))
.responseBody();
return Jsoup.parse(html) return Jsoup.parse(html)
.getElementById("customHeader") .getElementById("customHeader")
@ -50,17 +52,17 @@ public class BandcampChannelExtractor extends ChannelExtractor {
.first() .first()
.attr("src"); .attr("src");
} catch (IOException | ReCaptchaException e) { } catch (final IOException | ReCaptchaException e) {
throw new ParsingException("Could not download artist web site", e); throw new ParsingException("Could not download artist web site", e);
} catch (NullPointerException e) { } catch (final NullPointerException e) {
// No banner available // No banner available
return ""; return "";
} }
} }
/** /**
* I had to learn bandcamp stopped providing RSS feeds when appending /feed to any URL * bandcamp stopped providing RSS feeds when appending /feed to any URL
* because too few people used it. Bummer! * because too few people used it.
*/ */
@Override @Override
public String getFeedUrl() { public String getFeedUrl() {
@ -96,13 +98,13 @@ public class BandcampChannelExtractor extends ChannelExtractor {
@Override @Override
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ParsingException { 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++) { for (int i = 0; i < discography.size(); i++) {
// I define discograph as an item that can appear in a discography // 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; if (!discograph.getString("item_type").equals("track")) continue;

View File

@ -10,7 +10,7 @@ public class BandcampChannelInfoItemExtractor implements ChannelInfoItemExtracto
private final Element resultInfo, searchResult; private final Element resultInfo, searchResult;
public BandcampChannelInfoItemExtractor(Element searchResult) { public BandcampChannelInfoItemExtractor(final Element searchResult) {
this.searchResult = searchResult; this.searchResult = searchResult;
resultInfo = searchResult.getElementsByClass("result-info").first(); resultInfo = searchResult.getElementsByClass("result-info").first();
} }
@ -27,11 +27,13 @@ public class BandcampChannelInfoItemExtractor implements ChannelInfoItemExtracto
@Override @Override
public String getThumbnailUrl() throws ParsingException { public String getThumbnailUrl() throws ParsingException {
Element img = searchResult.getElementsByClass("art").first() final Element img = searchResult.getElementsByClass("art").first()
.getElementsByTag("img").first(); .getElementsByTag("img").first();
if (img != null) { if (img != null) {
return img.attr("src"); return img.attr("src");
} else return null; } else {
return null;
}
} }
@Override @Override

View File

@ -31,9 +31,10 @@ public class BandcampExtractorHelper {
* @param variable Name of the variable * @param variable Name of the variable
* @return The JsonObject stored in the variable with this name * @return The JsonObject stored in the variable with this name
*/ */
public static JsonObject getJsonData(String html, String variable) throws JsonParserException, ArrayIndexOutOfBoundsException, ParsingException { public static JsonObject getJsonData(final String html, final String variable)
Document document = Jsoup.parse(html); throws JsonParserException, ArrayIndexOutOfBoundsException {
String json = document.getElementsByAttribute(variable).attr(variable); final Document document = Jsoup.parse(html);
final String json = document.getElementsByAttribute(variable).attr(variable);
return JsonParser.object().from(json); 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 * Translate all these parameters together to the URL of the corresponding album or track
* using the mobile api * 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 { try {
String jsonString = NewPipe.getDownloader().get( final String jsonString = NewPipe.getDownloader().get(
"https://bandcamp.com/api/mobile/22/tralbum_details?band_id=" + bandId "https://bandcamp.com/api/mobile/22/tralbum_details?band_id=" + bandId
+ "&tralbum_id=" + itemId + "&tralbum_type=" + itemType.substring(0, 1)) + "&tralbum_id=" + itemId + "&tralbum_type=" + itemType.substring(0, 1))
.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 (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);
} }
@ -61,11 +63,11 @@ public class BandcampExtractorHelper {
* Concatenate all non-null and non-empty strings together while separating them using * Concatenate all non-null and non-empty strings together while separating them using
* the comma parameter * the comma parameter
*/ */
public static String smartConcatenate(String[] strings, String comma) { public static String smartConcatenate(final String[] strings, final String comma) {
StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
// Remove empty strings // 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--) { 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);
@ -74,8 +76,7 @@ public class BandcampExtractorHelper {
// Append remaining strings to result // Append remaining strings to result
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
String string = list.get(i); result.append(list.get(i));
result.append(string);
if (i != list.size() - 1) { if (i != list.size() - 1) {
// This is not the last iteration yet // This is not the last iteration yet
@ -107,7 +108,7 @@ public class BandcampExtractorHelper {
.getBytes() .getBytes()
).responseBody() ).responseBody()
); );
} catch (IOException | ReCaptchaException | JsonParserException e) { } catch (final IOException | ReCaptchaException | JsonParserException e) {
throw new ParsingException("Could not download band details", 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 * @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?) * 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"; 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 { try {
Date date = new SimpleDateFormat("dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH).parse(textDate); final Date date = new SimpleDateFormat("dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH).parse(textDate);
Calendar calendar = Calendar.getInstance(); final Calendar calendar = Calendar.getInstance();
calendar.setTime(date); calendar.setTime(date);
return new DateWrapper(calendar, false); return new DateWrapper(calendar, false);
} catch (ParseException e) { } catch (final ParseException e) {
throw new ParsingException("Could not extract date", e); throw new ParsingException("Could not extract date", e);
} }
} }

View File

@ -24,7 +24,8 @@ 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 = "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); super(streamingService, listLinkHandler, kioskId);
} }
@ -43,23 +44,23 @@ public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem>
@Override @Override
public InfoItemsPage<PlaylistInfoItem> getInitialPage() throws IOException, ExtractionException { public InfoItemsPage<PlaylistInfoItem> getInitialPage() throws IOException, ExtractionException {
PlaylistInfoItemsCollector c = new PlaylistInfoItemsCollector(getServiceId()); final PlaylistInfoItemsCollector c = new PlaylistInfoItemsCollector(getServiceId());
try { try {
JsonObject json = JsonParser.object().from( final JsonObject json = JsonParser.object().from(
getDownloader().post( getDownloader().post(
FEATURED_API_URL, null, "{\"platform\":\"\",\"version\":0}".getBytes() FEATURED_API_URL, null, "{\"platform\":\"\",\"version\":0}".getBytes()
).responseBody() ).responseBody()
); );
JsonArray featuredStories = json.getObject("feed_content") final JsonArray featuredStories = json.getObject("feed_content")
.getObject("stories") .getObject("stories")
.getArray("featured"); .getArray("featured");
for (int i = 0; i < featuredStories.size(); i++) { for (int i = 0; i < featuredStories.size(); i++) {
JsonObject featuredStory = featuredStories.getObject(i); final JsonObject featuredStory = featuredStories.getObject(i);
if (featuredStory.isNull("album_title")) { if (featuredStory.isNull("album_title")) {
// Is not an album, ignore // Is not an album, ignore
@ -70,7 +71,7 @@ public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem>
} }
return new InfoItemsPage<>(c, null); return new InfoItemsPage<>(c, null);
} catch (JsonParserException e) { } catch (final JsonParserException e) {
e.printStackTrace(); e.printStackTrace();
throw new ParsingException("JSON error", e); throw new ParsingException("JSON error", e);
} }

View File

@ -38,22 +38,22 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
private JsonArray trackInfo; private JsonArray trackInfo;
private String name; private String name;
public BandcampPlaylistExtractor(StreamingService service, ListLinkHandler linkHandler) { public BandcampPlaylistExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
super(service, linkHandler); super(service, linkHandler);
} }
@Override @Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
String html = downloader.get(getLinkHandler().getUrl()).responseBody(); final String html = downloader.get(getLinkHandler().getUrl()).responseBody();
document = Jsoup.parse(html); document = Jsoup.parse(html);
albumJson = getAlbumInfoJson(html); albumJson = getAlbumInfoJson(html);
trackInfo = albumJson.getArray("trackinfo"); trackInfo = albumJson.getArray("trackinfo");
try { try {
name = getJsonData(html, "data-embed").getString("album_title"); 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); 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); throw new ParsingException("JSON does not exist", e);
} }
@ -67,8 +67,11 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
@Override @Override
public String getThumbnailUrl() throws ParsingException { public String getThumbnailUrl() throws ParsingException {
if (albumJson.isNull("art_id")) return ""; if (albumJson.isNull("art_id")) {
else return getImageUrl(albumJson.getLong("art_id"), true); return "";
} else {
return getImageUrl(albumJson.getLong("art_id"), true);
}
} }
@Override @Override
@ -78,7 +81,7 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
@Override @Override
public String getUploaderUrl() throws ParsingException { public String getUploaderUrl() throws ParsingException {
String[] parts = getUrl().split("/"); final String[] parts = getUrl().split("/");
// https: (/) (/) * .bandcamp.com (/) and leave out the rest // https: (/) (/) * .bandcamp.com (/) and leave out the rest
return "https://" + parts[2] + "/"; return "https://" + parts[2] + "/";
} }
@ -124,7 +127,7 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
@Override @Override
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException { 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++) { for (int i = 0; i < trackInfo.size(); i++) {
JsonObject track = trackInfo.getObject(i); JsonObject track = trackInfo.getObject(i);

View File

@ -1,13 +1,14 @@
package org.schabi.newpipe.extractor.services.bandcamp.extractors; package org.schabi.newpipe.extractor.services.bandcamp.extractors;
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 javax.annotation.Nonnull;
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor { public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
private final Element searchResult, resultInfo; private final Element searchResult, resultInfo;
public BandcampPlaylistInfoItemExtractor(Element searchResult) { public BandcampPlaylistInfoItemExtractor(@Nonnull Element searchResult) {
this.searchResult = searchResult; this.searchResult = searchResult;
resultInfo = searchResult.getElementsByClass("result-info").first(); resultInfo = searchResult.getElementsByClass("result-info").first();
} }
@ -20,7 +21,7 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
@Override @Override
public long getStreamCount() { public long getStreamCount() {
String length = resultInfo.getElementsByClass("length").text(); final String length = resultInfo.getElementsByClass("length").text();
return Integer.parseInt(length.split(" track")[0]); return Integer.parseInt(length.split(" track")[0]);
} }
@ -36,7 +37,7 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
@Override @Override
public String getThumbnailUrl() { public String getThumbnailUrl() {
Element img = searchResult.getElementsByClass("art").first() final Element img = searchResult.getElementsByClass("art").first()
.getElementsByTag("img").first(); .getElementsByTag("img").first();
if (img != null) { if (img != null) {
return img.attr("src"); return img.attr("src");

View File

@ -9,7 +9,7 @@ public class BandcampPlaylistInfoItemFeaturedExtractor implements PlaylistInfoIt
private final JsonObject featuredStory; private final JsonObject featuredStory;
public BandcampPlaylistInfoItemFeaturedExtractor(JsonObject featuredStory) { public BandcampPlaylistInfoItemFeaturedExtractor(final JsonObject featuredStory) {
this.featuredStory = featuredStory; this.featuredStory = featuredStory;
} }

View File

@ -15,7 +15,6 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import javax.annotation.Nonnull; 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 KIOSK_RADIO = "Radio";
public static final String RADIO_API_URL = "https://bandcamp.com/api/bcweekly/1/list"; 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); super(streamingService, linkHandler, kioskId);
} }
@Override @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 @Nonnull
@Override @Override
public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionException { public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionException {
InfoItemsCollector c = new StreamInfoItemsCollector(getServiceId()); final InfoItemsCollector c = new StreamInfoItemsCollector(getServiceId());
try { try {
JsonObject json = JsonParser.object().from( final JsonObject json = JsonParser.object().from(
getDownloader().get( getDownloader().get(
RADIO_API_URL RADIO_API_URL
).responseBody() ).responseBody()
); );
JsonArray radioShows = json.getArray("results"); final JsonArray radioShows = json.getArray("results");
for (int i = 0; i < radioShows.size(); i++) { for (int i = 0; i < radioShows.size(); i++) {
JsonObject radioShow = radioShows.getObject(i); final JsonObject radioShow = radioShows.getObject(i);
c.commit( c.commit(
new BandcampRadioInfoItemExtractor(radioShow) new BandcampRadioInfoItemExtractor(radioShow)
); );
} }
} catch (JsonParserException e) { } catch (final JsonParserException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -72,7 +72,7 @@ public class BandcampRadioExtractor extends KioskExtractor<InfoItem> {
} }
@Override @Override
public InfoItemsPage<InfoItem> getPage(Page page) { public InfoItemsPage<InfoItem> getPage(final Page page) {
return null; return null;
} }
} }

View File

@ -16,7 +16,7 @@ public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
private JsonObject show; private JsonObject show;
public BandcampRadioInfoItemExtractor(JsonObject radioShow) { public BandcampRadioInfoItemExtractor(final JsonObject radioShow) {
show = radioShow; show = radioShow;
} }

View File

@ -29,23 +29,23 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
private JsonObject showInfo; private JsonObject showInfo;
private LinkHandler linkHandler; private LinkHandler linkHandler;
public BandcampRadioStreamExtractor(StreamingService service, LinkHandler linkHandler) { public BandcampRadioStreamExtractor(final StreamingService service, final LinkHandler linkHandler) {
super(service, linkHandler); super(service, linkHandler);
this.linkHandler = linkHandler; this.linkHandler = linkHandler;
} }
static JsonObject query(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("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); throw new ParsingException("could not get show data", e);
} }
} }
@Override @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())); showInfo = query(Integer.parseInt(getId()));
} }
@ -105,8 +105,8 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
@Override @Override
public List<AudioStream> getAudioStreams() { public List<AudioStream> getAudioStreams() {
ArrayList<AudioStream> list = new ArrayList<>(); final ArrayList<AudioStream> list = new ArrayList<>();
JsonObject streams = showInfo.getObject("audio_stream"); final JsonObject streams = showInfo.getObject("audio_stream");
if (streams.has("opus-lo")) { if (streams.has("opus-lo")) {
list.add(new AudioStream( list.add(new AudioStream(

View File

@ -37,21 +37,20 @@ public class BandcampSearchExtractor extends SearchExtractor {
return false; 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 // 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 : for (final Element searchResult : searchResultsElements) {
searchResultsElements) {
String type = searchResult.getElementsByClass("result-info").first() final String type = searchResult.getElementsByClass("result-info").first()
.getElementsByClass("itemtype").first().text(); .getElementsByClass("itemtype").first().text();
switch (type) { switch (type) {
@ -77,16 +76,16 @@ public class BandcampSearchExtractor extends SearchExtractor {
} }
// Count pages // Count pages
Elements pageLists = d.getElementsByClass("pagelist"); final Elements pageLists = d.getElementsByClass("pagelist");
if (pageLists.size() == 0) if (pageLists.size() == 0)
return new InfoItemsPage<>(collector, null); return new InfoItemsPage<>(collector, null);
Elements pages = pageLists.first().getElementsByTag("li"); final Elements pages = pageLists.first().getElementsByTag("li");
// Find current page // Find current page
int currentPage = -1; int currentPage = -1;
for (int i = 0; i < pages.size(); i++) { 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) { if (pageElement.getElementsByTag("span").size() > 0) {
currentPage = i + 1; currentPage = i + 1;
break; break;
@ -112,7 +111,7 @@ public class BandcampSearchExtractor extends SearchExtractor {
} }
@Override @Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
} }
} }

View File

@ -33,14 +33,14 @@ public class BandcampStreamExtractor extends StreamExtractor {
private JsonObject current; private JsonObject current;
private Document document; private Document document;
public BandcampStreamExtractor(StreamingService service, LinkHandler linkHandler) { public BandcampStreamExtractor(final StreamingService service, final LinkHandler linkHandler) {
super(service, linkHandler); super(service, linkHandler);
} }
@Override @Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
String html = downloader.get(getLinkHandler().getUrl()).responseBody(); final String html = downloader.get(getLinkHandler().getUrl()).responseBody();
document = Jsoup.parse(html); document = Jsoup.parse(html);
albumJson = getAlbumInfoJson(html); albumJson = getAlbumInfoJson(html);
current = albumJson.getObject("current"); current = albumJson.getObject("current");
@ -58,12 +58,12 @@ public class BandcampStreamExtractor extends StreamExtractor {
* @return Album metadata JSON * @return Album metadata JSON
* @throws ParsingException In case of a faulty website * @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 { try {
return BandcampExtractorHelper.getJsonData(html, "data-tralbum"); 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); 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); throw new ParsingException("JSON does not exist", e);
} }
} }
@ -77,7 +77,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
@Nonnull @Nonnull
@Override @Override
public String getUploaderUrl() throws ParsingException { public String getUploaderUrl() throws ParsingException {
String[] parts = getUrl().split("/"); final String[] parts = getUrl().split("/");
// https: (/) (/) * .bandcamp.com (/) and leave out the rest // https: (/) (/) * .bandcamp.com (/) and leave out the rest
return "https://" + parts[2] + "/"; return "https://" + parts[2] + "/";
} }
@ -118,7 +118,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
public String getUploaderAvatarUrl() { public String getUploaderAvatarUrl() {
try { try {
return document.getElementsByClass("band-photo").first().attr("src"); return document.getElementsByClass("band-photo").first().attr("src");
} catch (NullPointerException e) { } catch (final NullPointerException e) {
return ""; return "";
} }
} }
@ -144,7 +144,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
@Nonnull @Nonnull
@Override @Override
public Description getDescription() { public Description getDescription() {
String s = BandcampExtractorHelper.smartConcatenate( final String s = BandcampExtractorHelper.smartConcatenate(
new String[]{ new String[]{
current.getString("about"), current.getString("about"),
current.getString("lyrics"), current.getString("lyrics"),
@ -198,7 +198,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
@Override @Override
public List<AudioStream> getAudioStreams() { public List<AudioStream> getAudioStreams() {
List<AudioStream> audioStreams = new ArrayList<>(); final List<AudioStream> audioStreams = new ArrayList<>();
audioStreams.add(new AudioStream( audioStreams.add(new AudioStream(
albumJson.getArray("trackinfo").getObject(0) albumJson.getArray("trackinfo").getObject(0)
@ -303,11 +303,11 @@ public class BandcampStreamExtractor extends StreamExtractor {
@Nonnull @Nonnull
@Override @Override
public List<String> getTags() { 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()); tags.add(e.text());
} }

View File

@ -20,32 +20,32 @@ import java.util.List;
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 = "https://bandcamp.com/api/fuzzysearch/1/autocomplete?q=";
public BandcampSuggestionExtractor(StreamingService service) { public BandcampSuggestionExtractor(final StreamingService service) {
super(service); super(service);
} }
@Override @Override
public List<String> suggestionList(String query) throws IOException, ExtractionException { public List<String> suggestionList(final String query) throws IOException, ExtractionException {
Downloader downloader = NewPipe.getDownloader(); final Downloader downloader = NewPipe.getDownloader();
try { try {
JsonObject fuzzyResults = JsonParser.object().from( final JsonObject fuzzyResults = JsonParser.object().from(
downloader.get(AUTOCOMPLETE_URL + URLEncoder.encode(query, "UTF-8")).responseBody() downloader.get(AUTOCOMPLETE_URL + URLEncoder.encode(query, "UTF-8")).responseBody()
); );
JsonArray jsonArray = fuzzyResults.getObject("auto") final JsonArray jsonArray = fuzzyResults.getObject("auto")
.getArray("results"); .getArray("results");
ArrayList<String> suggestions = new ArrayList<>(); final ArrayList<String> suggestions = new ArrayList<>();
for (Object fuzzyResult : jsonArray) { for (final Object fuzzyResult : jsonArray) {
String res = ((JsonObject) fuzzyResult).getString("name"); final String res = ((JsonObject) fuzzyResult).getString("name");
if (!suggestions.contains(res)) suggestions.add(res); if (!suggestions.contains(res)) suggestions.add(res);
} }
return suggestions; return suggestions;
} catch (JsonParserException e) { } catch (final JsonParserException e) {
e.printStackTrace(); e.printStackTrace();
return new ArrayList<>(); return new ArrayList<>();

View File

@ -7,7 +7,7 @@ import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtract
public class BandcampDiscographStreamInfoItemExtractor extends BandcampStreamInfoItemExtractor { public class BandcampDiscographStreamInfoItemExtractor extends BandcampStreamInfoItemExtractor {
private final JsonObject discograph; private final JsonObject discograph;
public BandcampDiscographStreamInfoItemExtractor(JsonObject discograph, String uploaderUrl) { public BandcampDiscographStreamInfoItemExtractor(final JsonObject discograph, final String uploaderUrl) {
super(uploaderUrl); super(uploaderUrl);
this.discograph = discograph; this.discograph = discograph;

View File

@ -17,13 +17,15 @@ public class BandcampPlaylistStreamInfoItemExtractor extends BandcampStreamInfoI
private String substituteCoverUrl; private String substituteCoverUrl;
private final StreamingService service; 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); super(uploaderUrl);
this.track = track; this.track = track;
this.service = service; 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(track, uploaderUrl, (StreamingService) null);
this.substituteCoverUrl = substituteCoverUrl; this.substituteCoverUrl = substituteCoverUrl;
} }
@ -61,10 +63,10 @@ public class BandcampPlaylistStreamInfoItemExtractor extends BandcampStreamInfoI
return substituteCoverUrl; return substituteCoverUrl;
} else { } else {
try { try {
StreamExtractor extractor = service.getStreamExtractor(getUrl()); final StreamExtractor extractor = service.getStreamExtractor(getUrl());
extractor.fetchPage(); extractor.fetchPage();
return extractor.getThumbnailUrl(); return extractor.getThumbnailUrl();
} catch (ExtractionException | IOException e) { } catch (final ExtractionException | IOException e) {
throw new ParsingException("could not download cover art location", e); throw new ParsingException("could not download cover art location", e);
} }
} }

View File

@ -7,7 +7,7 @@ public class BandcampSearchStreamInfoItemExtractor extends BandcampStreamInfoIte
private final Element resultInfo, searchResult; private final Element resultInfo, searchResult;
public BandcampSearchStreamInfoItemExtractor(Element searchResult, String uploaderUrl) { public BandcampSearchStreamInfoItemExtractor(final Element searchResult, final String uploaderUrl) {
super(uploaderUrl); super(uploaderUrl);
this.searchResult = searchResult; this.searchResult = searchResult;
resultInfo = searchResult.getElementsByClass("result-info").first(); resultInfo = searchResult.getElementsByClass("result-info").first();
@ -15,8 +15,8 @@ public class BandcampSearchStreamInfoItemExtractor extends BandcampStreamInfoIte
@Override @Override
public String getUploaderName() { public String getUploaderName() {
String subhead = resultInfo.getElementsByClass("subhead").text(); final String subhead = resultInfo.getElementsByClass("subhead").text();
String[] splitBy = subhead.split("by "); final String[] splitBy = subhead.split("by ");
if (splitBy.length > 1) { if (splitBy.length > 1) {
return splitBy[1]; return splitBy[1];
} else { } else {
@ -36,11 +36,13 @@ public class BandcampSearchStreamInfoItemExtractor extends BandcampStreamInfoIte
@Override @Override
public String getThumbnailUrl() throws ParsingException { public String getThumbnailUrl() throws ParsingException {
Element img = searchResult.getElementsByClass("art").first() final Element img = searchResult.getElementsByClass("art").first()
.getElementsByTag("img").first(); .getElementsByTag("img").first();
if (img != null) { if (img != null) {
return img.attr("src"); return img.attr("src");
} else return null; } else {
return null;
}
} }
@Override @Override

View File

@ -13,7 +13,7 @@ import javax.annotation.Nullable;
public abstract class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor { public abstract class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor {
private final String uploaderUrl; private final String uploaderUrl;
public BandcampStreamInfoItemExtractor(String uploaderUrl) { public BandcampStreamInfoItemExtractor(final String uploaderUrl) {
this.uploaderUrl = uploaderUrl; this.uploaderUrl = uploaderUrl;
} }

View File

@ -20,16 +20,16 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory {
@Override @Override
public String getId(String url) throws ParsingException { public String getId(final String url) throws ParsingException {
try { try {
String response = NewPipe.getDownloader().get(url).responseBody(); final String response = NewPipe.getDownloader().get(url).responseBody();
// This variable contains band data! // 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")); 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); 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 * Uses the mobile endpoint as a "translator" from id to url
*/ */
@Override @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 { try {
return BandcampExtractorHelper.getArtistDetails(id) return BandcampExtractorHelper.getArtistDetails(id)
.getString("bandcamp_url") .getString("bandcamp_url")
.replace("http://", "https://"); .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); 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> * where the profile is at <code>* . * /releases</code>
*/ */
@Override @Override
public boolean onAcceptUrl(String url) { public boolean onAcceptUrl(final String url) {
// Is a subdomain of bandcamp.com? // Is a subdomain of bandcamp.com?
boolean isBandcampComArtistPage = url.matches("https?://.+\\.bandcamp\\.com/?"); boolean isBandcampComArtistPage = url.matches("https?://.+\\.bandcamp\\.com/?");

View File

@ -14,23 +14,30 @@ import static org.schabi.newpipe.extractor.services.bandcamp.extractors.Bandcamp
public class BandcampFeaturedLinkHandlerFactory extends ListLinkHandlerFactory { public class BandcampFeaturedLinkHandlerFactory extends ListLinkHandlerFactory {
@Override @Override
public String getUrl(String id, List<String> contentFilter, String sortFilter) { 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 if (id.equals(KIOSK_FEATURED)) {
else if (id.equals(KIOSK_RADIO)) return RADIO_API_URL; // doesn't have its own website return FEATURED_API_URL; // doesn't have a website
else return null; } else if (id.equals(KIOSK_RADIO)) {
return RADIO_API_URL; // doesn't have its own website
} else {
return null;
}
} }
@Override @Override
public String getId(String url) { public String getId(final String url) {
if (url.matches("https?://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL)) if (url.matches("https?://bandcamp\\.com/\\?show=\\d+") || url.equals(RADIO_API_URL)) {
return KIOSK_RADIO; return KIOSK_RADIO;
else if (url.equals(FEATURED_API_URL)) } else if (url.equals(FEATURED_API_URL)) {
return KIOSK_FEATURED; return KIOSK_FEATURED;
else return null; } else {
return null;
}
} }
@Override @Override
public boolean onAcceptUrl(String url) { public boolean onAcceptUrl(final String url) {
return url.equals(FEATURED_API_URL) || (url.equals(RADIO_API_URL) || url.matches("https?://bandcamp\\.com/\\?show=\\d+")); return url.equals(FEATURED_API_URL) || (url.equals(RADIO_API_URL)
|| url.matches("https?://bandcamp\\.com/\\?show=\\d+"));
} }
} }

View File

@ -12,17 +12,18 @@ import java.util.List;
*/ */
public class BandcampPlaylistLinkHandlerFactory extends ListLinkHandlerFactory { public class BandcampPlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
@Override @Override
public String getId(String url) throws ParsingException { public String getId(final String url) throws ParsingException {
return getUrl(url); return getUrl(url);
} }
@Override @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; return url;
} }
@Override @Override
public boolean onAcceptUrl(String url) { public boolean onAcceptUrl(final String url) {
return url.toLowerCase().matches("https?://.+\\..+/album/.+"); return url.toLowerCase().matches("https?://.+\\..+/album/.+");
} }
} }

View File

@ -13,14 +13,15 @@ public class BandcampSearchQueryHandlerFactory extends SearchQueryHandlerFactory
@Override @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 { try {
return "https://bandcamp.com/search?q=" + return "https://bandcamp.com/search?q=" +
URLEncoder.encode(query, "UTF-8") URLEncoder.encode(query, "UTF-8")
+ "&page=1"; + "&page=1";
} catch (UnsupportedEncodingException e) { } catch (final UnsupportedEncodingException e) {
throw new ParsingException("query \"" + query + "\" could not be encoded", e); throw new ParsingException("query \"" + query + "\" could not be encoded", e);
} }
} }

View File

@ -18,11 +18,12 @@ public class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
* @see BandcampStreamLinkHandlerFactory * @see BandcampStreamLinkHandlerFactory
*/ */
@Override @Override
public String getId(String url) throws ParsingException { public String getId(final String url) throws ParsingException {
if (url.matches("https?://bandcamp\\.com/\\?show=\\d+")) { if (url.matches("https?://bandcamp\\.com/\\?show=\\d+")) {
return url.split("bandcamp.com/\\?show=")[1]; return url.split("bandcamp.com/\\?show=")[1];
} else } else {
return getUrl(url); return getUrl(url);
}
} }
/** /**
@ -30,10 +31,12 @@ public class BandcampStreamLinkHandlerFactory extends LinkHandlerFactory {
* @see BandcampStreamLinkHandlerFactory * @see BandcampStreamLinkHandlerFactory
*/ */
@Override @Override
public String getUrl(String input) { public String getUrl(final String input) {
if (input.matches("\\d+")) if (input.matches("\\d+")) {
return "https://bandcamp.com/?show=" + input; 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> * <code>https:// * . * /track/ *</code>
*/ */
@Override @Override
public boolean onAcceptUrl(String url) { public boolean onAcceptUrl(final String url) {
return url.toLowerCase().matches("https?://.+\\..+/track/.+") || url.toLowerCase().matches("https?://bandcamp\\.com/\\?show=\\d+"); return url.toLowerCase().matches("https?://.+\\..+/track/.+")
|| url.toLowerCase().matches("https?://bandcamp\\.com/\\?show=\\d+");
} }
} }