Make sure that strict movie mode works exactly the same in GUI and CLI (it was only implemented correctly for the GUI)

This commit is contained in:
Reinhard Pointner 2017-09-22 13:53:49 +07:00
parent b95c51f152
commit 94a3ef60a8
4 changed files with 34 additions and 31 deletions

View File

@ -419,7 +419,12 @@ public class CmdlineOperations implements CmdlineInterface {
// unknown hash, try via imdb id from nfo file // unknown hash, try via imdb id from nfo file
if (movie == null) { if (movie == null) {
log.fine(format("Auto-detect movie from context: [%s]", file)); log.fine(format("Auto-detect movie from context: [%s]", file));
List<Movie> options = detectMovie(file, service, locale, strict); List<Movie> options = detectMovieWithYear(file, service, locale, strict);
// ignore files that cannot yield any acceptable matches (e.g. movie files without year in strict mode)
if (options == null) {
continue;
}
// apply filter if defined // apply filter if defined
options = applyExpressionFilter(options, filter); options = applyExpressionFilter(options, filter);
@ -447,15 +452,8 @@ public class CmdlineOperations implements CmdlineInterface {
// check if we managed to lookup the movie descriptor // check if we managed to lookup the movie descriptor
if (movie != null) { if (movie != null) {
// get file list for movie // add to file list for movie
SortedSet<File> movieParts = filesByMovie.get(movie); filesByMovie.computeIfAbsent(movie, k -> new TreeSet<File>()).add(file);
if (movieParts == null) {
movieParts = new TreeSet<File>();
filesByMovie.put(movie, movieParts);
}
movieParts.add(file);
} }
} }
@ -1182,13 +1180,7 @@ public class CmdlineOperations implements CmdlineInterface {
log.finest("Extracting files " + selection); log.finest("Extracting files " + selection);
// extract files selected by the given filter // extract files selected by the given filter
archive.extract(outputMapper.getOutputDir(), new FileFilter() { archive.extract(outputMapper.getOutputDir(), outputMapper.newPathFilter(selection));
@Override
public boolean accept(File entry) {
return selection.contains(outputMapper.getOutputFile(entry));
}
});
for (FileInfo it : selection) { for (FileInfo it : selection) {
extractedFiles.add(it.toFile()); extractedFiles.add(it.toFile());

View File

@ -273,8 +273,8 @@ public abstract class ScriptShellBaseClass extends Script {
// 3. run full-fledged movie detection // 3. run full-fledged movie detection
try { try {
List<Movie> options = MediaDetection.detectMovie(file, WebServices.TheMovieDB, Locale.US, strict); List<Movie> options = MediaDetection.detectMovieWithYear(file, WebServices.TheMovieDB, Locale.US, strict);
if (options.size() > 0) { if (options != null && options.size() > 0) {
return options.get(0); return options.get(0);
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -123,7 +123,7 @@ public class MediaDetection {
} }
// require a good S00E00 match // require a good S00E00 match
return MediaDetection.isEpisode(String.join("/", file.getParent(), file.getName()), strict); return isEpisode(String.join("/", file.getParent(), file.getName()), strict);
} }
public static boolean isMovie(File file, boolean strict) { public static boolean isMovie(File file, boolean strict) {
@ -677,6 +677,22 @@ public class MediaDetection {
return sortMoviesBySimilarity(options, terms); return sortMoviesBySimilarity(options, terms);
} }
public static List<Movie> detectMovieWithYear(File movieFile, MovieIdentificationService service, Locale locale, boolean strict) throws Exception {
// in non-strict mode, process all movie files as best as possible
if (!strict) {
return detectMovie(movieFile, service, locale, strict);
}
// in strict mode, only process movies that follow the name (year) pattern, so we can confirm each match by checking the movie year
List<Integer> year = parseMovieYear(getRelativePathTail(movieFile, 3).getPath());
if (year.isEmpty() || isEpisode(movieFile, true)) {
return null;
}
// allow only movie matches where the the movie year matches the year pattern in the filename
return detectMovie(movieFile, service, locale, strict).stream().filter(m -> year.contains(m.getYear())).collect(toList());
}
public static SimilarityMetric getMovieMatchMetric() { public static SimilarityMetric getMovieMatchMetric() {
return new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric(), new SequenceMatchSimilarity(0, true), new StringEqualsMetric() { return new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric(), new SequenceMatchSimilarity(0, true), new StringEqualsMetric() {

View File

@ -159,19 +159,14 @@ class MovieMatcher implements AutoCompleteMatcher {
try { try {
List<Future<Map<File, List<Movie>>>> tasks = movieMatchFiles.stream().filter(f -> movieByFile.get(f) == null).map(f -> { List<Future<Map<File, List<Movie>>>> tasks = movieMatchFiles.stream().filter(f -> movieByFile.get(f) == null).map(f -> {
return workerThreadPool.submit(() -> { return workerThreadPool.submit(() -> {
if (strict) { List<Movie> options = detectMovieWithYear(f, service, locale, strict);
// in strict mode, only process movies that follow the name (year) pattern
List<Integer> year = parseMovieYear(getRelativePathTail(f, 3).getPath());
if (year.isEmpty() || isEpisode(f, true)) {
return (Map<File, List<Movie>>) EMPTY_MAP;
}
// allow only movie matches where the the movie year matches the year pattern in the filename // ignore files that cannot yield any acceptable matches (e.g. movie files without year in strict mode)
return singletonMap(f, detectMovie(f, service, locale, strict).stream().filter(m -> year.contains(m.getYear())).collect(toList())); if (options == null) {
} else { return (Map<File, List<Movie>>) EMPTY_MAP;
// in non-strict mode just allow all options
return singletonMap(f, detectMovie(f, service, locale, strict));
} }
return singletonMap(f, options);
}); });
}).collect(toList()); }).collect(toList());