From 116262fbea380c19e65b9109851f86c7e32dfa8a Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 24 Nov 2011 17:52:11 +0000 Subject: [PATCH] * save subtitle with ISO3 language code --- .../filebot/cli/CmdlineOperations.java | 5 +++-- source/net/sourceforge/filebot/ui/Language.java | 15 +++++++++++++++ .../subtitle/VideoHashSubtitleDownloadDialog.java | 13 +------------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index 5bcb8019..8538d094 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -403,7 +403,7 @@ public class CmdlineOperations implements CmdlineInterface { try { collector.addAll(service.getName(), lookupSubtitleByFileName(service, querySet, language, collector.remainingVideos())); } catch (RuntimeException e) { - CLILogger.warning(format("Search for [%s] failed: %s", query, e.getMessage())); + CLILogger.warning(format("Search for [%s] failed: %s", querySet, e.getMessage())); } } } @@ -464,6 +464,7 @@ public class CmdlineOperations implements CmdlineInterface { // subtitle filename is based on movie filename String name = getName(movieFile); + String lang = Language.getISO3LanguageCodeByName(descriptor.getLanguageName()); String ext = getExtension(subtitleFile.getName()); ByteBuffer data = subtitleFile.getData(); @@ -476,7 +477,7 @@ public class CmdlineOperations implements CmdlineInterface { data = exportSubtitles(subtitleFile, outputFormat, 0, outputEncoding); } - File destination = new File(movieFile.getParentFile(), name + "." + ext); + File destination = new File(movieFile.getParentFile(), String.format("%s.%s.%s", name, lang, ext)); CLILogger.config(format("Writing [%s] to [%s]", subtitleFile.getName(), destination.getName())); writeFile(data, destination); diff --git a/source/net/sourceforge/filebot/ui/Language.java b/source/net/sourceforge/filebot/ui/Language.java index 7730891d..447f0c55 100644 --- a/source/net/sourceforge/filebot/ui/Language.java +++ b/source/net/sourceforge/filebot/ui/Language.java @@ -93,6 +93,21 @@ public class Language { } + public static String getISO3LanguageCodeByName(String languageName) { + Language language = Language.getLanguageByName(languageName); + if (language != null) { + try { + return new Locale(language.getCode()).getISO3Language(); + } catch (Exception e) { + return language.getCode(); + } + } + + // we won't get here, but just in case + return languageName.replaceAll("\\W", ""); + } + + public static List availableLanguages() { ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName()); return getLanguages(bundle.getString("languages.all").split(",")); diff --git a/source/net/sourceforge/filebot/ui/subtitle/VideoHashSubtitleDownloadDialog.java b/source/net/sourceforge/filebot/ui/subtitle/VideoHashSubtitleDownloadDialog.java index 1f13aa19..35398602 100644 --- a/source/net/sourceforge/filebot/ui/subtitle/VideoHashSubtitleDownloadDialog.java +++ b/source/net/sourceforge/filebot/ui/subtitle/VideoHashSubtitleDownloadDialog.java @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ExecutorService; @@ -614,17 +613,7 @@ class VideoHashSubtitleDownloadDialog extends JDialog { public String getLanguage() { - Language language = Language.getLanguageByName(subtitle.getLanguageName()); - if (language != null) { - try { - return new Locale(language.getCode()).getISO3Language(); - } catch (Exception e) { - return language.getCode(); - } - } - - // we won't get here, but just in case - return subtitle.getLanguageName().replaceAll("\\W", ""); + return Language.getISO3LanguageCodeByName(subtitle.getLanguageName()); }