diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index d304b3c7..173d33ff 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -56,6 +56,8 @@ String.metaClass.validateFilePath = { validateFilePath(delegate) } // helper for enforcing filename length limits, e.g. truncate filename but keep extension String.metaClass.truncateFileName = { int limit = 255 -> def ext = getExtension(delegate); def name = getNameWithoutExtension(delegate); return name.substring(0, Math.min(limit - (ext ? 1+ext.length() : 0), name.length())) + (ext ? '.'+ext : '') } +// helper for simplifying strings +String.metaClass.normalizePunctuation = { net.sourceforge.filebot.similarity.Normalization.normalizePunctuation(delegate) } // Parallel helper import java.util.concurrent.* @@ -223,11 +225,11 @@ def detectMovie(File movieFile, strict = true, queryLookupService = TheMovieDB, return movies == null || movies.isEmpty() ? null : movies.toList()[0] } -def matchMovie(movieFile, strict = false) { // same as detectMovie() using only the local movie index making it VERY FAST - return detectMovie(movieFile, strict, Locale.ENGLISH, null, null) +def matchMovie(String filename, strict = true, maxStartIndex = 0) { + def movies = MediaDetection.matchMovieName([filename], strict, maxStartIndex) + return movies == null || movies.isEmpty() ? null : movies.toList()[0] } - def similarity(o1, o2) { return new NameSimilarityMetric().getSimilarity(o1, o2) } diff --git a/website/scripts/amc.groovy b/website/scripts/amc.groovy index 71c4910f..45c2c596 100644 --- a/website/scripts/amc.groovy +++ b/website/scripts/amc.groovy @@ -122,14 +122,14 @@ def groups = input.groupBy{ f -> // DECIDE EPISODE VS MOVIE (IF NOT CLEAR) if (tvs && mov) { - def norm = { s -> s.ascii().lower().space(' ') } + def norm = { s -> s.ascii().normalizePunctuation().lower().space(' ') } def dn = norm(guessMovieFolder(f)?.name ?: '') def fn = norm(f.nameWithoutExtension) def sn = norm(tvs) def mn = norm(mov.name) // S00E00 | 2012.07.21 | One Piece 217 | Firefly - Serenity | [Taken 1, Taken 2, Taken 3, Taken 4, ..., Taken 10] - if (parseEpisodeNumber(fn, true) || parseDate(fn) || (fn =~ sn && parseEpisodeNumber(fn.after(sn), false) && !matchMovie(f, true)) || (fn.after(sn) ==~ /.{0,3} - .+/ && !matchMovie(f, true)) || f.dir.listFiles{ it.isVideo() && norm(it.name) =~ sn && it.name =~ /\b\d{1,3}\b/}.size() >= 10) { + if (parseEpisodeNumber(fn, true) || parseDate(fn) || (fn =~ sn && (parseEpisodeNumber(fn.after(sn), false) || fn.after(sn) =~ /\d{1,2}\D+\d{1,2}/) && matchMovie(fn, true) == null) || (fn.after(sn) ==~ /.{0,3} - .+/ && matchMovie(fn, true) == null) || f.dir.listFiles{ it.isVideo() && norm(it.name) =~ sn && it.name =~ /\b\d{1,3}\b/}.size() >= 10) { _log.fine("Exclude Movie: $mov") mov = null } else if ((detectMovie(f, true) && [dn, fn].find{ it =~ /(19|20)\d{2}/ }) || [dn, fn].find{ it =~ mn && !(it.after(mn) =~ /\b\d{1,3}\b/) }) {