OSDN Git Service

インタフェース名変更: LoginInfo -> LoginProfile
[coroid/inqubus.git] / frontend / src / saccubus / converter / filegetter / WebFileInstanciator.java
index ec0eb0b..23940a9 100644 (file)
@@ -3,11 +3,15 @@ package saccubus.converter.filegetter;
 
 import java.io.IOException;
 import java.text.Normalizer;
+import org.apache.commons.lang.StringUtils;
 import saccubus.ConvertStopFlag;
+import saccubus.net.CommentInfo;
 import saccubus.net.NicoClient;
 import saccubus.net.VideoInfo;
+import saccubus.util.WayBackTimeParser;
+import yukihane.inqubus.saccubus_adapter.NicoBrowserAdapter;
 import yukihane.saccubus.converter.profile.Proxy;
-import yukihane.saccubus.converter.profile.LoginInfo;
+import yukihane.saccubus.converter.profile.LoinProfile;
 
 /**
  * 動画ファイル, コメントファイルなど必要なファイルのうち, 1つでもダウンロード処理を必要とする場合のインスタンス化クラス.
@@ -17,13 +21,14 @@ public class WebFileInstanciator extends FileInstanciator {
 
     private final NicoClient client;
     private final VideoInfo videoInfo;
+    private final CommentInfo commentInfo;
 
     WebFileInstanciator(
             ConvertStopFlag stopFlag,
             InstanciationType videoType,
             CommentInstanciationType commentType,
             InstanciationType tcommType,
-            LoginInfo li,
+            LoinProfile li,
             Proxy proxy,
             String tag,
             String time) throws IOException {
@@ -42,28 +47,41 @@ public class WebFileInstanciator extends FileInstanciator {
             host = null;
             port = -1;
         }
-        client = new NicoClient(li.getMail(), li.getPass(), stopFlag, host, port);
+        client = new NicoBrowserAdapter(li.getMail(), li.getPass(), stopFlag, host, port) {
+        };
 
         if (!client.isLoggedIn()) {
             throw new IOException("ログインに失敗");
         }
 
         try {
-            videoInfo = client.getVideoInfo(tag, time);
+            videoInfo = client.getVideoInfo(tag);
+            if (StringUtils.isNotBlank(time)) {
+                System.out.print("Setting wayback time...");
+                final long waybacktime = WayBackTimeParser.parse(time);
+                String waybackkey = client.getWayBackKey(videoInfo);
+                commentInfo = new CommentInfo(waybackkey, waybacktime);
+            } else {
+                commentInfo = null;
+            }
+
         } catch (IOException ex) {
-            throw new IOException(tag + "の情報の取得に失敗", ex);
+            final String text = tag + "の情報の取得に失敗";
+            final String cause = (ex.getMessage() != null) ? "(" + ex.getMessage() + ")" : "";
+
+            throw new IOException(text + cause, ex);
         }
 
-        if (videoType.isDoanload()) {
+        if (videoType.isDownload()) {
             setVideoFileGetter(new VideoFileWebGetter(client, videoInfo));
         }
 
-        if (commentType.isDoanload()) {
-            setCommentFileGetter(new CommentFileWebGetter(client, videoInfo, commentType.isAutoCommentNum(),
-                    commentType.getBackComment()));
+        if (commentType.isDownload()) {
+            setCommentFileGetter(new CommentFileWebGetter(client, videoInfo, commentInfo, commentType.isAutoCommentNum(),
+                    commentType.getBackComment(), commentType.isReduceComment()));
         }
 
-        if (tcommType.isDoanload()) {
+        if (tcommType.isDownload()) {
             setTcommFileGetter(new TcommFileWebGetter(client, videoInfo));
         }
     }