OSDN Git Service

39ebf6b0bb59f5f3e7e07db69c762108d5843498
[coroid/inqubus.git] / frontend / src / saccubus / prompt / Prompt.java
1 package saccubus.prompt;
2
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;
18
19 /**
20  * <p>
21  * タイトル: さきゅばす
22  * </p>
23  *
24  * <p>
25  * 説明: ニコニコ動画の動画をコメントつきで保存
26  * </p>
27  *
28  * <p>
29  * 著作権: Copyright (c) 2007 PSI
30  * </p>
31  *
32  * <p>
33  * 会社名:
34  * </p>
35  *
36  * @author 未入力
37  * @version 1.0
38  */
39 public class Prompt {
40
41     public static void main(String[] args) throws Exception {
42         // 第1引数がメールアドレスと思しき時は昔の引数であるとみなしてパース、実行する.
43         if (args.length > 0 && args[0].contains("@")) {
44             doWithOldArguments(args);
45             return;
46         }
47
48         new Prompt().execute(args);
49     }
50
51     public void execute(String[] args) throws IOException {
52         Options options = createOptions(args);
53         Profile profile;
54         try {
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);
61             System.out.flush();
62             throw new IOException(e);
63         }
64
65         Download conv = new Download(profile, "dummy0");
66         ExecutorService es = Executors.newSingleThreadExecutor();
67         final Future<DownloadResult> future = es.submit(conv);
68         try {
69             boolean res = future.get().getResultValue();
70             if (!res) {
71                 throw new IOException("ffmpeg変換処理が正常に終了しませんでした。");
72             }
73         } catch (Exception ex) {
74             throw new IOException("取得失敗", ex);
75         }
76         System.out.println("Finished.");
77     }
78
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);
100         return options;
101     }
102
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");
111 //
112 //        // TODO 後で実装
113 ////        SProperties setting = SProperties.loadSetting(mail, pass);
114 ////        Profile p = setting.toProfile();
115 //        Profile p = null;
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();
124 //
125 //        FfmpegOption newFfmpegOption = new FfmpegOption(ffmpeg.getFfmpegOption().getExtOption(), "", "", ff, "", false,
126 //                "", "", 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,
131 //                true, true);
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());
135 //
136 //        p = new Profile(general, loginInfo, newVideoSetting, newCommentSetting, commentGetInfo, newTcommentSetting,
137 //                newOutputFileSetting, newFfmpeg);
138 //
139 //        return p;
140         return null;
141     }
142
143     /**
144      * 昔の引数形式でプログラムを実行する.
145      */
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];
151         // TODO
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("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
164         conv.call();
165         System.out.println("Finished.");
166     }
167 }