mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-10 06:20:27 -04:00
+ Support for --file-filter option (e.g. useful on Windows where find -exec isn't possible)
This commit is contained in:
parent
b3ee9f3520
commit
6d818f8ffe
@ -155,7 +155,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onStart(ArgumentBean args) {
|
private static void onStart(ArgumentBean args) throws Exception {
|
||||||
// publish file arguments
|
// publish file arguments
|
||||||
List<File> files = args.getFiles(false);
|
List<File> files = args.getFiles(false);
|
||||||
if (files.size() > 0) {
|
if (files.size() > 0) {
|
||||||
|
@ -4,6 +4,7 @@ import static java.util.Arrays.*;
|
|||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.hash.VerificationUtilities.*;
|
import static net.filebot.hash.VerificationUtilities.*;
|
||||||
|
import static net.filebot.media.XattrMetaInfo.*;
|
||||||
import static net.filebot.subtitle.SubtitleUtilities.*;
|
import static net.filebot.subtitle.SubtitleUtilities.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ public class ArgumentBean {
|
|||||||
@Option(name = "--conflict", usage = "Conflict resolution", metaVar = "[skip, override, auto, index, fail]")
|
@Option(name = "--conflict", usage = "Conflict resolution", metaVar = "[skip, override, auto, index, fail]")
|
||||||
public String conflict = "skip";
|
public String conflict = "skip";
|
||||||
|
|
||||||
@Option(name = "--filter", usage = "Filter expression", metaVar = "expression")
|
@Option(name = "--filter", usage = "Match filter expression", metaVar = "expression")
|
||||||
public String filter = null;
|
public String filter = null;
|
||||||
|
|
||||||
@Option(name = "--format", usage = "Format expression", metaVar = "expression")
|
@Option(name = "--format", usage = "Format expression", metaVar = "expression")
|
||||||
@ -144,6 +145,9 @@ public class ArgumentBean {
|
|||||||
@Option(name = "-exec", usage = "Execute command", metaVar = "command", handler = RestOfArgumentsHandler.class)
|
@Option(name = "-exec", usage = "Execute command", metaVar = "command", handler = RestOfArgumentsHandler.class)
|
||||||
public List<String> exec = new ArrayList<String>();
|
public List<String> exec = new ArrayList<String>();
|
||||||
|
|
||||||
|
@Option(name = "--file-filter", usage = "Input file filter expression", metaVar = "expression")
|
||||||
|
public String inputFileFilter = null;
|
||||||
|
|
||||||
@Argument
|
@Argument
|
||||||
public List<String> arguments = new ArrayList<String>();
|
public List<String> arguments = new ArrayList<String>();
|
||||||
|
|
||||||
@ -171,7 +175,7 @@ public class ArgumentBean {
|
|||||||
return clearPrefs;
|
return clearPrefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<File> getFiles(boolean resolveFolders) {
|
public List<File> getFiles(boolean resolveFolders) throws Exception {
|
||||||
if (arguments == null || arguments.isEmpty()) {
|
if (arguments == null || arguments.isEmpty()) {
|
||||||
return emptyList();
|
return emptyList();
|
||||||
}
|
}
|
||||||
@ -206,6 +210,11 @@ public class ArgumentBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// input file filter (e.g. useful on Windows where find -exec is not an option)
|
||||||
|
if (inputFileFilter != null) {
|
||||||
|
return filter(files, new ExpressionFileFilter(inputFileFilter, f -> f));
|
||||||
|
}
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +253,7 @@ public class ArgumentBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FileFilter getFileFilter() throws Exception {
|
public FileFilter getFileFilter() throws Exception {
|
||||||
return filter == null ? FILES : new ExpressionFileFilter(filter);
|
return filter == null ? FILES : new ExpressionFileFilter(filter, xattr::getMetaInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Datasource getDatasource() {
|
public Datasource getDatasource() {
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
package net.filebot.format;
|
package net.filebot.format;
|
||||||
|
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.media.XattrMetaInfo.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
|
|
||||||
public class ExpressionFileFilter implements FileFilter {
|
public class ExpressionFileFilter implements FileFilter {
|
||||||
|
|
||||||
private ExpressionFilter filter;
|
private ExpressionFilter filter;
|
||||||
|
private Function<File, Object> match;
|
||||||
|
|
||||||
public ExpressionFileFilter(String expression) throws ScriptException {
|
public ExpressionFileFilter(String expression) throws ScriptException {
|
||||||
|
// use file object as match object by default
|
||||||
|
this(expression, f -> f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionFileFilter(String expression, Function<File, Object> match) throws ScriptException {
|
||||||
this.filter = new ExpressionFilter(expression);
|
this.filter = new ExpressionFilter(expression);
|
||||||
|
this.match = match;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpressionFilter getExpressionFilter() {
|
public ExpressionFilter getExpressionFilter() {
|
||||||
@ -23,7 +30,7 @@ public class ExpressionFileFilter implements FileFilter {
|
|||||||
@Override
|
@Override
|
||||||
public boolean accept(File f) {
|
public boolean accept(File f) {
|
||||||
try {
|
try {
|
||||||
return filter.matches(new MediaBindingBean(xattr.getMetaInfo(f), f));
|
return filter.matches(new MediaBindingBean(match.apply(f), f));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
debug.warning("Filter expression failed: " + e);
|
debug.warning("Filter expression failed: " + e);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import static java.util.Collections.*;
|
|||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.Settings.*;
|
import static net.filebot.Settings.*;
|
||||||
import static net.filebot.WebServices.*;
|
import static net.filebot.WebServices.*;
|
||||||
|
import static net.filebot.media.XattrMetaInfo.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -60,7 +61,7 @@ public class Preset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ExpressionFileFilter getIncludeFilter() {
|
public ExpressionFileFilter getIncludeFilter() {
|
||||||
return getInputFolder() == null ? null : getValue(includes, expression -> new ExpressionFileFilter(expression));
|
return getInputFolder() == null ? null : getValue(includes, expression -> new ExpressionFileFilter(expression, xattr::getMetaInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpressionFileFormat getFormat() {
|
public ExpressionFileFormat getFormat() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user