package saccubus.converter;
-import saccubus.converter.profile.Profile;
-import saccubus.converter.filegetter.FileInstanciator;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.Callable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import saccubus.ConvertStopFlag;
-import saccubus.converter.classic.profile.FfmpegOption;
+import saccubus.converter.filegetter.FileInstanciator;
import saccubus.net.TextProgressListener;
+import yukihane.saccubus.converter.profile.FfmpegOption;
+import yukihane.saccubus.converter.profile.Profile;
/**
* <p>タイトル: さきゅばす</p>
* @author 未入力
* @version 1.0
*/
-public class Converter extends AbstractCommand implements Runnable, Callable<Boolean> {
+public class Converter extends AbstractCommand implements Callable<Boolean> {
- private static final String VIDEO_URL_PARSER = "http://www.nicovideo.jp/watch/";
private final Profile profile;
private final String movieId;
private final String time;
public Converter(String url, String time, Profile profile,
TextProgressListener listener, ConvertStopFlag flag) {
super(listener, flag);
- url = url.trim();
- if (url.startsWith(VIDEO_URL_PARSER)) {
- int index = url.indexOf('?', VIDEO_URL_PARSER.length());
- if (index >= 0) {
- movieId = url.substring(VIDEO_URL_PARSER.length(), index);
- } else {
- movieId = url.substring(VIDEO_URL_PARSER.length());
- }
+
+ // TODO 入力欄の値から動画IDの切り出しはGUI側でやるべきだろう
+ final int startIdIdx = url.lastIndexOf("/") + 1;
+ final String altId = url.substring(startIdIdx);
+ final Pattern idPattern = Pattern.compile("([a-z]*\\d+)");
+ final Matcher idMatcher = idPattern.matcher(altId);
+ if (idMatcher.find()) {
+ this.movieId = idMatcher.group(1);
} else {
- movieId = url;
+ throw new IllegalArgumentException("URL/IDの指定が不正です: " + url);
}
+
this.time = time;
this.profile = profile;
}
+ @Override
public Boolean call() throws Exception {
boolean result = false;
try {
return Boolean.valueOf(result);
}
+ // TODO Runnableを実装しなくなったので削除する
public void run() {
try {
call();
File tcommFile = fi.getTcommFile(getListener());
- if (!profile.needsConvert()) {
+ if (!profile.getOutputFileSetting().isConvert()) {
sendText("動画・コメントを保存し、変換は行いませんでした。");
return true;
}
boolean res = new FfmpegCommand(getListener(), getStopFlag(), commentFile, tcommFile, videoFile,
convertedVideoFile, profile.getFfmpeg(), profile.getGeneralSetting()).execute();
- if (res) {
- if (profile.getCommentSetting().isDelete()) {
- commentFile.delete();
- }
- if (profile.getVideoSetting().isDelete()) {
- videoFile.delete();
- }
- if (profile.getTcommentSetting().isDelete()) {
- tcommFile.delete();
- }
- }
return res;
}
FileInstanciator.InstanciationType videoType = new FileInstanciator.InstanciationType(profile.getVideoSetting());
FileInstanciator.CommentInstanciationType commentType = new FileInstanciator.CommentInstanciationType(profile.
- getCommentSetting(), profile.getCommentGetInfo().isselfAdjustCommentNum(), profile.getCommentGetInfo().
- getBackComment());
+ getCommentSetting(), profile.getCommentSetting().isSelfAdjustCommentNum(), profile.getCommentSetting().
+ getBackComment(), profile.getCommentSetting().isReduceComment());
FileInstanciator.InstanciationType tcommType = new FileInstanciator.InstanciationType(
- profile.getTcommentSetting());
+ profile.getCommentSetting());
- fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, profile.getLoginInfo(), movieId, time);
+ fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, profile.getLoginInfo(), profile.
+ getProxySetting(), movieId, time);
return fi;
}
* @throws IllegalArgumentException 設定に不備がある場合.
*/
private void validSetting() {
- if (profile.needsConvert()) {
+ if (profile.getOutputFileSetting().isConvert()) {
File a = profile.getFfmpeg().getFfmpeg();
if (!a.canRead()) {
throw new IllegalArgumentException("FFmpegが見つかりません。");
if (!a.canRead()) {
throw new IllegalArgumentException("フォントが見つかりません。");
}
- } else {
- if (profile.getVideoSetting().isDelete()) {
- throw new IllegalArgumentException("変換しないのに、動画削除しちゃって良いんですか?");
- }
- if (profile.getCommentSetting().isDelete()) {
- throw new IllegalArgumentException("変換しないのに、コメント削除しちゃって良いんですか?");
- }
- if (profile.getTcommentSetting().isDelete()) {
- throw new IllegalArgumentException("変換しないのに、投稿者コメント削除しちゃって良いんですか?");
- }
}
}
/** @return 何か実行すべき処理があればtrue. */
private static boolean shouldRun(Profile profile) {
- return profile.getOutputFileSetting().isConvert() || profile.needsDownload();
+ return profile.getOutputFileSetting().isConvert() || needsDownload(profile);
+ }
+
+ /** @return 何かダウンロードするものがあればtrue. */
+ private static boolean needsDownload(Profile profile) {
+ return (profile.getVideoSetting().isDownload() || profile.getCommentSetting().isDownload());
}
}