Refactor ScriptShellBaseClass
This commit is contained in:
parent
565555e0b3
commit
d82f454d94
|
@ -66,8 +66,8 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
try {
|
try {
|
||||||
return super.getProperty(property);
|
return super.getProperty(property);
|
||||||
} catch (MissingPropertyException e) {
|
} catch (MissingPropertyException e) {
|
||||||
// try user-defined default values
|
// try user-defined default values (support null values)
|
||||||
if (defaultValues != null && defaultValues.containsKey(property)) {
|
if (defaultValues.containsKey(property)) {
|
||||||
return defaultValues.get(property);
|
return defaultValues.get(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,14 +239,17 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore and move on
|
debug.log(Level.WARNING, e::toString); // ignore and move on
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. run full-fledged movie detection
|
// 3. run full-fledged movie detection
|
||||||
try {
|
try {
|
||||||
return MediaDetection.detectMovie(file, WebServices.TheMovieDB, Locale.ENGLISH, strict).get(0);
|
List<Movie> options = MediaDetection.detectMovie(file, WebServices.TheMovieDB, Locale.ENGLISH, strict);
|
||||||
|
if (options.size() > 0) {
|
||||||
|
return options.get(0);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore and fail
|
debug.log(Level.WARNING, e::toString); // ignore and fail
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -320,76 +323,71 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
RenameAction action = getRenameFunction(option.get(Option.action));
|
RenameAction action = getRenameFunction(option.get(Option.action));
|
||||||
boolean strict = DefaultTypeTransformation.castToBoolean(option.get(Option.strict));
|
boolean strict = DefaultTypeTransformation.castToBoolean(option.get(Option.strict));
|
||||||
|
|
||||||
synchronized (cli) {
|
|
||||||
try {
|
try {
|
||||||
if (input.isEmpty() && !getInputFileMap(parameters).isEmpty()) {
|
if (input.isEmpty() && !getInputFileMap(parameters).isEmpty()) {
|
||||||
return cli.rename(getInputFileMap(parameters), action, asString(option.get(Option.conflict)));
|
return cli.rename(getInputFileMap(parameters), action, asString(option.get(Option.conflict)));
|
||||||
|
} else {
|
||||||
|
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) {
|
||||||
|
printException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
|
||||||
printException(e, false);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<File> getSubtitles(Map<String, ?> parameters) throws Exception {
|
public List<File> getSubtitles(Map<String, ?> parameters) throws Exception {
|
||||||
List<File> input = getInputFileList(parameters);
|
List<File> input = getInputFileList(parameters);
|
||||||
Map<Option, Object> option = getDefaultOptions(parameters);
|
Map<Option, Object> option = getDefaultOptions(parameters);
|
||||||
boolean strict = DefaultTypeTransformation.castToBoolean(option.get(Option.strict));
|
boolean strict = DefaultTypeTransformation.castToBoolean(option.get(Option.strict));
|
||||||
|
|
||||||
synchronized (cli) {
|
|
||||||
try {
|
try {
|
||||||
return cli.getSubtitles(input, asString(option.get(Option.db)), asString(option.get(Option.query)), asString(option.get(Option.lang)), asString(option.get(Option.output)), asString(option.get(Option.encoding)), asString(option.get(Option.format)), strict);
|
return cli.getSubtitles(input, asString(option.get(Option.db)), asString(option.get(Option.query)), asString(option.get(Option.lang)), asString(option.get(Option.output)), asString(option.get(Option.encoding)), asString(option.get(Option.format)), strict);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
printException(e, false);
|
printException(e);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<File> getMissingSubtitles(Map<String, ?> parameters) throws Exception {
|
public List<File> getMissingSubtitles(Map<String, ?> parameters) throws Exception {
|
||||||
List<File> input = getInputFileList(parameters);
|
List<File> input = getInputFileList(parameters);
|
||||||
Map<Option, Object> option = getDefaultOptions(parameters);
|
Map<Option, Object> option = getDefaultOptions(parameters);
|
||||||
boolean strict = DefaultTypeTransformation.castToBoolean(option.get(Option.strict));
|
boolean strict = DefaultTypeTransformation.castToBoolean(option.get(Option.strict));
|
||||||
|
|
||||||
synchronized (cli) {
|
|
||||||
try {
|
try {
|
||||||
return cli.getMissingSubtitles(input, asString(option.get(Option.db)), asString(option.get(Option.query)), asString(option.get(Option.lang)), asString(option.get(Option.output)), asString(option.get(Option.encoding)), asString(option.get(Option.format)), strict);
|
return cli.getMissingSubtitles(input, asString(option.get(Option.db)), asString(option.get(Option.query)), asString(option.get(Option.lang)), asString(option.get(Option.output)), asString(option.get(Option.encoding)), asString(option.get(Option.format)), strict);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
printException(e, false);
|
printException(e);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean check(Map<String, ?> parameters) throws Exception {
|
public boolean check(Map<String, ?> parameters) throws Exception {
|
||||||
List<File> input = getInputFileList(parameters);
|
List<File> input = getInputFileList(parameters);
|
||||||
|
|
||||||
synchronized (cli) {
|
|
||||||
try {
|
try {
|
||||||
return cli.check(input);
|
return cli.check(input);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
printException(e, false);
|
printException(e);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public File compute(Map<String, ?> parameters) throws Exception {
|
public File compute(Map<String, ?> parameters) throws Exception {
|
||||||
List<File> input = getInputFileList(parameters);
|
List<File> input = getInputFileList(parameters);
|
||||||
Map<Option, Object> option = getDefaultOptions(parameters);
|
Map<Option, Object> option = getDefaultOptions(parameters);
|
||||||
|
|
||||||
synchronized (cli) {
|
|
||||||
try {
|
try {
|
||||||
return cli.compute(input, asString(option.get(Option.output)), asString(option.get(Option.encoding)));
|
return cli.compute(input, asString(option.get(Option.output)), asString(option.get(Option.encoding)));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
printException(e, false);
|
printException(e);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<File> extract(Map<String, ?> parameters) throws Exception {
|
public List<File> extract(Map<String, ?> parameters) throws Exception {
|
||||||
List<File> input = getInputFileList(parameters);
|
List<File> input = getInputFileList(parameters);
|
||||||
|
@ -397,36 +395,26 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
FileFilter filter = (FileFilter) DefaultTypeTransformation.castToType(option.get(Option.filter), FileFilter.class);
|
FileFilter filter = (FileFilter) DefaultTypeTransformation.castToType(option.get(Option.filter), FileFilter.class);
|
||||||
boolean forceExtractAll = DefaultTypeTransformation.castToBoolean(option.get(Option.forceExtractAll));
|
boolean forceExtractAll = DefaultTypeTransformation.castToBoolean(option.get(Option.forceExtractAll));
|
||||||
|
|
||||||
synchronized (cli) {
|
|
||||||
try {
|
try {
|
||||||
return cli.extract(input, asString(option.get(Option.output)), asString(option.get(Option.conflict)), filter, forceExtractAll);
|
return cli.extract(input, asString(option.get(Option.output)), asString(option.get(Option.conflict)), filter, forceExtractAll);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
printException(e, false);
|
printException(e);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> fetchEpisodeList(Map<String, ?> parameters) throws Exception {
|
public List<String> fetchEpisodeList(Map<String, ?> parameters) throws Exception {
|
||||||
Map<Option, Object> option = getDefaultOptions(parameters);
|
Map<Option, Object> option = getDefaultOptions(parameters);
|
||||||
|
|
||||||
synchronized (cli) {
|
|
||||||
try {
|
try {
|
||||||
return cli.fetchEpisodeList(asString(option.get(Option.query)), asString(option.get(Option.format)), asString(option.get(Option.db)), asString(option.get(Option.order)), asString(option.get(Option.filter)), asString(option.get(Option.lang)));
|
return cli.fetchEpisodeList(asString(option.get(Option.query)), asString(option.get(Option.format)), asString(option.get(Option.db)), asString(option.get(Option.order)), asString(option.get(Option.filter)), asString(option.get(Option.lang)));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
printException(e, false);
|
printException(e);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMediaInfo(File file, String format) throws Exception {
|
|
||||||
return cli.getMediaInfo(singleton(file), format, null).get(0); // explicitly ignore the --filter option
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getMediaInfo(Collection<?> files, String format) throws Exception {
|
|
||||||
return cli.getMediaInfo(asFileList(files), format, null); // explicitly ignore the --filter option
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getMediaInfo(Map<String, ?> parameters) throws Exception {
|
public Object getMediaInfo(Map<String, ?> parameters) throws Exception {
|
||||||
List<File> input = getInputFileList(parameters);
|
List<File> input = getInputFileList(parameters);
|
||||||
|
@ -435,19 +423,21 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Option, Object> option = getDefaultOptions(parameters);
|
Map<Option, Object> option = getDefaultOptions(parameters);
|
||||||
synchronized (cli) {
|
|
||||||
try {
|
try {
|
||||||
List<String> lines = cli.getMediaInfo(input, asString(option.get(Option.format)), asString(option.get(Option.filter)));
|
return cli.getMediaInfo(input, asString(option.get(Option.format)), asString(option.get(Option.filter)));
|
||||||
if (parameters.containsKey("file") && !(parameters.get("file") instanceof Collection)) {
|
|
||||||
return lines.get(0); // HACK for script backwards compatibility
|
|
||||||
} else {
|
|
||||||
return lines;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
printException(e, false);
|
printException(e);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMediaInfo(File file, String format) throws Exception {
|
||||||
|
return cli.getMediaInfo(singleton(file), format, null).get(0); // explicitly ignore the --filter option
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getMediaInfo(Collection<?> files, String format) throws Exception {
|
||||||
|
return cli.getMediaInfo(asFileList(files), format, null); // explicitly ignore the --filter option
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<File> getInputFileList(Map<String, ?> parameters) {
|
private List<File> getInputFileList(Map<String, ?> parameters) {
|
||||||
|
|
Loading…
Reference in New Issue