70 lines
2.2 KiB
Java
70 lines
2.2 KiB
Java
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
|
|
|
|
package org.schabi.newpipe.extractor.services.bandcamp.extractors.streaminfoitem;
|
|
|
|
import com.grack.nanojson.JsonObject;
|
|
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.stream.StreamExtractor;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
public class BandcampPlaylistStreamInfoItemExtractor extends BandcampStreamInfoItemExtractor {
|
|
|
|
private final JsonObject track;
|
|
private String substituteCoverUrl;
|
|
private StreamingService service;
|
|
|
|
public BandcampPlaylistStreamInfoItemExtractor(JsonObject track, String uploaderUrl, StreamingService service) {
|
|
super(uploaderUrl);
|
|
this.track = track;
|
|
this.service = service;
|
|
}
|
|
|
|
public BandcampPlaylistStreamInfoItemExtractor(JsonObject track, String uploaderUrl, String substituteCoverUrl) {
|
|
this(track, uploaderUrl, (StreamingService) null);
|
|
this.substituteCoverUrl = substituteCoverUrl;
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return track.getString("title");
|
|
}
|
|
|
|
@Override
|
|
public String getUrl() {
|
|
return getUploaderUrl() + track.getString("title_link");
|
|
}
|
|
|
|
@Override
|
|
public long getDuration() {
|
|
return track.getLong("duration");
|
|
}
|
|
|
|
@Override
|
|
public String getUploaderName() {
|
|
return "";
|
|
}
|
|
|
|
/**
|
|
* Each track can have its own cover art. Therefore, unless a substitute is provided,
|
|
* the thumbnail is extracted using a stream extractor.
|
|
*/
|
|
@Override
|
|
public String getThumbnailUrl() throws ParsingException {
|
|
if (substituteCoverUrl != null) {
|
|
return substituteCoverUrl;
|
|
} 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);
|
|
}
|
|
}
|
|
}
|
|
}
|