From 64f93c991be10af74db516269fd24ec8e0527f31 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 10 Mar 2012 10:24:35 +0000 Subject: [PATCH] * added --conflict option to -extract mode --- .../filebot/cli/ArgumentProcessor.java | 2 +- .../filebot/cli/CmdlineInterface.java | 2 +- .../filebot/cli/CmdlineOperations.java | 17 ++++++++--- .../filebot/cli/ScriptShell.lib.groovy | 29 +++++++++++-------- website/cli.html | 5 ++++ 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java index 8d32d432..326b35a5 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java +++ b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java @@ -63,7 +63,7 @@ public class ArgumentProcessor { Collection files = new LinkedHashSet(args.getFiles(true)); if (args.extract) { - files.addAll(cli.extract(files, args.output)); + files.addAll(cli.extract(files, args.output, args.conflict)); } if (args.getSubtitles) { diff --git a/source/net/sourceforge/filebot/cli/CmdlineInterface.java b/source/net/sourceforge/filebot/cli/CmdlineInterface.java index 343a9814..b44b9743 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineInterface.java +++ b/source/net/sourceforge/filebot/cli/CmdlineInterface.java @@ -30,6 +30,6 @@ public interface CmdlineInterface { String getMediaInfo(File file, String format) throws Exception; - List extract(Collection files, String output) throws Exception; + List extract(Collection files, String output, String conflict) throws Exception; } diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index 02887f97..83960d29 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -928,7 +928,9 @@ public class CmdlineOperations implements CmdlineInterface { @Override - public List extract(Collection files, String output) throws Exception { + public List extract(Collection files, String output, String conflict) throws Exception { + ConflictAction conflictAction = ConflictAction.forName(conflict); + // only keep single-volume archives or first part of multi-volume archives List archiveFiles = filter(files, Archive.VOLUME_ONE_FILTER); List extractedFiles = new ArrayList(); @@ -942,12 +944,19 @@ public class CmdlineOperations implements CmdlineInterface { FileMapper outputMapper = new FileMapper(outputFolder, false); List entries = archive.listFiles(); + boolean skip = true; for (File entry : entries) { - extractedFiles.add(outputMapper.getOutputFile(entry)); + File outputFile = outputMapper.getOutputFile(entry); + skip &= outputFile.exists(); + extractedFiles.add(outputFile); } - CLILogger.finest("Extracting files " + entries); - archive.extract(outputMapper); + if (!skip || conflictAction == ConflictAction.OVERRIDE) { + CLILogger.finest("Extracting files " + entries); + archive.extract(outputMapper); + } else { + CLILogger.finest("Skipped extracting files " + entries); + } } finally { archive.close(); } diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index da5d43f5..5d173385 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -187,19 +187,19 @@ List.metaClass.sortBySimilarity = { prime, Closure toStringFunction = { obj -> o // CLI bindings def rename(args) { args = _defaults(args) synchronized (_cli) { - _guarded { _cli.rename(_files(args), args.action, args.conflict, args.output, args.format, args.db, args.query, args.order, args.lang, args.strict) } + _guarded { _cli.rename(_files(args), args.action as String, args.conflict as String, args.output as String, args.format as String, args.db as String, args.query as String, args.order as String, args.lang as String, args.strict as Boolean) } } } def getSubtitles(args) { args = _defaults(args) synchronized (_cli) { - _guarded { _cli.getSubtitles(_files(args), args.query, args.lang, args.output, args.encoding, args.strict) } + _guarded { _cli.getSubtitles(_files(args), args.query as String, args.lang as String, args.output as String, args.encoding as String, args.strict as Boolean) } } } def getMissingSubtitles(args) { args = _defaults(args) synchronized (_cli) { - _guarded { _cli.getMissingSubtitles(_files(args), args.query, args.lang, args.output, args.encoding, args.strict) } + _guarded { _cli.getMissingSubtitles(_files(args), args.query as String, args.lang as String, args.output as String, args.encoding as String, args.strict as Boolean) } } } @@ -211,25 +211,25 @@ def check(args) { def compute(args) { args = _defaults(args) synchronized (_cli) { - _guarded { _cli.compute(_files(args), args.output, args.encoding) } + _guarded { _cli.compute(_files(args), args.output as String, args.encoding as String) } } } def extract(args) { args = _defaults(args) synchronized (_cli) { - _guarded { _cli.extract(_files(args), args.output) } + _guarded { _cli.extract(_files(args), args.output as String, args.conflict as String) } } } def fetchEpisodeList(args) { args = _defaults(args) synchronized (_cli) { - _guarded { _cli.fetchEpisodeList(args.query, args.format, args.db, args.order, args.lang) } + _guarded { _cli.fetchEpisodeList(args.query as String, args.format as String, args.db as String, args.order as String, args.lang as String) } } } def getMediaInfo(args) { args = _defaults(args) synchronized (_cli) { - _guarded { _cli.getMediaInfo(args.file, args.format) } + _guarded { _cli.getMediaInfo(args.file as File, args.format as String) } } } @@ -239,11 +239,16 @@ def getMediaInfo(args) { args = _defaults(args) */ def _files(args) { def files = []; - if (args.folder) - args.folder.traverse(type:FILES, maxDepth:0) { files += it } - if (args.file) - files += args.file - + if (args.folder) { + (args.folder as File).traverse(type:FILES, maxDepth:0) { files += it } + } + if (args.file) { + if (args.file instanceof Iterable || args.file instanceof File[]) { + files += args.file as List + } else { + files += args.file as File + } + } return files } diff --git a/website/cli.html b/website/cli.html index 8329ae46..db7cafad 100644 --- a/website/cli.html +++ b/website/cli.html @@ -193,6 +193,11 @@ rename action move | copy | keeplink | symlink | hardlink + + --conflict + conflict resolution + override | skip | fail + -get-subtitles fetch subtitles