OSDN Git Service

動画ファイルより先にコメントファイルをダウンロードする
[coroid/inqubus.git] / frontend / src / saccubus / converter / Converter.java
index b3ff1da..04c12bf 100644 (file)
@@ -1,13 +1,13 @@
 package saccubus.converter;
 
-import saccubus.converter.profile.Profile;
-import saccubus.converter.profile.FfmpegOption;
-import saccubus.converter.filegetter.FileInstanciator;
 import java.io.File;
 import java.io.IOException;
 import java.util.concurrent.Callable;
 import saccubus.ConvertStopFlag;
+import saccubus.converter.filegetter.FileInstanciator;
 import saccubus.net.TextProgressListener;
+import yukihane.saccubus.converter.profile.FfmpegOption;
+import yukihane.saccubus.converter.profile.Profile;
 
 /**
  * <p>タイトル: さきゅばす</p>
@@ -21,39 +21,27 @@ import saccubus.net.TextProgressListener;
  * @author 未入力
  * @version 1.0
  */
-public class Converter extends AbstractCommand implements Runnable, Callable<Boolean> {
+public class Converter extends AbstractCommand implements Callable<Boolean> {
 
-    private static final String VIDEO_URL_PARSER = "http://www.nicovideo.jp/watch/";
     private final Profile profile;
     private final String movieId;
-    private final String time;
 
     /**
      * コンバータを構築します.
-     * @param url 対象となる動画のURL.
+     * @param id 対象となる動画のID.
      * @param time
      * @param profile
      * @param listener
-     * @param flag 
+     * @param flag
      */
-    public Converter(String url, String time, Profile profile,
+    public Converter(String id, Profile profile,
             TextProgressListener listener, ConvertStopFlag flag) {
         super(listener, flag);
-        url = url.trim();
-        if (url.startsWith(VIDEO_URL_PARSER)) {
-            int index = url.indexOf('?', VIDEO_URL_PARSER.length());
-            if (index >= 0) {
-                movieId = url.substring(VIDEO_URL_PARSER.length(), index);
-            } else {
-                movieId = url.substring(VIDEO_URL_PARSER.length());
-            }
-        } else {
-            movieId = url;
-        }
-        this.time = time;
+        this.movieId = id;
         this.profile = profile;
     }
 
+    @Override
     public Boolean call() throws Exception {
         boolean result = false;
         try {
@@ -64,6 +52,7 @@ public class Converter extends AbstractCommand implements Runnable, Callable<Boo
         return Boolean.valueOf(result);
     }
 
+    // TODO Runnableを実装しなくなったので削除する
     public void run() {
         try {
             call();
@@ -75,7 +64,7 @@ public class Converter extends AbstractCommand implements Runnable, Callable<Boo
     }
 
     private boolean runConvert() throws IOException, InterruptedException {
-        if (!profile.shouldRun()) {
+        if (!shouldRun(profile)) {
             sendText("何もすることがありません");
             return true;
         }
@@ -89,17 +78,17 @@ public class Converter extends AbstractCommand implements Runnable, Callable<Boo
 
         stopFlagReturn();
 
-        final File videoFile = fi.getVideoFile(getListener());
+        File commentFile = fi.getCommentFile(getListener());
 
         stopFlagReturn();
 
-        File commentFile = fi.getCommentFile(getListener());
+        File tcommFile = fi.getTcommFile(getListener());
 
         stopFlagReturn();
 
-        File tcommFile = fi.getTcommFile(getListener());
+        final File videoFile = fi.getVideoFile(getListener());
 
-        if (!profile.needsConvert()) {
+        if (!profile.getOutputFileSetting().isConvert()) {
             sendText("動画・コメントを保存し、変換は行いませんでした。");
             return true;
         }
@@ -145,17 +134,6 @@ public class Converter extends AbstractCommand implements Runnable, Callable<Boo
 
         boolean res = new FfmpegCommand(getListener(), getStopFlag(), commentFile, tcommFile, videoFile,
                 convertedVideoFile, profile.getFfmpeg(), profile.getGeneralSetting()).execute();
-        if (res) {
-            if (profile.getCommentSetting().isDelete()) {
-                commentFile.delete();
-            }
-            if (profile.getVideoSetting().isDelete()) {
-                videoFile.delete();
-            }
-            if (profile.getTcommentSetting().isDelete()) {
-                tcommFile.delete();
-            }
-        }
         return res;
     }
 
@@ -165,13 +143,14 @@ public class Converter extends AbstractCommand implements Runnable, Callable<Boo
         FileInstanciator.InstanciationType videoType = new FileInstanciator.InstanciationType(profile.getVideoSetting());
 
         FileInstanciator.CommentInstanciationType commentType = new FileInstanciator.CommentInstanciationType(profile.
-                getCommentSetting(), profile.getCommentGetInfo().isselfAdjustCommentNum(), profile.getCommentGetInfo().
-                getBackComment());
+                getCommentSetting(), profile.getCommentSetting().isSelfAdjustCommentNum(), profile.getCommentSetting().
+                getBackComment(), profile.getCommentSetting().isReduceComment());
 
         FileInstanciator.InstanciationType tcommType = new FileInstanciator.InstanciationType(
-                profile.getTcommentSetting());
+                profile.getCommentSetting());
 
-        fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, profile.getLoginInfo(), movieId, time);
+        fi = FileInstanciator.create(getStopFlag(), videoType, commentType, tcommType, profile.getLoginInfo(), profile.
+                getProxySetting(), movieId, profile.getCommentSetting().getBackLogPoint());
         return fi;
     }
 
@@ -180,7 +159,7 @@ public class Converter extends AbstractCommand implements Runnable, Callable<Boo
      * @throws IllegalArgumentException 設定に不備がある場合.
      */
     private void validSetting() {
-        if (profile.needsConvert()) {
+        if (profile.getOutputFileSetting().isConvert()) {
             File a = profile.getFfmpeg().getFfmpeg();
             if (!a.canRead()) {
                 throw new IllegalArgumentException("FFmpegが見つかりません。");
@@ -196,16 +175,6 @@ public class Converter extends AbstractCommand implements Runnable, Callable<Boo
             if (!a.canRead()) {
                 throw new IllegalArgumentException("フォントが見つかりません。");
             }
-        } else {
-            if (profile.getVideoSetting().isDelete()) {
-                throw new IllegalArgumentException("変換しないのに、動画削除しちゃって良いんですか?");
-            }
-            if (profile.getCommentSetting().isDelete()) {
-                throw new IllegalArgumentException("変換しないのに、コメント削除しちゃって良いんですか?");
-            }
-            if (profile.getTcommentSetting().isDelete()) {
-                throw new IllegalArgumentException("変換しないのに、投稿者コメント削除しちゃって良いんですか?");
-            }
         }
     }
 
@@ -221,4 +190,14 @@ public class Converter extends AbstractCommand implements Runnable, Callable<Boo
     public ConvertStopFlag getStopFlag() {
         return super.getStopFlag();
     }
+
+    /** @return 何か実行すべき処理があればtrue. */
+    private static boolean shouldRun(Profile profile) {
+        return profile.getOutputFileSetting().isConvert() || needsDownload(profile);
+    }
+
+    /** @return 何かダウンロードするものがあればtrue. */
+    private static boolean needsDownload(Profile profile) {
+        return (profile.getVideoSetting().isDownload() || profile.getCommentSetting().isDownload());
+    }
 }