public class Converter extends AbstractCommand implements Runnable, Callable<Boolean> {
private static final String VIDEO_URL_PARSER = "http://www.nicovideo.jp/watch/";
- private final Profile Setting;
- private final String Tag;
- private final String Time;
+ private final Profile profile;
+ private final String movieId;
+ private final String time;
/**
* コンバータを構築します.
if (url.startsWith(VIDEO_URL_PARSER)) {
int index = url.indexOf('?', VIDEO_URL_PARSER.length());
if (index >= 0) {
- Tag = url.substring(VIDEO_URL_PARSER.length(), index);
+ movieId = url.substring(VIDEO_URL_PARSER.length(), index);
} else {
- Tag = url.substring(VIDEO_URL_PARSER.length());
+ movieId = url.substring(VIDEO_URL_PARSER.length());
}
} else {
- Tag = url;
+ movieId = url;
}
- Time = time;
- Setting = setting;
+ this.time = time;
+ this.profile = setting;
}
public Boolean call() throws Exception {
}
private boolean runConvert() throws IOException, InterruptedException {
- if (!Setting.shouldRun()) {
+ if (!profile.shouldRun()) {
sendText("何もすることがありません");
return true;
}
validSetting();
- final FfmpegOption ov = Setting.getFfmpeg().getFfmpegOption();
+ final FfmpegOption ov = profile.getFfmpeg().getFfmpegOption();
sendText("ログイン中");
File tcommFile = fi.getTcommFile(getListener());
- if (!Setting.needsConvert()) {
+ if (!profile.needsConvert()) {
sendText("動画・コメントを保存し、変換は行いませんでした。");
return true;
}
throw new IOException("入力動画ファイルが存在しません:" + videoFile.getPath());
}
- if (Setting.getOutputFileSetting().isAddComment()) {
+ if (profile.getOutputFileSetting().isAddComment()) {
if (!commentFile.isFile()) {
throw new IOException("入力コメントファイルが存在しません:" + commentFile.getPath());
}
commentFile = null;
}
- if (Setting.getOutputFileSetting().isAddTcomment()) {
+ if (profile.getOutputFileSetting().isAddTcomment()) {
if (!tcommFile.isFile()) {
throw new IOException("入力投稿者コメントファイルが存在しません" + tcommFile.getPath());
}
/*ビデオ名の確定*/
File convertedVideoFile;
- if (!Setting.getOutputFileSetting().getFile().isFile()) {
+ if (!profile.getOutputFileSetting().getFile().isFile()) {
String conv_name = fi.getVideoTitle();
- if (Setting.getOutputFileSetting().isAppendPrefixVideoId()) {
+ if (profile.getOutputFileSetting().isAppendPrefixVideoId()) {
conv_name = getVideoIDWithBracket() + conv_name;
}
- convertedVideoFile = new File(Setting.getOutputFileSetting().getFile().getFile(),
+ convertedVideoFile = new File(profile.getOutputFileSetting().getFile().getFile(),
conv_name + ov.getExtOption());
} else {
- String filename = Setting.getOutputFileSetting().getFile().getFile().getPath();
+ String filename = profile.getOutputFileSetting().getFile().getFile().getPath();
if (!filename.endsWith(ov.getExtOption())) {
filename = filename.substring(0, filename.lastIndexOf('.')) + ov.getExtOption();
convertedVideoFile = new File(filename);
} else {
- convertedVideoFile = Setting.getOutputFileSetting().getFile().getFile();
+ convertedVideoFile = profile.getOutputFileSetting().getFile().getFile();
}
}
boolean res = new FfmpegCommand(getListener(), getStopFlag(), commentFile, tcommFile, videoFile,
- convertedVideoFile, Setting.getFfmpeg(), Setting.getGeneralSetting()).execute();
+ convertedVideoFile, profile.getFfmpeg(), profile.getGeneralSetting()).execute();
if (res) {
- if (Setting.getCommentSetting().isDelete()) {
+ if (profile.getCommentSetting().isDelete()) {
commentFile.delete();
}
- if (Setting.getVideoSetting().isDelete()) {
+ if (profile.getVideoSetting().isDelete()) {
videoFile.delete();
}
- if (Setting.getTcommentSetting().isDelete()) {
+ if (profile.getTcommentSetting().isDelete()) {
tcommFile.delete();
}
}
private FileInstanciator createInstanciator() throws IOException {
FileInstanciator fi;
- FileInstanciator.InstanciationType videoType = new FileInstanciator.InstanciationType(Setting.getVideoSetting());
+ FileInstanciator.InstanciationType videoType = new FileInstanciator.InstanciationType(profile.getVideoSetting());
- FileInstanciator.CommentInstanciationType commentType = new FileInstanciator.CommentInstanciationType(Setting.
- getCommentSetting(), Setting.getCommentGetInfo().isselfAdjustCommentNum(), Setting.getCommentGetInfo().
+ FileInstanciator.CommentInstanciationType commentType = new FileInstanciator.CommentInstanciationType(profile.
+ getCommentSetting(), profile.getCommentGetInfo().isselfAdjustCommentNum(), profile.getCommentGetInfo().
getBackComment());
FileInstanciator.InstanciationType tcommType = new FileInstanciator.InstanciationType(
- Setting.getTcommentSetting());
+ profile.getTcommentSetting());
- fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, Setting.getLoginInfo(), Tag, Time);
+ fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, profile.getLoginInfo(), movieId, time);
return fi;
}
* @throws IllegalArgumentException 設定に不備がある場合.
*/
private void validSetting() {
- if (Setting.needsConvert()) {
- File a = Setting.getFfmpeg().getFfmpeg();
+ if (profile.needsConvert()) {
+ File a = profile.getFfmpeg().getFfmpeg();
if (!a.canRead()) {
throw new IllegalArgumentException("FFmpegが見つかりません。");
}
- if (Setting.getFfmpeg().getVhook().getPath().indexOf(' ') >= 0) {
+ if (profile.getFfmpeg().getVhook().getPath().indexOf(' ') >= 0) {
throw new IllegalArgumentException("すいません。現在vhookライブラリには半角空白は使えません。");
}
- a = Setting.getFfmpeg().getVhook();
+ a = profile.getFfmpeg().getVhook();
if (!a.canRead()) {
throw new IllegalArgumentException("Vhookライブラリが見つかりません。");
}
- a = Setting.getFfmpeg().getFont();
+ a = profile.getFfmpeg().getFont();
if (!a.canRead()) {
throw new IllegalArgumentException("フォントが見つかりません。");
}
} else {
- if (Setting.getVideoSetting().isDelete()) {
+ if (profile.getVideoSetting().isDelete()) {
throw new IllegalArgumentException("変換しないのに、動画削除しちゃって良いんですか?");
}
- if (Setting.getCommentSetting().isDelete()) {
+ if (profile.getCommentSetting().isDelete()) {
throw new IllegalArgumentException("変換しないのに、コメント削除しちゃって良いんですか?");
}
- if (Setting.getTcommentSetting().isDelete()) {
+ if (profile.getTcommentSetting().isDelete()) {
throw new IllegalArgumentException("変換しないのに、投稿者コメント削除しちゃって良いんですか?");
}
}
}
private String getVideoIDWithBracket() {
- return "[" + Tag + "]";
+ return "[" + movieId + "]";
}
public boolean isConverted() {