1 package saccubus.prompt;
3 import java.io.IOException;
4 import java.util.concurrent.Callable;
5 import java.util.concurrent.ExecutorService;
6 import java.util.concurrent.Executors;
7 import java.util.concurrent.Future;
8 import org.apache.commons.cli.BasicParser;
9 import org.apache.commons.cli.CommandLine;
10 import org.apache.commons.cli.CommandLineParser;
11 import org.apache.commons.cli.HelpFormatter;
12 import org.apache.commons.cli.Option;
13 import org.apache.commons.cli.OptionBuilder;
14 import org.apache.commons.cli.Options;
15 import saccubus.converter.Download;
16 import saccubus.converter.classic.profile.Profile;
24 * 説明: ニコニコ動画の動画をコメントつきで保存
28 * 著作権: Copyright (c) 2007 PSI
40 public static void main(String[] args) throws IOException {
41 // 第1引数がメールアドレスと思しき時は昔の引数であるとみなしてパース、実行する.
42 if (args.length > 0 && args[0].contains("@")) {
43 doWithOldArguments(args);
47 new Prompt().execute(args);
50 public void execute(String[] args) throws IOException {
51 Options options = createOptions(args);
54 CommandLineParser parser = new BasicParser();
55 CommandLine cmd = parser.parse(options, args);
56 profile = createExecuteOption(cmd);
57 } catch (Exception e) {
58 HelpFormatter hf = new HelpFormatter();
59 hf.printHelp("java -jar Saccubus.jar [opts]", options);
61 throw new IOException(e);
64 Download conv = new Download("dummy0", profile);
65 ExecutorService es = Executors.newSingleThreadExecutor();
66 Future<Boolean> future = es.submit((Callable<Boolean>) conv);
68 boolean res = future.get().booleanValue();
70 throw new IOException("ffmpeg変換処理が正常に終了しませんでした。");
72 } catch (Exception ex) {
73 throw new IOException("取得失敗", ex);
75 System.out.println("Finished.");
78 private Options createOptions(String[] args) {
79 Options options = new Options();
80 // Option id = OptionBuilder.withArgName("mail").hasArg().withDescription("ニコニコ動画ログインID(メールアドレス)").create("id");
81 // Option password = OptionBuilder.withArgName("password").hasArg().withDescription("ニコニコ動画ログインパスワード").
82 // create("password");
83 // Option video = OptionBuilder.withArgName("id").hasArg().withDescription("ニコニコ動画ビデオID").create("video");
84 Option videoFile = OptionBuilder.withArgName("file").hasArg().withDescription("動画ファイル").create("file_video");
85 Option commentFile = OptionBuilder.withArgName("file").hasArg().withDescription("コメントファイル").
86 create("file_comment");
87 Option tcommentFile = OptionBuilder.withArgName("file").hasArg().withDescription("投稿者コメントファイル").
88 create("file_tcomment");
89 Option outputFile = OptionBuilder.withArgName("file").hasArg().withDescription("出力ファイル").create("file_output");
90 Option ffmpeg = OptionBuilder.withArgName("option").hasArg().withDescription("ffmpeg変換オプション").create("ffmpeg");
91 // options.addOption(id);
92 // options.addOption(password);
93 // options.addOption(video);
94 options.addOption(videoFile);
95 options.addOption(commentFile);
96 options.addOption(tcommentFile);
97 options.addOption(outputFile);
98 options.addOption(ffmpeg);
102 private Profile createExecuteOption(CommandLine cmd) throws IOException {
103 // final String mail = "dmy";
104 // final String pass = "dmy";
105 // final String video = cmd.getOptionValue("file_video");
106 // final String comm = cmd.getOptionValue("file_comment");
107 // final String tcomm = cmd.getOptionValue("file_tcomment");
108 // final String output = cmd.getOptionValue("file_output");
109 // final String ff = cmd.getOptionValue("ffmpeg");
112 //// SProperties setting = SProperties.loadSetting(mail, pass);
113 //// Profile p = setting.toProfile();
115 // GeneralSetting general = p.getGeneralSetting();
116 // LoginInfo loginInfo = p.getLoginInfo();
117 //// InputFileSetting videoSetting = p.getVideoSetting();
118 //// InputFileSetting commentSetting = p.getCommentSetting();
119 // CommentGetInfo commentGetInfo = p.getCommentGetInfo();
120 //// InputFileSetting tcommentSetting = p.getTcommentSetting();
121 //// OutputFileSetting outputFileSetting = p.getOutputFileSetting();
122 // Ffmpeg ffmpeg = p.getFfmpeg();
124 // FfmpegOption newFfmpegOption = new FfmpegOption(ffmpeg.getFfmpegOption().getExtOption(), "", "", ff, "", false,
126 // InputFileSetting newVideoSetting = new InputFileSetting(new SFile(true, new File(video)), false, false, commentGetInfo, -1);
127 // InputFileSetting newCommentSetting = new InputFileSetting(new SFile(true, new File(comm)), false, false, commentGetInfo, -1);
128 // InputFileSetting newTcommentSetting = new InputFileSetting(new SFile(true, new File(tcomm)), false, false, commentGetInfo, -1);
129 // OutputFileSetting newOutputFileSetting = new OutputFileSetting(new SFile(true, new File(output)), true, false,
131 // Ffmpeg newFfmpeg = new Ffmpeg(ffmpeg.getFfmpeg(), ffmpeg.getVhook(), newFfmpegOption, ffmpeg.isVhookDisabled(), ffmpeg.
132 // getMaxNumOfComment(), ffmpeg.getFont(), ffmpeg.getFontIndex(), ffmpeg.getShadowIndex(), ffmpeg.
133 // isShowConverting(), ffmpeg.isSelfAdjustFontSize(), ffmpeg.isCommentOpaque(), ffmpeg.getNgSetting());
135 // p = new Profile(general, loginInfo, newVideoSetting, newCommentSetting, commentGetInfo, newTcommentSetting,
136 // newOutputFileSetting, newFfmpeg);
145 private static void doWithOldArguments(String[] args) throws IOException {
146 String mail = args[0];
147 String pass = args[1];
148 String tag = args[2];
149 String time = args.length < 4 ? "" : args[3];
151 // SProperties setting = SProperties.loadSetting(mail, pass);
152 // Converter conv = new Converter(tag, setting.toProfile(), TextProgressListener.EMPTY_LISTENER, new ConvertStopFlag(
153 // ConvertStopFlag.StateChangeListener.EMPTY_LISTENER));
154 Download conv = new Download(tag, null/*この部分*/);
155 System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
156 System.out.println("Saccubus on CUI");
157 System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
158 System.out.println("Mailaddr: " + mail);
159 System.out.println("Password: hidden");
160 System.out.println("VideoID: " + tag);
161 System.out.println("WaybackTime: " + time);
162 System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
164 System.out.println("Finished.");