* support simple rename function call that takes care of all the cmdline logging / rename action / conflict action / history

This commit is contained in:
Reinhard Pointner 2014-04-20 13:09:01 +00:00
parent b0da4330e8
commit 26d3b51a84
3 changed files with 35 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import net.filebot.RenameAction; import net.filebot.RenameAction;
@ -11,6 +12,8 @@ public interface CmdlineInterface {
List<File> rename(Collection<File> files, RenameAction action, String conflict, String output, String format, String db, String query, String sortOrder, String filter, String lang, boolean strict) throws Exception; List<File> rename(Collection<File> files, RenameAction action, String conflict, String output, String format, String db, String query, String sortOrder, String filter, String lang, boolean strict) throws Exception;
List<File> rename(Map<File, File> renameMap, RenameAction renameAction, String conflict) throws Exception;
List<File> getSubtitles(Collection<File> files, String db, String query, String lang, String output, String encoding, String format, boolean strict) throws Exception; List<File> getSubtitles(Collection<File> files, String db, String query, String lang, String output, String encoding, String format, boolean strict) throws Exception;
List<File> getMissingSubtitles(Collection<File> files, String db, String query, String lang, String output, String encoding, String format, boolean strict) throws Exception; List<File> getMissingSubtitles(Collection<File> files, String db, String query, String lang, String output, String encoding, String format, boolean strict) throws Exception;

View File

@ -138,6 +138,12 @@ public class CmdlineOperations implements CmdlineInterface {
} }
} }
@Override
public List<File> rename(Map<File, File> renameMap, RenameAction renameAction, String conflict) throws Exception {
// generic rename function that can be passed any set of files
return renameAll(renameMap, renameAction, ConflictAction.forName(conflict), null);
}
public List<File> renameSeries(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, EpisodeListProvider db, String query, SortOrder sortOrder, ExpressionFilter filter, Locale locale, boolean strict) throws Exception { public List<File> renameSeries(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, EpisodeListProvider db, String query, SortOrder sortOrder, ExpressionFilter filter, Locale locale, boolean strict) throws Exception {
CLILogger.config(format("Rename episodes using [%s]", db.getName())); CLILogger.config(format("Rename episodes using [%s]", db.getName()));
@ -554,7 +560,7 @@ public class CmdlineOperations implements CmdlineInterface {
public List<File> renameAll(Map<File, File> renameMap, RenameAction renameAction, ConflictAction conflictAction, List<Match<File, ?>> matches) throws Exception { public List<File> renameAll(Map<File, File> renameMap, RenameAction renameAction, ConflictAction conflictAction, List<Match<File, ?>> matches) throws Exception {
if (renameMap.isEmpty()) { if (renameMap.isEmpty()) {
throw new Exception("Unable to identify and process any files"); throw new Exception("Unable to identify or process any files");
} }
// rename files // rename files

View File

@ -299,6 +299,10 @@ public abstract class ScriptShellBaseClass extends Script {
synchronized (cli) { synchronized (cli) {
try { try {
if (input.isEmpty() && !getInputFileMap(parameters).isEmpty()) {
return cli.rename(getInputFileMap(parameters), action, asString(option.get(Option.conflict)));
}
return cli.rename(input, action, asString(option.get(Option.conflict)), asString(option.get(Option.output)), asString(option.get(Option.format)), asString(option.get(Option.db)), asString(option.get(Option.query)), asString(option.get(Option.order)), asString(option.get(Option.filter)), asString(option.get(Option.lang)), strict); return cli.rename(input, action, asString(option.get(Option.conflict)), asString(option.get(Option.output)), asString(option.get(Option.format)), asString(option.get(Option.db)), asString(option.get(Option.query)), asString(option.get(Option.order)), asString(option.get(Option.filter)), asString(option.get(Option.lang)), strict);
} catch (Exception e) { } catch (Exception e) {
printException(e); printException(e);
@ -406,18 +410,35 @@ public abstract class ScriptShellBaseClass extends Script {
} }
} }
private List<File> getInputFileList(Map<String, ?> map) { private List<File> getInputFileList(Map<String, ?> parameters) {
Object file = map.get("file"); Object file = parameters.get("file");
if (file != null) { if (file != null) {
return FileUtilities.asFileList(file); return FileUtilities.asFileList(file);
} }
Object folder = map.get("folder"); Object folder = parameters.get("folder");
if (folder != null) { if (folder != null) {
return FileUtilities.listFiles(FileUtilities.asFileList(folder), 0, false, true, false); return FileUtilities.listFiles(FileUtilities.asFileList(folder), 0, false, true, false);
} }
throw new IllegalArgumentException("file is not set"); return emptyList();
}
private Map<File, File> getInputFileMap(Map<String, ?> parameters) {
Map<?, ?> map = (Map<?, ?>) parameters.get("map");
Map<File, File> files = new LinkedHashMap<File, File>();
if (map != null) {
for (Entry<?, ?> it : map.entrySet()) {
List<File> key = FileUtilities.asFileList(it.getKey());
List<File> value = FileUtilities.asFileList(it.getValue());
if (key.size() == 1 && value.size() == 1) {
files.put(key.get(0), value.get(0));
} else {
throw new IllegalArgumentException("Illegal file mapping: " + it);
}
}
}
return files;
} }
private Map<Option, Object> getDefaultOptions(Map<String, ?> parameters) throws Exception { private Map<Option, Object> getDefaultOptions(Map<String, ?> parameters) throws Exception {