mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-15 22:05:00 -05:00
Support filebot -mediainfo -exec (similar to find -exec)
This commit is contained in:
parent
aa10510e87
commit
8f4ec6511f
@ -63,6 +63,11 @@ public class ArgumentProcessor {
|
|||||||
return print(cli.fetchEpisodeList(args.getEpisodeListProvider(), args.getSearchQuery(), args.getExpressionFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale(), args.isStrict()));
|
return print(cli.fetchEpisodeList(args.getEpisodeListProvider(), args.getSearchQuery(), args.getExpressionFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale(), args.isStrict()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// execute command for each file
|
||||||
|
if (args.mediaInfo && args.getExecCommand() != null) {
|
||||||
|
return cli.execute(args.getFiles(true), args.getFileFilter(), args.getExecCommand()) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
// print media info
|
// print media info
|
||||||
if (args.mediaInfo) {
|
if (args.mediaInfo) {
|
||||||
return print(cli.getMediaInfo(args.getFiles(true), args.getFileFilter(), args.getExpressionFormat()));
|
return print(cli.getMediaInfo(args.getFiles(true), args.getFileFilter(), args.getExpressionFormat()));
|
||||||
|
@ -43,6 +43,8 @@ public interface CmdlineInterface {
|
|||||||
|
|
||||||
Stream<String> getMediaInfo(Collection<File> files, FileFilter filter, ExpressionFormat format) throws Exception;
|
Stream<String> getMediaInfo(Collection<File> files, FileFilter filter, ExpressionFormat format) throws Exception;
|
||||||
|
|
||||||
|
boolean execute(Collection<File> files, FileFilter filter, ExecCommand exec) throws Exception;
|
||||||
|
|
||||||
List<File> extract(Collection<File> files, File output, ConflictAction conflict, FileFilter filter, boolean forceExtractAll) throws Exception;
|
List<File> extract(Collection<File> files, File output, ConflictAction conflict, FileFilter filter, boolean forceExtractAll) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -649,13 +649,9 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||||||
|
|
||||||
// execute command
|
// execute command
|
||||||
if (exec != null) {
|
if (exec != null) {
|
||||||
Map<File, Object> context = renameLog.values().stream().filter(Objects::nonNull).collect(toMap(f -> f, f -> xattr.getMetaInfo(f), (a, b) -> a, LinkedHashMap::new));
|
execute(renameLog.values(), Objects::nonNull, exec); // destination files may include null values
|
||||||
if (context.size() > 0) {
|
|
||||||
exec.execute(context.entrySet().stream().map(m -> new MediaBindingBean(m.getValue(), m.getKey(), context)).toArray(MediaBindingBean[]::new));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// destination files may include null values
|
|
||||||
return new ArrayList<File>(renameLog.values());
|
return new ArrayList<File>(renameLog.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1075,6 +1071,25 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||||||
}).filter(Objects::nonNull);
|
}).filter(Objects::nonNull);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(Collection<File> files, FileFilter filter, ExecCommand exec) throws Exception {
|
||||||
|
// collect files
|
||||||
|
List<File> f = filter(files, filter);
|
||||||
|
|
||||||
|
if (f.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// collect object metadata
|
||||||
|
List<Object> m = f.stream().map(xattr::getMetaInfo).collect(toList());
|
||||||
|
|
||||||
|
// build and execute commands
|
||||||
|
MediaBindingBean[] group = IntStream.range(0, f.size()).mapToObj(i -> new MediaBindingBean(m.get(i), f.get(i), new EntryList<File, Object>(f, m))).toArray(MediaBindingBean[]::new);
|
||||||
|
exec.execute(group);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<File> revert(Collection<File> files, FileFilter filter, RenameAction action) throws Exception {
|
public List<File> revert(Collection<File> files, FileFilter filter, RenameAction action) throws Exception {
|
||||||
if (files.isEmpty()) {
|
if (files.isEmpty()) {
|
||||||
|
@ -72,7 +72,7 @@ public class ExecCommand {
|
|||||||
process.directory(directory);
|
process.directory(directory);
|
||||||
process.inheritIO();
|
process.inheritIO();
|
||||||
|
|
||||||
debug.finest(message("Execute", command));
|
debug.finest(format("Execute %s", command));
|
||||||
|
|
||||||
int exitCode = process.start().waitFor();
|
int exitCode = process.start().waitFor();
|
||||||
if (exitCode != 0) {
|
if (exitCode != 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user