From 8073e511740760b6f6fcc691e807d1b31d4ffffb Mon Sep 17 00:00:00 2001 From: yukihane Date: Thu, 11 Aug 2011 13:54:17 +0900 Subject: [PATCH] =?utf8?q?NicoBrowser=E3=82=A2=E3=83=80=E3=83=97=E3=82=BF?= =?utf8?q?=E3=81=AE=E5=AE=9F=E8=A3=85=20(cherry=20picked=20from=20commit?= =?utf8?q?=20d8c728f80abba3407266caa91acaaa6f453cce59)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../saccubus_adapter/NicoBrowserAdapter.java | 52 +++++++++++++++++----- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java b/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java index f6c1d92..adc581c 100644 --- a/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java +++ b/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java @@ -4,7 +4,9 @@ import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import nicobrowser.GetFlvResult; import nicobrowser.NicoHttpClient; +import nicobrowser.ProgressListener; import saccubus.ConvertStopFlag; import saccubus.net.CommentInfo; import saccubus.net.NicoClient; @@ -22,6 +24,7 @@ public class NicoBrowserAdapter implements NicoClient { private final NicoHttpClient client; private final boolean hasLogin; private final ConvertStopFlag stopFlag; + private nicobrowser.VideoInfo nicoBrowserVi; public NicoBrowserAdapter(final String mail, final String pass, final ConvertStopFlag flag, final String proxyHost, final int proxyPort) { @@ -46,8 +49,10 @@ public class NicoBrowserAdapter implements NicoClient { } @Override - public VideoInfo getVideoInfo(String tag) throws IOException { - final nicobrowser.VideoInfo vi = client.getVideoInfo(tag); + public VideoInfo getVideoInfo(String videoId) throws IOException { + nicoBrowserVi = client.getVideoInfo(videoId); + final nicobrowser.VideoInfo vi = nicoBrowserVi; + final VideoInfo.OfficialOption oo = new VideoInfo.OfficialOption(vi.getKeyMap().get("threadkey"), vi.getKeyMap().get("force_184")); @@ -57,31 +62,56 @@ public class NicoBrowserAdapter implements NicoClient { @Override public String getWayBackKey(VideoInfo vi) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); + return client.getWayBackKey(nicoBrowserVi); } @Override public File getComment(VideoInfo videoInfo, CommentInfo commentInfo, File file, TextProgressListener listener, String com) { - throw new UnsupportedOperationException("Not supported yet."); + try { + // TODO CommentInfo を使用するようにしなければ + return client.getCommentFile(nicoBrowserVi, file.getPath()); + } catch (Exception ex) { + logger.log(Level.SEVERE, "コメント取得失敗", ex); + } + // TODO 失敗した場合何を返す? + return null; } @Override public File getTcomment(VideoInfo videoInfo, File file, TextProgressListener listener) { - throw new UnsupportedOperationException("Not supported yet."); + try { + return client.getTCommentFile(nicoBrowserVi, file.getParent()); + } catch (Exception ex) { + logger.log(Level.SEVERE, "投稿者コメント取得失敗", ex); + } + // TODO 失敗した場合何を返す? + return null; } @Override - public File getVideo(VideoInfo videoInfo, File file, TextProgressListener listener) { - throw new UnsupportedOperationException("Not supported yet."); + public File getVideo(final VideoInfo videoInfo, File file, final TextProgressListener listener) { + try { + GetFlvResult res = client.getFlvFile(nicoBrowserVi, file.getPath(), new ProgressListener() { + + @Override + public void progress(long fileSize, long downloadSize) { + final double p = ((double) downloadSize / fileSize) * 100.0; + final String msg = "動画ダウンロード:" + p + "パーセント完了"; + listener.setText(msg); + } + }); + + return res.getFile(); + } catch (Exception ex) { + logger.log(Level.SEVERE, null, ex); + } + // TODO 失敗した場合何を返す? + return null; } @Override public boolean isLoggedIn() { return hasLogin; } - - private boolean login() { - return false; - } } -- 2.11.0