From 5b79ef3557fc1569dd09e487c6369a1cbf6570a0 Mon Sep 17 00:00:00 2001 From: John Zhen Mo Date: Thu, 1 Feb 2018 22:51:53 -0800 Subject: [PATCH] -Fixed extraction to only output manual and autogenerated scripts, omitting autotranslated scripts. --- .../youtube/YoutubeStreamExtractor.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index 14b49e155..bf6470d1a 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -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 manualLanguageCodes = new HashSet<>(); - for (int i = 0; i < captionsSize; i++) { - manualLanguageCodes.add(captionsArray.getObject(i).getString("languageCode")); - } - Set automaticLanguageCodes = new HashSet<>(); - for (int i = 0; i < autoCaptionsArray.size(); i++) { - automaticLanguageCodes.add(autoCaptionsArray.getObject(i).getString("languageCode")); - } List 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; } /*//////////////////////////////////////////////////////////////////////////