1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 16:28:51 -05:00

Catch exceptions and log as warning before the interrupt the program flow (i.e. when using -mediainfo and -list with custom --format options that yield empty strings)

This commit is contained in:
Reinhard Pointner 2017-01-05 17:04:40 +08:00
parent c122e1f275
commit ba772e03c8
2 changed files with 25 additions and 12 deletions

View File

@ -56,22 +56,17 @@ public class ArgumentProcessor {
// print episode info // print episode info
if (args.list) { if (args.list) {
List<String> lines = cli.fetchEpisodeList(args.getDatasource(), args.getSearchQuery(), args.getExpressionFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale()); return print(cli.fetchEpisodeList(args.getDatasource(), args.getSearchQuery(), args.getExpressionFormat(), args.getExpressionFilter(), args.getSortOrder(), args.getLanguage().getLocale()));
lines.forEach(System.out::println);
return lines.isEmpty() ? 1 : 0;
} }
// print media info // print media info
if (args.mediaInfo) { if (args.mediaInfo) {
List<String> lines = cli.getMediaInfo(args.getFiles(true), args.getExpressionFileFilter(), args.getExpressionFormat()); return print(cli.getMediaInfo(args.getFiles(true), args.getExpressionFileFilter(), args.getExpressionFormat()));
lines.forEach(System.out::println);
return lines.isEmpty() ? 1 : 0;
} }
// revert files // revert files
if (args.revert) { if (args.revert) {
List<File> files = cli.revert(args.getFiles(false), args.getExpressionFileFilter(), args.getRenameAction()); return cli.revert(args.getFiles(false), args.getExpressionFileFilter(), args.getRenameAction()).isEmpty() ? 1 : 0;
return files.isEmpty() ? 1 : 0;
} }
// file operations // file operations
@ -103,6 +98,21 @@ public class ArgumentProcessor {
return 0; return 0;
} }
private int print(List<?> values) {
int lines = 0;
for (int i = 0; i < values.size(); i++) {
try {
System.out.println(values.get(i));
lines++;
} catch (Exception e) {
debug.warning(e::getMessage);
}
}
return lines == 0 ? 1 : 0;
}
public void runScript(CmdlineInterface cli, ArgumentBean args) throws Throwable { public void runScript(CmdlineInterface cli, ArgumentBean args) throws Throwable {
Bindings bindings = new SimpleBindings(); Bindings bindings = new SimpleBindings();
bindings.put(ScriptShell.SHELL_ARGS_BINDING_NAME, args); bindings.put(ScriptShell.SHELL_ARGS_BINDING_NAME, args);

View File

@ -995,9 +995,10 @@ public class CmdlineOperations implements CmdlineInterface {
List<Episode> episodes = applyExpressionFilter(service.getEpisodeList(options.get(0), order, locale), filter); List<Episode> episodes = applyExpressionFilter(service.getEpisodeList(options.get(0), order, locale), filter);
Map<File, Episode> context = new EntryList<File, Episode>(null, episodes); Map<File, Episode> context = new EntryList<File, Episode>(null, episodes);
return episodes.stream().map(episode -> { // lazy format
return format != null ? format.format(new MediaBindingBean(episode, null, context)) : EpisodeFormat.SeasonEpisode.format(episode); return new FunctionList<Episode, String>(episodes, e -> {
}).collect(toList()); return format != null ? format.format(new MediaBindingBean(e, null, context)) : EpisodeFormat.SeasonEpisode.format(e);
});
} }
@Override @Override
@ -1013,7 +1014,9 @@ public class CmdlineOperations implements CmdlineInterface {
ExpressionFormat formatter = format != null ? format : new ExpressionFormat("{fn} [{resolution} {vc} {channels} {ac} {minutes}m]"); ExpressionFormat formatter = format != null ? format : new ExpressionFormat("{fn} [{resolution} {vc} {channels} {ac} {minutes}m]");
// lazy format // lazy format
return new FunctionList<File, String>(selection, f -> formatter.format(new MediaBindingBean(xattr.getMetaInfo(f), f))); return new FunctionList<File, String>(selection, f -> {
return formatter.format(new MediaBindingBean(xattr.getMetaInfo(f), f));
});
} }
@Override @Override