import java.io.IOException;
import java.net.URISyntaxException;
import java.util.concurrent.Callable;
+import java.util.logging.Logger;
+import javax.swing.SwingWorker;
import nicobrowser.GetFlvResult;
import nicobrowser.NamePattern;
import nicobrowser.NicoHttpClient;
import nicobrowser.WayBackInfo;
import nicobrowser.entity.NicoContent.Status;
import org.apache.http.HttpException;
-import saccubus.ConvertStopFlag;
-import saccubus.net.TextProgressListener;
-import yukihane.saccubus.converter.profile.CommentProfile;
-import yukihane.saccubus.converter.profile.FfmpegOption;
-import yukihane.saccubus.converter.profile.GeneralProfile;
-import yukihane.saccubus.converter.profile.OutputProfile;
-import yukihane.saccubus.converter.profile.Profile;
-import yukihane.saccubus.converter.profile.ProxyProfile;
+import saccubus.converter.profile.CommentProfile;
+import saccubus.converter.profile.FfmpegProfile;
+import saccubus.converter.profile.GeneralProfile;
+import saccubus.converter.profile.OutputProfile;
+import saccubus.converter.profile.Profile;
+import saccubus.converter.profile.ProxyProfile;
/**
* <p>タイトル: さきゅばす</p>
* @author 未入力
* @version 1.0
*/
-public class Converter extends AbstractCommand implements Callable<Boolean> {
+public class Converter extends SwingWorker<ConvertResult, ConvertProgress> implements Callable<Boolean> {
+ private static final Logger logger = Logger.getLogger(Converter.class.getName());
private final Profile profile;
private final String movieId;
* @param listener
* @param flag
*/
- public Converter(String id, Profile profile,
- TextProgressListener listener, ConvertStopFlag flag) {
- super(listener, flag);
+ public Converter(String id, Profile profile) {
this.movieId = id;
this.profile = profile;
}
@Override
public Boolean call() throws Exception {
- boolean result = false;
try {
- result = runConvert();
+ final ConvertResult result = doInBackground();
+ return Boolean.valueOf(result.getResultValue());
} finally {
- getStopFlag().finished();
+ // TODO 何か処理が必要?
+// getStopFlag().finished();
}
- return Boolean.valueOf(result);
}
- // TODO Runnableを実装しなくなったので削除する
- public void run() {
- try {
- call();
- } catch (Exception ex) {
- String text = (ex.getMessage() != null) ? ex.getMessage() : "予期しないエラー発生のため中断しました。";
- sendText(text);
- ex.printStackTrace();
- }
- }
-
- private boolean runConvert() throws IOException, InterruptedException, Exception {
+// // TODO Runnableを実装しなくなったので削除する
+// public void run() {
+// try {
+// call();
+// } catch (Exception ex) {
+// String text = (ex.getMessage() != null) ? ex.getMessage() : "予期しないエラー発生のため中断しました。";
+// sendText(text);
+// logger.log(Level.SEVERE, null, ex);
+// }
+// }
+ @Override
+ protected ConvertResult doInBackground() throws Exception {
if (!shouldRun(profile)) {
- sendText("何もすることがありません");
- return true;
+ publish(new ConvertProgress("何もすることがありません"));
+ return new ConvertResult(true);
}
validSetting();
- final FfmpegOption ov = profile.getFfmpeg().getFfmpegOption();
+ final FfmpegProfile ov = profile.getFfmpeg().getFfmpegOption();
// TODO ログインしないで良い場合もある.
- sendText("ログイン中");
+ publish(new ConvertProgress("ログイン中"));
}
}
- stopFlagReturn();
-
+ checkStop();
File commentFile;
if (profile.getCommentSetting().isDownload()) {
final String name = pattern.createFileName(movieId, true);
final File file = new File(profile.getCommentSetting().getDir(), name);
- commentFile = client.getCommentFile(vi, file.getPath(), wbi, profile.getCommentSetting().getLengthRelatedCommentSize(),
+ commentFile = client.getCommentFile(vi, file.getPath(), wbi, profile.getCommentSetting().
+ getLengthRelatedCommentSize(),
profile.getCommentSetting().isDisablePerMinComment());
} else {
commentFile = profile.getCommentSetting().getLocalFile();
}
- stopFlagReturn();
+ checkStop();
File videoFile;
GetFlvResult vf = null;
}
if (!profile.getOutputFileSetting().isConvert()) {
- sendText("動画・コメントを保存し、変換は行いませんでした。");
- return true;
+ publish(new ConvertProgress("動画・コメントを保存し、変換は行いませんでした。"));
+ return new ConvertResult(true);
}
if (!videoFile.isFile()) {
final boolean isNotLow = (vf == null) ? true : (vf.getStatus() != Status.GET_LOW);
File convertedVideoFile = getOutputFileName(vi.getTitleInWatchPage(), isNotLow);
- boolean res = new FfmpegCommand(getListener(), getStopFlag(), commentFile, videoFile,
- convertedVideoFile, profile.getFfmpeg(), profile.getGeneralSetting()).execute();
- return res;
- }
+ return new ConvertResult(true);
- public boolean isConverted() {
- return getStopFlag().isFinished();
- }
-
- @Override
- public ConvertStopFlag getStopFlag() {
- return super.getStopFlag();
+ // TODO FFMPEG 実行開始は別タスクとして実装する.
+// boolean res = new FfmpegCommand(getListener(), getStopFlag(), commentFile, videoFile,
+// convertedVideoFile, profile.getFfmpeg(), profile.getGeneralSetting()).execute();
+// return res;
}
/** @return 何か実行すべき処理があればtrue. */
final String name = pattern.createFileName(movieId, isNotLow);
return new File(dir, name);
}
+
+ private void checkStop() throws InterruptedException {
+ if (Thread.interrupted()) {
+ throw new InterruptedException("中止要求を受け付けました");
+ }
+ }
}