Advertisement
Guest User

Untitled

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