From de98fab2ed05a3522016078001f8b262156406f1 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 23 Apr 2017 10:03:11 +0800 Subject: [PATCH] Fix for Brazilian Portuguese language preferences when using OpenSubtitles @see https://www.filebot.net/forums/viewtopic.php?f=8&t=4992 --- .../net/filebot/web/OpenSubtitlesClient.java | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index bda82ff4..858db96e 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -456,42 +456,36 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS } }); - // some additional special handling - subLanguageMap.put("iw", "heb"); // Hebrew - subLanguageMap.put("pb", "pob"); // Brazilian Portuguese - subLanguageMap.put("zh", "chi"); // Chinese (Simplified) - subLanguageMap.put("tw", "zht"); // Chinese (Traditional) - return subLanguageMap; } - protected String getLanguageCode(Locale locale) { - switch (locale.toString()) { - case "pt_BR": - return "pb"; - case "zh_TW": - return "tw"; - default: - return locale.getLanguage(); - } - } - - protected String[] getLanguageFilter(Locale locale) { - return locale == null || locale.getLanguage().isEmpty() ? new String[0] : new String[] { getSubLanguageID(locale) }; - } - protected String getSubLanguageID(Locale locale) { - if (locale == null || locale.getLanguage().isEmpty()) { + if (locale == null || locale.equals(Locale.ROOT)) { return "all"; } - String subLanguageID = null; + // some special handling + switch (locale.toString()) { + case "en_US": + return "eng"; // English + case "pt_BR": + return "pob"; // Brazilian Portuguese + case "zh_CN": + return "chi"; // Chinese (Simplified) + case "zh_TW": + return "zht"; // Chinese (Traditional) + case "iw_IL": + return "heb"; // Hebrew + } + + Map languageMap; try { - subLanguageID = getSubLanguageMap().get(getLanguageCode(locale)); + languageMap = getSubLanguageMap(); } catch (Exception e) { throw new IllegalStateException("Failed to retrieve subtitle language map", e); } + String subLanguageID = languageMap.get(locale.getLanguage()); if (subLanguageID == null) { throw new IllegalArgumentException("SubLanguageID not found: " + locale); } @@ -499,6 +493,10 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS return subLanguageID; } + protected String[] getLanguageFilter(Locale locale) { + return locale == null || locale.getLanguage().isEmpty() ? new String[0] : new String[] { getSubLanguageID(locale) }; + } + public Cache getCache(String section) { return Cache.getCache(getName() + "_" + section, CacheType.Daily); }