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"),
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;
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 java.io.IOException;
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
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.artist = artist;
this.url = url;
this.cover = cover;
this.service = service;
}
@Override
@ -19,8 +27,14 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
}
@Override
public long getStreamCount() {
return -1;
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);
}
}
@Override

View File

@ -74,7 +74,7 @@ public class BandcampSearchExtractor extends SearchExtractor {
case "ALBUM":
String artist = subhead.split(" by")[0];
collector.commit(new BandcampPlaylistInfoItemExtractor(heading, artist, url, image));
collector.commit(new BandcampPlaylistInfoItemExtractor(heading, artist, url, image, getService()));
break;
case "TRACK":

View File

@ -2,12 +2,16 @@
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.localization.DateWrapper;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.StreamType;
import javax.annotation.Nullable;
import java.io.IOException;
public class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor {
@ -16,6 +20,12 @@ public class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor
private String cover;
private String artist;
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) {
this(title, url, cover, artist, -1);
@ -76,9 +86,22 @@ public class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor
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
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);
}
}
}
/**