-Modified subtitles to use locale rather than language code.

-Fixed locale parsing for youtube.
This commit is contained in:
John Zhen Mo 2018-02-03 13:52:49 -08:00
parent 02dd281395
commit 7fd21ec085
2 changed files with 11 additions and 13 deletions

View File

@ -6,24 +6,22 @@ import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
public class Subtitles implements Serializable { public class Subtitles implements Serializable {
private final static String AUTO_GENERATED_TAG = " (auto-generated)";
private final SubtitlesFormat format; private final SubtitlesFormat format;
private final String languageCode; private final Locale locale;
private final String URL; private final String URL;
private final boolean autoGenerated; 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.format = format;
this.languageCode = languageCode; this.locale = locale;
this.URL = URL; this.URL = URL;
this.autoGenerated = autoGenerated; this.autoGenerated = autoGenerated;
} }
public SubtitlesFormat getFileType() { return format; } public SubtitlesFormat getFileType() { return format; }
public String getLanguageCode() { public Locale getLocale() {
return languageCode; return locale;
} }
public String getURL() { public String getURL() {
@ -33,9 +31,4 @@ public class Subtitles implements Serializable {
public boolean isAutoGenerated() { public boolean isAutoGenerated() {
return autoGenerated; return autoGenerated;
} }
public String getDisplayName() {
final Locale locale = new Locale(languageCode.replace("-", "_"));
return locale.getDisplayLanguage() + (isAutoGenerated() ? AUTO_GENERATED_TAG : "");
}
} }

View File

@ -775,16 +775,21 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final String languageCode; final String languageCode;
final boolean isGenerated; final boolean isGenerated;
final Locale locale;
public SubtitlesInfo(final String baseUrl, final String languageCode, final boolean isGenerated) { public SubtitlesInfo(final String baseUrl, final String languageCode, final boolean isGenerated) {
this.cleanUrl = baseUrl this.cleanUrl = baseUrl
.replaceAll("&fmt=[^&]*", "") // Remove preexisting format if exists .replaceAll("&fmt=[^&]*", "") // Remove preexisting format if exists
.replaceAll("&tlang=[^&]*", ""); // Remove translation language .replaceAll("&tlang=[^&]*", ""); // Remove translation language
this.languageCode = languageCode; this.languageCode = languageCode;
this.isGenerated = isGenerated; 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) { 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);
} }
} }