-Fixed extraction to only output manual and autogenerated scripts, omitting autotranslated scripts.
This commit is contained in:
parent
aafe543334
commit
5b79ef3557
|
@ -735,29 +735,26 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
final JsonObject renderer = captions.getObject("playerCaptionsTracklistRenderer");
|
final JsonObject renderer = captions.getObject("playerCaptionsTracklistRenderer");
|
||||||
final JsonArray captionsArray = renderer.getArray("captionTracks");
|
final JsonArray captionsArray = renderer.getArray("captionTracks");
|
||||||
|
|
||||||
|
// todo: use this to apply auto translation to different language from a source language
|
||||||
final JsonArray autoCaptionsArray = renderer.getArray("translationLanguages");
|
final JsonArray autoCaptionsArray = renderer.getArray("translationLanguages");
|
||||||
|
|
||||||
final int captionsSize = captionsArray.size();
|
final int captionsSize = captionsArray.size();
|
||||||
// Should not happen, if there is the "captions" object, it should always has some captions in it
|
// Should not happen, if there is the "captions" object, it should always has some captions in it
|
||||||
if(captionsSize == 0) return Collections.emptyList();
|
if(captionsSize == 0) return Collections.emptyList();
|
||||||
// Obtain the base url, this only needs to be done once
|
// Obtain the base url, this only needs to be done once
|
||||||
final String baseUrl = captionsArray.getObject(0).getString("baseUrl");
|
|
||||||
|
|
||||||
Set<String> manualLanguageCodes = new HashSet<>();
|
|
||||||
for (int i = 0; i < captionsSize; i++) {
|
|
||||||
manualLanguageCodes.add(captionsArray.getObject(i).getString("languageCode"));
|
|
||||||
}
|
|
||||||
Set<String> automaticLanguageCodes = new HashSet<>();
|
|
||||||
for (int i = 0; i < autoCaptionsArray.size(); i++) {
|
|
||||||
automaticLanguageCodes.add(autoCaptionsArray.getObject(i).getString("languageCode"));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Subtitles> result = new ArrayList<>();
|
List<Subtitles> result = new ArrayList<>();
|
||||||
result.addAll(getVideoSubtitlesUrl(baseUrl, new ArrayList<>(manualLanguageCodes),
|
for (int i = 0; i < captionsSize; i++) {
|
||||||
new ArrayList<>(automaticLanguageCodes), SubtitlesFormat.VTT));
|
final String languageCode = captionsArray.getObject(i).getString("languageCode");
|
||||||
result.addAll(getVideoSubtitlesUrl(baseUrl, new ArrayList<>(manualLanguageCodes),
|
final String baseUrl = captionsArray.getObject(i).getString("baseUrl");
|
||||||
new ArrayList<>(automaticLanguageCodes), SubtitlesFormat.TTML));
|
final boolean isAutoGenerated = captionsArray.getObject(i).getString("vssId").startsWith("a.");
|
||||||
// todo: add transcripts, they are currently omitted since they are incompatible with ExoPlayer
|
|
||||||
|
result.add(new Subtitles(SubtitlesFormat.TTML, languageCode, baseUrl, isAutoGenerated));
|
||||||
|
result.add(new Subtitles(SubtitlesFormat.VTT, languageCode, baseUrl, isAutoGenerated));
|
||||||
|
// todo: add transcripts, they are currently omitted since they are incompatible with ExoPlayer
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue