OSDN Git Service

コメントの過去ログを取得できるように対応
authoryukihane <yukihane.feather@gmail.com>
Thu, 11 Aug 2011 05:43:41 +0000 (14:43 +0900)
committeryukihane <yukihane.feather@gmail.com>
Thu, 11 Aug 2011 07:23:26 +0000 (16:23 +0900)
src/nicobrowser/NicoHttpClient.java
src/nicobrowser/WayBackInfo.java [new file with mode: 0644]
test/nicobrowser/NicoHttpClientTest.java

index e1f1a22..e55da39 100644 (file)
@@ -735,7 +735,7 @@ public class NicoHttpClient {
             out.write(buffer, 0, i);
             downloadSize += i;
             listener.progress(fileSize, downloadSize);
-            if(listener.getCancel()){
+            if (listener.getCancel()) {
                 return new GetFlvResult(null, Status.GET_INFO, userName);
             }
         }
@@ -791,21 +791,21 @@ public class NicoHttpClient {
         return getFlvFile(vi, vi.getRealVideoId(), Status.GET_INFO, true, ProgressListener.EMPTY_LISTENER);
     }
 
-    public File getCommentFile(VideoInfo vi, String fileName) throws Exception {
-        return downloadComment(vi, fileName, false);
+    public File getCommentFile(VideoInfo vi, String fileName, WayBackInfo wayback) throws Exception {
+        return downloadComment(vi, fileName, false, wayback);
     }
 
     public File getTCommentFile(VideoInfo vi, String fileName) throws Exception {
-        return downloadComment(vi, fileName, true);
+        return downloadComment(vi, fileName, true, null);
     }
 
-    private File downloadComment(VideoInfo vi, String fileName, boolean isTcomm) throws Exception {
+    private File downloadComment(VideoInfo vi, String fileName, boolean isTcomm, WayBackInfo wayback) throws Exception {
         HttpResponse response = null;
         BufferedOutputStream bos = null;
 
         try {
             final HttpPost post = new HttpPost(vi.getMessageUrl().toString());
-            final String param = createCommendDownloadParameter(vi, isTcomm);
+            final String param = createCommendDownloadParameter(vi, isTcomm, wayback);
             final StringEntity se = new StringEntity(param);
             post.setEntity(se);
             response = http.execute(post);
@@ -834,8 +834,10 @@ public class NicoHttpClient {
         }
     }
 
-    private String createCommendDownloadParameter(VideoInfo vi, boolean isTcomm) {
+    private String createCommendDownloadParameter(VideoInfo vi, boolean isTcomm, WayBackInfo wayback) {
         final String tcommStr = (isTcomm) ? "fork=\"1\" " : "";
+        final String wayBackStr = (wayback != null) ? "when=" + "\"" + wayback.getTime() + "\"" + " waybackkey=" + "\""
+                + wayback.getKey() + " " : "";
         StringBuilder builder = new StringBuilder();
         Set<String> keySet = vi.getKeyMap().keySet();
         for (String key : keySet) {
diff --git a/src/nicobrowser/WayBackInfo.java b/src/nicobrowser/WayBackInfo.java
new file mode 100644 (file)
index 0000000..5171650
--- /dev/null
@@ -0,0 +1,28 @@
+package nicobrowser;
+
+/**
+ * 過去ログを取得するための情報.
+ * @author yuki
+ */
+public class WayBackInfo {
+
+    private final String key;
+    private final String time;
+
+    public WayBackInfo(String key, String time) {
+        if (key == null || time == null) {
+            throw new IllegalArgumentException(" key: " + key + ", time: " + time);
+        }
+
+        this.key = key;
+        this.time = time;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public String getTime() {
+        return time;
+    }
+}
index 2ba4809..4b425ce 100644 (file)
@@ -111,7 +111,7 @@ public class NicoHttpClientTest {
         assertSame(0, list.size());
     }
 
-//    
+//
     public void loadMyListDaily() throws URISyntaxException, HttpException, InterruptedException {
         System.out.println("loadMyListDaily");
         List<NicoContent> list = instance.loadMyListDaily();
@@ -281,7 +281,7 @@ public class NicoHttpClientTest {
 
         instance.login(OK_MAIL, OK_PASS);
         VideoInfo vi = instance.getVideoInfo(NORMAL_VIDEO);
-        instance.getCommentFile(vi, comm);
+        instance.getCommentFile(vi, comm, null);
         instance.getTCommentFile(vi, tcomm);
 
         assertTrue(commFile.exists());
@@ -300,7 +300,7 @@ public class NicoHttpClientTest {
 
         instance.login(OK_MAIL, OK_PASS);
         VideoInfo vi = instance.getVideoInfo(OFFICIAL_VIDEO);
-        instance.getCommentFile(vi, comm);
+        instance.getCommentFile(vi, comm, null);
         instance.getTCommentFile(vi, tcomm);
 
         assertTrue(commFile.exists());