OSDN Git Service

プロファイルクラス名を変更し保持する情報を再考
authoryukihane <yukihane.feather@gmail.com>
Mon, 22 Aug 2011 10:54:39 +0000 (19:54 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 22 Aug 2011 10:54:39 +0000 (19:54 +0900)
frontend/src/saccubus/worker/Download.java
frontend/src/saccubus/worker/TestFrame.java
frontend/src/saccubus/worker/classic/profile/Ffmpeg.java
frontend/src/saccubus/worker/classic/profile/Profile.java
frontend/src/saccubus/worker/profile/ConvertProfile.java
frontend/src/saccubus/worker/profile/Profile.java [deleted file]

index 30ebd89..5ddf99b 100644 (file)
@@ -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<DownloadResult, DownloadProgress> implements Callable<Boolean> {
 
     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<DownloadResult, DownloadProgress> 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<DownloadResult, DownloadProgress> 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<DownloadResult, DownloadProgress> 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<DownloadResult, DownloadProgress> 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("中止要求を受け付けました");
index 2476a53..88c0a41 100644 (file)
@@ -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() {
index bf04a7a..c4e4db4 100644 (file)
@@ -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.");
+    }
 }
index 3f89661..0793fe9 100644 (file)
@@ -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;
     }
index 2d526aa..8e7868f 100644 (file)
@@ -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 (file)
index 516663e..0000000
+++ /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();
-}