application.title=Saccubus\r
application.vendor=yuki\r
build.classes.dir=${build.dir}/classes\r
-build.classes.excludes=**/*.java,**/*.form\r
+build.classes.excludes=\r
# This directory is removed when the project is cleaned:\r
build.dir=build\r
build.generated.dir=${build.dir}/generated\r
${libs.Commons-Collections.classpath}:\\r
${libs.toplink.classpath}:\\r
${libs.HttpClient4.0.classpath}:\\r
- ${libs.H2_DB.classpath}\r
+ ${libs.H2_DB.classpath}:\\r
+ ${libs.Commons-CLI.classpath}\r
# Space-separated list of extra javac options\r
javac.compilerargs=\r
javac.deprecation=false\r
main.class=saccubus.Saccubus\r
manifest.file=manifest.mf\r
meta.inf.dir=${src.dir}/META-INF\r
+no.dependencies=true\r
platform.active=default_platform\r
project.NicoBrowser=../NicoLib/NicoBrowser/release_20091201_ver_0_4_0\r
reference.NicoBrowser.jar=${project.NicoBrowser}/dist/NicoBrowser.jar\r
public interface StateChangeListener {
void changeState(State s);
+ /**
+ * StateChangeListener\82Ì\89½\82à\82µ\82È\82¢\83o\81[\83W\83\87\83\93\82Ì\8eÀ\91\95.
+ */
+ static final ConvertStopFlag.StateChangeListener EMPTY_LISTENER = new ConvertStopFlag.StateChangeListener() {
+
+ public void changeState(State s) {
+ }
+ };
}
public enum State {
public static final String VERSION = "1.22r NicoBrowser\8ag\92£ 1.3.5";
public static final Image WinIcon = Toolkit.getDefaultToolkit().createImage(saccubus.MainFrame.class.getResource(
"icon32.png"));
+ // TODO GUI\82ª\96³\82¢\82½\82ß\83t\83B\81[\83\8b\83h\82É\95Û\8e\9d.
+ private File tempDir;
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JMenuBar jMenuBar1 = new JMenuBar();
private void setSetting(SProperties setting) {
// \8aî\96{\90Ý\92è
final BasicSetting basic = setting.getBasicSetting();
+ tempDir = basic.getTempDir();
MailAddrField.setText(basic.getUser().getMail());
PasswordField.setText(basic.getUser().getPassword());
// \83v\83\8d\83L\83V\8aÖ\98A
} catch (NumberFormatException e) {
proxyPort = -1;
}
- return new BasicSetting(mail, pass, proxyUse, proxyHost, proxyPort);
+ // TODO \8dì\8bÆ\97p\83f\83B\83\8c\83N\83g\83\8a\82Ì\90Ý\92èGUI\96³\82µ
+ return new BasicSetting(tempDir, mail, pass, proxyUse, proxyHost, proxyPort);
}
private InputVideoSetting getInputVideoSetting() {
public static void main(String[] args) throws IOException {
//\88ø\90\94\82ª\97L\82é\8fê\8d\87\82ÍCUI\82Å\8bN\93®
if (args.length > 0) {
- Prompt prompt = new Prompt();
- prompt.main(args);
+ Prompt.main(args);
return;
}
//\88ø\90\94\82ª\96³\82¢\8fê\8d\87\82ÍGUI\82Å\8bN\93®
import saccubus.converter.filegetter.FileInstanciator;
import java.io.File;
import java.io.IOException;
+import java.util.concurrent.Callable;
import saccubus.ConvertStopFlag;
import saccubus.net.TextProgressListener;
* @author \96¢\93ü\97Í
* @version 1.0
*/
-public class Converter extends AbstractCommand implements Runnable {
+public class Converter extends AbstractCommand implements Runnable, Callable<Boolean> {
private static final String VIDEO_URL_PARSER = "http://www.nicovideo.jp/watch/";
private final Profile Setting;
Setting = setting;
}
- @Override
+ public Boolean call() throws Exception {
+ boolean result = false;
+ try {
+ result = runConvert();
+ } finally {
+ getStopFlag().finished();
+ }
+ return Boolean.valueOf(result);
+ }
+
public void run() {
try {
- runConvert();
+ call();
} catch (Exception ex) {
String text = (ex.getMessage() != null) ? ex.getMessage() : "\97\\8aú\82µ\82È\82¢\83G\83\89\81[\94\90¶\82Ì\82½\82ß\92\86\92f\82µ\82Ü\82µ\82½\81B";
sendText(text);
ex.printStackTrace();
- } finally {
- getStopFlag().finished();
}
}
- private void runConvert() throws IOException, InterruptedException {
+ private boolean runConvert() throws IOException, InterruptedException {
if (!Setting.shouldRun()) {
sendText("\89½\82à\82·\82é\82±\82Æ\82ª\82 \82è\82Ü\82¹\82ñ");
- return;
+ return true;
}
validSetting();
if (!Setting.needsConvert()) {
sendText("\93®\89æ\81E\83R\83\81\83\93\83g\82ð\95Û\91¶\82µ\81A\95Ï\8a·\82Í\8ds\82¢\82Ü\82¹\82ñ\82Å\82µ\82½\81B");
- return;
+ return true;
}
if (!videoFile.isFile()) {
}
boolean res = new FfmpegCommand(getListener(), getStopFlag(), commentFile, tcommFile, videoFile,
- convertedVideoFile, Setting.getFfmpeg()).execute();
+ convertedVideoFile, Setting.getFfmpeg(), Setting.getGeneralSetting()).execute();
if (res) {
if (Setting.getCommentSetting().isDelete()) {
commentFile.delete();
tcommFile.delete();
}
}
+ return res;
}
private FileInstanciator createInstanciator() throws IOException {
import saccubus.conv.ConvertToVideoHook;
import saccubus.converter.profile.Ffmpeg;
import saccubus.converter.profile.FfmpegOption;
+import saccubus.converter.profile.GeneralSetting;
import saccubus.converter.profile.NgSetting;
import saccubus.net.TextProgressListener;
import yukihane.swf.Cws2Fws;
private final Ffmpeg ffmpeg;
FfmpegCommand(TextProgressListener listener, ConvertStopFlag flag, File commentFile, File tcommFile,
- File videoFile, File convertedVideoFile, Ffmpeg ffmpeg) throws IOException {
+ File videoFile, File convertedVideoFile, Ffmpeg ffmpeg,GeneralSetting general) throws IOException {
super(listener, flag);
this.commentFile = commentFile;
this.tcommFile = tcommFile;
this.convertedVideoFile = convertedVideoFile;
this.ffmpeg = ffmpeg;
- File tmpDir = new File("tmp");
+ File tmpDir = general.getTempDir();
commentMiddleFile = File.createTempFile("vhk", ".tmp", tmpDir);
tcommMiddleFile = File.createTempFile("tcom", ".tmp", tmpDir);
TMP_CWS = File.createTempFile("cws", ".swf", tmpDir);
--- /dev/null
+/* $Id$ */
+package saccubus.converter.profile;
+
+import java.io.File;
+
+public class GeneralSetting {
+
+ private final File tempDir;
+
+ public GeneralSetting(File tempDir) {
+ this.tempDir = tempDir;
+ }
+
+ public File getTempDir() {
+ return tempDir;
+ }
+}
*/
public class Profile {
+ private final GeneralSetting generalSetting;
private final LoginInfo loginInfo;
private final InputFileSetting videoSetting;
private final InputFileSetting commentSetting;
private final Ffmpeg ffmpeg;
public Profile(
+ GeneralSetting generalSetting,
LoginInfo loginInfo,
InputFileSetting videoSetting,
InputFileSetting commentSetting,
InputFileSetting tcommentSetting,
OutputFileSetting outputFileSetting,
Ffmpeg ffmpeg) {
+ this.generalSetting = generalSetting;
this.loginInfo = loginInfo;
this.videoSetting = videoSetting;
this.commentSetting = commentSetting;
public Ffmpeg getFfmpeg() {
return ffmpeg;
}
+
+ public GeneralSetting getGeneralSetting() {
+ return generalSetting;
+ }
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
-
package saccubus.net;
/**
*
* @author yuki
*/
-public interface TextProgressListener {
+public interface TextProgressListener {
+
void setText(String text);
+ /**
+ * TextProgressListener\82Ì\89½\82à\82µ\82È\82¢\83o\81[\83W\83\87\83\93\82Ì\8eÀ\91\95.
+ */
+ static final TextProgressListener EMPTY_LISTENER = new TextProgressListener() {
+
+ public void setText(String text) {
+ }
+ };
}
package saccubus.prompt;
+import java.io.File;
import java.io.IOException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.commons.cli.BasicParser;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
import saccubus.ConvertStopFlag;
import saccubus.ConvertStopFlag.State;
import saccubus.converter.Converter;
+import saccubus.converter.filegetter.LoginInfo;
+import saccubus.converter.profile.CommentGetInfo;
+import saccubus.converter.profile.Ffmpeg;
+import saccubus.converter.profile.FfmpegOption;
+import saccubus.converter.profile.GeneralSetting;
+import saccubus.converter.profile.InputFileSetting;
+import saccubus.converter.profile.OutputFileSetting;
+import saccubus.converter.profile.Profile;
+import saccubus.converter.profile.SFile;
import saccubus.properties.SProperties;
import saccubus.net.TextProgressListener;
* @version 1.0
*/
public class Prompt {
- public static void main(String[] args) throws IOException {
- TextProgressListener sl = new TextProgressListener() {
- public void setText(String text) {
- }
- };
- ConvertStopFlag.StateChangeListener scl = new ConvertStopFlag.StateChangeListener() {
+ public static void main(String[] args) throws IOException {
+ // \91æ1\88ø\90\94\82ª\83\81\81[\83\8b\83A\83h\83\8c\83X\82Æ\8ev\82µ\82«\8e\9e\82Í\90Ì\82Ì\88ø\90\94\82Å\82 \82é\82Æ\82Ý\82È\82µ\82Ä\83p\81[\83X\81A\8eÀ\8ds\82·\82é.
+ if (args.length > 0 && args[0].contains("@")) {
+ doWithOldArguments(args);
+ return;
+ }
+
+ new Prompt().execute(args);
+ }
+
+ public void execute(String[] args) throws IOException {
+ execute(args, TextProgressListener.EMPTY_LISTENER, ConvertStopFlag.StateChangeListener.EMPTY_LISTENER);
+ }
- public void changeState(State s) {
+ public void execute(String[] args, TextProgressListener tpl, ConvertStopFlag.StateChangeListener scl) throws
+ IOException {
+ Options options = createOptions(args);
+ Profile profile;
+ try {
+ CommandLineParser parser = new BasicParser();
+ CommandLine cmd = parser.parse(options, args);
+ profile = createExecuteOption(cmd);
+ } catch (Exception e) {
+ HelpFormatter hf = new HelpFormatter();
+ hf.printHelp("java -jar Saccubus.jar [opts]", options);
+ System.out.flush();
+ throw new IOException(e);
+ }
+
+ Converter conv = new Converter("dummy", "", profile, tpl, new ConvertStopFlag(scl));
+ ExecutorService es = Executors.newSingleThreadExecutor();
+ Future<Boolean> future = es.submit((Callable<Boolean>) conv);
+ try {
+ boolean res = future.get().booleanValue();
+ if (!res) {
+ throw new IOException("ffmpeg\95Ï\8a·\8f\88\97\9d\82ª\90³\8fí\82É\8fI\97¹\82µ\82Ü\82¹\82ñ\82Å\82µ\82½\81B");
}
- };
- String mail = args[0];
- String pass = args[1];
- String tag = args[2];
- String time = args.length < 4 ? "" : args[3];
- SProperties setting = SProperties.loadSetting(mail, pass);
- Converter conv = new Converter(tag, time, setting.toProfile(), sl, new ConvertStopFlag(scl));
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- System.out.println("Saccubus on CUI");
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- System.out.println("Mailaddr: " + mail);
- System.out.println("Password: hidden");
- System.out.println("VideoID: " + tag);
- System.out.println("WaybackTime: " + time);
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- conv.run();
- System.out.println("Finished.");
- }
+ } catch (Exception ex) {
+ throw new IOException("\8eæ\93¾\8e¸\94s", ex);
+ }
+ System.out.println("Finished.");
+ }
+
+ private Options createOptions(String[] args) {
+ Options options = new Options();
+// Option id = OptionBuilder.withArgName("mail").hasArg().withDescription("\83j\83R\83j\83R\93®\89æ\83\8d\83O\83C\83\93ID(\83\81\81[\83\8b\83A\83h\83\8c\83X)").create("id");
+// Option password = OptionBuilder.withArgName("password").hasArg().withDescription("\83j\83R\83j\83R\93®\89æ\83\8d\83O\83C\83\93\83p\83X\83\8f\81[\83h").
+// create("password");
+// Option video = OptionBuilder.withArgName("id").hasArg().withDescription("\83j\83R\83j\83R\93®\89æ\83r\83f\83IID").create("video");
+ Option videoFile = OptionBuilder.withArgName("file").hasArg().withDescription("\93®\89æ\83t\83@\83C\83\8b").create("file_video");
+ Option commentFile = OptionBuilder.withArgName("file").hasArg().withDescription("\83R\83\81\83\93\83g\83t\83@\83C\83\8b").
+ create("file_comment");
+ Option tcommentFile = OptionBuilder.withArgName("file").hasArg().withDescription("\93\8a\8de\8eÒ\83R\83\81\83\93\83g\83t\83@\83C\83\8b").
+ create("file_tcomment");
+ Option outputFile = OptionBuilder.withArgName("file").hasArg().withDescription("\8fo\97Í\83t\83@\83C\83\8b").create("file_output");
+ Option ffmpeg = OptionBuilder.withArgName("option").hasArg().withDescription("ffmpeg\95Ï\8a·\83I\83v\83V\83\87\83\93").create("ffmpeg");
+// options.addOption(id);
+// options.addOption(password);
+// options.addOption(video);
+ options.addOption(videoFile);
+ options.addOption(commentFile);
+ options.addOption(tcommentFile);
+ options.addOption(outputFile);
+ options.addOption(ffmpeg);
+ return options;
+ }
+
+ private Profile createExecuteOption(CommandLine cmd) throws IOException {
+ final String mail = "dmy";
+ final String pass = "dmy";
+ final String video = cmd.getOptionValue("file_video");
+ final String comm = cmd.getOptionValue("file_comment");
+ final String tcomm = cmd.getOptionValue("file_tcomment");
+ final String output = cmd.getOptionValue("file_output");
+ final String ff = cmd.getOptionValue("ffmpeg");
+
+ SProperties setting = SProperties.loadSetting(mail, pass);
+ Profile p = setting.toProfile();
+ GeneralSetting general = p.getGeneralSetting();
+ LoginInfo loginInfo = p.getLoginInfo();
+// InputFileSetting videoSetting = p.getVideoSetting();
+// InputFileSetting commentSetting = p.getCommentSetting();
+ CommentGetInfo commentGetInfo = p.getCommentGetInfo();
+// InputFileSetting tcommentSetting = p.getTcommentSetting();
+// OutputFileSetting outputFileSetting = p.getOutputFileSetting();
+ Ffmpeg ffmpeg = p.getFfmpeg();
+
+ FfmpegOption newFfmpegOption = new FfmpegOption(ffmpeg.getFfmpegOption().getExtOption(), "", "", ff);
+ InputFileSetting newVideoSetting = new InputFileSetting(new SFile(true, new File(video)), false, false);
+ InputFileSetting newCommentSetting = new InputFileSetting(new SFile(true, new File(comm)), false, false);
+ InputFileSetting newTcommentSetting = new InputFileSetting(new SFile(true, new File(tcomm)), false, false);
+ OutputFileSetting newOutputFileSetting = new OutputFileSetting(new SFile(true, new File(output)), true, false,
+ true, true);
+ Ffmpeg newFfmpeg = new Ffmpeg(ffmpeg.getFfmpeg(), ffmpeg.getVhook(), newFfmpegOption, ffmpeg.isVhookDisabled(), ffmpeg.
+ getMaxNumOfComment(), ffmpeg.getFont(), ffmpeg.getFontIndex(), ffmpeg.getShadowIndex(), ffmpeg.
+ isShowConverting(), ffmpeg.isSelfAdjustFontSize(), ffmpeg.isCommentOpaque(), ffmpeg.getNgSetting());
+
+ p = new Profile(general, loginInfo, newVideoSetting, newCommentSetting, commentGetInfo, newTcommentSetting,
+ newOutputFileSetting, newFfmpeg);
+
+ return p;
+ }
+
+ /**
+ * \90Ì\82Ì\88ø\90\94\8c`\8e®\82Å\83v\83\8d\83O\83\89\83\80\82ð\8eÀ\8ds\82·\82é.
+ */
+ private static void doWithOldArguments(String[] args) throws IOException {
+ String mail = args[0];
+ String pass = args[1];
+ String tag = args[2];
+ String time = args.length < 4 ? "" : args[3];
+ SProperties setting = SProperties.loadSetting(mail, pass);
+ Converter conv = new Converter(tag, time, setting.toProfile(), TextProgressListener.EMPTY_LISTENER, new ConvertStopFlag(
+ ConvertStopFlag.StateChangeListener.EMPTY_LISTENER));
+ System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
+ System.out.println("Saccubus on CUI");
+ System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
+ System.out.println("Mailaddr: " + mail);
+ System.out.println("Password: hidden");
+ System.out.println("VideoID: " + tag);
+ System.out.println("WaybackTime: " + time);
+ System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
+ conv.run();
+ System.out.println("Finished.");
+ }
}
/* $Id$ */
package saccubus.properties;
+import java.io.File;
import java.util.Properties;
import saccubus.converter.profile.User;
*/
public class BasicSetting {
+ private static final String PROP_TEMP_DIR = "TempDir";
private static final String PROP_MAILADDR = "MailAddress";
private static final String PROP_PASSWORD = "Password";
private static final String PROP_USE_PROXY = "UseProxy";
private static final String PROP_PROXY = "Proxy";
private static final String PROP_PROXY_PORT = "ProxyPort";
+ private final File tempDir;
private final User user;
private final boolean proxyUse;
private final String proxyHost;
private final int proxyPort;
- public BasicSetting(String mail, String password, boolean proxyUse, String proxyHost, int proxyPort) {
+ public BasicSetting(File tempDir, String mail, String password, boolean proxyUse, String proxyHost, int proxyPort) {
+ this.tempDir = tempDir;
this.user = new User(mail, password);
this.proxyUse = proxyUse;
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
}
+ public File getTempDir() {
+ return tempDir;
+ }
+
public User getUser() {
return user;
}
}
public void save(Properties prop) {
+ prop.setProperty(PROP_TEMP_DIR, getTempDir().getPath());
prop.setProperty(PROP_MAILADDR, getUser().getMail());
prop.setProperty(PROP_PASSWORD, getUser().getPassword());
prop.setProperty(PROP_USE_PROXY, Boolean.toString(isProxyUse()));
}
public static BasicSetting load(Properties prop, String user, String pass) {
+ String tempDir = prop.getProperty(PROP_TEMP_DIR, ".");
if (user == null) {
user = prop.getProperty(PROP_MAILADDR, "");
}
String proxyHost = prop.getProperty(PROP_PROXY, "");
int proxyPort = Integer.parseInt(prop.getProperty(PROP_PROXY_PORT, "-1"));
- return new BasicSetting(user, pass, proxyUse, proxyHost, proxyPort);
+ return new BasicSetting(new File(tempDir), user, pass, proxyUse, proxyHost, proxyPort);
}
}
import saccubus.converter.profile.CommentGetInfo;
import saccubus.converter.profile.Ffmpeg;
import saccubus.converter.profile.FfmpegOption;
+import saccubus.converter.profile.GeneralSetting;
import saccubus.converter.profile.InputFileSetting;
import saccubus.converter.profile.OutputFileSetting;
import saccubus.converter.profile.Profile;
private class ProfileBuilder {
private Profile build() throws IOException {
+ GeneralSetting generalSetting = buildGeneralSetting();
LoginInfo loginInfo = buildLoginInfo();
InputFileSetting videoSetting = buildVideoSetting();
InputFileSetting commentSetting = buildCommentSetting();
OutputFileSetting outputFileSetting = buildOutputFileSetting();
Ffmpeg ffmpeg = buildFfmpeg();
- return new Profile(loginInfo, videoSetting, commentSetting, commentGetInfo, tcommentSetting,
+ return new Profile(generalSetting, loginInfo, videoSetting, commentSetting, commentGetInfo, tcommentSetting,
outputFileSetting, ffmpeg);
}
+ private GeneralSetting buildGeneralSetting() {
+ final BasicSetting basic = getBasicSetting();
+ return new GeneralSetting(basic.getTempDir());
+ }
+
private LoginInfo buildLoginInfo() {
final BasicSetting basic = getBasicSetting();
Proxy proxy = Proxy.NO_PROXY;