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.classic.profile.LoginInfo;
import saccubus.converter.classic.profile.CommentGetInfo;
import saccubus.converter.classic.profile.Ffmpeg;
import saccubus.converter.classic.profile.FfmpegOption;
import saccubus.converter.classic.profile.GeneralSetting;
import saccubus.converter.classic.profile.InputFileSetting;
import saccubus.converter.classic.profile.OutputFileSetting;
import saccubus.converter.classic.profile.Profile;
import saccubus.net.TextProgressListener;
/**
*
* タイトル: さきゅばす
*
*
*
* 説明: ニコニコ動画の動画をコメントつきで保存
*
*
*
* 著作権: Copyright (c) 2007 PSI
*
*
*
* 会社名:
*
*
* @author 未入力
* @version 1.0
*/
public class Prompt {
public static void main(String[] args) throws IOException {
// 第1引数がメールアドレスと思しき時は昔の引数であるとみなしてパース、実行する.
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 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("dummy0", profile, tpl, new ConvertStopFlag(scl));
ExecutorService es = Executors.newSingleThreadExecutor();
Future future = es.submit((Callable) conv);
try {
boolean res = future.get().booleanValue();
if (!res) {
throw new IOException("ffmpeg変換処理が正常に終了しませんでした。");
}
} catch (Exception ex) {
throw new IOException("取得失敗", ex);
}
System.out.println("Finished.");
}
private Options createOptions(String[] args) {
Options options = new Options();
// Option id = OptionBuilder.withArgName("mail").hasArg().withDescription("ニコニコ動画ログインID(メールアドレス)").create("id");
// Option password = OptionBuilder.withArgName("password").hasArg().withDescription("ニコニコ動画ログインパスワード").
// create("password");
// Option video = OptionBuilder.withArgName("id").hasArg().withDescription("ニコニコ動画ビデオID").create("video");
Option videoFile = OptionBuilder.withArgName("file").hasArg().withDescription("動画ファイル").create("file_video");
Option commentFile = OptionBuilder.withArgName("file").hasArg().withDescription("コメントファイル").
create("file_comment");
Option tcommentFile = OptionBuilder.withArgName("file").hasArg().withDescription("投稿者コメントファイル").
create("file_tcomment");
Option outputFile = OptionBuilder.withArgName("file").hasArg().withDescription("出力ファイル").create("file_output");
Option ffmpeg = OptionBuilder.withArgName("option").hasArg().withDescription("ffmpeg変換オプション").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");
//
// // TODO 後で実装
//// SProperties setting = SProperties.loadSetting(mail, pass);
//// Profile p = setting.toProfile();
// Profile p = null;
// 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, "", false,
// "", "", false);
// InputFileSetting newVideoSetting = new InputFileSetting(new SFile(true, new File(video)), false, false, commentGetInfo, -1);
// InputFileSetting newCommentSetting = new InputFileSetting(new SFile(true, new File(comm)), false, false, commentGetInfo, -1);
// InputFileSetting newTcommentSetting = new InputFileSetting(new SFile(true, new File(tcomm)), false, false, commentGetInfo, -1);
// 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;
return null;
}
/**
* 昔の引数形式でプログラムを実行する.
*/
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];
// TODO
// SProperties setting = SProperties.loadSetting(mail, pass);
// Converter conv = new Converter(tag, setting.toProfile(), TextProgressListener.EMPTY_LISTENER, new ConvertStopFlag(
// ConvertStopFlag.StateChangeListener.EMPTY_LISTENER));
Converter conv = new Converter(tag, null/*この部分*/, 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.");
}
}