Bandcamp search extractor: read track count from result page
This commit is contained in:
parent
9b16baffb7
commit
13e4908b83
3 changed files with 9 additions and 13 deletions
|
@ -11,14 +11,14 @@ import java.io.IOException;
|
|||
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
||||
|
||||
private String title, artist, url, cover;
|
||||
private StreamingService service;
|
||||
private int trackCount;
|
||||
|
||||
public BandcampPlaylistInfoItemExtractor(String title, String artist, String url, String cover, StreamingService service) {
|
||||
public BandcampPlaylistInfoItemExtractor(String title, String artist, String url, String cover, int trackCount) {
|
||||
this.title = title;
|
||||
this.artist = artist;
|
||||
this.url = url;
|
||||
this.cover = cover;
|
||||
this.service = service;
|
||||
this.trackCount = trackCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,14 +27,8 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
|
|||
}
|
||||
|
||||
@Override
|
||||
public long getStreamCount() throws ParsingException {
|
||||
try {
|
||||
PlaylistExtractor extractor = service.getPlaylistExtractor(url);
|
||||
extractor.fetchPage();
|
||||
return extractor.getStreamCount();
|
||||
} catch (ExtractionException | IOException e) {
|
||||
throw new ParsingException("Could not find out how many tracks there are", e);
|
||||
}
|
||||
public long getStreamCount() {
|
||||
return trackCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -74,7 +74,9 @@ public class BandcampSearchExtractor extends SearchExtractor {
|
|||
|
||||
case "ALBUM":
|
||||
String artist = subhead.split(" by")[0];
|
||||
collector.commit(new BandcampPlaylistInfoItemExtractor(heading, artist, url, image, getService()));
|
||||
String length = resultInfo.getElementsByClass("length").text();
|
||||
int tracks = Integer.parseInt(length.split(" track")[0]);
|
||||
collector.commit(new BandcampPlaylistInfoItemExtractor(heading, artist, url, image, tracks));
|
||||
break;
|
||||
|
||||
case "TRACK":
|
||||
|
|
|
@ -85,7 +85,7 @@ public class BandcampSearchExtractorTest {
|
|||
assertTrue(minecraft.getThumbnailUrl().contains("f4.bcbits.com/img/"));
|
||||
assertEquals("https://c418.bandcamp.com/album/minecraft-volume-alpha", minecraft.getUrl());
|
||||
|
||||
// Verify that playlists get counted correctly
|
||||
// Verify that playlist tracks counts get extracted correctly
|
||||
assertEquals(24, ((PlaylistInfoItem) minecraft).getStreamCount());
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue