mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-15 06:40:33 +05:30
Bandcamp search extractor: read track count from result page
This commit is contained in:
parent
9b16baffb7
commit
13e4908b83
@ -11,14 +11,14 @@ import java.io.IOException;
|
|||||||
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
||||||
|
|
||||||
private String title, artist, url, cover;
|
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.title = title;
|
||||||
this.artist = artist;
|
this.artist = artist;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.cover = cover;
|
this.cover = cover;
|
||||||
this.service = service;
|
this.trackCount = trackCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,14 +27,8 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getStreamCount() throws ParsingException {
|
public long getStreamCount() {
|
||||||
try {
|
return trackCount;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,7 +74,9 @@ public class BandcampSearchExtractor extends SearchExtractor {
|
|||||||
|
|
||||||
case "ALBUM":
|
case "ALBUM":
|
||||||
String artist = subhead.split(" by")[0];
|
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;
|
break;
|
||||||
|
|
||||||
case "TRACK":
|
case "TRACK":
|
||||||
|
@ -85,7 +85,7 @@ public class BandcampSearchExtractorTest {
|
|||||||
assertTrue(minecraft.getThumbnailUrl().contains("f4.bcbits.com/img/"));
|
assertTrue(minecraft.getThumbnailUrl().contains("f4.bcbits.com/img/"));
|
||||||
assertEquals("https://c418.bandcamp.com/album/minecraft-volume-alpha", minecraft.getUrl());
|
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());
|
assertEquals(24, ((PlaylistInfoItem) minecraft).getStreamCount());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user