From 440a3bf9231a9752730081824edef1a657a3c7ca Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 28 Jul 2016 23:22:57 +0800 Subject: [PATCH] Fix --db option issues when using -get-subtitles --- source/net/filebot/cli/ArgumentProcessor.java | 2 +- source/net/filebot/cli/CmdlineOperations.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/source/net/filebot/cli/ArgumentProcessor.java b/source/net/filebot/cli/ArgumentProcessor.java index d6b7a7f1..118a13b3 100644 --- a/source/net/filebot/cli/ArgumentProcessor.java +++ b/source/net/filebot/cli/ArgumentProcessor.java @@ -83,7 +83,7 @@ public class ArgumentProcessor { } if (args.getSubtitles) { - files.addAll(cli.getMissingSubtitles(files, WebServices.OpenSubtitles.getName(), args.query, args.lang, args.output, args.encoding, args.format, !args.nonStrict)); + files.addAll(cli.getMissingSubtitles(files, args.db, args.query, args.lang, args.output, args.encoding, args.format, !args.nonStrict)); } if (args.rename) { diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index 51b4ec7b..2b9b4496 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -38,8 +38,8 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import java.util.function.Predicate; import java.util.logging.Level; -import java.util.regex.Pattern; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -670,13 +670,15 @@ public class CmdlineOperations implements CmdlineInterface { @Override public List getSubtitles(Collection files, String db, String query, String languageName, String output, String csn, String format, boolean strict) throws Exception { - final Language language = getLanguage(languageName); - final Pattern databaseFilter = (db != null) ? Pattern.compile(db, Pattern.CASE_INSENSITIVE) : null; - final SubtitleNaming naming = getSubtitleNaming(format); + Language language = getLanguage(languageName); + SubtitleNaming naming = getSubtitleNaming(format); + + // use all or only selected subtitle services + Predicate serviceFilter = service -> db == null ? true : db.contains(service.getName()) || db.contains(service.getIdentifier()); // when rewriting subtitles to target format an encoding must be defined, default to UTF-8 - final Charset outputEncoding = csn != null ? Charset.forName(csn) : output != null ? UTF_8 : null; - final SubtitleFormat outputFormat = (output != null) ? getSubtitleFormatByName(output) : null; + Charset outputEncoding = csn != null ? Charset.forName(csn) : output != null ? UTF_8 : null; + SubtitleFormat outputFormat = output != null ? getSubtitleFormatByName(output) : null; // ignore anything that is not a video files = filter(files, VIDEO_FILES); @@ -697,7 +699,7 @@ public class CmdlineOperations implements CmdlineInterface { // lookup subtitles by hash for (VideoHashSubtitleService service : getVideoHashSubtitleServices(language.getLocale())) { - if (remainingVideos.isEmpty() || (databaseFilter != null && !databaseFilter.matcher(service.getName()).matches()) || !requireLogin(service)) { + if (remainingVideos.isEmpty() || !serviceFilter.test(service) || !requireLogin(service)) { continue; } @@ -713,7 +715,7 @@ public class CmdlineOperations implements CmdlineInterface { } for (SubtitleProvider service : getSubtitleProviders()) { - if (strict || remainingVideos.isEmpty() || (databaseFilter != null && !databaseFilter.matcher(service.getName()).matches()) || !requireLogin(service)) { + if (strict || remainingVideos.isEmpty() || !serviceFilter.test(service) || !requireLogin(service)) { continue; }