diff --git a/source/net/filebot/media/ReleaseInfo.java b/source/net/filebot/media/ReleaseInfo.java index b4d50e5d..c4e7410e 100644 --- a/source/net/filebot/media/ReleaseInfo.java +++ b/source/net/filebot/media/ReleaseInfo.java @@ -493,7 +493,7 @@ public class ReleaseInfo { return patterns; } - private Map getLanguageMap(Locale... supportedDisplayLocale) { + public Map getLanguageMap(Locale... supportedDisplayLocale) { // use maximum strength collator by default Collator collator = Collator.getInstance(Locale.ROOT); collator.setDecomposition(Collator.FULL_DECOMPOSITION); @@ -520,6 +520,7 @@ public class ReleaseInfo { // unofficial language for pb/pob for Portuguese (Brazil) Locale brazil = new Locale("pob"); + languageMap.put("brazilian", brazil); languageMap.put("pb", brazil); languageMap.put("pob", brazil); diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index b56c8ca2..8564aae9 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -33,6 +33,7 @@ import javax.swing.Icon; import net.filebot.Cache; import net.filebot.Cache.Key; import net.filebot.ResourceManager; +import net.filebot.media.MediaDetection; import net.filebot.mediainfo.MediaInfo; import net.filebot.mediainfo.MediaInfo.StreamKind; import net.filebot.util.ExceptionUtilities; @@ -550,21 +551,39 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS Cache cache = Cache.getCache("web-datasource-lv2"); String cacheKey = getClass().getName() + ".subLanguageMap"; + // try to get language map from cache Map subLanguageMap = cache.get(cacheKey, Map.class); if (subLanguageMap == null) { subLanguageMap = new HashMap(); + // add additional language aliases for improved compatibility + Map additionalLanguageMappings = MediaDetection.releaseInfo.getLanguageMap(Locale.ENGLISH); + // fetch language data for (Entry entry : xmlrpc.getSubLanguages().entrySet()) { // map id by name - subLanguageMap.put(entry.getValue().toLowerCase(), entry.getKey().toLowerCase()); - subLanguageMap.put(entry.getKey().toLowerCase(), entry.getKey().toLowerCase()); // add reverse mapping as well for improved compatibility + String subLanguageID = entry.getKey().toLowerCase(); + String subLanguageName = entry.getValue().toLowerCase(); + + subLanguageMap.put(subLanguageName, subLanguageID); + subLanguageMap.put(subLanguageID, subLanguageID); // add reverse mapping as well for improved compatibility + + // add additional language aliases for improved compatibility + for (String key : asList(subLanguageID, subLanguageName)) { + Locale locale = additionalLanguageMappings.get(key); + if (locale != null) { + for (String identifier : asList(locale.getLanguage(), locale.getISO3Language(), locale.getDisplayLanguage(Locale.ENGLISH))) { + if (identifier != null && identifier.length() > 0 && !subLanguageMap.containsKey(identifier.toLowerCase())) { + subLanguageMap.put(identifier.toLowerCase(), subLanguageID); + } + } + } + } } // some additional special handling subLanguageMap.put("brazilian", "pob"); - subLanguageMap.put("pob", "pob"); // cache data cache.put(cacheKey, subLanguageMap); @@ -574,14 +593,11 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS } protected String getSubLanguageID(String languageName) throws Exception { - Map subLanguageMap = getSubLanguageMap(); - String key = languageName.toLowerCase(); - - if (!subLanguageMap.containsKey(key)) { - throw new IllegalArgumentException(String.format("SubLanguageID for '%s' not found", key)); + String subLanguageID = getSubLanguageMap().get(languageName.toLowerCase()); + if (subLanguageID == null) { + throw new IllegalArgumentException(String.format("SubLanguageID for '%s' not found", languageName)); } - - return subLanguageMap.get(key); + return subLanguageID; } protected String getLanguageName(String subLanguageID) throws Exception {