OSDN Git Service

動画変換クラスのクラス名変更
authoryukihane <yukihane.feather@gmail.com>
Mon, 22 Aug 2011 06:03:29 +0000 (15:03 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 22 Aug 2011 06:03:29 +0000 (15:03 +0900)
frontend/src/saccubus/converter/Convert.java [moved from frontend/src/saccubus/converter/Ffmpeg.java with 89% similarity]
frontend/src/saccubus/converter/ConvertProgress.java [moved from frontend/src/saccubus/converter/FfmpegProgress.java with 73% similarity]
frontend/src/saccubus/converter/ConvertResult.java [moved from frontend/src/saccubus/converter/FfmpegResult.java with 77% similarity]
frontend/src/saccubus/converter/TestFrame.java [new file with mode: 0644]

similarity index 89%
rename from frontend/src/saccubus/converter/Ffmpeg.java
rename to frontend/src/saccubus/converter/Convert.java
index dfaa539..f066aab 100644 (file)
@@ -28,9 +28,9 @@ import yukihane.swf.Cws2Fws;
  *
  * @author yuki
  */
-public class Ffmpeg extends SwingWorker<FfmpegResult, FfmpegProgress> {
+public class Convert extends SwingWorker<ConvertResult, ConvertProgress> {
 
-    private static final Logger logger = Logger.getLogger(Ffmpeg.class.getName());
+    private static final Logger logger = Logger.getLogger(Convert.class.getName());
     private final File commentMiddleFile;
     private final File tcommMiddleFile;
     private final File TMP_CWS;
@@ -39,7 +39,7 @@ public class Ffmpeg extends SwingWorker<FfmpegResult, FfmpegProgress> {
     private final File convertedVideoFile;
     private final ConvertProfile ffmpeg;
 
-    Ffmpeg(File commentFile, File videoFile, File convertedVideoFile, ConvertProfile ffmpeg) throws IOException {
+    Convert(ConvertProfile ffmpeg, File commentFile, File videoFile, File convertedVideoFile) throws IOException {
         this.commentFile = commentFile;
         this.videoFile = videoFile;
         this.convertedVideoFile = convertedVideoFile;
@@ -52,7 +52,7 @@ public class Ffmpeg extends SwingWorker<FfmpegResult, FfmpegProgress> {
     }
 
     @Override
-    protected FfmpegResult doInBackground() throws Exception {
+    protected ConvertResult doInBackground() throws Exception {
         try {
             return exec();
         } finally {
@@ -68,15 +68,15 @@ public class Ffmpeg extends SwingWorker<FfmpegResult, FfmpegProgress> {
         }
     }
 
-    private FfmpegResult exec() throws InterruptedException, IOException {
+    private ConvertResult exec() throws InterruptedException, IOException {
         final HideCondition ngSetting = getFfmpeg().getNgSetting();
         if (commentFile != null) {
-            publish(new FfmpegProgress("コメントの中間ファイルへの変換中"));
+            publish(new ConvertProgress("コメントの中間ファイルへの変換中"));
             boolean conv = ConvertToVideoHook.convert(commentFile, commentMiddleFile, ngSetting.getId(), ngSetting.
                     getWord());
             if (!conv) {
-                publish(new FfmpegProgress("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?"));
-                return new FfmpegResult(false);
+                publish(new ConvertProgress("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?"));
+                return new ConvertResult(false);
             }
         }
         checkStop();
@@ -89,16 +89,16 @@ public class Ffmpeg extends SwingWorker<FfmpegResult, FfmpegProgress> {
 //            }
 //        }
 //        stopFlagReturn();
-        publish(new FfmpegProgress("動画の変換を開始"));
+        publish(new ConvertProgress("動画の変換を開始"));
         int code;
         if ((code = converting_video(videoFile, convertedVideoFile, (commentFile != null), commentMiddleFile.getPath(),
                 false, tcommMiddleFile.getPath(), getFfmpeg().getFfmpegOption())) == 0) {
-            publish(new FfmpegProgress("変換が正常に終了しました。"));
-            return new FfmpegResult(true);
+            publish(new ConvertProgress("変換が正常に終了しました。"));
+            return new ConvertResult(true);
         } else {
-            publish(new FfmpegProgress("変換エラー:" + convertedVideoFile.getPath()));
+            publish(new ConvertProgress("変換エラー:" + convertedVideoFile.getPath()));
         }
-        return new FfmpegResult(false);
+        return new ConvertResult(false);
     }
 
     private int converting_video(File videoFile, File convertedVideoFile, boolean addComment, String commPath,
@@ -177,7 +177,7 @@ public class Ffmpeg extends SwingWorker<FfmpegResult, FfmpegProgress> {
             while ((e = ebr.readLine()) != null) {
                 String state = e;
                 if (state.startsWith("frame=")) {
-                    publish(new FfmpegProgress(state));
+                    publish(new ConvertProgress(state));
                 } else if (!state.endsWith("No accelerated colorspace conversion found")) {
                     logger.log(Level.INFO, e);
                 }
@@ -4,11 +4,11 @@ package saccubus.converter;
  *
  * @author yuki
  */
-public class FfmpegProgress {
+public class ConvertProgress {
 
     private final String message;
 
-    FfmpegProgress(String message) {
+    ConvertProgress(String message) {
         this.message = message;
     }
 
@@ -4,11 +4,11 @@ package saccubus.converter;
  *
  * @author yuki
  */
-public class FfmpegResult {
+public class ConvertResult {
 
     private final boolean resultValue;
 
-    FfmpegResult(boolean b) {
+    ConvertResult(boolean b) {
         this.resultValue = b;
     }
 
diff --git a/frontend/src/saccubus/converter/TestFrame.java b/frontend/src/saccubus/converter/TestFrame.java
new file mode 100644 (file)
index 0000000..91a7dc4
--- /dev/null
@@ -0,0 +1,271 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package saccubus.converter;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import javax.swing.GroupLayout;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+import saccubus.converter.profile.CommentProfile;
+import saccubus.converter.profile.GeneralProfile;
+import saccubus.converter.profile.LoginProfile;
+import saccubus.converter.profile.OutputProfile;
+import saccubus.converter.profile.Profile;
+import saccubus.converter.profile.ProxyProfile;
+import saccubus.converter.profile.VideoProfile;
+
+/**
+ *
+ * @author yuki
+ */
+public class TestFrame extends JFrame {
+
+    private static final long serialVersionUID = 1L;
+    private final JTextField fldVideoId = new JTextField();
+    private final JButton btnDownload = new JButton("DOWNLOAD");
+    private final JButton btnCancel = new JButton("Cancel");
+    private final JTextField fldStatus = new JTextField();
+    private Download downloadWorker;
+
+    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.setVerticalGroup(lo.createSequentialGroup()
+                .addGroup(lo.createParallelGroup()
+                    .addComponent(fldVideoId).addComponent(btnDownload))
+                .addGroup(lo.createParallelGroup()
+                    .addComponent(fldStatus).addComponent(btnCancel)));
+
+        setContentPane(panel);
+        pack();
+
+
+        btnDownload.addActionListener(new DownloadListener());
+        btnCancel.addActionListener(new CancelListener());
+    }
+
+    private class CancelListener implements ActionListener {
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            if(downloadWorker != null){
+                downloadWorker.cancel(true);
+            }
+        }
+    }
+
+    private class DownloadListener implements ActionListener {
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            downloadWorker = new Download(new MyProfile(), fldVideoId.getText()){
+                @Override
+                protected void process(List<DownloadProgress> chunks){
+                    DownloadProgress chunk = chunks.get(chunks.size()-1);
+                    fldStatus.setText(chunk.getMessage());
+                }
+
+                @Override
+                protected void done(){
+                    btnDownload.setEnabled(true);
+                    try {
+                        DownloadResult res = get();
+                    } catch (InterruptedException ex) {
+                        ex.printStackTrace();
+                    } catch (ExecutionException ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            };
+
+            btnDownload.setEnabled(false);
+            downloadWorker.execute();
+
+        }
+
+    }
+
+    public static void main(String[] args){
+        SwingUtilities.invokeLater(new Runnable() {
+
+            @Override
+            public void run() {
+                TestFrame view = new TestFrame();
+                view.setDefaultCloseOperation(EXIT_ON_CLOSE);
+                view.setVisible(true);
+            }
+        });
+    }
+
+    private static class MyProfile implements Profile{
+
+        @Override
+        public LoginProfile getLoginInfo() {
+            return new LoginProfile() {
+
+                @Override
+                public String getMail() {
+                    return "yamamoto5_5963@hotmail.com";
+                }
+
+                @Override
+                public String getPassword() {
+                    return "piyopiyo";
+                }
+            };
+        }
+
+        @Override
+        public ProxyProfile getProxySetting() {
+            return new ProxyProfile() {
+
+                @Override
+                public boolean use() {
+                    return false;
+                }
+
+                @Override
+                public String getHost() {
+                    throw new UnsupportedOperationException("Not supported yet.");
+                }
+
+                @Override
+                public int getPort() {
+                    throw new UnsupportedOperationException("Not supported yet.");
+                }
+            };
+        }
+
+        @Override
+        public VideoProfile getVideoSetting() {
+            return new VideoProfile() {
+
+                @Override
+                public boolean isDownload() {
+                    return true;
+                }
+
+                @Override
+                public File getDir() {
+                    return new File("out");
+                }
+
+                @Override
+                public String getFileName() {
+                    return "{id}_{title}";
+                }
+
+                @Override
+                public File getLocalFile() {
+                    throw new UnsupportedOperationException("Not supported yet.");
+                }
+            };
+        }
+
+        @Override
+        public CommentProfile getCommentSetting() {
+            return new CommentProfile() {
+
+                @Override
+                public int getLengthRelatedCommentSize() {
+                    return -1;
+                }
+
+                @Override
+                public boolean isDisablePerMinComment() {
+                    return false;
+                }
+
+                @Override
+                public int getPerMinCommentSize() {
+                    return -1;
+                }
+
+                @Override
+                public long getBackLogPoint() {
+                    return -1;
+                }
+
+                @Override
+                public boolean isDownload() {
+                    return true;
+                }
+
+                @Override
+                public File getDir() {
+                    return new File("out");
+                }
+
+                @Override
+                public String getFileName() {
+                    return "{id}_{title}";
+                }
+
+                @Override
+                public File getLocalFile() {
+                    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() {
+            return new GeneralProfile() {
+
+                @Override
+                public String getReplaceFrom() {
+                    return "<>\\/#";
+                }
+
+                @Override
+                public String getReplaceTo() {
+                    return "_";
+                }
+            };
+        }
+
+    }
+
+}