From ba119efdde4d46da8e47ca8fdcb67dda36bc4372 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 3 Nov 2011 05:50:57 +0000 Subject: [PATCH] * added new example script --- .../filebot/cli/ScriptShell.lib.groovy | 6 +++++- website/data/shell/mvrn.groovy | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 website/data/shell/mvrn.groovy diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index b1c720f3..91227e89 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -8,6 +8,7 @@ File.metaClass.isSubtitle = { _types.getFilter("subtitle").accept(delegate) } File.metaClass.isVerification = { _types.getFilter("verification").accept(delegate) } File.metaClass.hasFile = { c -> isDirectory() && listFiles().find{ c.call(it) }} +File.metaClass.plus = { path -> new File(delegate, path) } File.metaClass.getFiles = { def files = []; traverse(type:FILES) { files += it }; return files } List.metaClass.getFiles = { findResults{ it.getFiles() }.flatten().unique() } @@ -15,9 +16,12 @@ List.metaClass.getFiles = { findResults{ it.getFiles() }.flatten().unique() } File.metaClass.getFolders = { def folders = []; traverse(type:DIRECTORIES, visitRoot:true) { folders += it }; return folders } List.metaClass.getFolders = { findResults{ it.getFolders() }.flatten().unique() } +File.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) } List.metaClass.eachMediaFolder = { c -> getFolders().findAll{ it.hasFile{ it.isVideo() } }.each(c) } - +def require(cond) { + if (!cond()) throw new Exception('Require failed') +} def rename(args) { args = _defaults(args) diff --git a/website/data/shell/mvrn.groovy b/website/data/shell/mvrn.groovy new file mode 100644 index 00000000..bef745c0 --- /dev/null +++ b/website/data/shell/mvrn.groovy @@ -0,0 +1,19 @@ +// filebot -script "http://filebot.sourceforge.net/data/shell/mvrn.groovy" --format "{n}/{n} - {'S'+s.pad(2)}E{e.pad(2)} - {t}" --db thetvdb + +// sanity check +require { args.size == 2 && _args.format && _args.db } + +// handle arguments +def source = args[0] +def destination = args[1] + _args.format + +println 'Source Folder: ' + source +println 'Target Format: ' + destination.path + +/* + * Move/Rename videos from source folder into destination folder + */ +source.eachMediaFolder { + println 'Processing ' + it + rename(folder:it, format:destination.path, db:_args.db) +}