fix: add Bandcamp URL suffixes

This commit is contained in:
ThetaDev 2023-04-27 11:47:19 +02:00
parent 6a38811af8
commit d47d0f982e
2 changed files with 32 additions and 15 deletions

View File

@ -18,6 +18,7 @@ import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.linkhandler.ReadyChannelTabListLinkHandler;
import org.schabi.newpipe.extractor.services.bandcamp.linkHandler.BandcampChannelTabLinkHandlerFactory;
import java.io.IOException;
import java.util.ArrayList;
@ -116,14 +117,16 @@ public class BandcampChannelExtractor extends ChannelExtractor {
if (discography.stream().anyMatch(o -> (
(JsonObject) o).getString("item_type").equals("track"))) {
tabs.add(new ReadyChannelTabListLinkHandler(getUrl(), getId(),
ChannelTabs.TRACKS, builder));
tabs.add(new ReadyChannelTabListLinkHandler(getUrl()
+ BandcampChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.TRACKS),
getId(), ChannelTabs.TRACKS, builder));
}
if (discography.stream().anyMatch(o -> (
(JsonObject) o).getString("item_type").equals("album"))) {
tabs.add(new ReadyChannelTabListLinkHandler(getUrl(), getId(),
ChannelTabs.ALBUMS, builder));
tabs.add(new ReadyChannelTabListLinkHandler(getUrl()
+ BandcampChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.ALBUMS),
getId(), ChannelTabs.ALBUMS, builder));
}
return tabs;

View File

@ -10,10 +10,6 @@ public final class BandcampChannelTabLinkHandlerFactory extends ListLinkHandlerF
private static final BandcampChannelTabLinkHandlerFactory INSTANCE
= 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() {
}
@ -21,6 +17,27 @@ public final class BandcampChannelTabLinkHandlerFactory extends ListLinkHandlerF
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
public String getId(final String url) throws ParsingException {
return BandcampChannelLinkHandlerFactory.getInstance().getId(url);
@ -29,12 +46,8 @@ public final class BandcampChannelTabLinkHandlerFactory extends ListLinkHandlerF
@Override
public String getUrl(final String id, final List<String> contentFilter, final String sortFilter)
throws ParsingException {
final String tab = contentFilter.get(0);
if (!tab.equals(ChannelTabs.ALBUMS)) {
throw new ParsingException("tab " + tab + " not supported");
}
return BandcampChannelLinkHandlerFactory.getInstance().getUrl(id) + URL_SUFFIX;
return BandcampChannelLinkHandlerFactory.getInstance().getUrl(id)
+ getUrlSuffix(contentFilter.get(0));
}
@Override
@ -44,7 +57,8 @@ public final class BandcampChannelTabLinkHandlerFactory extends ListLinkHandlerF
@Override
public String[] getAvailableContentFilter() {
return new String[] {
return new String[]{
ChannelTabs.TRACKS,
ChannelTabs.ALBUMS,
};
}