From 7fd21ec08581deb40f642b9859e9cc045d26e05b Mon Sep 17 00:00:00 2001 From: John Zhen Mo Date: Sat, 3 Feb 2018 13:52:49 -0800 Subject: [PATCH] -Modified subtitles to use locale rather than language code. -Fixed locale parsing for youtube. --- .../org/schabi/newpipe/extractor/Subtitles.java | 17 +++++------------ .../youtube/YoutubeStreamExtractor.java | 7 ++++++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/schabi/newpipe/extractor/Subtitles.java b/src/main/java/org/schabi/newpipe/extractor/Subtitles.java index dd0b94407..affd854e9 100644 --- a/src/main/java/org/schabi/newpipe/extractor/Subtitles.java +++ b/src/main/java/org/schabi/newpipe/extractor/Subtitles.java @@ -6,24 +6,22 @@ import java.io.Serializable; import java.util.Locale; public class Subtitles implements Serializable { - private final static String AUTO_GENERATED_TAG = " (auto-generated)"; - private final SubtitlesFormat format; - private final String languageCode; + private final Locale locale; private final String URL; private final boolean autoGenerated; - public Subtitles(SubtitlesFormat format, String languageCode, String URL, boolean autoGenerated) { + public Subtitles(SubtitlesFormat format, Locale locale, String URL, boolean autoGenerated) { this.format = format; - this.languageCode = languageCode; + this.locale = locale; this.URL = URL; this.autoGenerated = autoGenerated; } public SubtitlesFormat getFileType() { return format; } - public String getLanguageCode() { - return languageCode; + public Locale getLocale() { + return locale; } public String getURL() { @@ -33,9 +31,4 @@ public class Subtitles implements Serializable { public boolean isAutoGenerated() { return autoGenerated; } - - public String getDisplayName() { - final Locale locale = new Locale(languageCode.replace("-", "_")); - return locale.getDisplayLanguage() + (isAutoGenerated() ? AUTO_GENERATED_TAG : ""); - } } 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 6219937e5..7d8b14c89 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 @@ -775,16 +775,21 @@ public class YoutubeStreamExtractor extends StreamExtractor { final String languageCode; final boolean isGenerated; + final Locale locale; + public SubtitlesInfo(final String baseUrl, final String languageCode, final boolean isGenerated) { this.cleanUrl = baseUrl .replaceAll("&fmt=[^&]*", "") // Remove preexisting format if exists .replaceAll("&tlang=[^&]*", ""); // Remove translation language this.languageCode = languageCode; this.isGenerated = isGenerated; + + final String[] splits = languageCode.split("-"); + this.locale = splits.length == 2 ? new Locale(splits[0], splits[1]) : new Locale(languageCode); } public Subtitles getSubtitle(final SubtitlesFormat format) { - return new Subtitles(format, languageCode, cleanUrl + "&fmt=" + format.getExtension(), isGenerated); + return new Subtitles(format, locale, cleanUrl + "&fmt=" + format.getExtension(), isGenerated); } }