+++ /dev/null
-/* $Id$ */
-package saccubus.converter;
-
-import javax.swing.SwingWorker;
-import static org.apache.commons.lang.Validate.*;
-import saccubus.ConvertStopFlag;
-import saccubus.net.TextProgressListener;
-
-/**
- *
- * @author yuki
- */
-public abstract class AbstractCommand<T, V> extends SwingWorker<T, V> {
-
- private final TextProgressListener listener;
-
- public AbstractCommand(TextProgressListener listener) {
- notNull(listener);
-
- this.listener = listener;
- }
-
- protected void checkStop() throws InterruptedException {
- if (Thread.interrupted()) {
- throw new InterruptedException("中止要求を受け付けました");
- }
- }
-
- protected void sendText(String text) {
- getListener().setText(text);
- }
-
- /**
- * @return the listener
- */
- protected TextProgressListener getListener() {
- return listener;
- }
-}
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;
* @author 未入力
* @version 1.0
*/
-public abstract class Converter extends AbstractCommand<ConvertResult, ConvertProgress> implements Callable<Boolean> {
+public abstract class Converter extends SwingWorker<ConvertResult, ConvertProgress> implements Callable<Boolean> {
private static final Logger logger = Logger.getLogger(Converter.class.getName());
private final Profile profile;
*/
public Converter(String id, Profile profile,
TextProgressListener listener, ConvertStopFlag flag) {
- super(listener);
this.movieId = id;
this.profile = profile;
}
// logger.log(Level.SEVERE, null, ex);
// }
// }
-
@Override
protected ConvertResult doInBackground() throws Exception {
if (!shouldRun(profile)) {
- sendText("何もすることがありません");
+ publish(new ConvertProgress("何もすることがありません"));
return new ConvertResult(true);
}
final FfmpegProfile ov = profile.getFfmpeg().getFfmpegOption();
// TODO ログインしないで良い場合もある.
- sendText("ログイン中");
+ publish(new ConvertProgress("ログイン中"));
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();
}
if (!profile.getOutputFileSetting().isConvert()) {
- sendText("動画・コメントを保存し、変換は行いませんでした。");
+ publish(new ConvertProgress("動画・コメントを保存し、変換は行いませんでした。"));
return new ConvertResult(true);
}
final String name = pattern.createFileName(movieId, isNotLow);
return new File(dir, name);
}
+
+ private void checkStop() throws InterruptedException {
+ if (Thread.interrupted()) {
+ throw new InterruptedException("中止要求を受け付けました");
+ }
+ }
}
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.swing.SwingWorker;
import org.apache.commons.lang.StringUtils;
import saccubus.ConvertStopFlag;
import saccubus.conv.ConvertToVideoHook;
*
* @author yuki
*/
-public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCommandProgress> {
+public class FfmpegCommand extends SwingWorker<FfmpegCommandResult, FfmpegCommandProgress> {
+
private static final Logger logger = Logger.getLogger(FfmpegCommand.class.getName());
private final File commentMiddleFile;
private final File tcommMiddleFile;
FfmpegCommand(TextProgressListener listener, ConvertStopFlag flag, File commentFile,
File videoFile, File convertedVideoFile, ConvertProfile ffmpeg, GeneralProfile general) throws IOException {
- super(listener);
this.commentFile = commentFile;
this.videoFile = videoFile;
this.convertedVideoFile = convertedVideoFile;
TMP_CWS = File.createTempFile("cws", ".swf", tmpDir);
}
-
@Override
protected FfmpegCommandResult doInBackground() throws Exception {
try {
private FfmpegCommandResult exec() throws InterruptedException, IOException {
final HideCondition ngSetting = getFfmpeg().getNgSetting();
if (commentFile != null) {
- sendText("コメントの中間ファイルへの変換中");
+ publish(new FfmpegCommandProgress("コメントの中間ファイルへの変換中"));
boolean conv = ConvertToVideoHook.convert(commentFile, commentMiddleFile, ngSetting.getId(), ngSetting.
getWord());
if (!conv) {
- sendText("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?");
+ publish(new FfmpegCommandProgress("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?"));
return new FfmpegCommandResult(false);
}
}
// }
// }
// stopFlagReturn();
- sendText("動画の変換を開始");
+ publish(new FfmpegCommandProgress("動画の変換を開始"));
int code;
if ((code = converting_video(videoFile, convertedVideoFile, (commentFile != null), commentMiddleFile.getPath(),
false, tcommMiddleFile.getPath(), getFfmpeg().getFfmpegOption())) == 0) {
- sendText("変換が正常に終了しました。");
+ publish(new FfmpegCommandProgress("変換が正常に終了しました。"));
return new FfmpegCommandResult(true);
} else {
- sendText("変換エラー:" + convertedVideoFile.getPath());
+ publish(new FfmpegCommandProgress("変換エラー:" + convertedVideoFile.getPath()));
}
return new FfmpegCommandResult(false);
}
final Info info = MediaInfo.getInfo(new File("bin", "MediaInfo"), videoFile);
// 4:3 なら1.33, 16:9 なら1.76
- boolean isHD = ((double)info.getWidth()/(double)info.getHeight() > 1.5);
+ boolean isHD = ((double) info.getWidth() / (double) info.getHeight() > 1.5);
if (ov.isResize()) {
final Size scaled = (ov.isAdjustRatio()) ? MediaInfo.adjustSize(info, ov.getResizeWidth(), ov.
getResizeHeight()) : new Size(info.getWidth(), info.getHeight());
List<String> avfilterArgs = getAvfilterOptions(ov.getAvfilterOption());
if (!getFfmpeg().isVhookDisabled()) {
String vhookArg = getVhookArg(addComment, commPath, addTcomment, tcommPath, isHD);
- if(StringUtils.isNotBlank(vhookArg)){
+ if (StringUtils.isNotBlank(vhookArg)) {
avfilterArgs.add(vhookArg);
}
}
while ((e = ebr.readLine()) != null) {
String state = e;
if (state.startsWith("frame=")) {
- sendText(state);
+ publish(new FfmpegCommandProgress(state));
} else if (!state.endsWith("No accelerated colorspace conversion found")) {
logger.log(Level.INFO, e);
}
sb.append("--enable-opaque-comment");
sb.append("|");
}
- if(isHD){
+ if (isHD) {
sb.append("--aspect-mode:1");
sb.append("|");
}
private ConvertProfile getFfmpeg() {
return ffmpeg;
}
+
+ protected void checkStop() throws InterruptedException {
+ if (Thread.interrupted()) {
+ throw new InterruptedException("中止要求を受け付けました");
+ }
+ }
}