fix: add Bandcamp URL suffixes
This commit is contained in:
parent
6a38811af8
commit
d47d0f982e
|
@ -18,6 +18,7 @@ import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
|
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ReadyChannelTabListLinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.ReadyChannelTabListLinkHandler;
|
||||||
|
import org.schabi.newpipe.extractor.services.bandcamp.linkHandler.BandcampChannelTabLinkHandlerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -116,14 +117,16 @@ public class BandcampChannelExtractor extends ChannelExtractor {
|
||||||
|
|
||||||
if (discography.stream().anyMatch(o -> (
|
if (discography.stream().anyMatch(o -> (
|
||||||
(JsonObject) o).getString("item_type").equals("track"))) {
|
(JsonObject) o).getString("item_type").equals("track"))) {
|
||||||
tabs.add(new ReadyChannelTabListLinkHandler(getUrl(), getId(),
|
tabs.add(new ReadyChannelTabListLinkHandler(getUrl()
|
||||||
ChannelTabs.TRACKS, builder));
|
+ BandcampChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.TRACKS),
|
||||||
|
getId(), ChannelTabs.TRACKS, builder));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (discography.stream().anyMatch(o -> (
|
if (discography.stream().anyMatch(o -> (
|
||||||
(JsonObject) o).getString("item_type").equals("album"))) {
|
(JsonObject) o).getString("item_type").equals("album"))) {
|
||||||
tabs.add(new ReadyChannelTabListLinkHandler(getUrl(), getId(),
|
tabs.add(new ReadyChannelTabListLinkHandler(getUrl()
|
||||||
ChannelTabs.ALBUMS, builder));
|
+ BandcampChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.ALBUMS),
|
||||||
|
getId(), ChannelTabs.ALBUMS, builder));
|
||||||
}
|
}
|
||||||
|
|
||||||
return tabs;
|
return tabs;
|
||||||
|
|
|
@ -10,10 +10,6 @@ public final class BandcampChannelTabLinkHandlerFactory extends ListLinkHandlerF
|
||||||
private static final BandcampChannelTabLinkHandlerFactory INSTANCE
|
private static final BandcampChannelTabLinkHandlerFactory INSTANCE
|
||||||
= new BandcampChannelTabLinkHandlerFactory();
|
= new BandcampChannelTabLinkHandlerFactory();
|
||||||
|
|
||||||
// This is not an actual page on the Bandcamp website, but it auto-redirects
|
|
||||||
// to the main page and we need a unique URL for the album tab
|
|
||||||
public static final String URL_SUFFIX = "/album";
|
|
||||||
|
|
||||||
private BandcampChannelTabLinkHandlerFactory() {
|
private BandcampChannelTabLinkHandlerFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +17,27 @@ public final class BandcampChannelTabLinkHandlerFactory extends ListLinkHandlerF
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tab's URL suffix
|
||||||
|
* <p>
|
||||||
|
* These URLs dont actually exist on the Bandcamp website as both albums and tracks
|
||||||
|
* are listed on the main page, but they redirect to the main page and we need a
|
||||||
|
* unique URL for each tab.
|
||||||
|
*
|
||||||
|
* @param tab Tab value
|
||||||
|
* @return URL suffix
|
||||||
|
* @throws ParsingException if the tab is not supported
|
||||||
|
*/
|
||||||
|
public static String getUrlSuffix(final String tab) throws ParsingException {
|
||||||
|
switch (tab) {
|
||||||
|
case ChannelTabs.TRACKS:
|
||||||
|
return "/track";
|
||||||
|
case ChannelTabs.ALBUMS:
|
||||||
|
return "/album";
|
||||||
|
}
|
||||||
|
throw new ParsingException("tab " + tab + " not supported");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId(final String url) throws ParsingException {
|
public String getId(final String url) throws ParsingException {
|
||||||
return BandcampChannelLinkHandlerFactory.getInstance().getId(url);
|
return BandcampChannelLinkHandlerFactory.getInstance().getId(url);
|
||||||
|
@ -29,12 +46,8 @@ public final class BandcampChannelTabLinkHandlerFactory extends ListLinkHandlerF
|
||||||
@Override
|
@Override
|
||||||
public String getUrl(final String id, final List<String> contentFilter, final String sortFilter)
|
public String getUrl(final String id, final List<String> contentFilter, final String sortFilter)
|
||||||
throws ParsingException {
|
throws ParsingException {
|
||||||
final String tab = contentFilter.get(0);
|
return BandcampChannelLinkHandlerFactory.getInstance().getUrl(id)
|
||||||
if (!tab.equals(ChannelTabs.ALBUMS)) {
|
+ getUrlSuffix(contentFilter.get(0));
|
||||||
throw new ParsingException("tab " + tab + " not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
return BandcampChannelLinkHandlerFactory.getInstance().getUrl(id) + URL_SUFFIX;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,7 +57,8 @@ public final class BandcampChannelTabLinkHandlerFactory extends ListLinkHandlerF
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getAvailableContentFilter() {
|
public String[] getAvailableContentFilter() {
|
||||||
return new String[] {
|
return new String[]{
|
||||||
|
ChannelTabs.TRACKS,
|
||||||
ChannelTabs.ALBUMS,
|
ChannelTabs.ALBUMS,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue