--- /dev/null
+package saccubus.worker.impl;
+
+/**
+ *
+ * @author yuki
+ */
+public interface PercentageReportable {
+ double getPercentage();
+}
* @param output 変換後出力動画.
* @throws IOException 変換失敗.
*/
- public Convert(ConvertProfile profile, File video, File comment, WorkerListener<ConvertResult, ConvertProgress> listener) {
+ public Convert(ConvertProfile profile, File video, File comment,
+ WorkerListener<ConvertResult, ConvertProgress> listener) {
super(listener);
this.profile = profile;
this.videoFile = video;
if (profile.isCommentOverlay()) {
transformedComment = File.createTempFile("vhk", ".tmp", profile.getTempDir());
final HideCondition hide = profile.getNgSetting();
- publish(new ConvertProgress(PROCESS, "コメントの中間ファイルへの変換中"));
+ publish(new ConvertProgress(PROCESS, 0.0, "コメントの中間ファイルへの変換中"));
ConvertToVideoHook.convert(commentFile, transformedComment, hide.getId(), hide.getWord());
}
checkStop();
- publish(new ConvertProgress(PROCESS, "動画の変換を開始"));
+ publish(new ConvertProgress(PROCESS, 0.0, "動画の変換を開始"));
final int code = convert(transformedComment, outputFile);
if (code != 0) {
throw new IOException("ffmpeg実行失敗: " + outputFile.getPath());
}
- publish(new ConvertProgress(PROCESS, "変換が正常に終了しました。"));
+ publish(new ConvertProgress(PROCESS, 100.0, "変換が正常に終了しました。"));
return new ConvertResult(true, outputFile.getName());
} finally {
if (transformedComment != null && transformedComment.exists()) {
String msg;
while ((msg = ebr.readLine()) != null) {
if (msg.startsWith("frame=")) {
- publish(new ConvertProgress(PROCESS, msg));
+ // TODO パーセンテージ計算、出力
+ publish(new ConvertProgress(PROCESS, 0.0, msg));
} else if (!msg.endsWith("No accelerated colorspace conversion found")) {
logger.log(Level.INFO, msg);
}
package saccubus.worker.impl.convert;
import org.apache.commons.lang.builder.ToStringBuilder;
+import saccubus.worker.impl.MessageReportable;
+import saccubus.worker.impl.PercentageReportable;
/**
*
* @author yuki
*/
-public class ConvertProgress {
+public class ConvertProgress implements PercentageReportable, MessageReportable {
private final ConvertStatus status;
+ private final double percentage;
private final String message;
- ConvertProgress(ConvertStatus status, String message) {
+ ConvertProgress(ConvertStatus status, double percentage, String message) {
this.status = status;
+ this.percentage = percentage;
this.message = message;
}
}
@Override
+ public double getPercentage() {
+ return percentage;
+ }
+
+ @Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
@Override
public DownloadResult work() throws Exception {
- publish(new DownloadProgress(PROCESS, "ログイン中"));
+ publish(new DownloadProgress(PROCESS, 0.0, "ログイン中"));
NicoHttpClient client = null;
nicobrowser.VideoInfo vi = null;
@Override
public void progress(long fileSize, long downloadSize) {
final double vol = (double) downloadSize / (double) fileSize * 100.0;
- publish(new DownloadProgress(PROCESS, String.format("ダウンロード%.2f%%", vol)));
+ publish(new DownloadProgress(PROCESS, vol, String.format("ダウンロード%.2f%%", vol)));
}
});
package saccubus.worker.impl.download;
import org.apache.commons.lang.builder.ToStringBuilder;
+import saccubus.worker.impl.MessageReportable;
+import saccubus.worker.impl.PercentageReportable;
/**
*
* @author yuki
*/
-public class DownloadProgress {
+public class DownloadProgress implements PercentageReportable, MessageReportable {
private final DownloadStatus status;
+ private final double percentage;
private final String message;
- DownloadProgress(DownloadStatus status, String message) {
+ DownloadProgress(DownloadStatus status, double percentage, String message) {
this.status = status;
+ this.percentage = percentage;
this.message = message;
}
}
@Override
+ public double getPercentage() {
+ return percentage;
+ }
+
+ @Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
import java.util.logging.Level;
import java.util.logging.Logger;
import saccubus.worker.WorkerListener;
+import saccubus.worker.impl.MessageReportable;
+import saccubus.worker.impl.PercentageReportable;
import saccubus.worker.impl.convert.Convert;
import saccubus.worker.impl.convert.ConvertProgress;
import saccubus.worker.impl.convert.ConvertResult;
* @author yuki
*/
public class TaskManage {
+
private static final Logger logger = Logger.getLogger(TaskManage.class.getName());
private final ExecutorService downloadExecutorService;
private final ExecutorService convertExecutorService;
}
}
- abstract class TaskManageInnerListener<T, V> implements WorkerListener<T, V> {
+ abstract class TaskManageInnerListener<T, V extends PercentageReportable & MessageReportable> implements WorkerListener<T, V> {
private final int rowId;
@Override
public void process(V progress) {
logger.log(Level.FINEST, "process: {0}", progress);
- // TOOD
- notify(TaskStatus.DOING, 0.0, "");
+ notify(TaskStatus.DOING, progress.getPercentage(), progress.getMessage());
}
@Override