2011-12-22 14:36:31 -05:00
|
|
|
// PERSONALIZED SETTINGS
|
|
|
|
def episodeDir = "V:/in/TV"
|
|
|
|
def episodeFormat = "V:/out/TV/{n}{'/Season '+s}/{episode}"
|
|
|
|
def movieDir = "V:/in/Movies"
|
|
|
|
def movieFormat = "V:/out/Movies/{movie}/{movie}"
|
|
|
|
|
2012-01-04 09:39:39 -05:00
|
|
|
// XBMC ON LOCAL MACHINE
|
|
|
|
def xbmc = ['localhost'] // (use [] to not notify any XBMC instances about updates)
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-22 14:36:31 -05:00
|
|
|
// ignore chunk, part, par and hidden files
|
2011-12-27 13:54:25 -05:00
|
|
|
def incomplete(f) { f.name =~ /[.]chunk|[.]part\d{0,3}$|[.]par$|[.]dat$/ || f.isHidden() }
|
2011-11-29 01:03:41 -05:00
|
|
|
|
2011-11-29 04:00:18 -05:00
|
|
|
|
2011-12-01 22:15:33 -05:00
|
|
|
// run cmdline unrar (require -trust-script) on multi-volume rar files
|
2011-12-22 14:36:31 -05:00
|
|
|
[episodeDir, movieDir].getFiles().findAll { it =~ /[.]part01[.]rar$/ || (it =~ /[.]rar$/ && !(it =~ /[.]part\d{2}[.]rar$/)) }.each { rar ->
|
2011-12-01 22:15:33 -05:00
|
|
|
// 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 00:23:43 -05:00
|
|
|
|
|
|
|
// find all volumes of the same name
|
2011-12-01 22:15:33 -05:00
|
|
|
def volumes = rar.getParentFile().listFiles{
|
|
|
|
it =~ (partLayout ? /$name[.]part\d{2}[.]/ : /$name[.](r\d{2}|rar)/)
|
|
|
|
}
|
2011-11-30 00:23:43 -05:00
|
|
|
|
|
|
|
// find all incomplete volumes
|
|
|
|
def incomplete = volumes.findAll{ incomplete(it) }
|
|
|
|
|
|
|
|
// all volumes complete, call unrar on first volume
|
|
|
|
if (incomplete.isEmpty()) {
|
2011-12-01 22:15:33 -05:00
|
|
|
def exitCode = execute("unrar", "x", "-y", "-p-", rar.getAbsolutePath(), rar.getPathWithoutExtension() + "/")
|
2011-12-01 12:06:51 -05:00
|
|
|
|
|
|
|
// delete all volumes after successful extraction
|
|
|
|
if (exitCode == 0) {
|
|
|
|
volumes*.delete()
|
|
|
|
}
|
2011-11-30 00:23:43 -05:00
|
|
|
}
|
2011-11-29 01:03:41 -05:00
|
|
|
}
|
|
|
|
|
2011-12-01 22:15:33 -05:00
|
|
|
|
2011-11-29 01:03:41 -05:00
|
|
|
/*
|
|
|
|
* Fetch subtitles and sort into folders
|
|
|
|
*/
|
2011-12-22 14:36:31 -05:00
|
|
|
episodeDir.getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it.isVideo() } }.each{ dir ->
|
|
|
|
println "Processing $dir"
|
|
|
|
def files = dir.listFiles{ it.isVideo() }
|
2011-11-29 01:03:41 -05:00
|
|
|
|
|
|
|
// fetch subtitles
|
|
|
|
files += getSubtitles(file:files)
|
|
|
|
|
|
|
|
// sort episodes / subtitles
|
2011-11-29 04:00:18 -05:00
|
|
|
rename(file:files, db:'TVRage', format:episodeFormat)
|
2011-11-29 01:03:41 -05:00
|
|
|
}
|
|
|
|
|
2011-12-22 14:36:31 -05:00
|
|
|
movieDir.getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it.isVideo() } }.each{ dir ->
|
|
|
|
println "Processing $dir"
|
|
|
|
def files = dir.listFiles{ it.isVideo() }
|
2011-11-29 01:03:41 -05:00
|
|
|
|
|
|
|
// fetch subtitles
|
|
|
|
files += getSubtitles(file:files)
|
|
|
|
|
|
|
|
// sort movies / subtitles
|
2011-11-29 04:00:18 -05:00
|
|
|
rename(file:files, db:'OpenSubtitles', format:movieFormat)
|
2011-11-29 01:03:41 -05:00
|
|
|
}
|
2012-01-04 09:39:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
// make XBMC scan for new content
|
|
|
|
xbmc.each { host ->
|
|
|
|
telnet(host, 9090) { writer, reader ->
|
|
|
|
writer.println('{"jsonrpc": "2.0", "method": "VideoLibrary.ScanForContent", "id": 1}')
|
|
|
|
}
|
|
|
|
}
|