From 3cf322da2e2ea8c0a06074c211c6b36c0dc2d791 Mon Sep 17 00:00:00 2001 From: yukihane Date: Thu, 11 Aug 2011 11:35:27 +0900 Subject: [PATCH] =?utf8?q?getWayBackKey=E3=83=A1=E3=82=BD=E3=83=83?= =?utf8?q?=E3=83=89=E3=81=A7=E3=81=AFwaybackkey=E5=8F=96=E5=BE=97=E3=81=AE?= =?utf8?q?=E3=81=BF=E3=82=92=E8=A1=8C=E3=81=86=E3=82=88=E3=81=86=E3=81=AB?= =?utf8?q?=E3=82=A4=E3=83=B3=E3=82=BF=E3=83=95=E3=82=A7=E3=83=BC=E3=82=B9?= =?utf8?q?=E3=82=92=E5=AE=9A=E7=BE=A9=E3=81=97=E3=81=AA=E3=81=8A=E3=81=97?= =?utf8?q?=20(cherry=20picked=20from=20commit=2056a076782cd214327e6752e79b?= =?utf8?q?6539ef8ee425a7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Conflicts: frontend/src/saccubus/converter/filegetter/WebFileInstanciator.java --- .../converter/filegetter/WebFileInstanciator.java | 14 ++++++- frontend/src/saccubus/net/NicoClient.java | 6 ++- frontend/src/saccubus/net/NicoClientImpl.java | 45 +--------------------- .../saccubus_adapter/NicoBrowserAdapter.java | 2 +- 4 files changed, 20 insertions(+), 47 deletions(-) diff --git a/frontend/src/saccubus/converter/filegetter/WebFileInstanciator.java b/frontend/src/saccubus/converter/filegetter/WebFileInstanciator.java index bcda523..e53a5b9 100644 --- a/frontend/src/saccubus/converter/filegetter/WebFileInstanciator.java +++ b/frontend/src/saccubus/converter/filegetter/WebFileInstanciator.java @@ -3,12 +3,14 @@ package saccubus.converter.filegetter; import java.io.IOException; import java.text.Normalizer; +import org.apache.commons.lang.StringUtils; import saccubus.ConvertStopFlag; import saccubus.converter.profile.Proxy; import saccubus.net.CommentInfo; import saccubus.net.NicoClient; import saccubus.net.NicoClientImpl; import saccubus.net.VideoInfo; +import saccubus.util.WayBackTimeParser; /** * 動画ファイル, コメントファイルなど必要なファイルのうち, 1つでもダウンロード処理を必要とする場合のインスタンス化クラス. @@ -44,7 +46,8 @@ public class WebFileInstanciator extends FileInstanciator { port = -1; } // TODO Implを直接newしている - client = new NicoClientImpl(li.getMail(), li.getPass(), stopFlag, host, port) {}; + client = new NicoClientImpl(li.getMail(), li.getPass(), stopFlag, host, port) { + }; if (!client.isLoggedIn()) { throw new IOException("ログインに失敗"); @@ -52,7 +55,14 @@ public class WebFileInstanciator extends FileInstanciator { try { videoInfo = client.getVideoInfo(tag); - commentInfo = client.getWayBackKey(videoInfo, time); + if (StringUtils.isNotBlank(time)) { + System.out.print("Setting wayback time..."); + final String waybacktime = WayBackTimeParser.parse(time); + String waybackkey = client.getWayBackKey(videoInfo); + commentInfo = new CommentInfo(waybackkey, waybacktime); + }else{ + commentInfo = CommentInfo.DEFAULT; + } } catch (IOException ex) { throw new IOException(tag + "の情報の取得に失敗", ex); diff --git a/frontend/src/saccubus/net/NicoClient.java b/frontend/src/saccubus/net/NicoClient.java index 1fc2991..c54f6c8 100644 --- a/frontend/src/saccubus/net/NicoClient.java +++ b/frontend/src/saccubus/net/NicoClient.java @@ -15,7 +15,11 @@ public interface NicoClient { VideoInfo getVideoInfo(String videoId) throws IOException; - CommentInfo getWayBackKey(VideoInfo vi, String time) throws IOException; + /** + * 過去ログ取得のためのキーを取得する. + * @param vi {@link #getVideoInfo(java.lang.String) }で取得したビデオ情報. + */ + String getWayBackKey(VideoInfo vi) throws IOException; File getVideo(VideoInfo videoInfo, File file, TextProgressListener listener); diff --git a/frontend/src/saccubus/net/NicoClientImpl.java b/frontend/src/saccubus/net/NicoClientImpl.java index a540fa0..1a808b7 100644 --- a/frontend/src/saccubus/net/NicoClientImpl.java +++ b/frontend/src/saccubus/net/NicoClientImpl.java @@ -14,14 +14,9 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URLEncoder; import java.net.URLDecoder; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.HashMap; import java.util.Map; import javax.net.ssl.HttpsURLConnection; -import org.apache.commons.lang.StringUtils; import saccubus.ConvertStopFlag; import saccubus.util.FileUtil; import yukihane.Util; @@ -325,44 +320,8 @@ public class NicoClientImpl implements NicoClient { } @Override - public CommentInfo getWayBackKey(VideoInfo vi, String time) throws IOException { - if (StringUtils.isBlank(time)) { - return CommentInfo.DEFAULT; - } + public String getWayBackKey(VideoInfo vi) throws IOException { - System.out.print("Setting wayback time..."); - Date date = null; - String waybacktime = "0"; - try { - final DateFormat fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); - date = fmt.parse(time); - } catch (ParseException ex2) { - date = null; - } - if (date == null) { - try { - final DateFormat fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm"); - date = fmt.parse(time); - } catch (ParseException ex3) { - date = null; - } - } - if (date != null) { - waybacktime = Long.toString(date.getTime() / 1000); - System.out.println("ok.(" + date.toString() + "):" + waybacktime); - } else { - try { - long tmp_time = Long.parseLong(time); - waybacktime = Long.toString(tmp_time); - date = new Date(tmp_time * 1000); - System.out.println("ok.(" + date.toString() + "):" - + waybacktime); - } catch (NumberFormatException ex4) { - System.out.println("ng."); - System.out.println("Cannot parse wayback time."); - throw new IOException("Cannot parse wayback time.", ex4); - } - } System.out.print("Getting wayback key..."); String url = "http://flapi.nicovideo.jp/api/getwaybackkey?thread=" + vi.getThreadId(); @@ -407,7 +366,7 @@ public class NicoClientImpl implements NicoClient { throw new IOException("Cannot get wayback key."); } System.out.println("ok. key:" + waybackkey); - return new CommentInfo(waybackkey, waybacktime); + return waybackkey; } @Override diff --git a/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java b/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java index b8be283..f6c1d92 100644 --- a/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java +++ b/frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java @@ -56,7 +56,7 @@ public class NicoBrowserAdapter implements NicoClient { } @Override - public CommentInfo getWayBackKey(VideoInfo vi, String time) throws IOException { + public String getWayBackKey(VideoInfo vi) throws IOException { throw new UnsupportedOperationException("Not supported yet."); } -- 2.11.0