OSDN Git Service

2010年年末コメント方式でダウンロードするインタフェースを追加. 過去ログ取得処理を再実装.
authoryukihane <yukihane.feather@gmail.com>
Fri, 19 Aug 2011 13:22:35 +0000 (22:22 +0900)
committeryukihane <yukihane.feather@gmail.com>
Fri, 19 Aug 2011 13:22:35 +0000 (22:22 +0900)
src/nicobrowser/NicoHttpClient.java

index 0c099c7..f4e2664 100644 (file)
@@ -791,23 +791,19 @@ public class NicoHttpClient {
         return getFlvFile(vi, vi.getRealVideoId(), Status.GET_INFO, true, ProgressListener.EMPTY_LISTENER);
     }
 
-    public File getCommentFile(VideoInfo vi, String fileName, WayBackInfo wayback, int commentNum) throws Exception {
-        return downloadComment(vi, fileName, false, wayback, Integer.valueOf(commentNum));
+    public File getCommentFile(VideoInfo vi, String fileName, WayBackInfo wayback, int commentNum, boolean oldVersion)
+            throws Exception {
+        return downloadComment(vi, fileName, false, wayback, Integer.valueOf(commentNum), oldVersion);
     }
 
     public File getCommentFile(VideoInfo vi, String fileName) throws Exception {
-        return downloadComment(vi, fileName, false, null, null);
+        return downloadComment(vi, fileName, false, null, null, false);
     }
 
     public File getTCommentFile(VideoInfo vi, String fileName) throws Exception {
         return downloadComment(vi, fileName, true, null, Integer.valueOf(1000), true);
     }
 
-    private File downloadComment(VideoInfo vi, String fileName, boolean isTcomm, WayBackInfo wayback, Integer commentNum)
-            throws Exception {
-        return downloadComment(vi, fileName, isTcomm, wayback, commentNum, false);
-    }
-
     private File downloadComment(VideoInfo vi, String fileName, boolean isTcomm, WayBackInfo wayback, Integer commentNum,
             boolean oldVersion)
             throws Exception {
@@ -924,20 +920,33 @@ public class NicoHttpClient {
      */
     private String createCommentDownloadParameter20101222(VideoInfo vi, boolean isTcomm, WayBackInfo wayback,
             Integer commentNum) {
+        final Map<String, String> params = new HashMap<String, String>();
+
+        params.put(VideoInfo.KEY_USER_ID, vi.getUserId());
+        params.put("thread", vi.getThreadId());
+        params.put("version", "20061206");
+
         final int resFrom = (commentNum == null || commentNum <= 0) ? vi.getResFrom() : commentNum.intValue();
-        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) {
-            builder.append(key).append("=\"").append(vi.getKeyMap().get(key)).append("\" ");
-        }
-        final String officialOption = builder.toString();
-
-        return "<thread " + VideoInfo.KEY_USER_ID + "=\"" + vi.getUserId() + "\" res_from=\"" + (-1 * resFrom)
-                + "\" version=\"20061206\" thread=\"" + vi.getThreadId() + "\" " + wayBackStr + tcommStr
-                + officialOption + "/>";
+        params.put("res_from", "-" + Integer.toString(resFrom));
+
+        if (isTcomm) {
+            params.put("fork", "1");
+        }
+
+        if (wayback != null) {
+            params.put("waybackkey", wayback.getKey());
+            params.put("when", Long.toString(wayback.getTime()));
+        }
+
+        final StringBuilder str = new StringBuilder();
+        str.append("<thread");
+
+        addMapToAttr(str, vi.getKeyMap());
+        addMapToAttr(str, params);
+
+        str.append("/>");
+
+        return str.toString();
     }
 
     /**