Guest User

Untitled

a guest
Sep 10th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 3.23 KB | None | 0 0
  1. def input = []
  2.     def failOnError = _args.conflict == 'fail'
  3.      
  4.     // print input parameters
  5.     _args.parameters.each{ k, v -> println "Parameter: $k = $v" }
  6.      
  7.     if (args.empty) {
  8.             // assume we're called with utorrent parameters
  9.             if (ut_kind == "multi") {
  10.                     input += new File(ut_dir).getFiles() // multi-file torrent
  11.             } else {
  12.                     input += new File(ut_dir, ut_file) // single-file torrent
  13.             }
  14.     } else {
  15.             // assume we're called normally with arguments
  16.             input += args.getFiles()
  17.     }
  18.      
  19.     // extract archives if necessary
  20.     input += extract(file:input, output:".", conflict:"override")
  21.      
  22.     // process only media files
  23.     input = input.findAll{ it.isVideo() || it.isSubtitle() }
  24.      
  25.     // ignore clutter files
  26.     input = input.findAll{ !(it.path =~ /\b(?i:sample|trailer|extras|deleted.scenes|music.video|scrapbook)\b/) }
  27.      
  28.     // print input fileset
  29.     input.each{ println "Input: $it" }
  30.      
  31.     // group episodes/movies and rename according to XBMC standards
  32.     def groups = input.groupBy{ f ->
  33.             def tvs = detectSeriesName(f)
  34.             def mov = (parseEpisodeNumber(f) || parseDate(f)) ? null : detectMovie(f, false) // skip movie detection if we can already tell it's an episode
  35.             println "$f.name [series: $tvs, movie: $mov]"
  36.            
  37.             // DECIDE EPISODE VS MOVIE (IF NOT CLEAR)
  38.             if (tvs && mov) {
  39.                     def fn = f.nameWithoutExtension.space(' ')
  40.                     if (fn =~ "(?i:$tvs - .+)" || parseEpisodeNumber(fn, true) || parseDate(fn)) {
  41.                             println "Exclude Movie: $mov"
  42.                             mov = null
  43.                     } else if (detectMovie(f, true) && (fn =~ /(19|20)\d{2}/ || !(tvs =~ "(?i:$mov.name)"))) {
  44.                             println "Exclude Series: $tvs"
  45.                             tvs = null
  46.                     } else if (fn =~ "(?i:$tvs)" && parseEpisodeNumber(fn.after(tvs), false)) {
  47.                             println "Exclude Movie: $mov"
  48.                             mov = null
  49.                     } else if (fn =~ "(?i:$mov.name)" && !parseEpisodeNumber(fn.after(mov.name), false)) {
  50.                             println "Exclude Series: $tvs"
  51.                             tvs = null
  52.                     }
  53.             }
  54.            
  55.             // CHECK CONFLICT
  56.             if (((mov && tvs) || (!mov && !tvs)) && failOnError) {
  57.                     throw new Exception("Media detection failed")
  58.             }
  59.            
  60.             return [tvs:tvs, mov:mov]
  61.     }
  62.      
  63.     groups.each{ group, files ->
  64.            
  65.            
  66.             // EPISODE MODE
  67.             if (group.tvs && !group.mov) {
  68.                     def dest = rename(file:files, format:'TV Shows/{n}/{"[$sdhd]"}{episode.special ? "Special" : "Season "+s}/{n} - {episode.special ? "S00E"+special.pad(2) : s00e00} - {t}', db:'TheTVDB')
  69.             }
  70.            
  71.             // MOVIE MODE
  72.             if (group.mov && !group.tvs) {
  73.                     def dest = rename(file:files, format:'Movies/{"[$vf]"}{"[$group]"}{"[$vc]"} {n} ({y})/{n} ({y}){" CD$pi"}', db:'TheMovieDB')
  74.             }
  75.     }
Add Comment
Please, Sign In to add comment