Various improvements concerning bandcamp playlists

This commit is contained in:
Fynn Godau 2019-12-22 03:10:54 +01:00
parent ba700bfb3e
commit 655df356a2
4 changed files with 44 additions and 7 deletions

View file

@ -107,8 +107,8 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
track.getString("title"), track.getString("title"),
getUploaderUrl() + track.getString("title_link"), getUploaderUrl() + track.getString("title_link"),
"", "",
"", track.getLong("duration"),
track.getLong("duration") getService()
)); ));
} }

View file

@ -1,16 +1,24 @@
package org.schabi.newpipe.extractor.services.bandcamp.extractors; package org.schabi.newpipe.extractor.services.bandcamp.extractors;
import org.schabi.newpipe.extractor.StreamingService;
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;
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;
public BandcampPlaylistInfoItemExtractor(String title, String artist, String url, String cover) { public BandcampPlaylistInfoItemExtractor(String title, String artist, String url, String cover, StreamingService service) {
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;
} }
@Override @Override
@ -19,8 +27,14 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
} }
@Override @Override
public long getStreamCount() { public long getStreamCount() throws ParsingException {
return -1; 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);
}
} }
@Override @Override

View file

@ -74,7 +74,7 @@ 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)); collector.commit(new BandcampPlaylistInfoItemExtractor(heading, artist, url, image, getService()));
break; break;
case "TRACK": case "TRACK":

View file

@ -2,12 +2,16 @@
package org.schabi.newpipe.extractor.services.bandcamp.extractors; package org.schabi.newpipe.extractor.services.bandcamp.extractors;
import org.schabi.newpipe.extractor.StreamingService;
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.localization.DateWrapper; import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.StreamType;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.IOException;
public class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor { public class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor {
@ -16,6 +20,12 @@ public class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor
private String cover; private String cover;
private String artist; private String artist;
private long duration; private long duration;
private StreamingService service;
public BandcampStreamInfoItemExtractor(String title, String url, String artist, long duration, StreamingService service) {
this(title, url, null, artist, duration);
this.service = service;
}
public BandcampStreamInfoItemExtractor(String title, String url, String cover, String artist) { public BandcampStreamInfoItemExtractor(String title, String url, String cover, String artist) {
this(title, url, cover, artist, -1); this(title, url, cover, artist, -1);
@ -76,9 +86,22 @@ public class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor
return url; return url;
} }
/**
* There is no guarantee that every track of an album has the same cover art, so it needs to be fetched
* per-track if in playlist view
*/
@Override @Override
public String getThumbnailUrl() throws ParsingException { public String getThumbnailUrl() throws ParsingException {
return cover; if (cover != null) return cover;
else {
try {
StreamExtractor extractor = service.getStreamExtractor(getUrl());
extractor.fetchPage();
return extractor.getThumbnailUrl();
} catch (ExtractionException | IOException e) {
throw new ParsingException("could not download cover art location", e);
}
}
} }
/** /**