OSDN Git Service

NicoBrowserをいんきゅばすから使用するためのAdapter
authoryukihane <yukihane.feather@gmail.com>
Wed, 10 Aug 2011 22:36:34 +0000 (07:36 +0900)
committeryukihane <yukihane.feather@gmail.com>
Thu, 11 Aug 2011 07:09:59 +0000 (16:09 +0900)
(cherry picked from commit 1cbcf73ac41cccefa90b81f937f7652a85ebb88e)

frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java [new file with mode: 0644]

diff --git a/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java b/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java
new file mode 100644 (file)
index 0000000..b8be283
--- /dev/null
@@ -0,0 +1,87 @@
+package yukihane.inqubus.saccubus_adapter;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import nicobrowser.NicoHttpClient;
+import saccubus.ConvertStopFlag;
+import saccubus.net.CommentInfo;
+import saccubus.net.NicoClient;
+import saccubus.net.TextProgressListener;
+import saccubus.net.VideoInfo;
+import saccubus.util.FileUtil;
+
+/**
+ *
+ * @author yuki
+ */
+public class NicoBrowserAdapter implements NicoClient {
+
+    private static final Logger logger = Logger.getLogger(NicoBrowserAdapter.class.getName());
+    private final NicoHttpClient client;
+    private final boolean hasLogin;
+    private final ConvertStopFlag stopFlag;
+
+    public NicoBrowserAdapter(final String mail, final String pass,
+            final ConvertStopFlag flag, final String proxyHost, final int proxyPort) {
+
+        if (proxyHost != null && proxyHost.length() > 0 && proxyPort >= 0 && proxyPort <= 65535) {
+            this.client = new NicoHttpClient(proxyHost, proxyPort);
+        } else {
+            this.client = new NicoHttpClient();
+        }
+
+        // ログイン
+        boolean loginned = false;
+        try {
+            loginned = client.login(mail, pass);
+        } catch (Exception ex) {
+            logger.log(Level.SEVERE, "ログイン処理時に例外発生", ex);
+        }
+        this.hasLogin = loginned;
+
+        this.stopFlag = flag;
+
+    }
+
+    @Override
+    public VideoInfo getVideoInfo(String tag) throws IOException {
+        final nicobrowser.VideoInfo vi = client.getVideoInfo(tag);
+        final VideoInfo.OfficialOption oo =
+                new VideoInfo.OfficialOption(vi.getKeyMap().get("threadkey"), vi.getKeyMap().get("force_184"));
+
+        return new VideoInfo(FileUtil.safeFileName(vi.getTitleInWatchPage()), vi.getThreadId(), vi.getVideoUrl().
+                toString(), vi.getMessageUrl().toString(), vi.getUserId(), vi.getVideoLength(), oo);
+    }
+
+    @Override
+    public CommentInfo getWayBackKey(VideoInfo vi, String time) throws IOException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public File getComment(VideoInfo videoInfo, CommentInfo commentInfo, File file, TextProgressListener listener,
+            String com) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public File getTcomment(VideoInfo videoInfo, File file, TextProgressListener listener) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public File getVideo(VideoInfo videoInfo, File file, TextProgressListener listener) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public boolean isLoggedIn() {
+        return hasLogin;
+    }
+
+    private boolean login() {
+        return false;
+    }
+}