2012-04-29 05:28:38 +00:00
|
|
|
// filebot -script "fn:utorrent-postprocess" --output "X:/media" --action copy --conflict override -non-strict -trust-script -Xxbmc=localhost "-Xut_dir=%D" "-Xut_file=%F" "-Xut_label=%L" "-Xut_state=%S" "-Xut_kind=%K"
|
2012-04-28 18:15:15 +00:00
|
|
|
def input = []
|
2012-07-08 06:29:07 +00:00
|
|
|
def failOnError = _args.conflict == 'fail'
|
2012-04-26 11:25:58 +00:00
|
|
|
|
2012-04-28 18:15:15 +00:00
|
|
|
// print input parameters
|
|
|
|
_args.parameters.each{ k, v -> println "Parameter: $k = $v" }
|
|
|
|
|
2012-07-13 14:33:39 +00:00
|
|
|
if (args.empty) {
|
|
|
|
// assume we're called with utorrent parameters
|
2012-07-16 12:19:13 +00:00
|
|
|
if (ut_kind == "single") {
|
2012-07-13 14:33:39 +00:00
|
|
|
input += new File(ut_dir, ut_file) // single-file torrent
|
2012-07-16 12:19:13 +00:00
|
|
|
} else {
|
|
|
|
input += new File(ut_dir).getFiles() // multi-file torrent
|
2012-07-13 14:33:39 +00:00
|
|
|
}
|
2012-04-28 18:15:15 +00:00
|
|
|
} else {
|
2012-07-13 14:33:39 +00:00
|
|
|
// assume we're called normally with arguments
|
|
|
|
input += args.getFiles()
|
2012-04-28 18:15:15 +00:00
|
|
|
}
|
2012-04-26 11:25:58 +00:00
|
|
|
|
|
|
|
// extract archives if necessary
|
2012-05-01 16:33:55 +00:00
|
|
|
input += extract(file:input, output:".", conflict:"override")
|
2012-04-26 11:25:58 +00:00
|
|
|
|
|
|
|
// process only media files
|
|
|
|
input = input.findAll{ it.isVideo() || it.isSubtitle() }
|
|
|
|
|
2012-05-31 12:10:50 +00:00
|
|
|
// ignore clutter files
|
2012-06-15 10:42:39 +00:00
|
|
|
input = input.findAll{ !(it.path =~ /\b(?i:sample|trailer|extras|deleted.scenes|music.video|scrapbook)\b/) }
|
2012-05-31 12:10:50 +00:00
|
|
|
|
2012-04-28 18:15:15 +00:00
|
|
|
// print input fileset
|
|
|
|
input.each{ println "Input: $it" }
|
2012-04-26 11:25:58 +00:00
|
|
|
|
2012-04-29 05:28:38 +00:00
|
|
|
// xbmc artwork/nfo utility
|
|
|
|
include("fn:lib/xbmc")
|
|
|
|
|
2012-04-26 11:25:58 +00:00
|
|
|
// group episodes/movies and rename according to XBMC standards
|
2012-07-08 12:01:19 +00:00
|
|
|
def groups = input.groupBy{ f ->
|
|
|
|
def tvs = detectSeriesName(f)
|
2012-07-13 13:52:20 +00:00
|
|
|
def mov = (parseEpisodeNumber(f) || parseDate(f)) ? null : detectMovie(f, false) // skip movie detection if we can already tell it's an episode
|
2012-07-08 12:01:19 +00:00
|
|
|
println "$f.name [series: $tvs, movie: $mov]"
|
2012-04-26 11:25:58 +00:00
|
|
|
|
|
|
|
// DECIDE EPISODE VS MOVIE (IF NOT CLEAR)
|
|
|
|
if (tvs && mov) {
|
2012-07-21 14:32:55 +00:00
|
|
|
def norm = { s -> s.lower().space(' ') }
|
|
|
|
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)) || fn.after(sn) =~ / - .+/ || f.dir.listFiles{ it.isVideo() && norm(it.name) =~ sn && it.name =~ /\b\d{1,3}\b/}.size() >= 10) {
|
2012-04-26 11:25:58 +00:00
|
|
|
println "Exclude Movie: $mov"
|
|
|
|
mov = null
|
2012-07-21 14:32:55 +00:00
|
|
|
} else if ((detectMovie(f, true) && fn =~ /(19|20)\d{2}/) || (fn =~ mn && !(fn.after(mn) =~ /\b\d{1,3}\b/))) {
|
2012-07-08 13:13:18 +00:00
|
|
|
println "Exclude Series: $tvs"
|
|
|
|
tvs = null
|
2012-04-26 11:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-08 06:29:07 +00:00
|
|
|
|
|
|
|
// CHECK CONFLICT
|
|
|
|
if (((mov && tvs) || (!mov && !tvs)) && failOnError) {
|
|
|
|
throw new Exception("Media detection failed")
|
|
|
|
}
|
|
|
|
|
2012-04-26 11:25:58 +00:00
|
|
|
return [tvs:tvs, mov:mov]
|
|
|
|
}
|
|
|
|
|
|
|
|
groups.each{ group, files ->
|
2012-04-29 05:28:38 +00:00
|
|
|
// fetch subtitles
|
|
|
|
def subs = getMissingSubtitles(file:files, output:"srt", encoding:"utf-8")
|
|
|
|
if (subs) files += subs
|
|
|
|
|
2012-04-26 11:25:58 +00:00
|
|
|
// EPISODE MODE
|
|
|
|
if (group.tvs && !group.mov) {
|
2012-04-29 05:28:38 +00:00
|
|
|
def dest = rename(file:files, format:'TV Shows/{n}/{episode.special ? "Special" : "Season "+s}/{n} - {episode.special ? "S00E"+special.pad(2) : s00e00} - {t}', db:'TheTVDB')
|
2012-07-08 06:29:07 +00:00
|
|
|
if (dest || failOnError) {
|
|
|
|
dest.mapByFolder().each{ dir, fs ->
|
2012-05-31 12:10:50 +00:00
|
|
|
println "Fetching artwork for $dir from TheTVDB"
|
|
|
|
def query = group.tvs
|
|
|
|
def sxe = dest.findResult{ parseEpisodeNumber(it) }
|
|
|
|
def options = TheTVDB.search(query)
|
|
|
|
if (options.isEmpty()) {
|
|
|
|
println "TV Series not found: $query"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
options = options.sortBySimilarity(query, { it.name })
|
|
|
|
fetchSeriesArtworkAndNfo(dir.dir, dir, options[0], sxe && sxe.season > 0 ? sxe.season : 1)
|
2012-04-28 18:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-26 11:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MOVIE MODE
|
|
|
|
if (group.mov && !group.tvs) {
|
2012-04-29 05:28:38 +00:00
|
|
|
def dest = rename(file:files, format:'Movies/{n} ({y})/{n} ({y}){" CD$pi"}', db:'TheMovieDB')
|
2012-07-08 06:29:07 +00:00
|
|
|
if (dest || failOnError) {
|
|
|
|
dest.mapByFolder().each{ dir, fs ->
|
2012-05-31 12:10:50 +00:00
|
|
|
println "Fetching artwork for $dir from TheMovieDB"
|
|
|
|
fetchMovieArtworkAndNfo(dir, group.mov)
|
|
|
|
}
|
2012-04-28 18:15:15 +00:00
|
|
|
}
|
2012-04-26 11:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// make XBMC scan for new content
|
2012-04-29 05:28:38 +00:00
|
|
|
xbmc.split(/[\s,|]+/).each{
|
2012-05-01 16:33:55 +00:00
|
|
|
println "Notify XBMC: $it"
|
2012-04-29 05:28:38 +00:00
|
|
|
invokeScanVideoLibrary(it)
|
2012-04-28 18:15:15 +00:00
|
|
|
}
|