OSDN Git Service

コマンドラインからのダウンロード処理実装
[coroid/inqubus.git] / frontend / src / saccubus / prompt / Prompt.java
1 package saccubus.prompt;
2
3 import java.io.File;
4 import java.io.IOException;
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.FfmpegOption;
16 import saccubus.util.WayBackTimeParser;
17 import saccubus.worker.impl.download.Download;
18 import saccubus.worker.impl.download.DownloadResult;
19 import saccubus.worker.profile.DownloadProfile;
20
21 /**
22  * <p>
23  * タイトル: さきゅばす
24  * </p>
25  *
26  * <p>
27  * 説明: ニコニコ動画の動画をコメントつきで保存
28  * </p>
29  *
30  * <p>
31  * 著作権: Copyright (c) 2007 PSI
32  * </p>
33  *
34  * <p>
35  * 会社名:
36  * </p>
37  *
38  * @author 未入力
39  * @version 1.0
40  */
41 public class Prompt {
42
43     public static void main(String[] args) throws Exception {
44         // 第1引数がメールアドレスと思しき時は昔の引数であるとみなしてパース、実行する.
45         if (args.length > 0 && args[0].contains("@")) {
46             doWithOldArguments(args);
47             return;
48         }
49
50         new Prompt().execute(args);
51     }
52
53     public void execute(String[] args) throws IOException {
54         throw new UnsupportedOperationException();
55 //        Options options = createOptions(args);
56 //        Profile profile;
57 //        try {
58 //            CommandLineParser parser = new BasicParser();
59 //            CommandLine cmd = parser.parse(options, args);
60 //            profile = createExecuteOption(cmd);
61 //        } catch (Exception e) {
62 //            HelpFormatter hf = new HelpFormatter();
63 //            hf.printHelp("java -jar Saccubus.jar [opts]", options);
64 //            System.out.flush();
65 //            throw new IOException(e);
66 //        }
67 //
68 //        Download conv = new Download(profile, "dummy0");
69 //        ExecutorService es = Executors.newSingleThreadExecutor();
70 //        final Future<DownloadResult> future = es.submit(conv);
71 //        try {
72 //            boolean res = future.get().getResultValue();
73 //            if (!res) {
74 //                throw new IOException("ffmpeg変換処理が正常に終了しませんでした。");
75 //            }
76 //        } catch (Exception ex) {
77 //            throw new IOException("取得失敗", ex);
78 //        }
79 //        System.out.println("Finished.");
80     }
81
82     private Options createOptions(String[] args) {
83         Options options = new Options();
84 //        Option id = OptionBuilder.withArgName("mail").hasArg().withDescription("ニコニコ動画ログインID(メールアドレス)").create("id");
85 //        Option password = OptionBuilder.withArgName("password").hasArg().withDescription("ニコニコ動画ログインパスワード").
86 //                create("password");
87 //        Option video = OptionBuilder.withArgName("id").hasArg().withDescription("ニコニコ動画ビデオID").create("video");
88         Option videoFile = OptionBuilder.withArgName("file").hasArg().withDescription("動画ファイル").create("file_video");
89         Option commentFile = OptionBuilder.withArgName("file").hasArg().withDescription("コメントファイル").
90                 create("file_comment");
91         Option tcommentFile = OptionBuilder.withArgName("file").hasArg().withDescription("投稿者コメントファイル").
92                 create("file_tcomment");
93         Option outputFile = OptionBuilder.withArgName("file").hasArg().withDescription("出力ファイル").create("file_output");
94         Option ffmpeg = OptionBuilder.withArgName("option").hasArg().withDescription("ffmpeg変換オプション").create("ffmpeg");
95 //        options.addOption(id);
96 //        options.addOption(password);
97 //        options.addOption(video);
98         options.addOption(videoFile);
99         options.addOption(commentFile);
100         options.addOption(tcommentFile);
101         options.addOption(outputFile);
102         options.addOption(ffmpeg);
103         return options;
104     }
105
106 //    private Profile createExecuteOption(CommandLine cmd) throws IOException {
107 //        final String mail = "dmy";
108 //        final String pass = "dmy";
109 //        final String video = cmd.getOptionValue("file_video");
110 //        final String comm = cmd.getOptionValue("file_comment");
111 //        final String tcomm = cmd.getOptionValue("file_tcomment");
112 //        final String output = cmd.getOptionValue("file_output");
113 //        final String ff = cmd.getOptionValue("ffmpeg");
114 //
115 //        // TODO 後で実装
116 ////        SProperties setting = SProperties.loadSetting(mail, pass);
117 ////        Profile p = setting.toProfile();
118 //        Profile p = null;
119 //        GeneralSetting general = p.getGeneralSetting();
120 //        LoginInfo loginInfo = p.getLoginInfo();
121 ////        InputFileSetting videoSetting = p.getVideoSetting();
122 ////        InputFileSetting commentSetting = p.getCommentSetting();
123 //        CommentGetInfo commentGetInfo = p.getCommentGetInfo();
124 ////        InputFileSetting tcommentSetting = p.getTcommentSetting();
125 ////        OutputFileSetting outputFileSetting = p.getOutputFileSetting();
126 //        Ffmpeg ffmpeg = p.getFfmpeg();
127 //
128 //        FfmpegOption newFfmpegOption = new FfmpegOption(ffmpeg.getFfmpegOption().getExtOption(), "", "", ff, "", false,
129 //                "", "", false);
130 //        InputFileSetting newVideoSetting = new InputFileSetting(new SFile(true, new File(video)), false, false, commentGetInfo, -1);
131 //        InputFileSetting newCommentSetting = new InputFileSetting(new SFile(true, new File(comm)), false, false, commentGetInfo, -1);
132 //        InputFileSetting newTcommentSetting = new InputFileSetting(new SFile(true, new File(tcomm)), false, false, commentGetInfo, -1);
133 //        OutputFileSetting newOutputFileSetting = new OutputFileSetting(new SFile(true, new File(output)), true, false,
134 //                true, true);
135 //        Ffmpeg newFfmpeg = new Ffmpeg(ffmpeg.getFfmpeg(), ffmpeg.getVhook(), newFfmpegOption, ffmpeg.isVhookDisabled(), ffmpeg.
136 //                getMaxNumOfComment(), ffmpeg.getFont(), ffmpeg.getFontIndex(), ffmpeg.getShadowIndex(), ffmpeg.
137 //                isShowConverting(), ffmpeg.isSelfAdjustFontSize(), ffmpeg.isCommentOpaque(), ffmpeg.getNgSetting());
138 //
139 //        p = new Profile(general, loginInfo, newVideoSetting, newCommentSetting, commentGetInfo, newTcommentSetting,
140 //                newOutputFileSetting, newFfmpeg);
141 //
142 //        return p;
143 //    }
144
145     /**
146      * 昔の引数形式でプログラムを実行する.
147      */
148     private static void doWithOldArguments(String[] args) throws Exception {
149         String mail = args[0];
150         String pass = args[1];
151         String tag = args[2];
152         long time = args.length < 4 ? -1L : WayBackTimeParser.parse(args[3]);
153
154         final DownloadProfile profile = new DownloadProfileImpl(mail, pass, time);
155         final Download download = new Download(profile, 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         download.call();
165         // TODO 変換処理が必要
166         System.out.println("Finished.");
167     }
168 }