From bcfb4d338073c316f2e9c62e0568a7aa4cbbb06c Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 13 Jul 2012 13:52:20 +0000 Subject: [PATCH] * don't check movie db if we already know it's gonna be an episode * "backport" utorrent-postprocess features to sortivo --- website/scripts/sortivo.groovy | 35 +++++++++++++++------ website/scripts/utorrent-postprocess.groovy | 2 +- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/website/scripts/sortivo.groovy b/website/scripts/sortivo.groovy index c381c1d8..d546a5a8 100644 --- a/website/scripts/sortivo.groovy +++ b/website/scripts/sortivo.groovy @@ -1,34 +1,51 @@ -// filebot -script "http://filebot.sf.net/scripts/sortivo.groovy" -trust-script [-non-strict] [--output path/to/folder] +// filebot -script "http://filebot.sf.net/scripts/sortivo.groovy" --output path/to/folder [-non-strict] + +// process only media files +def input = args.getFiles{ it.isVideo() || it.isSubtitle() } + +// ignore clutter files +input = input.findAll{ !(it.path =~ /\b(?i:sample|trailer|extras|deleted.scenes|music.video|scrapbook)\b/) } + +// print input fileset +input.each{ println "Input: $it" } /* * Move/Rename a mix of episodes and movies that are all in the same folder. */ -def groups = args.getFiles().groupBy{ - def tvs = detectSeriesName(it) - def mov = detectMovie(it, false) - println "$it.name [series: $tvs, movie: $mov]" +def groups = input.groupBy{ f -> + def tvs = detectSeriesName(f) + def mov = (parseEpisodeNumber(f) || parseDate(f)) ? null : detectMovie(f, false) // skip movie detection if we can already tell it's an episode + println "$f.name [series: $tvs, movie: $mov]" // DECIDE EPISODE VS MOVIE (IF NOT CLEAR) if (tvs && mov) { - if (it.name =~ "(?i:$tvs - .+)" || parseEpisodeNumber(it.name) || parseDate(it.name)) { + def fn = f.nameWithoutExtension.space(' ') + if (fn =~ "(?i:$tvs - .+)" || parseEpisodeNumber(fn, true) || parseDate(fn)) { println "Exclude Movie: $mov" mov = null - } else if (detectMovie(it, true)) { + } else if (detectMovie(f, true) && (fn =~ /(19|20)\d{2}/ || !(tvs =~ "(?i:$mov.name)"))) { + println "Exclude Series: $tvs" + tvs = null + } else if (fn =~ "(?i:$tvs)" && parseEpisodeNumber(fn.after(tvs), false)) { + println "Exclude Movie: $mov" + mov = null + } else if (fn =~ "(?i:$mov.name)" && !parseEpisodeNumber(fn.after(mov.name), false)) { println "Exclude Series: $tvs" tvs = null } } + return [tvs:tvs, mov:mov] } groups.each{ group, files -> // EPISODE MODE if (group.tvs && !group.mov) { - return rename(file:files, format:'{n} - {s00e00} - {t}', db:'TheTVDB') + return rename(file:files, format:'TV Shows/{n} - {s00e00} - {t}', db:'TheTVDB') } // MOVIE MODE if (group.mov && !group.tvs) { - return rename(file:files, format:'{n} ({y}){" CD$pi"}', db:'TheMovieDB') + return rename(file:files, format:'Movies/{n} ({y}){" CD$pi"}', db:'TheMovieDB') } } diff --git a/website/scripts/utorrent-postprocess.groovy b/website/scripts/utorrent-postprocess.groovy index 0b8b1f92..8272e5d4 100644 --- a/website/scripts/utorrent-postprocess.groovy +++ b/website/scripts/utorrent-postprocess.groovy @@ -29,7 +29,7 @@ include("fn:lib/xbmc") // group episodes/movies and rename according to XBMC standards def groups = input.groupBy{ f -> def tvs = detectSeriesName(f) - def mov = detectMovie(f, false) + def mov = (parseEpisodeNumber(f) || parseDate(f)) ? null : detectMovie(f, false) // skip movie detection if we can already tell it's an episode println "$f.name [series: $tvs, movie: $mov]" // DECIDE EPISODE VS MOVIE (IF NOT CLEAR)