2012-07-13 09:52:20 -04:00
|
|
|
// filebot -script "http://filebot.sf.net/scripts/sortivo.groovy" <folder> --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" }
|
2012-03-02 02:08:54 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Move/Rename a mix of episodes and movies that are all in the same folder.
|
|
|
|
*/
|
2012-07-13 09:52:20 -04:00
|
|
|
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]"
|
2012-03-02 02:08:54 -05:00
|
|
|
|
|
|
|
// DECIDE EPISODE VS MOVIE (IF NOT CLEAR)
|
|
|
|
if (tvs && mov) {
|
2012-07-13 09:52:20 -04:00
|
|
|
def fn = f.nameWithoutExtension.space(' ')
|
|
|
|
if (fn =~ "(?i:$tvs - .+)" || parseEpisodeNumber(fn, true) || parseDate(fn)) {
|
|
|
|
println "Exclude Movie: $mov"
|
|
|
|
mov = null
|
|
|
|
} 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)) {
|
2012-03-02 02:08:54 -05:00
|
|
|
println "Exclude Movie: $mov"
|
|
|
|
mov = null
|
2012-07-13 09:52:20 -04:00
|
|
|
} else if (fn =~ "(?i:$mov.name)" && !parseEpisodeNumber(fn.after(mov.name), false)) {
|
2012-03-02 02:08:54 -05:00
|
|
|
println "Exclude Series: $tvs"
|
|
|
|
tvs = null
|
|
|
|
}
|
|
|
|
}
|
2012-07-13 09:52:20 -04:00
|
|
|
|
2012-03-12 09:45:37 -04:00
|
|
|
return [tvs:tvs, mov:mov]
|
|
|
|
}
|
|
|
|
|
|
|
|
groups.each{ group, files ->
|
2012-03-02 02:08:54 -05:00
|
|
|
// EPISODE MODE
|
2012-03-12 09:45:37 -04:00
|
|
|
if (group.tvs && !group.mov) {
|
2012-07-13 10:33:39 -04:00
|
|
|
rename(file:files, format:'TV Shows/{n}/{episode.special ? "Special" : "Season "+s}/{n} - {episode.special ? "S00E"+special.pad(2) : s00e00} - {t}', db:'TheTVDB')
|
2012-03-02 02:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// MOVIE MODE
|
2012-03-12 09:45:37 -04:00
|
|
|
if (group.mov && !group.tvs) {
|
2012-07-13 10:33:39 -04:00
|
|
|
rename(file:files, format:'Movies/{n} ({y})/{n} ({y}){" CD$pi"}', db:'TheMovieDB')
|
2012-03-02 02:08:54 -05:00
|
|
|
}
|
|
|
|
}
|