Bandcamp: Fetch channelInfo in onFetchPage
This commit is contained in:
parent
433d72c26a
commit
00c0333059
|
@ -22,10 +22,8 @@ public class BandcampChannelExtractor extends ChannelExtractor {
|
||||||
|
|
||||||
private JsonObject channelInfo;
|
private JsonObject channelInfo;
|
||||||
|
|
||||||
public BandcampChannelExtractor(StreamingService service, ListLinkHandler linkHandler) throws ParsingException {
|
public BandcampChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
|
|
||||||
channelInfo = getArtistDetails(getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,6 +154,7 @@ public class BandcampChannelExtractor extends ChannelExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||||
|
channelInfo = getArtistDetails(getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
|
@ -72,13 +72,7 @@ public class BandcampFeaturedExtractor extends KioskExtractor<InfoItem> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.commit(new BandcampPlaylistInfoItemExtractor(
|
c.commit(new BandcampPlaylistInfoItemExtractor(featuredStory));
|
||||||
featuredStory.getString("album_title"),
|
|
||||||
featuredStory.getString("band_name"),
|
|
||||||
featuredStory.getString("item_url"),
|
|
||||||
featuredStory.has("art_id") ? getImageUrl(featuredStory.getLong("art_id"), true) : "",
|
|
||||||
featuredStory.getInt("num_streamable_tracks")
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new InfoItemsPage<InfoItem>(c, null);
|
return new InfoItemsPage<InfoItem>(c, null);
|
||||||
|
|
|
@ -1,24 +1,44 @@
|
||||||
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.jsoup.nodes.Element;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl;
|
||||||
|
|
||||||
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
||||||
|
|
||||||
private String title, artist, url, cover;
|
private String title, artist, url, cover;
|
||||||
private int trackCount;
|
private int trackCount;
|
||||||
|
|
||||||
public BandcampPlaylistInfoItemExtractor(String title, String artist, String url, String cover, int trackCount) {
|
public BandcampPlaylistInfoItemExtractor(Element searchResult) {
|
||||||
this.title = title;
|
|
||||||
this.artist = artist;
|
Element resultInfo = searchResult.getElementsByClass("result-info").first();
|
||||||
this.url = url;
|
|
||||||
this.cover = cover;
|
Element img = searchResult.getElementsByClass("art").first()
|
||||||
this.trackCount = trackCount;
|
.getElementsByTag("img").first();
|
||||||
|
if (img != null) {
|
||||||
|
cover = img.attr("src");
|
||||||
|
}
|
||||||
|
|
||||||
|
title = resultInfo.getElementsByClass("heading").text();
|
||||||
|
url = resultInfo.getElementsByClass("itemurl").text();
|
||||||
|
|
||||||
|
artist = resultInfo.getElementsByClass("subhead").text()
|
||||||
|
.split(" by")[0];
|
||||||
|
|
||||||
|
String length = resultInfo.getElementsByClass("length").text();
|
||||||
|
trackCount = Integer.parseInt(length.split(" track")[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public BandcampPlaylistInfoItemExtractor(JsonObject featuredStory) {
|
||||||
|
title = featuredStory.getString("album_title");
|
||||||
|
artist = featuredStory.getString("band_name");
|
||||||
|
url = featuredStory.getString("item_url");
|
||||||
|
cover = featuredStory.has("art_id") ? getImageUrl(featuredStory.getLong("art_id"), true) : "";
|
||||||
|
trackCount = featuredStory.getInt("num_streamable_tracks");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.schabi.newpipe.DownloaderTestImpl;
|
import org.schabi.newpipe.DownloaderTestImpl;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
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.services.bandcamp.extractors.BandcampChannelExtractor;
|
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor;
|
||||||
|
@ -18,12 +19,17 @@ import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
|
||||||
public class BandcampChannelExtractorTest {
|
public class BandcampChannelExtractorTest {
|
||||||
|
|
||||||
private static BandcampChannelExtractor extractor;
|
private static BandcampChannelExtractor extractor;
|
||||||
|
private static ChannelExtractor noAvatarExtractor;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||||
extractor = (BandcampChannelExtractor) Bandcamp
|
extractor = (BandcampChannelExtractor) Bandcamp
|
||||||
.getChannelExtractor("https://zachbenson.bandcamp.com/");
|
.getChannelExtractor("https://zachbenson.bandcamp.com/");
|
||||||
|
extractor.fetchPage();
|
||||||
|
|
||||||
|
noAvatarExtractor = Bandcamp.getChannelExtractor("https://powertothequeerkids.bandcamp.com/");
|
||||||
|
noAvatarExtractor.fetchPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -51,11 +57,11 @@ public class BandcampChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetNoAvatar() throws ExtractionException {
|
public void testGetNoAvatar() throws ExtractionException {
|
||||||
assertEquals("", Bandcamp.getChannelExtractor("https://powertothequeerkids.bandcamp.com/").getAvatarUrl());
|
assertEquals("", noAvatarExtractor.getAvatarUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetNoBanner() throws ExtractionException {
|
public void testGetNoBanner() throws ExtractionException {
|
||||||
assertEquals("", Bandcamp.getChannelExtractor("https://powertothequeerkids.bandcamp.com/").getBannerUrl());
|
assertEquals("", noAvatarExtractor.getBannerUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue