mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-04 16:35:08 -05:00
* continue porting
This commit is contained in:
parent
3c1306ec2c
commit
f360c4f99a
@ -18,7 +18,14 @@ import org.w3c.dom.Node;
|
||||
|
||||
public class MediaTypes {
|
||||
|
||||
private static final MediaTypes defaultInstance = parseDefault();
|
||||
private static MediaTypes defaultInstance;
|
||||
|
||||
public static synchronized MediaTypes getDefault() {
|
||||
if (defaultInstance == null) {
|
||||
defaultInstance = parseDefault();
|
||||
}
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
private static MediaTypes parseDefault() {
|
||||
try {
|
||||
@ -70,10 +77,6 @@ public class MediaTypes {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public static MediaTypes getDefault() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getTypes() {
|
||||
return types;
|
||||
}
|
||||
@ -88,13 +91,15 @@ public class MediaTypes {
|
||||
}
|
||||
|
||||
public static ExtensionFileFilter getDefaultFilter(String name) {
|
||||
return defaultInstance.getFilter(name);
|
||||
return getDefault().getFilter(name);
|
||||
}
|
||||
|
||||
// some convenience filters
|
||||
public static final ExtensionFileFilter AUDIO_FILES = getDefaultFilter("audio");
|
||||
public static final ExtensionFileFilter VIDEO_FILES = getDefaultFilter("video");
|
||||
public static final ExtensionFileFilter SUBTITLE_FILES = getDefaultFilter("subtitle");
|
||||
public static final ExtensionFileFilter ARCHIVE_FILES = getDefaultFilter("archive");
|
||||
public static final ExtensionFileFilter VERIFICATION_FILES = getDefaultFilter("verification");
|
||||
public static final ExtensionFileFilter NFO_FILES = getDefaultFilter("application/nfo");
|
||||
public static final ExtensionFileFilter LIST_FILES = getDefaultFilter("application/list");
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.sourceforge.filebot.cli;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
import static net.sourceforge.filebot.Settings.*;
|
||||
import static net.sourceforge.filebot.cli.CLILogging.*;
|
||||
import groovy.lang.Closure;
|
||||
@ -8,10 +7,6 @@ import groovy.lang.MissingPropertyException;
|
||||
import groovy.lang.Script;
|
||||
|
||||
import java.io.Console;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -20,6 +15,7 @@ import javax.script.SimpleBindings;
|
||||
|
||||
import net.sourceforge.filebot.MediaTypes;
|
||||
import net.sourceforge.filebot.format.AssociativeScriptObject;
|
||||
import net.sourceforge.filebot.util.FileUtilities;
|
||||
|
||||
public abstract class ScriptShellBaseClass extends Script {
|
||||
|
||||
@ -27,6 +23,31 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||
System.out.println(this);
|
||||
}
|
||||
|
||||
private Map<String, ?> defaultValues;
|
||||
|
||||
public void setDefaultValues(Map<String, ?> values) {
|
||||
this.defaultValues = values;
|
||||
}
|
||||
|
||||
public Map<String, ?> getDefaultValues() {
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProperty(String property) {
|
||||
try {
|
||||
return super.getProperty(property);
|
||||
} catch (MissingPropertyException e) {
|
||||
// try user-defined default values
|
||||
if (defaultValues != null && defaultValues.containsKey(property)) {
|
||||
return defaultValues.get(property);
|
||||
}
|
||||
|
||||
// can't use default value, rethrow exception
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void include(String input) throws Throwable {
|
||||
try {
|
||||
executeScript(input, null);
|
||||
@ -47,38 +68,13 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||
if (bindings != null) {
|
||||
parameters.putAll(bindings);
|
||||
}
|
||||
parameters.put(ScriptShell.ARGV_BINDING_NAME, asFileList(args));
|
||||
parameters.put(ScriptShell.ARGV_BINDING_NAME, FileUtilities.asFileList(args));
|
||||
|
||||
// run given script
|
||||
ScriptShell shell = (ScriptShell) getBinding().getVariable(ScriptShell.SHELL_BINDING_NAME);
|
||||
return shell.runScript(input, parameters);
|
||||
}
|
||||
|
||||
private Map<String, ?> defaultValues;
|
||||
|
||||
public void setDefaultValues(Map<String, ?> values) {
|
||||
this.defaultValues = values;
|
||||
}
|
||||
|
||||
public Map<String, ?> getDefaultValues() {
|
||||
return defaultValues == null ? null : unmodifiableMap(defaultValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProperty(String property) {
|
||||
try {
|
||||
return super.getProperty(property);
|
||||
} catch (MissingPropertyException e) {
|
||||
// try user-defined default values
|
||||
if (defaultValues != null && defaultValues.containsKey(property)) {
|
||||
return defaultValues.get(property);
|
||||
}
|
||||
|
||||
// can't use default value, rethrow exception
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public Object tryQuietly(Closure<?> c) {
|
||||
try {
|
||||
return c.call();
|
||||
@ -104,11 +100,6 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object run() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// define global variable: _args
|
||||
public ArgumentBean get_args() {
|
||||
return getApplicationArguments();
|
||||
@ -144,18 +135,9 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||
return System.console();
|
||||
}
|
||||
|
||||
public static List<File> asFileList(Object... paths) {
|
||||
List<File> files = new ArrayList<File>();
|
||||
for (Object it : paths) {
|
||||
if (it instanceof CharSequence) {
|
||||
files.add(new File(it.toString()));
|
||||
} else if (it instanceof File) {
|
||||
files.add((File) it);
|
||||
} else if (it instanceof Path) {
|
||||
files.add(((Path) it).toFile());
|
||||
}
|
||||
}
|
||||
return files;
|
||||
@Override
|
||||
public Object run() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,8 +15,10 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.AtomicMoveNotSupportedException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@ -395,6 +397,14 @@ public final class FileUtilities {
|
||||
return f;
|
||||
}
|
||||
|
||||
public static List<File> listFiles(File... folders) {
|
||||
return listFiles(Arrays.asList(folders));
|
||||
}
|
||||
|
||||
public static List<File> listFiles(Iterable<File> folders) {
|
||||
return listFiles(folders, 255, false);
|
||||
}
|
||||
|
||||
public static List<File> listFiles(Iterable<File> folders, int maxDepth, boolean listHiddenFiles) {
|
||||
List<File> files = new ArrayList<File>();
|
||||
|
||||
@ -539,6 +549,20 @@ public final class FileUtilities {
|
||||
return Pattern.compile("\\s*[\\\\/]+\\s*").matcher(path).replaceAll(replacement);
|
||||
}
|
||||
|
||||
public static List<File> asFileList(Object... paths) {
|
||||
List<File> files = new ArrayList<File>(paths.length);
|
||||
for (Object it : paths) {
|
||||
if (it instanceof CharSequence) {
|
||||
files.add(new File(it.toString()));
|
||||
} else if (it instanceof File) {
|
||||
files.add((File) it);
|
||||
} else if (it instanceof Path) {
|
||||
files.add(((Path) it).toFile());
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
public static String getXmlString(Document dom) throws TransformerException {
|
||||
Transformer tr = TransformerFactory.newInstance().newTransformer();
|
||||
tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
|
Loading…
Reference in New Issue
Block a user