* add filtering to selectors
This commit is contained in:
parent
8bccdd1523
commit
ae896e3cbd
|
@ -1,7 +1,6 @@
|
||||||
// File selector methods
|
// File selector methods
|
||||||
import static groovy.io.FileType.*
|
import static groovy.io.FileType.*
|
||||||
|
|
||||||
|
|
||||||
File.metaClass.node = { path -> new File(delegate, path) }
|
File.metaClass.node = { path -> new File(delegate, path) }
|
||||||
File.metaClass.listFiles = { c -> delegate.isDirectory() ? delegate.listFiles().findAll(c) : []}
|
File.metaClass.listFiles = { c -> delegate.isDirectory() ? delegate.listFiles().findAll(c) : []}
|
||||||
|
|
||||||
|
@ -10,18 +9,19 @@ File.metaClass.isAudio = { _types.getFilter("audio").accept(delegate) }
|
||||||
File.metaClass.isSubtitle = { _types.getFilter("subtitle").accept(delegate) }
|
File.metaClass.isSubtitle = { _types.getFilter("subtitle").accept(delegate) }
|
||||||
File.metaClass.isVerification = { _types.getFilter("verification").accept(delegate) }
|
File.metaClass.isVerification = { _types.getFilter("verification").accept(delegate) }
|
||||||
|
|
||||||
File.metaClass.hasFile = { c -> isDirectory() && listFiles().find{ c.call(it) }}
|
File.metaClass.dir = { getParentFile() }
|
||||||
|
File.metaClass.hasFile = { c -> isDirectory() && listFiles().find(c) }
|
||||||
|
|
||||||
File.metaClass.getFiles = { def files = []; traverse(type:FILES) { files += it }; return files }
|
String.metaClass.getFiles = { c -> new File(delegate).getFiles(c) }
|
||||||
String.metaClass.getFiles = { new File(delegate).getFiles() }
|
File.metaClass.getFiles = { c -> def files = []; traverse(type:FILES) { files += it }; return c ? files.findAll(c) : files }
|
||||||
List.metaClass.getFiles = { findResults{ it.getFiles() }.flatten().unique() }
|
List.metaClass.getFiles = { c -> findResults{ it.getFiles(c) }.flatten().unique() }
|
||||||
|
|
||||||
File.metaClass.getFolders = { def folders = []; traverse(type:DIRECTORIES, visitRoot:true) { folders += it }; return folders }
|
String.metaClass.getFolders = { c -> new File(delegate).getFolders(c) }
|
||||||
String.metaClass.getFolders = { new File(delegate).getFolders() }
|
File.metaClass.getFolders = { c -> def folders = []; traverse(type:DIRECTORIES, visitRoot:true) { folders += it }; return c ? folders.findAll(c) : folders }
|
||||||
List.metaClass.getFolders = { findResults{ it.getFolders() }.flatten().unique() }
|
List.metaClass.getFolders = { c -> findResults{ it.getFolders(c) }.flatten().unique() }
|
||||||
|
|
||||||
File.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) }
|
|
||||||
String.metaClass.eachMediaFolder = { c -> new File(delegate).eachMediaFolder(c) }
|
String.metaClass.eachMediaFolder = { c -> new File(delegate).eachMediaFolder(c) }
|
||||||
|
File.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) }
|
||||||
List.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) }
|
List.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,20 +7,28 @@ def movieFormat = "X:/out/Movies/{movie}/{movie}"
|
||||||
|
|
||||||
def incomplete(f) { f =~ /[.]chunk|[.]part$/ }
|
def incomplete(f) { f =~ /[.]chunk|[.]part$/ }
|
||||||
|
|
||||||
// run cmdline unrar (require -trust-script) on multi-volume rar files (foo.part1.rar, foo.part2.rar, ...)
|
// run cmdline unrar (require -trust-script) on multi-volume rar files
|
||||||
[episodeDir, movieDir].getFiles().findAll{ it =~ /[.]part01[.]rar$/ }.each { rarP1 ->
|
[episodeDir, movieDir].getFiles().findAll {
|
||||||
// extract name from name.part01.rar
|
it =~ /[.]part01[.]rar$/ || (it =~ /[.]rar$/ && !(it =~ /[.]part\d{2}[.]rar$/))
|
||||||
def name = rarP1.getName()[0 .. -12];
|
}.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)]
|
||||||
|
|
||||||
// find all volumes of the same name
|
// find all volumes of the same name
|
||||||
def volumes = rarP1.getParentFile().listFiles{ it.getName().startsWith(name) && it =~ /[.]part\d{2}[.]rar/ }
|
def volumes = rar.getParentFile().listFiles{
|
||||||
|
it =~ (partLayout ? /$name[.]part\d{2}[.]/ : /$name[.](r\d{2}|rar)/)
|
||||||
|
}
|
||||||
|
|
||||||
// find all incomplete volumes
|
// find all incomplete volumes
|
||||||
def incomplete = volumes.findAll{ incomplete(it) }
|
def incomplete = volumes.findAll{ incomplete(it) }
|
||||||
|
|
||||||
// all volumes complete, call unrar on first volume
|
// all volumes complete, call unrar on first volume
|
||||||
if (incomplete.isEmpty()) {
|
if (incomplete.isEmpty()) {
|
||||||
def exitCode = execute("unrar", "x", "-y", "-p-", rarP1.getAbsolutePath(), rarP1.getPathWithoutExtension() + "/")
|
def exitCode = execute("unrar", "x", "-y", "-p-", rar.getAbsolutePath(), rar.getPathWithoutExtension() + "/")
|
||||||
|
|
||||||
// delete all volumes after successful extraction
|
// delete all volumes after successful extraction
|
||||||
if (exitCode == 0) {
|
if (exitCode == 0) {
|
||||||
|
@ -29,6 +37,7 @@ def incomplete(f) { f =~ /[.]chunk|[.]part$/ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fetch subtitles and sort into folders
|
* Fetch subtitles and sort into folders
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue