add subtitles support for peertube
This commit is contained in:
parent
bb5ad49fac
commit
318f600527
|
@ -40,6 +40,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
|
|
||||||
private JsonObject json;
|
private JsonObject json;
|
||||||
|
private List<SubtitlesStream> subtitles = new ArrayList<>();
|
||||||
|
|
||||||
public PeertubeStreamExtractor(StreamingService service, LinkHandler linkHandler, Localization localization) {
|
public PeertubeStreamExtractor(StreamingService service, LinkHandler linkHandler, Localization localization) {
|
||||||
super(service, linkHandler, localization);
|
super(service, linkHandler, localization);
|
||||||
|
@ -173,12 +174,18 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SubtitlesStream> getSubtitlesDefault() throws IOException, ExtractionException {
|
public List<SubtitlesStream> getSubtitlesDefault() throws IOException, ExtractionException {
|
||||||
return Collections.emptyList();
|
return subtitles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SubtitlesStream> getSubtitles(final MediaFormat format) throws IOException, ExtractionException {
|
public List<SubtitlesStream> getSubtitles(final MediaFormat format) throws IOException, ExtractionException {
|
||||||
return Collections.emptyList();
|
List<SubtitlesStream> filteredSubs = new ArrayList<>();
|
||||||
|
for(SubtitlesStream sub: subtitles) {
|
||||||
|
if(sub.getFormat() == format) {
|
||||||
|
filteredSubs.add(sub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredSubs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -274,6 +281,8 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
}else {
|
}else {
|
||||||
throw new ExtractionException("Unable to extract peertube channel data");
|
throw new ExtractionException("Unable to extract peertube channel data");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadSubtitles();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setInitialData(String responseBody) throws ExtractionException {
|
private void setInitialData(String responseBody) throws ExtractionException {
|
||||||
|
@ -285,6 +294,28 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
if(null == json) throw new ExtractionException("Unable to extract peertube stream data");
|
if(null == json) throw new ExtractionException("Unable to extract peertube stream data");
|
||||||
PeertubeParsingHelper.validate(json);
|
PeertubeParsingHelper.validate(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadSubtitles() {
|
||||||
|
if (subtitles.isEmpty()) {
|
||||||
|
try {
|
||||||
|
DownloadResponse response = getDownloader().get(getUrl() + "/captions");
|
||||||
|
JsonObject captionsJson = JsonParser.object().from(response.getResponseBody());
|
||||||
|
JsonArray captions = JsonUtils.getArray(captionsJson, "data");
|
||||||
|
for(Object c: captions) {
|
||||||
|
if(c instanceof JsonObject) {
|
||||||
|
JsonObject caption = (JsonObject)c;
|
||||||
|
String url = ServiceList.PeerTube.getBaseUrl() + JsonUtils.getString(caption, "captionPath");
|
||||||
|
String languageCode = JsonUtils.getString(caption, "language.id");
|
||||||
|
String ext = url.substring(url.lastIndexOf(".") + 1);
|
||||||
|
MediaFormat fmt = MediaFormat.getFromSuffix(ext);
|
||||||
|
if(fmt != null && languageCode != null) subtitles.add(new SubtitlesStream(fmt, languageCode, url, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore all exceptions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
|
|
Loading…
Reference in New Issue