From 0fe20b4cd1c7054f390751aa1450f6dbd36b3e41 Mon Sep 17 00:00:00 2001 From: yukihane Date: Thu, 11 Aug 2011 07:36:34 +0900 Subject: [PATCH] =?utf8?q?NicoBrowser=E3=82=92=E3=81=84=E3=82=93=E3=81=8D?= =?utf8?q?=E3=82=85=E3=81=B0=E3=81=99=E3=81=8B=E3=82=89=E4=BD=BF=E7=94=A8?= =?utf8?q?=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81=E3=81=AEAdapter=20(cherry?= =?utf8?q?=20picked=20from=20commit=201cbcf73ac41cccefa90b81f937f7652a85eb?= =?utf8?q?b88e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../saccubus_adapter/NicoBrowserAdapter.java | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java diff --git a/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java b/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java new file mode 100644 index 0000000..b8be283 --- /dev/null +++ b/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java @@ -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; + } +} -- 2.11.0