-Fixed url format property.

-Removed unused code.
This commit is contained in:
John Zhen Mo 2018-02-01 23:03:06 -08:00
parent 5b79ef3557
commit c1cfb2b223
1 changed files with 6 additions and 22 deletions

View File

@ -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<Subtitles> getVideoSubtitlesUrl(final String baseUrl,
final List<String> manualCaptionLanguageCodes,
final List<String> 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> 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<String, ItagItem> getItags(String encodedUrlMapKey, ItagItem.ItagType itagTypeWanted) throws ParsingException {