OSDN Git Service

コマンドラインからのダウンロード処理実装
authoryukihane <yukihane.feather@gmail.com>
Mon, 5 Sep 2011 22:43:05 +0000 (07:43 +0900)
committeryukihane <yukihane.feather@gmail.com>
Fri, 9 Sep 2011 11:42:08 +0000 (20:42 +0900)
frontend/src/saccubus/prompt/DownloadProfileImpl.java [new file with mode: 0644]
frontend/src/saccubus/prompt/Prompt.java

diff --git a/frontend/src/saccubus/prompt/DownloadProfileImpl.java b/frontend/src/saccubus/prompt/DownloadProfileImpl.java
new file mode 100644 (file)
index 0000000..ae32c04
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package saccubus.prompt;
+
+import java.io.File;
+import saccubus.worker.profile.CommentProfile;
+import saccubus.worker.profile.DownloadProfile;
+import saccubus.worker.profile.GeneralProfile;
+import saccubus.worker.profile.LoginProfile;
+import saccubus.worker.profile.ProxyProfile;
+import saccubus.worker.profile.VideoProfile;
+import yukihane.inqubus.Config;
+
+/**
+ *
+ * @author user
+ */
+public class DownloadProfileImpl implements DownloadProfile {
+
+    private final LoginProfile loginProfile;
+    private final ProxyProfile proxyProfile;
+    private final VideoProfile videoProfile;
+    private final CommentProfile commentProfile;
+    private final GeneralProfile generalProfile;
+
+    DownloadProfileImpl(final String mail, final String pass, final long time) {
+        this.loginProfile = new LoginProfile() {
+
+            @Override
+            public String getMail() {
+                return mail;
+            }
+
+            @Override
+            public String getPassword() {
+                return pass;
+            }
+        };
+
+        this.proxyProfile = new ProxyProfileImpl();
+        this.videoProfile = new VideoProfileImpl();
+        this.commentProfile = new CommentProfileImpl(time);
+        this.generalProfile = new GeneralProfileImpl();
+    }
+
+    @Override
+    public LoginProfile getLoginInfo() {
+        return loginProfile;
+    }
+
+    @Override
+    public ProxyProfile getProxyProfile() {
+        return this.proxyProfile;
+    }
+
+    @Override
+    public VideoProfile getVideoProfile() {
+        return this.videoProfile;
+    }
+
+    @Override
+    public CommentProfile getCommentProfile() {
+        return this.commentProfile;
+    }
+
+    @Override
+    public GeneralProfile getGeneralProfile() {
+        return this.generalProfile;
+    }
+}
+
+class ProxyProfileImpl implements ProxyProfile {
+
+    private final boolean use;
+    private final String host;
+    private final int port;
+
+    ProxyProfileImpl() {
+        final Config p = Config.INSTANCE;
+        use = p.getProxyUse();
+        host = p.getProxyHost();
+        port = Integer.parseInt(p.getProxyPort());
+    }
+
+    @Override
+    public boolean use() {
+        return use;
+    }
+
+    @Override
+    public String getHost() {
+        return host;
+    }
+
+    @Override
+    public int getPort() {
+        return port;
+    }
+}
+
+class VideoProfileImpl implements VideoProfile {
+
+    private final boolean download;
+    private final File dir;
+    private final String fileName;
+
+    VideoProfileImpl() {
+        final Config p = Config.INSTANCE;
+        this.download = !p.getVideoUseLocal();
+        this.dir = new File(p.getVideoDir());
+        this.fileName = p.getVideoFileNamePattern();
+    }
+
+    @Override
+    public boolean isDownload() {
+        return download;
+    }
+
+    @Override
+    public File getDir() {
+        return dir;
+    }
+
+    @Override
+    public String getFileName() {
+        return fileName;
+    }
+
+    @Override
+    public File getLocalFile() {
+        return getDir();
+    }
+}
+
+class CommentProfileImpl implements CommentProfile {
+
+    private final int lengthRelatedCommentSize;
+    private final int perMinCommentSize;
+    private final boolean disablePerMinComment;
+    private final long backLogPoint;
+    private final boolean download;
+    private final File dir;
+    private final String fileName;
+
+    CommentProfileImpl(final long backLogPoint) {
+        final Config p = Config.INSTANCE;
+        this.lengthRelatedCommentSize = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
+        this.perMinCommentSize = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
+        // TODO disablePerMinComment がデフォルト設定値に無い
+        this.disablePerMinComment = false;
+        this.backLogPoint = backLogPoint;
+        this.download = !p.getCommentUseLocal();
+        this.dir = new File(p.getCommentDir());
+        this.fileName = p.getCommentFileNamePattern();
+    }
+
+    @Override
+    public int getLengthRelatedCommentSize() {
+        return lengthRelatedCommentSize;
+    }
+
+    @Override
+    public boolean isDisablePerMinComment() {
+        return disablePerMinComment;
+    }
+
+    @Override
+    public int getPerMinCommentSize() {
+        return perMinCommentSize;
+    }
+
+    @Override
+    public long getBackLogPoint() {
+        return backLogPoint;
+    }
+
+    @Override
+    public boolean isDownload() {
+        return download;
+    }
+
+    @Override
+    public File getDir() {
+        return dir;
+    }
+
+    @Override
+    public String getFileName() {
+        return fileName;
+    }
+
+    @Override
+    public File getLocalFile() {
+        return getDir();
+    }
+}
+
+class GeneralProfileImpl implements GeneralProfile {
+
+    private final String replaceFrom;
+    private final String replaceTo;
+
+    GeneralProfileImpl() {
+        final Config p = Config.INSTANCE;
+        this.replaceFrom = p.getReplaceFrom();
+        this.replaceTo = p.getReplaceTo();
+    }
+
+    @Override
+    public String getReplaceFrom() {
+        return replaceFrom;
+    }
+
+    @Override
+    public String getReplaceTo() {
+        return replaceTo;
+    }
+}
index d7b9c16..37ccafa 100644 (file)
@@ -1,7 +1,7 @@
 package saccubus.prompt;
 
+import java.io.File;
 import java.io.IOException;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -12,9 +12,11 @@ import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
+import saccubus.FfmpegOption;
+import saccubus.util.WayBackTimeParser;
 import saccubus.worker.impl.download.Download;
 import saccubus.worker.impl.download.DownloadResult;
-import saccubus.worker.classic.profile.Profile;
+import saccubus.worker.profile.DownloadProfile;
 
 /**
  * <p>
@@ -49,31 +51,32 @@ public class Prompt {
     }
 
     public void execute(String[] args) throws IOException {
-        Options options = createOptions(args);
-        Profile profile;
-        try {
-            CommandLineParser parser = new BasicParser();
-            CommandLine cmd = parser.parse(options, args);
-            profile = createExecuteOption(cmd);
-        } catch (Exception e) {
-            HelpFormatter hf = new HelpFormatter();
-            hf.printHelp("java -jar Saccubus.jar [opts]", options);
-            System.out.flush();
-            throw new IOException(e);
-        }
-
-        Download conv = new Download(profile, "dummy0");
-        ExecutorService es = Executors.newSingleThreadExecutor();
-        final Future<DownloadResult> future = es.submit(conv);
-        try {
-            boolean res = future.get().getResultValue();
-            if (!res) {
-                throw new IOException("ffmpeg変換処理が正常に終了しませんでした。");
-            }
-        } catch (Exception ex) {
-            throw new IOException("取得失敗", ex);
-        }
-        System.out.println("Finished.");
+        throw new UnsupportedOperationException();
+//        Options options = createOptions(args);
+//        Profile profile;
+//        try {
+//            CommandLineParser parser = new BasicParser();
+//            CommandLine cmd = parser.parse(options, args);
+//            profile = createExecuteOption(cmd);
+//        } catch (Exception e) {
+//            HelpFormatter hf = new HelpFormatter();
+//            hf.printHelp("java -jar Saccubus.jar [opts]", options);
+//            System.out.flush();
+//            throw new IOException(e);
+//        }
+//
+//        Download conv = new Download(profile, "dummy0");
+//        ExecutorService es = Executors.newSingleThreadExecutor();
+//        final Future<DownloadResult> future = es.submit(conv);
+//        try {
+//            boolean res = future.get().getResultValue();
+//            if (!res) {
+//                throw new IOException("ffmpeg変換処理が正常に終了しませんでした。");
+//            }
+//        } catch (Exception ex) {
+//            throw new IOException("取得失敗", ex);
+//        }
+//        System.out.println("Finished.");
     }
 
     private Options createOptions(String[] args) {
@@ -100,7 +103,7 @@ public class Prompt {
         return options;
     }
 
-    private Profile createExecuteOption(CommandLine cmd) throws IOException {
+//    private Profile createExecuteOption(CommandLine cmd) throws IOException {
 //        final String mail = "dmy";
 //        final String pass = "dmy";
 //        final String video = cmd.getOptionValue("file_video");
@@ -137,8 +140,7 @@ public class Prompt {
 //                newOutputFileSetting, newFfmpeg);
 //
 //        return p;
-        return null;
-    }
+//    }
 
     /**
      * 昔の引数形式でプログラムを実行する.
@@ -147,12 +149,10 @@ public class Prompt {
         String mail = args[0];
         String pass = args[1];
         String tag = args[2];
-        String time = args.length < 4 ? "" : args[3];
-        // TODO
-//        SProperties setting = SProperties.loadSetting(mail, pass);
-//        Converter conv = new Converter(tag, setting.toProfile(), TextProgressListener.EMPTY_LISTENER, new ConvertStopFlag(
-//                ConvertStopFlag.StateChangeListener.EMPTY_LISTENER));
-        Download conv = new Download(null/*この部分*/, tag);
+        long time = args.length < 4 ? -1L : WayBackTimeParser.parse(args[3]);
+
+        final DownloadProfile profile = new DownloadProfileImpl(mail, pass, time);
+        final Download download = new Download(profile, tag);
         System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
         System.out.println("Saccubus on CUI");
         System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
@@ -161,7 +161,8 @@ public class Prompt {
         System.out.println("VideoID: " + tag);
         System.out.println("WaybackTime: " + time);
         System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
-        conv.call();
+        download.call();
+        // TODO 変換処理が必要
         System.out.println("Finished.");
     }
 }