2011-11-29 06:03:41 +00:00
|
|
|
// Settings
|
2011-11-29 09:00:18 +00:00
|
|
|
def episodeDir = "X:/in/TV"
|
|
|
|
def movieDir = "X:/in/Movies"
|
2011-11-29 06:03:41 +00:00
|
|
|
|
2011-11-29 09:00:18 +00:00
|
|
|
def episodeFormat = "X:/out/TV/{n}{'/Season '+s}/{episode}"
|
|
|
|
def movieFormat = "X:/out/Movies/{movie}/{movie}"
|
2011-11-29 06:03:41 +00:00
|
|
|
|
2011-11-30 05:23:43 +00:00
|
|
|
def incomplete(f) { f =~ /[.]chunk|[.]part$/ }
|
2011-11-29 09:00:18 +00:00
|
|
|
|
2011-12-02 03:15:33 +00:00
|
|
|
// run cmdline unrar (require -trust-script) on multi-volume rar files
|
|
|
|
[episodeDir, movieDir].getFiles().findAll {
|
|
|
|
it =~ /[.]part01[.]rar$/ || (it =~ /[.]rar$/ && !(it =~ /[.]part\d{2}[.]rar$/))
|
|
|
|
}.each { rar ->
|
|
|
|
// new layout: foo.part1.rar, foo.part2.rar
|
|
|
|
// old layout: foo.rar, foo.r00, foo.r01
|
|
|
|
boolean partLayout = (rar =~ /[.]part01[.]rar/)
|
|
|
|
|
|
|
|
// extract name from name.part01.rar or name.rar
|
|
|
|
def name = rar.getName()[0 .. (partLayout ? -12 : -5)]
|
2011-11-30 05:23:43 +00:00
|
|
|
|
|
|
|
// find all volumes of the same name
|
2011-12-02 03:15:33 +00:00
|
|
|
def volumes = rar.getParentFile().listFiles{
|
|
|
|
it =~ (partLayout ? /$name[.]part\d{2}[.]/ : /$name[.](r\d{2}|rar)/)
|
|
|
|
}
|
2011-11-30 05:23:43 +00:00
|
|
|
|
|
|
|
// find all incomplete volumes
|
|
|
|
def incomplete = volumes.findAll{ incomplete(it) }
|
|
|
|
|
|
|
|
// all volumes complete, call unrar on first volume
|
|
|
|
if (incomplete.isEmpty()) {
|
2011-12-02 03:15:33 +00:00
|
|
|
def exitCode = execute("unrar", "x", "-y", "-p-", rar.getAbsolutePath(), rar.getPathWithoutExtension() + "/")
|
2011-12-01 17:06:51 +00:00
|
|
|
|
|
|
|
// delete all volumes after successful extraction
|
|
|
|
if (exitCode == 0) {
|
|
|
|
volumes*.delete()
|
|
|
|
}
|
2011-11-30 05:23:43 +00:00
|
|
|
}
|
2011-11-29 06:03:41 +00:00
|
|
|
}
|
|
|
|
|
2011-12-02 03:15:33 +00:00
|
|
|
|
2011-11-29 06:03:41 +00:00
|
|
|
/*
|
|
|
|
* Fetch subtitles and sort into folders
|
|
|
|
*/
|
2011-11-29 09:00:18 +00:00
|
|
|
episodeDir.eachMediaFolder() { dir ->
|
2011-11-30 05:23:43 +00:00
|
|
|
def files = dir.listFiles { !incomplete(it) }
|
2011-11-29 06:03:41 +00:00
|
|
|
|
|
|
|
// fetch subtitles
|
|
|
|
files += getSubtitles(file:files)
|
|
|
|
|
|
|
|
// sort episodes / subtitles
|
2011-11-29 09:00:18 +00:00
|
|
|
rename(file:files, db:'TVRage', format:episodeFormat)
|
2011-11-29 06:03:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 09:00:18 +00:00
|
|
|
movieDir.eachMediaFolder() { dir ->
|
2011-11-30 05:23:43 +00:00
|
|
|
def files = dir.listFiles { !incomplete(it) }
|
2011-11-29 06:03:41 +00:00
|
|
|
|
|
|
|
// fetch subtitles
|
|
|
|
files += getSubtitles(file:files)
|
|
|
|
|
|
|
|
// sort movies / subtitles
|
2011-11-29 09:00:18 +00:00
|
|
|
rename(file:files, db:'OpenSubtitles', format:movieFormat)
|
2011-11-29 06:03:41 +00:00
|
|
|
}
|