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 bf6470d1a..3e60e0265 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 @@ -750,8 +750,10 @@ public class YoutubeStreamExtractor extends StreamExtractor { 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)); + result.add(new Subtitles(SubtitlesFormat.TTML, languageCode, + getSubtitleFormatUrl(baseUrl, SubtitlesFormat.TTML), isAutoGenerated)); + result.add(new Subtitles(SubtitlesFormat.VTT, languageCode, + getSubtitleFormatUrl(baseUrl, SubtitlesFormat.VTT), isAutoGenerated)); // todo: add transcripts, they are currently omitted since they are incompatible with ExoPlayer } @@ -783,26 +785,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { } @Nonnull - private static List getVideoSubtitlesUrl(final String baseUrl, - final List manualCaptionLanguageCodes, - final List automaticCaptionLanguageCodes, - final SubtitlesFormat format) { - final String cleanUrl = baseUrl - .replaceAll("&fmt=[^&]*", "") // Remove preexisting format if exists - .replaceAll("&tlang=[^&]*", "") // Remove translation language - .replaceAll("&kind=[^&]*", ""); // Remove automatic generation toggle - final String builderUrl = cleanUrl + "&fmt=" + format.getExtension() + "&tlang="; - - List subtitles = new ArrayList<>(manualCaptionLanguageCodes.size() + - automaticCaptionLanguageCodes.size()); - for (final String languageCode : manualCaptionLanguageCodes) { - subtitles.add(new Subtitles(format, languageCode, builderUrl + languageCode, false)); - } - for (final String languageCode : automaticCaptionLanguageCodes) { - final String fullUrl = builderUrl + languageCode + "&kind=asr"; - subtitles.add(new Subtitles(format, languageCode, fullUrl, true)); - } - return subtitles; + private static String getSubtitleFormatUrl(final String baseUrl, final SubtitlesFormat format) { + return baseUrl.replaceAll("&fmt=[^&]*", "") + "&fmt=" + format.getExtension(); } private Map getItags(String encodedUrlMapKey, ItagItem.ItagType itagTypeWanted) throws ParsingException {