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:
parent
b95c51f152
commit
94a3ef60a8
|
@ -419,7 +419,12 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
// unknown hash, try via imdb id from nfo file
|
||||
if (movie == null) {
|
||||
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
|
||||
options = applyExpressionFilter(options, filter);
|
||||
|
@ -447,15 +452,8 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
|
||||
// check if we managed to lookup the movie descriptor
|
||||
if (movie != null) {
|
||||
// get file list for movie
|
||||
SortedSet<File> movieParts = filesByMovie.get(movie);
|
||||
|
||||
if (movieParts == null) {
|
||||
movieParts = new TreeSet<File>();
|
||||
filesByMovie.put(movie, movieParts);
|
||||
}
|
||||
|
||||
movieParts.add(file);
|
||||
// add to file list for movie
|
||||
filesByMovie.computeIfAbsent(movie, k -> new TreeSet<File>()).add(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1182,13 +1180,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
log.finest("Extracting files " + selection);
|
||||
|
||||
// extract files selected by the given filter
|
||||
archive.extract(outputMapper.getOutputDir(), new FileFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File entry) {
|
||||
return selection.contains(outputMapper.getOutputFile(entry));
|
||||
}
|
||||
});
|
||||
archive.extract(outputMapper.getOutputDir(), outputMapper.newPathFilter(selection));
|
||||
|
||||
for (FileInfo it : selection) {
|
||||
extractedFiles.add(it.toFile());
|
||||
|
|
|
@ -273,8 +273,8 @@ public abstract class ScriptShellBaseClass extends Script {
|
|||
|
||||
// 3. run full-fledged movie detection
|
||||
try {
|
||||
List<Movie> options = MediaDetection.detectMovie(file, WebServices.TheMovieDB, Locale.US, strict);
|
||||
if (options.size() > 0) {
|
||||
List<Movie> options = MediaDetection.detectMovieWithYear(file, WebServices.TheMovieDB, Locale.US, strict);
|
||||
if (options != null && options.size() > 0) {
|
||||
return options.get(0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -123,7 +123,7 @@ public class MediaDetection {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
|
@ -677,6 +677,22 @@ public class MediaDetection {
|
|||
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() {
|
||||
return new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric(), new SequenceMatchSimilarity(0, true), new StringEqualsMetric() {
|
||||
|
||||
|
|
|
@ -159,19 +159,14 @@ class MovieMatcher implements AutoCompleteMatcher {
|
|||
try {
|
||||
List<Future<Map<File, List<Movie>>>> tasks = movieMatchFiles.stream().filter(f -> movieByFile.get(f) == null).map(f -> {
|
||||
return workerThreadPool.submit(() -> {
|
||||
if (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;
|
||||
}
|
||||
List<Movie> options = detectMovieWithYear(f, service, locale, strict);
|
||||
|
||||
// allow only movie matches where the the movie year matches the year pattern in the filename
|
||||
return singletonMap(f, detectMovie(f, service, locale, strict).stream().filter(m -> year.contains(m.getYear())).collect(toList()));
|
||||
} else {
|
||||
// in non-strict mode just allow all options
|
||||
return singletonMap(f, detectMovie(f, service, locale, strict));
|
||||
// ignore files that cannot yield any acceptable matches (e.g. movie files without year in strict mode)
|
||||
if (options == null) {
|
||||
return (Map<File, List<Movie>>) EMPTY_MAP;
|
||||
}
|
||||
|
||||
return singletonMap(f, options);
|
||||
});
|
||||
}).collect(toList());
|
||||
|
||||
|
|
Loading…
Reference in New Issue