From 9551767595bf93d63130783fcbcee38b648087cf Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 13 Sep 2013 06:56:30 +0000 Subject: [PATCH] * exit with error code if nothing can be renamed (all modes) @see http://www.filebot.net/forums/viewtopic.php?f=4&t=941 --- .../filebot/cli/CmdlineOperations.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index eddf287d..4a8a9c07 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -369,14 +369,13 @@ public class CmdlineOperations implements CmdlineInterface { } else { CLILogger.fine(format("Looking up movie by query [%s]", query)); List results = service.searchMovie(query, locale); - results = applyExpressionFilter(results, filter); - - if (results.isEmpty()) { - throw new Exception(format("Failed to look up movie by query [%s]", query)); + List validResults = applyExpressionFilter(results, filter); + if (validResults.isEmpty()) { + throw new Exception("Unable to find a valid match: " + results); } // force all mappings - Movie result = (Movie) selectSearchResult(query, results, strict).get(0); + Movie result = (Movie) selectSearchResult(query, validResults, strict).get(0); for (File file : files) { movieByFile.put(file, result); } @@ -405,9 +404,11 @@ public class CmdlineOperations implements CmdlineInterface { if (movie == null) { CLILogger.fine(format("Auto-detect movie from context: [%s]", file)); Collection results = detectMovie(file, null, service, locale, strict); - results = applyExpressionFilter(results, filter); + List validResults = applyExpressionFilter(results, filter); try { - movie = (Movie) selectSearchResult(query, results, strict).get(0); + if (validResults.size() > 0) { + movie = (Movie) selectSearchResult(query, validResults, strict).get(0); + } } catch (Exception e) { CLILogger.log(Level.WARNING, String.format("%s: [%s/%s] %s", e.getClass().getSimpleName(), guessMovieFolder(file) != null ? guessMovieFolder(file).getName() : null, file.getName(), e.getMessage())); } @@ -556,6 +557,10 @@ public class CmdlineOperations implements CmdlineInterface { } public List renameAll(Map renameMap, RenameAction renameAction, ConflictAction conflictAction) throws Exception { + if (renameMap.isEmpty()) { + throw new Exception(format("[%s] Unable to process any files", renameAction)); + } + // rename files final List> renameLog = new ArrayList>();