* simplify sorty.groovy multi-volume rar extraction

This commit is contained in:
Reinhard Pointner 2012-03-07 04:14:33 +00:00
parent 03bf30596b
commit db3be3e9d1
2 changed files with 9 additions and 26 deletions

View File

@ -937,7 +937,7 @@ public class CmdlineOperations implements CmdlineInterface {
extractedFiles.add(outputMapper.getOutputFile(entry)); extractedFiles.add(outputMapper.getOutputFile(entry));
} }
CLILogger.finest("Extract files " + entries); CLILogger.finest("Extracting files " + entries);
archive.extract(outputMapper); archive.extract(outputMapper);
} finally { } finally {
archive.close(); archive.close();

View File

@ -10,34 +10,17 @@ def xbmc = ['localhost'] // (use [] to not notify any XBMC instances about updat
// ignore chunk, part, par and hidden files // ignore chunk, part, par and hidden files
def incomplete(f) { f.name =~ /[.]chunk|[.]part\d{0,3}$|[.]par$|[.]dat$/ || f.isHidden() } def incomplete(f) { f.name =~ /[.]incomplete|[.]chunk|[.]par$|[.]dat$/ || f.isHidden() }
// run cmdline unrar (require -trust-script) on multi-volume rar files // extract completed multi-volume rar files
[episodeDir, movieDir].getFiles().findAll { it =~ /[.]part01[.]rar$/ || (it =~ /[.]rar$/ && !(it =~ /[.]part\d{2}[.]rar$/)) }.each { rar -> [episodeDir, movieDir].getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it =~ /[.]rar$/ } }.each{ dir ->
// new layout: foo.part1.rar, foo.part2.rar // extract all archives found in this folder
// old layout: foo.rar, foo.r00, foo.r01 def paths = extract(folder:dir)
boolean partLayout = (rar =~ /[.]part01[.]rar/)
// extract name from name.part01.rar or name.rar // delete original archive volumes after successful extraction
def name = rar.getName()[0 .. (partLayout ? -12 : -5)] if (paths != null && !paths.isEmpty()) {
dir.listFiles{ it =~ /[.]rar$|[.]r[\d]+$/ }*.delete()
// find all volumes of the same name
def volumes = rar.getParentFile().listFiles{
it =~ (partLayout ? /$name[.]part\d{2}[.]/ : /$name[.](r\d{2}|rar)/)
}
// find all incomplete volumes
def incomplete = volumes.findAll{ incomplete(it) }
// all volumes complete, call unrar on first volume
if (incomplete.isEmpty()) {
def exitCode = execute("unrar", "x", "-y", "-p-", rar.getAbsolutePath(), rar.getPathWithoutExtension() + "/")
// delete all volumes after successful extraction
if (exitCode == 0) {
volumes*.delete()
}
} }
} }