Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def input = []
- def failOnError = _args.conflict == 'fail'
- // print input parameters
- _args.parameters.each{ k, v -> println "Parameter: $k = $v" }
- if (args.empty) {
- // assume we're called with utorrent parameters
- if (ut_kind == "multi") {
- input += new File(ut_dir).getFiles() // multi-file torrent
- } else {
- input += new File(ut_dir, ut_file) // single-file torrent
- }
- } else {
- // assume we're called normally with arguments
- input += args.getFiles()
- }
- // extract archives if necessary
- input += extract(file:input, output:".", conflict:"override")
- // process only media files
- input = input.findAll{ 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" }
- // group episodes/movies and rename according to XBMC standards
- 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) {
- 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)) {
- println "Exclude Movie: $mov"
- mov = null
- } else if (fn =~ "(?i:$mov.name)" && !parseEpisodeNumber(fn.after(mov.name), false)) {
- println "Exclude Series: $tvs"
- tvs = null
- }
- }
- // CHECK CONFLICT
- if (((mov && tvs) || (!mov && !tvs)) && failOnError) {
- throw new Exception("Media detection failed")
- }
- return [tvs:tvs, mov:mov]
- }
- groups.each{ group, files ->
- // fetch subtitles
- files += (getMissingSubtitles(file:files, lang:"he") ?: [])
- files += (getMissingSubtitles(file:files, lang:"en") ?: [])
- // EPISODE MODE
- if (group.tvs && !group.mov) {
- 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')
- }
- // MOVIE MODE
- if (group.mov && !group.tvs) {
- def dest = rename(file:files, format:'Movies/{n} ({y})/{n} ({y}){" CD$pi"}', db:'TheMovieDB')
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement