diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index 51153bd4..c877a59e 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -11,6 +11,7 @@ import static net.filebot.WebServices.*; import static net.filebot.hash.VerificationUtilities.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.media.XattrMetaInfo.*; +import static net.filebot.similarity.Normalization.*; import static net.filebot.subtitle.SubtitleUtilities.*; import static net.filebot.util.FileUtilities.*; @@ -409,7 +410,7 @@ public class CmdlineOperations implements CmdlineInterface { } // force all mappings - Movie movie = selectSearchResult(query, options); + Movie movie = selectMovie(query, options); for (File file : files) { movieByFile.put(file, movie); } @@ -458,7 +459,7 @@ public class CmdlineOperations implements CmdlineInterface { try { // select first element if matches are reliable if (options.size() > 0) { - movie = selectSearchResult(stripReleaseInfo(getName(file)), options); + movie = selectMovie(checkMovieStripReleaseInfo(file, strict), options); // make sure to get the language-specific movie object for the selected option movie = getLocalizedMovie(service, movie, locale); @@ -500,6 +501,37 @@ public class CmdlineOperations implements CmdlineInterface { return renameAll(formatMatches(matches, format, outputDir), renameAction, conflictAction, matches, exec); } + protected Movie selectMovie(String query, Collection options) throws Exception { + // auto-select perfect match + for (Movie movie : options) { + String movieIdentifier = normalizePunctuation(movie.toString()).toLowerCase(); + if (query.toLowerCase().startsWith(movieIdentifier)) { + return movie; + } + } + + List matches = selectSearchResult(query, options, false, false, false, 1); + return matches.size() > 0 ? matches.get(0) : null; + } + + protected String checkMovieStripReleaseInfo(File file, boolean strict) { + String name = stripReleaseInfo(getName(file)); + + // try to redeem possible false negative matches + if (name.length() < 2) { + try { + Movie match = checkMovie(file, strict); + if (match != null) { + return match.getName(); + } + } catch (Exception e) { + debug.warning(e::toString); + } + } + + return name; + } + public List renameMusic(Collection files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFileFormat format, List services, ExecCommand exec) throws Exception { List audioFiles = sortByUniquePath(filter(files, AUDIO_FILES, VIDEO_FILES)); @@ -927,11 +959,6 @@ public class CmdlineOperations implements CmdlineInterface { }).filter(Objects::nonNull).distinct().collect(toList()); } - protected T selectSearchResult(String query, Collection options) throws Exception { - List matches = selectSearchResult(query, options, false, false, false, 1); - return matches.size() > 0 ? matches.get(0) : null; - } - protected List selectSearchResult(String query, Collection options, boolean sort, boolean alias, boolean strict, int limit) throws Exception { List probableMatches = getProbableMatches(sort ? query : null, options, alias, strict);