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