diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index b7eed83c..f25e4ff6 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -278,7 +278,7 @@ public class CmdlineOperations implements CmdlineInterface { // select search result if (results.size() > 0) { - List selectedSearchResults = selectSearchResult(query, results, true, strict, limit); + List selectedSearchResults = selectSearchResult(query, results, true, true, strict, limit); if (selectedSearchResults != null) { for (SearchResult it : selectedSearchResults) { @@ -389,7 +389,7 @@ public class CmdlineOperations implements CmdlineInterface { } // force all mappings - Movie movie = (Movie) selectSearchResult(query, options); + Movie movie = selectSearchResult(query, options); for (File file : files) { movieByFile.put(file, movie); } @@ -424,6 +424,8 @@ public class CmdlineOperations implements CmdlineInterface { // reduce options to perfect matches if possible List perfectMatches = matchMovieByWordSequence(getName(file), options, 0); + + // narrow down options if possible if (perfectMatches.size() > 0) { options = perfectMatches; } @@ -431,13 +433,13 @@ public class CmdlineOperations implements CmdlineInterface { try { // select first element if matches are reliable if (options.size() > 0) { - movie = (Movie) selectSearchResult(null, options); + movie = selectSearchResult(stripReleaseInfo(getName(file)), options); // make sure to get the language-specific movie object for the selected option movie = getLocalizedMovie(service, movie, locale); } } catch (Exception e) { - log.log(Level.WARNING, format("%s: [%s] %s", e.getClass().getSimpleName(), getStructurePathTail(file), e.getMessage())); + log.warning(cause(e)); } } @@ -844,18 +846,18 @@ public class CmdlineOperations implements CmdlineInterface { return output; } - protected SearchResult selectSearchResult(String query, Collection options) throws Exception { - List matches = selectSearchResult(query, options, false, false, 1); + 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 alias, boolean strict, int limit) throws Exception { - List probableMatches = getProbableMatches(query, options, alias, strict); + 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); if (probableMatches.isEmpty() || (strict && probableMatches.size() != 1)) { // allow single search results to just pass through in non-strict mode even if match confidence is low if (options.size() == 1 && !strict) { - return new ArrayList(options); + return options.stream().collect(toList()); } if (strict) { @@ -863,8 +865,8 @@ public class CmdlineOperations implements CmdlineInterface { } // just pick the best N matches - if (query != null) { - probableMatches = new ArrayList(sortBySimilarity(options, singleton(query), getSeriesMatchMetric())); + if (sort) { + probableMatches = sortBySimilarity(options, singleton(query), getSeriesMatchMetric()).stream().collect(toList()); } } diff --git a/source/net/filebot/cli/CmdlineOperationsTextUI.java b/source/net/filebot/cli/CmdlineOperationsTextUI.java index 1a7616c2..f1784c6e 100644 --- a/source/net/filebot/cli/CmdlineOperationsTextUI.java +++ b/source/net/filebot/cli/CmdlineOperationsTextUI.java @@ -95,15 +95,15 @@ public class CmdlineOperationsTextUI extends CmdlineOperations { } @Override - protected List selectSearchResult(String query, Collection options, boolean alias, boolean strict, int limit) throws Exception { - List matches = getProbableMatches(query, options, alias, false); + protected List selectSearchResult(String query, Collection options, boolean sort, boolean alias, boolean strict, int limit) throws Exception { + List matches = getProbableMatches(sort ? query : null, options, alias, false); - if (matches.size() < 2) { + if (matches.size() <= 1) { return matches; } // manually select option if there is more than one - SearchResult selection = showInputDialog(matches, "Multiple Options", String.format("Select best match for \"%s\"", query)); + T selection = showInputDialog(matches, "Multiple Options", String.format("Select best match for \"%s\"", query)); if (selection == null) { return emptyList(); diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index ce7ab33f..be28053b 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -1290,16 +1290,16 @@ public class MediaDetection { return tvdbId.isEmpty() ? null : WebServices.TheTVDB.getSeriesInfo(tvdbId.get(0), locale); } - public static List getProbableMatches(String query, Collection options, boolean alias, boolean strict) { + public static List getProbableMatches(String query, Collection options, boolean alias, boolean strict) { if (query == null) { return options.stream().distinct().collect(toList()); } // check all alias names, or just the primary name - Function> names = alias ? SearchResult::getEffectiveNames : (it) -> singleton(it.getName()); + Function> names = alias ? SearchResult::getEffectiveNames : f -> singleton(f.getName()); // auto-select most probable search result - List probableMatches = new ArrayList(); + List probableMatches = new ArrayList(); // use name similarity metric SimilarityMetric metric = new NameSimilarityMetric(); @@ -1310,7 +1310,7 @@ public class MediaDetection { String q = removeTrailingBrackets(query).toLowerCase(); // find probable matches using name similarity > 0.8 (or > 0.6 in non-strict mode) - for (SearchResult option : options) { + for (T option : options) { float f = 0; for (String n : names.apply(option)) { n = removeTrailingBrackets(n).toLowerCase();