1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-21 23:38:50 -05:00

Fine-tune CLI movie selection and bring it more inline with GUI behaviour

This commit is contained in:
Reinhard Pointner 2019-06-11 04:39:09 +07:00
parent 5d59bddebf
commit dc5b35d3f3
3 changed files with 25 additions and 38 deletions

View File

@ -502,34 +502,17 @@ public class CmdlineOperations implements CmdlineInterface {
}
protected Movie selectMovie(String query, Collection<Movie> options) throws Exception {
query = query.toLowerCase();
// auto-select perfect match
for (Movie movie : options) {
String movieIdentifier = normalizePunctuation(movie.toString()).toLowerCase();
if (query.toLowerCase().startsWith(movieIdentifier)) {
String movieIdentifier = normalizePunctuation(movie.getNameWithYear()).toLowerCase();
if (query.startsWith(movieIdentifier)) {
return movie;
}
}
List<Movie> 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;
return selectSearchResult(query, options, false, false, false, 1).stream().findFirst().orElse(null);
}
public List<File> renameMusic(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFileFormat format, List<MusicIdentificationService> services, ExecCommand exec) throws Exception {

View File

@ -1208,6 +1208,24 @@ public class MediaDetection {
return stripReleaseInfo(name, true);
}
public static 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.log(Level.SEVERE, "Failed to strip release info: " + e.getMessage(), e);
}
}
return name;
}
private static final Resource<Pattern> blacklistPattern = Resource.lazy(releaseInfo::getBlacklistPattern);
public static List<String> stripBlacklistedTerms(Collection<String> names) {

View File

@ -270,20 +270,6 @@ class MovieMatcher implements AutoCompleteMatcher {
return html.toString();
}
protected String checkedStripReleaseInfo(File file, boolean strict) throws Exception {
String name = stripReleaseInfo(getName(file));
// try to redeem possible false negative matches
if (name.length() < 2) {
Movie match = checkMovie(file, strict);
if (match != null) {
return match.getName();
}
}
return name;
}
protected Movie selectMovie(File movieFile, boolean strict, String userQuery, List<Movie> options, Component parent) throws Exception {
// just auto-pick singleton results
if (options.size() == 1) {
@ -291,11 +277,11 @@ class MovieMatcher implements AutoCompleteMatcher {
}
// 1. movie by filename
String fileQuery = (userQuery != null) ? userQuery : checkedStripReleaseInfo(movieFile, strict);
String fileQuery = userQuery != null ? userQuery : checkMovieStripReleaseInfo(movieFile, strict);
// 2. movie by directory
File movieFolder = guessMovieFolder(movieFile);
String folderQuery = (userQuery != null || movieFolder == null) ? "" : checkedStripReleaseInfo(movieFolder, strict);
String folderQuery = userQuery != null || movieFolder == null ? "" : checkMovieStripReleaseInfo(movieFolder, strict);
// auto-ignore invalid files
if (userQuery == null && fileQuery.length() < 2 && folderQuery.length() < 2) {