From 64de406c3b7accf36d342591c853b0f30c2852b0 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 15 Jan 2017 15:44:52 +0800 Subject: [PATCH] Fix rename(map: ...) function @see https://www.filebot.net/forums/viewtopic.php?f=11&t=4628&p=25807#p25807 --- .../net/filebot/cli/ScriptShellBaseClass.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index 8be890cc..1f2b4922 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Stream; @@ -341,18 +340,19 @@ public abstract class ScriptShellBaseClass extends Script { } public List rename(Map parameters) throws Exception { + // consume all parameters List files = getInputFileList(parameters); + Map map = files.isEmpty() ? getInputFileMap(parameters) : emptyMap(); // check map parameter if file/folder is not set RenameAction action = getRenameAction(parameters); ArgumentBean args = getArgumentBean(parameters); try { if (files.size() > 0) { return getCLI().rename(files, args.getRenameAction(), args.getConflictAction(), args.getAbsoluteOutputFolder(), args.getExpressionFormat(), args.getDatasource(), args.getSearchQuery(), args.getSortOrder(), args.getExpressionFilter(), args.getLanguage().getLocale(), args.isStrict()); - } else { - Map map = getInputFileMap(parameters); - if (map.size() > 0) { - return getCLI().rename(map, action, args.getConflictAction()); - } + } + + if (map.size() > 0) { + return getCLI().rename(map, action, args.getConflictAction()); } } catch (Exception e) { printException(e); @@ -484,9 +484,17 @@ public abstract class ScriptShellBaseClass extends Script { private Map getInputFileMap(Map parameters) { // convert keys and values to files - Function mapping = f -> asFileList(f).iterator().next(); + Map map = new LinkedHashMap(); - return consumeParameter(parameters, "map").map(Map.class::cast).collect(toMap(mapping, mapping, (a, b) -> a, LinkedHashMap::new)); + consumeParameter(parameters, "map").map(Map.class::cast).forEach(m -> { + m.forEach((k, v) -> { + File from = asFileList(k).get(0); + File to = asFileList(v).get(0); + map.put(from, to); + }); + }); + + return map; } private RenameAction getRenameAction(Map parameters) {