-Fixed extraction to only output manual and autogenerated scripts, omitting autotranslated scripts.

This commit is contained in:
John Zhen Mo 2018-02-01 22:51:53 -08:00
parent aafe543334
commit 5b79ef3557
1 changed files with 12 additions and 15 deletions

View File

@ -735,29 +735,26 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final JsonObject renderer = captions.getObject("playerCaptionsTracklistRenderer");
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 int captionsSize = captionsArray.size();
// Should not happen, if there is the "captions" object, it should always has some captions in it
if(captionsSize == 0) return Collections.emptyList();
// 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<>();
result.addAll(getVideoSubtitlesUrl(baseUrl, new ArrayList<>(manualLanguageCodes),
new ArrayList<>(automaticLanguageCodes), SubtitlesFormat.VTT));
result.addAll(getVideoSubtitlesUrl(baseUrl, new ArrayList<>(manualLanguageCodes),
new ArrayList<>(automaticLanguageCodes), SubtitlesFormat.TTML));
// todo: add transcripts, they are currently omitted since they are incompatible with ExoPlayer
for (int i = 0; i < captionsSize; i++) {
final String languageCode = captionsArray.getObject(i).getString("languageCode");
final String baseUrl = captionsArray.getObject(i).getString("baseUrl");
final boolean isAutoGenerated = captionsArray.getObject(i).getString("vssId").startsWith("a.");
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;
}
/*//////////////////////////////////////////////////////////////////////////