From bc6a47cda41173b5143193a55e15f1e68e6b7672 Mon Sep 17 00:00:00 2001 From: yukihane Date: Mon, 22 Aug 2011 19:54:39 +0900 Subject: [PATCH] =?utf8?q?=E3=83=97=E3=83=AD=E3=83=95=E3=82=A1=E3=82=A4?= =?utf8?q?=E3=83=AB=E3=82=AF=E3=83=A9=E3=82=B9=E5=90=8D=E3=82=92=E5=A4=89?= =?utf8?q?=E6=9B=B4=E3=81=97=E4=BF=9D=E6=8C=81=E3=81=99=E3=82=8B=E6=83=85?= =?utf8?q?=E5=A0=B1=E3=82=92=E5=86=8D=E8=80=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- frontend/src/saccubus/worker/Download.java | 77 ++++++++-------------- frontend/src/saccubus/worker/TestFrame.java | 54 +++++++-------- .../saccubus/worker/classic/profile/Ffmpeg.java | 6 ++ .../saccubus/worker/classic/profile/Profile.java | 3 +- .../saccubus/worker/profile/ConvertProfile.java | 2 + frontend/src/saccubus/worker/profile/Profile.java | 22 ------- 6 files changed, 64 insertions(+), 100 deletions(-) delete mode 100644 frontend/src/saccubus/worker/profile/Profile.java diff --git a/frontend/src/saccubus/worker/Download.java b/frontend/src/saccubus/worker/Download.java index 30ebd89..5ddf99b 100644 --- a/frontend/src/saccubus/worker/Download.java +++ b/frontend/src/saccubus/worker/Download.java @@ -16,7 +16,7 @@ import org.apache.http.HttpException; import saccubus.worker.profile.CommentProfile; import saccubus.worker.profile.GeneralProfile; import saccubus.worker.profile.OutputProfile; -import saccubus.worker.profile.Profile; +import saccubus.worker.profile.DownloadProfile; import saccubus.worker.profile.ProxyProfile; /** @@ -34,7 +34,7 @@ import saccubus.worker.profile.ProxyProfile; public class Download extends SwingWorker implements Callable { private static final Logger logger = Logger.getLogger(Download.class.getName()); - private final Profile profile; + private final DownloadProfile profile; private final String videoId; /** @@ -45,7 +45,7 @@ public class Download extends SwingWorker impl * @param listener * @param flag */ - public Download(Profile profile, String videoId) { + public Download(DownloadProfile profile, String videoId) { this.videoId = videoId; this.profile = profile; } @@ -73,7 +73,7 @@ public class Download extends SwingWorker impl // } @Override protected DownloadResult doInBackground() throws Exception { - if (!shouldRun(profile)) { + if (!needsDownload(profile)) { publish(new DownloadProgress("何もすることがありません")); return new DownloadResult(true); } @@ -138,43 +138,39 @@ public class Download extends SwingWorker impl } else { videoFile = profile.getVideoSetting().getLocalFile(); } - - if (!profile.getOutputFileSetting().isConvert()) { - publish(new DownloadProgress("動画・コメントを保存し、変換は行いませんでした。")); - return new DownloadResult(true); - } - - if (!videoFile.isFile()) { - throw new IOException("入力動画ファイルが存在しません:" + videoFile.getPath()); - } - - if (profile.getOutputFileSetting().isAddComment()) { - if (!commentFile.isFile()) { - throw new IOException("入力コメントファイルが存在しません:" + commentFile.getPath()); - } - } else { - commentFile = null; - } - - /*ビデオ名の確定*/ - final boolean isNotLow = (vf == null) ? true : (vf.getStatus() != Status.GET_LOW); - File convertedVideoFile = getOutputFileName(vi.getTitleInWatchPage(), isNotLow); - return new DownloadResult(true); + // TODO FFMPEG 実行開始は別タスクとして実装する. +// if (!profile.getOutputFileSetting().isConvert()) { +// publish(new DownloadProgress("動画・コメントを保存し、変換は行いませんでした。")); +// return new DownloadResult(true); +// } +// +// if (!videoFile.isFile()) { +// throw new IOException("入力動画ファイルが存在しません:" + videoFile.getPath()); +// } +// +// if (profile.getOutputFileSetting().isAddComment()) { +// if (!commentFile.isFile()) { +// throw new IOException("入力コメントファイルが存在しません:" + commentFile.getPath()); +// } +// } else { +// commentFile = null; +// } +// +// /*ビデオ名の確定*/ +// 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 何か実行すべき処理があればtrue. */ - private static boolean shouldRun(Profile profile) { - return profile.getOutputFileSetting().isConvert() || needsDownload(profile); - } - /** @return 何かダウンロードするものがあればtrue. */ - private static boolean needsDownload(Profile profile) { + private static boolean needsDownload(DownloadProfile profile) { return (profile.getVideoSetting().isDownload() || profile.getCommentSetting().isDownload()); } @@ -242,23 +238,6 @@ public class Download extends SwingWorker impl return profile.getCommentSetting().getBackLogPoint() >= 0L; } - /** - * 出力ファイルの保存先を確定します. - * @param title 動画タイトル. - * @param isNotLow 入力動画ファイルがlowでないかどうか. - * @return 出力ファイルの保存先. - */ - private File getOutputFileName(String title, boolean isNotLow) { - final OutputProfile prof = profile.getOutputFileSetting(); - final GeneralProfile gene = profile.getGeneralSetting(); - final File dir = prof.getDir(); - final String replaceFrom = gene.getReplaceFrom(); - final String replaceTo = gene.getReplaceTo(); - final NamePattern pattern = new NamePattern(prof.getFileName(), replaceFrom, replaceTo, title); - final String name = pattern.createFileName(videoId, isNotLow); - return new File(dir, name); - } - private void checkStop() throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException("中止要求を受け付けました"); diff --git a/frontend/src/saccubus/worker/TestFrame.java b/frontend/src/saccubus/worker/TestFrame.java index 2476a53..88c0a41 100644 --- a/frontend/src/saccubus/worker/TestFrame.java +++ b/frontend/src/saccubus/worker/TestFrame.java @@ -19,7 +19,7 @@ import saccubus.worker.profile.CommentProfile; import saccubus.worker.profile.GeneralProfile; import saccubus.worker.profile.LoginProfile; import saccubus.worker.profile.OutputProfile; -import saccubus.worker.profile.Profile; +import saccubus.worker.profile.DownloadProfile; import saccubus.worker.profile.ProxyProfile; import saccubus.worker.profile.VideoProfile; @@ -113,7 +113,7 @@ public class TestFrame extends JFrame { }); } - private static class MyProfile implements Profile{ + private static class MyProfile implements DownloadProfile{ @Override public LoginProfile getLoginInfo() { @@ -224,31 +224,31 @@ public class TestFrame extends JFrame { }; } - @Override - public OutputProfile getOutputFileSetting() { - return new OutputProfile() { - - @Override - public boolean isConvert() { - return false; - } - - @Override - public boolean isAddComment() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getDir() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public String getFileName() { - throw new UnsupportedOperationException("Not supported yet."); - } - }; - } +// @Override +// public OutputProfile getOutputFileSetting() { +// return new OutputProfile() { +// +// @Override +// public boolean isConvert() { +// return false; +// } +// +// @Override +// public boolean isAddComment() { +// throw new UnsupportedOperationException("Not supported yet."); +// } +// +// @Override +// public File getDir() { +// throw new UnsupportedOperationException("Not supported yet."); +// } +// +// @Override +// public String getFileName() { +// throw new UnsupportedOperationException("Not supported yet."); +// } +// }; +// } @Override public GeneralProfile getGeneralSetting() { diff --git a/frontend/src/saccubus/worker/classic/profile/Ffmpeg.java b/frontend/src/saccubus/worker/classic/profile/Ffmpeg.java index bf04a7a..c4e4db4 100644 --- a/frontend/src/saccubus/worker/classic/profile/Ffmpeg.java +++ b/frontend/src/saccubus/worker/classic/profile/Ffmpeg.java @@ -2,6 +2,7 @@ package saccubus.worker.classic.profile; import java.io.File; +import saccubus.worker.profile.OutputProfile; /** * @@ -93,4 +94,9 @@ public class Ffmpeg implements saccubus.worker.profile.ConvertProfile { public File getTempDir() { return new File("."); } + + @Override + public OutputProfile getOutputProvile() { + throw new UnsupportedOperationException("Not supported yet."); + } } diff --git a/frontend/src/saccubus/worker/classic/profile/Profile.java b/frontend/src/saccubus/worker/classic/profile/Profile.java index 3f89661..0793fe9 100644 --- a/frontend/src/saccubus/worker/classic/profile/Profile.java +++ b/frontend/src/saccubus/worker/classic/profile/Profile.java @@ -8,7 +8,7 @@ import saccubus.worker.profile.VideoProfile; * Converterに処理させるための設定. * @author yuki */ -public class Profile implements saccubus.worker.profile.Profile { +public class Profile implements saccubus.worker.profile.DownloadProfile { private final GeneralSetting generalSetting; private final LoginInfo loginInfo; @@ -62,7 +62,6 @@ public class Profile implements saccubus.worker.profile.Profile { return tcommentSetting; } - @Override public OutputFileSetting getOutputFileSetting() { return outputFileSetting; } diff --git a/frontend/src/saccubus/worker/profile/ConvertProfile.java b/frontend/src/saccubus/worker/profile/ConvertProfile.java index 2d526aa..8e7868f 100644 --- a/frontend/src/saccubus/worker/profile/ConvertProfile.java +++ b/frontend/src/saccubus/worker/profile/ConvertProfile.java @@ -8,6 +8,8 @@ import java.io.File; */ public interface ConvertProfile { + OutputProfile getOutputProvile(); + FfmpegProfile getFfmpegOption(); /** @return ffmpeg実行ファイル. */ diff --git a/frontend/src/saccubus/worker/profile/Profile.java b/frontend/src/saccubus/worker/profile/Profile.java deleted file mode 100644 index 516663e..0000000 --- a/frontend/src/saccubus/worker/profile/Profile.java +++ /dev/null @@ -1,22 +0,0 @@ -package saccubus.worker.profile; - -/** - * {@link saccubus.converter.Converter.Converter}が必要とするプロファイルです. - * Converterを使用するクライアントは, このインタフェースを実装するクラスのインスタンスで - * Converterへ処理させる内容を通知します. - * @author yuki - */ -public interface Profile { - - LoginProfile getLoginInfo(); - - ProxyProfile getProxySetting(); - - VideoProfile getVideoSetting(); - - CommentProfile getCommentSetting(); - - OutputProfile getOutputFileSetting(); - - GeneralProfile getGeneralSetting(); -} -- 2.11.0