2011-09-09 10:50:01 -04:00
|
|
|
|
|
|
|
package net.sourceforge.filebot.cli;
|
|
|
|
|
|
|
|
|
|
|
|
import static java.util.Collections.*;
|
|
|
|
import static net.sourceforge.tuned.FileUtilities.*;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2011-09-14 14:13:34 -04:00
|
|
|
import java.nio.charset.Charset;
|
2011-09-09 10:50:01 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2011-09-13 14:16:38 -04:00
|
|
|
import java.util.logging.Level;
|
2011-09-09 10:50:01 -04:00
|
|
|
|
|
|
|
import javax.script.ScriptException;
|
|
|
|
|
|
|
|
import org.kohsuke.args4j.Argument;
|
|
|
|
import org.kohsuke.args4j.Option;
|
|
|
|
|
|
|
|
import net.sourceforge.filebot.MediaTypes;
|
|
|
|
import net.sourceforge.filebot.format.ExpressionFormat;
|
|
|
|
import net.sourceforge.filebot.ui.Language;
|
|
|
|
|
|
|
|
|
|
|
|
public class ArgumentBean {
|
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
@Option(name = "-rename", usage = "Rename episode/movie files", metaVar = "fileset")
|
|
|
|
public boolean rename = false;
|
2011-09-09 10:50:01 -04:00
|
|
|
|
2011-09-14 18:34:54 -04:00
|
|
|
@Option(name = "--db", usage = "Episode/Movie database", metaVar = "[TVRage, AniDB, TheTVDB] or [OpenSubtitles, TheMovieDB]")
|
2011-09-14 14:13:34 -04:00
|
|
|
public String db;
|
2011-09-09 10:50:01 -04:00
|
|
|
|
|
|
|
@Option(name = "--format", usage = "Episode naming scheme", metaVar = "expression")
|
2011-09-14 14:13:34 -04:00
|
|
|
public String format;
|
2011-09-09 10:50:01 -04:00
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
@Option(name = "-non-strict", usage = "Use less strict matching")
|
|
|
|
public boolean nonStrict = false;
|
2011-09-09 10:50:01 -04:00
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
@Option(name = "-get-subtitles", usage = "Fetch subtitles", metaVar = "fileset")
|
|
|
|
public boolean getSubtitles;
|
2011-09-09 10:50:01 -04:00
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
@Option(name = "--q", usage = "Search query", metaVar = "title")
|
2011-09-14 14:13:34 -04:00
|
|
|
public String query;
|
2011-09-13 14:16:38 -04:00
|
|
|
|
|
|
|
@Option(name = "--lang", usage = "Language", metaVar = "2-letter language code")
|
2011-09-09 10:50:01 -04:00
|
|
|
public String lang = "en";
|
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
@Option(name = "-check", usage = "Create/Check verification file", metaVar = "fileset")
|
|
|
|
public boolean check;
|
|
|
|
|
2011-09-14 18:34:54 -04:00
|
|
|
@Option(name = "--output", usage = "Output options", metaVar = "[sfv, md5, sha1]")
|
2011-09-14 14:13:34 -04:00
|
|
|
public String output;
|
2011-09-13 14:16:38 -04:00
|
|
|
|
2011-09-14 18:34:54 -04:00
|
|
|
@Option(name = "--encoding", usage = "Character encoding", metaVar = "[UTF-8, windows-1252, GB18030, etc]")
|
2011-09-14 14:13:34 -04:00
|
|
|
public String encoding;
|
|
|
|
|
2011-09-14 18:34:54 -04:00
|
|
|
@Option(name = "--log", usage = "Log level", metaVar = "[all, config, info, warning]")
|
2011-09-13 14:16:38 -04:00
|
|
|
public String log = "all";
|
|
|
|
|
2011-09-09 10:50:01 -04:00
|
|
|
@Option(name = "-help", usage = "Print this help message")
|
|
|
|
public boolean help = false;
|
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
@Option(name = "-open", usage = "Open file in GUI", metaVar = "file")
|
2011-09-09 10:50:01 -04:00
|
|
|
public boolean open = false;
|
|
|
|
|
|
|
|
@Option(name = "-clear", usage = "Clear application settings")
|
|
|
|
public boolean clear = false;
|
|
|
|
|
|
|
|
@Argument
|
|
|
|
public List<String> arguments = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
|
|
|
public boolean runCLI() {
|
2011-09-13 14:16:38 -04:00
|
|
|
return getSubtitles || rename || check;
|
2011-09-09 10:50:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean openSFV() {
|
|
|
|
return open && containsOnly(getFiles(false), MediaTypes.getDefaultFilter("verification"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
public boolean printHelp() {
|
|
|
|
return help;
|
2011-09-09 10:50:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
public boolean clearUserData() {
|
|
|
|
return clear;
|
2011-09-09 10:50:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ExpressionFormat getEpisodeFormat() throws ScriptException {
|
2011-09-14 14:13:34 -04:00
|
|
|
return format != null ? new ExpressionFormat(format) : null;
|
2011-09-09 10:50:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Language getLanguage() {
|
|
|
|
Language language = Language.getLanguage(lang);
|
|
|
|
|
|
|
|
if (language == null)
|
|
|
|
throw new IllegalArgumentException("Illegal language code: " + lang);
|
|
|
|
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-14 14:13:34 -04:00
|
|
|
public Charset getEncoding() {
|
|
|
|
return encoding != null ? Charset.forName(encoding) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
public Level getLogLevel() {
|
|
|
|
return Level.parse(log.toUpperCase());
|
2011-09-09 10:50:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
public List<File> getFiles(boolean resolveFolders) {
|
|
|
|
List<File> files = new ArrayList<File>();
|
2011-09-09 10:50:01 -04:00
|
|
|
|
2011-09-13 14:16:38 -04:00
|
|
|
// resolve given paths
|
|
|
|
for (String argument : arguments) {
|
|
|
|
try {
|
|
|
|
File file = new File(argument).getCanonicalFile();
|
|
|
|
|
|
|
|
// resolve folders
|
|
|
|
files.addAll(resolveFolders && file.isDirectory() ? listFiles(singleton(file), 0, false) : singleton(file));
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new IllegalArgumentException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return files;
|
2011-09-09 10:50:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|