add subtitles support for peertube
This commit is contained in:
parent
bb5ad49fac
commit
318f600527
1 changed files with 33 additions and 2 deletions
|
@ -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 {
|
||||||
|
@ -286,6 +295,28 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
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 {
|
||||||
return JsonUtils.getString(json, "name");
|
return JsonUtils.getString(json, "name");
|
||||||
|
|
Loading…
Reference in a new issue