OSDN Git Service

Convert再考
authoryukihane <yukihane.feather@gmail.com>
Mon, 22 Aug 2011 21:01:39 +0000 (06:01 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 22 Aug 2011 21:01:39 +0000 (06:01 +0900)
13 files changed:
frontend/src/saccubus/worker/Convert.java
frontend/src/saccubus/worker/ConvertResult.java
frontend/src/saccubus/worker/Download.java
frontend/src/saccubus/worker/DownloadResult.java
frontend/src/saccubus/worker/TestFrame.java
frontend/src/saccubus/worker/classic/profile/Ffmpeg.java
frontend/src/saccubus/worker/classic/profile/FfmpegOption.java
frontend/src/saccubus/worker/classic/profile/OutputFileSetting.java
frontend/src/saccubus/worker/profile/ConvertProfile.java
frontend/src/saccubus/worker/profile/DownloadProfile.java [new file with mode: 0644]
frontend/src/saccubus/worker/profile/FfmpegProfile.java
frontend/src/saccubus/worker/profile/OutputProfile.java
frontend/src/yukihane/inqubus/util/OutputNamePattern.java [new file with mode: 0644]

index f8873be..571fe0f 100644 (file)
@@ -1,6 +1,9 @@
 /* $Id$ */
 package saccubus.worker;
 
+import static org.apache.commons.io.FilenameUtils.getBaseName;
+import static org.apache.commons.lang.StringUtils.*;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
@@ -12,14 +15,16 @@ 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.conv.ConvertToVideoHook;
 import saccubus.worker.profile.ConvertProfile;
+import saccubus.worker.profile.ConvertProfile.HideCondition;
 import saccubus.worker.profile.FfmpegProfile;
+import saccubus.worker.profile.GeneralProfile;
+import saccubus.worker.profile.OutputProfile;
+import yukihane.inqubus.util.OutputNamePattern;
 import yukihane.mediainfowrapper.Info;
 import yukihane.mediainfowrapper.MediaInfo;
 import yukihane.mediainfowrapper.Size;
-import saccubus.worker.profile.ConvertProfile.HideCondition;
 import yukihane.swf.Cws2Fws;
 
 /**
@@ -43,11 +48,23 @@ public class Convert extends SwingWorker<ConvertResult, ConvertProgress> {
      * @param output 変換後出力動画.
      * @throws IOException 変換失敗.
      */
-    public Convert(ConvertProfile profile, File video, File comment, File output) throws IOException {
+    public Convert(ConvertProfile profile, File video, File comment) {
         this.profile = profile;
         this.videoFile = video;
         this.commentFile = comment;
-        this.outputFile = output;
+
+        final GeneralProfile gene = profile.getGeneralProfile();
+        final OutputProfile outprof = profile.getOutputProfile();
+        final OutputNamePattern pattern = new OutputNamePattern();
+        final String id = outprof.getVideoId();
+        pattern.setId(isNotEmpty(id) ? id : "");
+        final String title = outprof.getTitile();
+        pattern.setTitle(isNotEmpty(title) ? title : "");
+        final String fileName = getBaseName(video.getPath());
+        pattern.setFileName(fileName);
+        pattern.setReplaceFrom(gene.getReplaceFrom());
+        pattern.setReplaceFrom(gene.getReplaceTo());
+        this.outputFile = new File(outprof.getDir(), pattern.createFileName());
     }
 
     @Override
@@ -71,10 +88,10 @@ public class Convert extends SwingWorker<ConvertResult, ConvertProgress> {
             final int code = convert();
             if (code != 0) {
                 publish(new ConvertProgress("変換エラー:" + outputFile.getPath()));
-                return new ConvertResult(false);
+                return new ConvertResult(false, null);
             }
             publish(new ConvertProgress("変換が正常に終了しました。"));
-            return new ConvertResult(true);
+            return new ConvertResult(true, outputFile.getName());
         } finally {
             if (transformedComment != null && transformedComment.exists()) {
                 transformedComment.delete();
@@ -111,13 +128,13 @@ public class Convert extends SwingWorker<ConvertResult, ConvertProgress> {
         cmdList.add("-y");
         final String[] mainOptions = ffop.getMainOption().split(" +");
         for (String opt : mainOptions) {
-            if (StringUtils.isNotBlank(opt)) {
+            if (isNotBlank(opt)) {
                 cmdList.add(opt);
             }
         }
         final String[] inOptions = ffop.getInOption().split(" +");
         for (String opt : inOptions) {
-            if (StringUtils.isNotBlank(opt)) {
+            if (isNotBlank(opt)) {
                 cmdList.add(opt);
             }
         }
@@ -125,7 +142,7 @@ public class Convert extends SwingWorker<ConvertResult, ConvertProgress> {
         cmdList.add(targetVideoFile.getPath());
         final String[] outOptions = ffop.getOutOption().split(" +");
         for (String opt : outOptions) {
-            if (StringUtils.isNotBlank(opt)) {
+            if (isNotBlank(opt)) {
                 cmdList.add(opt);
             }
         }
@@ -142,13 +159,13 @@ public class Convert extends SwingWorker<ConvertResult, ConvertProgress> {
         if (!profile.isVhookDisabled()) {
             final boolean addComment = (commentFile != null);
             final String vhookArg = getVhookArg(profile, addComment, transformedComment.getPath(), isHD);
-            if (StringUtils.isNotBlank(vhookArg)) {
+            if (isNotBlank(vhookArg)) {
                 avfilterArgs.add(vhookArg);
             }
         }
         if (!avfilterArgs.isEmpty()) {
             cmdList.add("-vfilters");
-            final String args = "\"" + StringUtils.join(avfilterArgs, ", ") + "\"";
+            final String args = "\"" + join(avfilterArgs, ", ") + "\"";
             cmdList.add(args);
         }
         cmdList.add(outputFile.getPath());
@@ -191,7 +208,7 @@ public class Convert extends SwingWorker<ConvertResult, ConvertProgress> {
 
     private static List<String> createAvfilterOptions(String avfilterOption) {
         final List<String> avfilterArgs = new ArrayList<String>();
-        if (StringUtils.isNotBlank(avfilterOption)) {
+        if (isNotBlank(avfilterOption)) {
             avfilterArgs.add(avfilterOption);
         }
         return avfilterArgs;
index 796dead..d340ec4 100644 (file)
@@ -7,12 +7,18 @@ package saccubus.worker;
 public class ConvertResult {
 
     private final boolean resultValue;
+    private final String title;
 
-    ConvertResult(boolean b) {
+    ConvertResult(boolean b, String title) {
         this.resultValue = b;
+        this.title = title;
     }
 
     public boolean isResultValue() {
         return resultValue;
     }
+
+    public String getTitle() {
+        return title;
+    }
 }
index 5ddf99b..b042604 100644 (file)
@@ -73,10 +73,6 @@ public class Download extends SwingWorker<DownloadResult, DownloadProgress> impl
 //    }
     @Override
     protected DownloadResult doInBackground() throws Exception {
-        if (!needsDownload(profile)) {
-            publish(new DownloadProgress("何もすることがありません"));
-            return new DownloadResult(true);
-        }
 
         publish(new DownloadProgress("ログイン中"));
 
@@ -122,7 +118,7 @@ public class Download extends SwingWorker<DownloadResult, DownloadProgress> impl
         checkStop();
 
         File videoFile;
-        GetFlvResult vf = null;
+        GetFlvResult vf;
         if (profile.getVideoSetting().isDownload()) {
             vf = client.getFlvFile(vi, profile.getVideoSetting().getDir(), videoNamePattern,
                     Status.GET_INFO, true, new ProgressListener() {
@@ -138,7 +134,7 @@ public class Download extends SwingWorker<DownloadResult, DownloadProgress> impl
         } else {
             videoFile = profile.getVideoSetting().getLocalFile();
         }
-        return new DownloadResult(true);
+        return new DownloadResult(true, videoFile, commentFile);
 
 
         // TODO FFMPEG 実行開始は別タスクとして実装する.
index b19876e..44280de 100644 (file)
@@ -1,5 +1,7 @@
 package saccubus.worker;
 
+import java.io.File;
+
 /**
  *
  * @author yuki
@@ -7,12 +9,24 @@ package saccubus.worker;
 public class DownloadResult {
 
     private final boolean resultValue;
+    private final File downloadVideo;
+    private final File downloadComment;
 
-    DownloadResult(boolean b) {
+    DownloadResult(boolean b, File downloadVideo, File downloadComment) {
         this.resultValue = b;
+        this.downloadVideo = downloadVideo;
+        this.downloadComment = downloadComment;
     }
 
     public boolean getResultValue() {
         return resultValue;
     }
+
+    public File getDownloadComment() {
+        return downloadComment;
+    }
+
+    public File getDownloadVideo() {
+        return downloadVideo;
+    }
 }
index 88c0a41..8f5a06e 100644 (file)
@@ -16,6 +16,8 @@ import javax.swing.JPanel;
 import javax.swing.JTextField;
 import javax.swing.SwingUtilities;
 import saccubus.worker.profile.CommentProfile;
+import saccubus.worker.profile.ConvertProfile;
+import saccubus.worker.profile.FfmpegProfile;
 import saccubus.worker.profile.GeneralProfile;
 import saccubus.worker.profile.LoginProfile;
 import saccubus.worker.profile.OutputProfile;
@@ -34,24 +36,23 @@ public class TestFrame extends JFrame {
     private final JButton btnDownload = new JButton("DOWNLOAD");
     private final JButton btnCancel = new JButton("Cancel");
     private final JTextField fldStatus = new JTextField();
-    private Download downloadWorker;
+    private final JButton btnConv = new JButton("Conv");
+    private final JButton btnConvCancel = new JButton("ConvCancl");
+    private Download downloader;
+    private Convert converter;
 
     public TestFrame() {
         JPanel panel = new JPanel();
         GroupLayout lo = new GroupLayout(panel);
         panel.setLayout(lo);
 
-        lo.setHorizontalGroup(lo.createParallelGroup()
-                .addGroup(lo.createSequentialGroup()
-                    .addComponent(fldVideoId).addComponent(btnDownload))
-                .addGroup(lo.createSequentialGroup()
-                    .addComponent(fldStatus).addComponent(btnCancel)));
+        lo.setHorizontalGroup(lo.createParallelGroup().addGroup(lo.createSequentialGroup().addComponent(fldVideoId).
+                addComponent(btnDownload)).addGroup(lo.createSequentialGroup().addComponent(fldStatus).addComponent(
+                btnCancel)));
 
-        lo.setVerticalGroup(lo.createSequentialGroup()
-                .addGroup(lo.createParallelGroup()
-                    .addComponent(fldVideoId).addComponent(btnDownload))
-                .addGroup(lo.createParallelGroup()
-                    .addComponent(fldStatus).addComponent(btnCancel)));
+        lo.setVerticalGroup(lo.createSequentialGroup().addGroup(lo.createParallelGroup().addComponent(fldVideoId).
+                addComponent(btnDownload)).addGroup(lo.createParallelGroup().addComponent(fldStatus).addComponent(
+                btnCancel)));
 
         setContentPane(panel);
         pack();
@@ -59,30 +60,75 @@ public class TestFrame extends JFrame {
 
         btnDownload.addActionListener(new DownloadListener());
         btnCancel.addActionListener(new CancelListener());
+        btnConv.addActionListener(new ConvertListener());
+        btnConvCancel.addActionListener(new ConvCnclListener());
+    }
+
+    private class ConvCnclListener implements ActionListener {
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            if (converter != null) {
+                converter.cancel(true);
+            }
+        }
+    }
+
+    private class ConvertListener implements ActionListener {
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            converter = new Convert(new MyConvProfile(), new File("out/sm9.flv"), new File("out/sm9.xml")) {
+
+                @Override
+                protected void process(List<ConvertProgress> chunks) {
+                    ConvertProgress chunk = chunks.get(chunks.size() - 1);
+                    fldStatus.setText(chunk.getMessage());
+                }
+
+                @Override
+                protected void done() {
+                    btnConv.setEnabled(true);
+                    try {
+                        ConvertResult res = get();
+                    } catch (InterruptedException ex) {
+                        ex.printStackTrace();
+                    } catch (ExecutionException ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            };
+
+            btnConv.setEnabled(false);
+            converter.execute();
+
+        }
     }
 
     private class CancelListener implements ActionListener {
 
         @Override
         public void actionPerformed(ActionEvent e) {
-            if(downloadWorker != null){
-                downloadWorker.cancel(true);
+            if (downloader != null) {
+                downloader.cancel(true);
             }
         }
     }
 
     private class DownloadListener implements ActionListener {
+
         @Override
         public void actionPerformed(ActionEvent e) {
-            downloadWorker = new Download(new MyProfile(), fldVideoId.getText()){
+            downloader = new Download(new MyProfile(), fldVideoId.getText()) {
+
                 @Override
-                protected void process(List<DownloadProgress> chunks){
-                    DownloadProgress chunk = chunks.get(chunks.size()-1);
+                protected void process(List<DownloadProgress> chunks) {
+                    DownloadProgress chunk = chunks.get(chunks.size() - 1);
                     fldStatus.setText(chunk.getMessage());
                 }
 
                 @Override
-                protected void done(){
+                protected void done() {
                     btnDownload.setEnabled(true);
                     try {
                         DownloadResult res = get();
@@ -95,13 +141,12 @@ public class TestFrame extends JFrame {
             };
 
             btnDownload.setEnabled(false);
-            downloadWorker.execute();
+            downloader.execute();
 
         }
-
     }
 
-    public static void main(String[] args){
+    public static void main(String[] args) {
         SwingUtilities.invokeLater(new Runnable() {
 
             @Override
@@ -113,7 +158,7 @@ public class TestFrame extends JFrame {
         });
     }
 
-    private static class MyProfile implements DownloadProfile{
+    private static class MyProfile implements DownloadProfile {
 
         @Override
         public LoginProfile getLoginInfo() {
@@ -249,7 +294,6 @@ public class TestFrame extends JFrame {
 //                }
 //            };
 //        }
-
         @Override
         public GeneralProfile getGeneralSetting() {
             return new GeneralProfile() {
@@ -265,7 +309,83 @@ public class TestFrame extends JFrame {
                 }
             };
         }
-
     }
 
+    private class MyConvProfile implements ConvertProfile {
+
+        @Override
+        public FfmpegProfile getFfmpegOption() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public File getFfmpeg() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public boolean isVhookDisabled() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public File getVhook() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public File getTempDir() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public File getFont() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public int getFontIndex() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public boolean isCommentOpaque() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public boolean isDisableFontSizeArrange() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public int getShadowIndex() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public boolean isShowConverting() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public int getMaxNumOfComment() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public HideCondition getNgSetting() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public OutputProfile getOutputProfile() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public GeneralProfile getGeneralProfile() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+    }
 }
index c4e4db4..122b41e 100644 (file)
@@ -2,6 +2,7 @@
 package saccubus.worker.classic.profile;
 
 import java.io.File;
+import saccubus.worker.profile.GeneralProfile;
 import saccubus.worker.profile.OutputProfile;
 
 /**
@@ -96,7 +97,12 @@ public class Ffmpeg implements saccubus.worker.profile.ConvertProfile {
     }
 
     @Override
-    public OutputProfile getOutputProvile() {
+    public OutputProfile getOutputProfile() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public GeneralProfile getGeneralProfile() {
         throw new UnsupportedOperationException("Not supported yet.");
     }
 }
index 2002e3f..8634e7c 100644 (file)
@@ -6,6 +6,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Properties;
 import org.apache.commons.lang.StringUtils;
+import saccubus.worker.profile.GeneralProfile;
 
 /**
  *
@@ -101,4 +102,9 @@ public class FfmpegOption implements saccubus.worker.profile.FfmpegProfile {
     public boolean isAdjustRatio() {
         return adjustRatio;
     }
+
+    @Override
+    public GeneralProfile getGeneralSetting() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
 }
index 4e6f0ff..6732b70 100644 (file)
@@ -48,4 +48,14 @@ public class OutputFileSetting implements saccubus.worker.profile.OutputProfile
     public String getFileName() {
         throw new UnsupportedOperationException("Not supported yet.");
     }
+
+    @Override
+    public String getVideoId() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public String getTitile() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
 }
index 8e7868f..a1187f2 100644 (file)
@@ -8,7 +8,9 @@ import java.io.File;
  */
 public interface ConvertProfile {
 
-    OutputProfile getOutputProvile();
+    OutputProfile getOutputProfile();
+
+    GeneralProfile getGeneralProfile();
 
     FfmpegProfile getFfmpegOption();
 
diff --git a/frontend/src/saccubus/worker/profile/DownloadProfile.java b/frontend/src/saccubus/worker/profile/DownloadProfile.java
new file mode 100644 (file)
index 0000000..948e327
--- /dev/null
@@ -0,0 +1,20 @@
+package saccubus.worker.profile;
+
+/**
+ * {@link saccubus.converter.Converter.Converter}が必要とするプロファイルです.
+ * Converterを使用するクライアントは, このインタフェースを実装するクラスのインスタンスで
+ * Converterへ処理させる内容を通知します.
+ * @author yuki
+ */
+public interface DownloadProfile {
+
+    LoginProfile getLoginInfo();
+
+    ProxyProfile getProxySetting();
+
+    VideoProfile getVideoSetting();
+
+    CommentProfile getCommentSetting();
+
+    GeneralProfile getGeneralSetting();
+}
index 96e730d..b100e7c 100644 (file)
@@ -23,4 +23,6 @@ public interface FfmpegProfile {
     int getResizeHeight();
 
     boolean isAdjustRatio();
+
+    GeneralProfile getGeneralSetting();
 }
index edafa77..a39b8d7 100644 (file)
@@ -30,5 +30,21 @@ public interface OutputProfile {
      * 変換した動画のファイル名パターン.
      * {@link #isConvert()}がfalseの場合未定義.
      */
-    public String getFileName();
+    String getFileName();
+
+    /**
+     * ファイル名パターンを置換するのに用いる情報.
+     * @return {@link #isConvert()}がtrueの場合に
+     * 変換した動画の動画ID.
+     * {@link #isConvert()}がfalseの場合未定義.
+     */
+    String getVideoId();
+
+    /**
+     * ファイル名パターンを置換するのに用いる情報.
+     * @return {@link #isConvert()}がtrueの場合に
+     * 変換した動画のタイトル.
+     * {@link #isConvert()}がfalseの場合未定義.
+     */
+    String getTitile();
 }
diff --git a/frontend/src/yukihane/inqubus/util/OutputNamePattern.java b/frontend/src/yukihane/inqubus/util/OutputNamePattern.java
new file mode 100644 (file)
index 0000000..e1a8e0e
--- /dev/null
@@ -0,0 +1,28 @@
+package yukihane.inqubus.util;
+
+import nicobrowser.NamePattern;
+
+/**
+ *
+ * @author yuki
+ */
+public class OutputNamePattern extends NamePattern {
+
+    private static final String FILE_NAME_PATTERN = "{filename}";
+    private String fileName = "";
+
+    public OutputNamePattern() {
+        super();
+        setIsNotLow(true);
+    }
+
+    public final void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    @Override
+    protected String replacePlaceHolder(String str) {
+        String res = super.replacePlaceHolder(str);
+        return res.replace(FILE_NAME_PATTERN, fileName);
+    }
+}