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); } }