OSDN Git Service

optional threadに対するパラメータ生成
authoryukihane <yukihane.feather@gmail.com>
Wed, 21 Sep 2011 06:46:01 +0000 (15:46 +0900)
committeryukihane <yukihane.feather@gmail.com>
Wed, 21 Sep 2011 07:57:07 +0000 (16:57 +0900)
src/nicobrowser/NicoHttpClient.java

index 687d649..6e20682 100644 (file)
@@ -48,6 +48,7 @@ import nicobrowser.util.Result;
 import nicobrowser.util.Util;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.http.Header;
@@ -963,6 +964,11 @@ public class NicoHttpClient {
         }
     }
 
+    private enum ThreadType {
+
+        MAIN, OPTIONAL;
+    }
+
     /**
      * 2011/2/3 以降のコメント表示仕様に基づいた取得パラメータ生成.
      * @param vi ビデオ情報.
@@ -971,9 +977,25 @@ public class NicoHttpClient {
      * @return 生成されたパラメータ.
      */
     private String createCommentDownloadParameter(VideoInfo vi, WayBackInfo wayback, int commentNum) {
+        final String mainParam = createCommentDownloadParameter(ThreadType.MAIN, vi, wayback, commentNum);
+        final String optionParam;
+        if (StringUtils.isNotEmpty(vi.getOptionalThreadId())) {
+            optionParam = createCommentDownloadParameter(ThreadType.OPTIONAL, vi, wayback, commentNum);
+        } else {
+            optionParam = "";
+        }
+        return mainParam + optionParam;
+    }
+
+    private String createCommentDownloadParameter(ThreadType threadType, VideoInfo vi, WayBackInfo wayback,
+            int commentNum) {
         final Map<String, String> threadKey = vi.getKeyMap();
         final Map<String, String> th = new HashMap<String, String>();
-        th.put("thread", vi.getThreadId());
+        if (threadType != ThreadType.OPTIONAL) {
+            th.put("thread", vi.getThreadId());
+        } else {
+            th.put("thread", vi.getOptionalThreadId());
+        }
         th.put("version", "20090904");
         th.put("user_id", vi.getUserId());
         if (wayback != null) {
@@ -1026,10 +1048,27 @@ public class NicoHttpClient {
      */
     private String createCommentDownloadParameter20101222(VideoInfo vi, boolean isTcomm, WayBackInfo wayback,
             int commentNum) {
+        final String mainParam = createCommentDownloadParameter20101222(ThreadType.MAIN, vi, isTcomm, wayback,
+                commentNum);
+        final String optionParam;
+        if (StringUtils.isNotEmpty(vi.getOptionalThreadId())) {
+            optionParam = createCommentDownloadParameter20101222(ThreadType.OPTIONAL, vi, isTcomm, wayback, commentNum);
+        } else {
+            optionParam = "";
+        }
+        return mainParam + optionParam;
+    }
+
+    private String createCommentDownloadParameter20101222(ThreadType threadType, VideoInfo vi, boolean isTcomm,
+            WayBackInfo wayback, int commentNum) {
         final Map<String, String> params = new HashMap<String, String>();
 
         params.put(VideoInfo.KEY_USER_ID, vi.getUserId());
-        params.put("thread", vi.getThreadId());
+        if (threadType != ThreadType.OPTIONAL) {
+            params.put("thread", vi.getThreadId());
+        } else {
+            params.put("thread", vi.getOptionalThreadId());
+        }
         params.put("version", "20061206");
 
         final int resFrom = (commentNum > 0) ? commentNum : vi.getResFrom();