* mixi.el (mixi-news-category-list): Add game-anime and column.
[elisp/mixi.git] / mixi.el
diff --git a/mixi.el b/mixi.el
index b53da72..b0ee69e 100644 (file)
--- a/mixi.el
+++ b/mixi.el
@@ -18,9 +18,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with this program; if not, you can either send email to this
-;; program's maintainer or write to: The Free Software Foundation,
-;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 ;;  * mixi-get-friends
 ;;  * mixi-get-favorites
 ;;  * mixi-get-logs
+;;  * mixi-get-recommended-friends (indies)
 ;;  * mixi-get-diaries
 ;;  * mixi-get-new-diaries
 ;;  * mixi-search-diaries
 ;;  * mixi-get-communities
 ;;  * mixi-search-communities
+;;  * mixi-get-recommended-communities (indies)
 ;;  * mixi-get-bbses
 ;;  * mixi-get-new-bbses
 ;;  * mixi-search-bbses
 ;;  * mixi-get-comments
 ;;  * mixi-get-new-comments
+;;  * mixi-get-new-bbs-comments
 ;;  * mixi-get-messages
-;;  * mixi-get-introductions
+;;  * mixi-get-introductions (broken)
 ;;  * mixi-get-news
 ;;
 ;; APIs for posting:
   (autoload 'w3m-retrieve "w3m")
   (autoload 'url-retrieve-synchronously "url"))
 
+(defconst mixi-revision "$Revision: 1.179 $")
+
 (defgroup mixi nil
   "API library for accessing to mixi."
   :group 'hypermedia)
@@ -1144,6 +1149,23 @@ Increase this value when unexpected error frequently occurs."
                                          (string-to-number (nth 0 item)))))
            items)))
 
+;; Recommended friend.
+(defmacro mixi-recommended-friend-list-page ()
+  `(concat "http://indies.mixi.jp/recommend.pl"))
+
+(defconst mixi-recommended-friend-list-regexp
+  "<div class=\"iconListImage\"><a href=\"http://mixi\\.jp/show_friend\\.pl\\?id=\\([0-9]+\\)\" [^>]+>.+</a></div><span>\\(.+?\\)¤µ¤ó([0-9]+)</span>")
+
+;;;###autoload
+(defun mixi-get-recommended-friends (&optional range)
+  "Get recommended friends."
+  (let ((items (mixi-get-matched-items (mixi-recommended-friend-list-page)
+                                      mixi-recommended-friend-list-regexp
+                                      range)))
+    (mapcar (lambda (item)
+             (mixi-make-friend (nth 0 item) (nth 1 item)))
+           items)))
+
 ;; Diary object.
 (defvar mixi-diary-cache (make-hash-table :test 'equal))
 (defun mixi-make-diary (owner id &optional comment-count time title content)
@@ -1456,7 +1478,7 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-community-nodata-regexp
   "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
 (defconst mixi-community-name-regexp
-  "<div class=\"pageTitle communityTitle002\">
+  "<div class=\"pageTitle communityTitle002 communityTop\">
 <h2>\\(.*\\)</h2>")
 (defconst mixi-community-birthday-regexp
   "<dt>³«ÀßÆü</dt>
@@ -1698,6 +1720,23 @@ Increase this value when unexpected error frequently occurs."
              (mixi-make-community (nth 0 item) (nth 1 item)))
            items)))
 
+;; Recommended community.
+(defalias 'mixi-recommended-community-list-page
+  'mixi-recommended-friend-list-page)
+
+(defconst mixi-recommended-community-list-regexp
+  "<div class=\"iconListImage\"><a href=\"http://mixi\\.jp/view_community\\.pl\\?id=\\([0-9]+\\)\" [^>]+>.+</a></div><span>\\(.+\\)([0-9]+)</span>")
+
+;;;###autoload
+(defun mixi-get-recommended-communities (&optional range)
+  "Get recommended communities."
+  (let ((items (mixi-get-matched-items (mixi-recommended-community-list-page)
+                                      mixi-recommended-community-list-regexp
+                                      range)))
+    (mapcar (lambda (item)
+             (mixi-make-community (nth 0 item) (nth 1 item)))
+           items)))
+
 ;; Topic object.
 (defvar mixi-topic-cache (make-hash-table :test 'equal))
 (defun mixi-make-topic (community id &optional comment-count time title owner
@@ -1917,9 +1956,9 @@ Increase this value when unexpected error frequently occurs."
   "<dt>³«ºÅ¾ì½ê</dt>
 <dd>\\(.+\\)</dd>")
 (defconst mixi-event-owner-regexp
-  "<dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>")
+  "<dt>\\((mixi Âà²ñºÑ)\\|<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>\\)</dt>")
 (defconst mixi-event-owner-seceded-regexp
-  "<dt>\\((mixi Âà²ñºÑ)\\)</dt>")
+  "(mixi Âà²ñºÑ)")
 (defconst mixi-event-detail-regexp
   "<dd>\\(\\(.\\|\r?\n\\)*?\\)</dd>
 </dl>")
@@ -1958,12 +1997,14 @@ Increase this value when unexpected error frequently occurs."
            (mixi-event-set-place event (match-string 1))
          (mixi-realization-error 'cannot-find-place event))
        (if (re-search-forward mixi-event-owner-regexp nil t)
-           (mixi-event-set-owner event (mixi-make-friend (match-string 1)
-                                                         (match-string 2)))
-         (if (re-search-forward mixi-event-owner-seceded-regexp nil t)
-             (mixi-event-set-owner event
-                                   (mixi-make-friend nil (match-string 1)))
-           (mixi-realization-error 'cannot-find-owner event)))
+           (let ((seceded-or-not (match-string 1))
+                 (id (match-string 2))
+                 (nick (match-string 3)))
+             (if (string= mixi-event-owner-seceded-regexp seceded-or-not)
+                 (mixi-event-set-owner event
+                                       (mixi-make-friend nil seceded-or-not))
+               (mixi-event-set-owner event (mixi-make-friend id nick))))
+         (mixi-realization-error 'cannot-find-owner event))
        (if (re-search-forward mixi-event-detail-regexp nil t)
            (mixi-event-set-detail event (match-string 1))
          (mixi-realization-error 'cannot-find-detail event))
@@ -2230,9 +2271,9 @@ Increase this value when unexpected error frequently occurs."
     (funcall func parent page)))
 
 ;; Comment object.
-(defun mixi-make-comment (parent owner time content)
+(defun mixi-make-comment (parent owner time content &optional count)
   "Return a comment object."
-  (cons 'mixi-comment (vector parent owner time content)))
+  (cons 'mixi-comment (vector parent owner time content count)))
 
 (defmacro mixi-comment-p (comment)
   `(eq (mixi-object-class ,comment) 'mixi-comment))
@@ -2261,6 +2302,12 @@ Increase this value when unexpected error frequently occurs."
     (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
   (aref (cdr comment) 3))
 
+(defun mixi-comment-count (comment)
+  "Return the count of COMMENT."
+  (unless (mixi-comment-p comment)
+    (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
+  (aref (cdr comment) 4))
+
 (defun mixi-diary-comment-list-page (diary)
   (concat "/view_diary.pl?full=1"
          "&id=" (mixi-diary-id diary)
@@ -2275,23 +2322,8 @@ Increase this value when unexpected error frequently occurs."
 \\|\\)</span>
 
 <span class=\"commentTitleDate\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü&nbsp;\\([0-9]+\\):\\([0-9]+\\)</span>
-
-
-?
 </dt>
-
-
-
-
-
-
-
-
-
-
-
-
-?
++
 <dd>
 \\(\\(.\\|\r?\n\\)*?\\)
 </dd>
@@ -2305,7 +2337,8 @@ Increase this value when unexpected error frequently occurs."
 
 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
 (defconst mixi-topic-comment-list-regexp
-  "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
+  "<dt class=\"commentDate clearfix\"><span class=\"senderId\">\\(<input id=\"commentCheck01\" name=\"comment_id\" type=\"checkbox\" value=\"[0-9]+\" /><label for=\"commentCheck01\">\\|\\)\\([0-9]+\\)\\(<span class=\"deleteTextArea\"><a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a></span>\\|</label>\\|\\)</span>
+<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
 <dd>
 <dl class=\"commentContent01\">
 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
@@ -2320,7 +2353,8 @@ Increase this value when unexpected error frequently occurs."
 
 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
 (defconst mixi-event-comment-list-regexp
-  "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
+  "<dt class=\"commentDate clearfix\"><span class=\"senderId\">\\(<input id=\"commentCheck01\" name=\"comment_id\" type=\"checkbox\" value=\"[0-9]+\" /><label for=\"commentCheck01\">\\|\\)\\([0-9]+\\)\\(<span class=\"deleteTextArea\"><a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a></span>\\|</label>\\|\\)</span>
+<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
 <dd>
 <dl class=\"commentContent01\">
 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
@@ -2344,7 +2378,8 @@ Increase this value when unexpected error frequently occurs."
       (setq page nil))
     (let ((items (mixi-get-matched-items page regexp range t)))
       (mapcar (lambda (item)
-               (let (owner-id owner-nick year month day hour minute content)
+               (let (owner-id owner-nick year month day hour minute content
+                              count)
                  (if (eq (mixi-object-class parent) 'mixi-diary)
                      (progn
                        (setq owner-id (nth 1 item))
@@ -2355,14 +2390,15 @@ Increase this value when unexpected error frequently occurs."
                        (setq hour (nth 7 item))
                        (setq minute (nth 8 item))
                        (setq content (nth 9 item)))
-                   (setq owner-id (nth 5 item))
-                   (setq owner-nick (nth 6 item))
-                   (setq year (nth 0 item))
-                   (setq month (nth 1 item))
-                   (setq day (nth 2 item))
-                   (setq hour (nth 3 item))
-                   (setq minute (nth 4 item))
-                   (setq content (nth 7 item)))
+                   (setq owner-id (nth 8 item))
+                   (setq owner-nick (nth 9 item))
+                   (setq year (nth 3 item))
+                   (setq month (nth 4 item))
+                   (setq day (nth 5 item))
+                   (setq hour (nth 6 item))
+                   (setq minute (nth 7 item))
+                   (setq content (nth 10 item))
+                   (setq count (nth 1 item)))
                  (mixi-make-comment parent (mixi-make-friend owner-id
                                                              owner-nick)
                                     (encode-time
@@ -2372,7 +2408,7 @@ Increase this value when unexpected error frequently occurs."
                                      (string-to-number day)
                                      (string-to-number month)
                                      (string-to-number year))
-                                    content)))
+                                    content count)))
              items))))
 
 (defmacro mixi-new-comment-list-page ()
@@ -2400,6 +2436,40 @@ Increase this value when unexpected error frequently occurs."
                        diary)))
                  items))))
 
+(defmacro mixi-new-bbs-comment-list-page ()
+  `(concat "/new_bbs_comment.pl?page=%d"))
+
+(defconst mixi-new-bbs-comment-list-regexp
+  "<a href=\"?view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\"?>")
+
+;;;###autoload
+(defun mixi-get-new-bbs-comments (&optional range)
+  "Get new BBS comments."
+  (let ((items (mixi-get-matched-items (mixi-new-bbs-comment-list-page)
+                                      mixi-new-bbs-comment-list-regexp
+                                      range)))
+    (delq nil
+         (mapcar (lambda (item)
+                   (let ((name (nth 0 item)))
+                     (when (string= name "bbs")
+                       (setq name "topic"))
+                     (let ((make-func (intern (concat "mixi-make-" name)))
+                           (comment-count-func
+                            (intern (concat "mixi-" name "-comment-count")))
+                           (set-comment-count-func
+                            (intern (concat "mixi-" name
+                                            "-set-comment-count"))))
+                       (let* ((bbs (funcall make-func
+                                    (mixi-make-community (nth 3 item))
+                                    (nth 1 item)))
+                              (comment-count (funcall comment-count-func bbs))
+                              (count (string-to-number (nth 2 item))))
+                         (when (or (null comment-count)
+                                   (< comment-count count))
+                           (funcall set-comment-count-func bbs count)
+                           bbs)))))
+                 items))))
+
 (defun mixi-post-diary-comment-page (diary)
   (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
 
@@ -2879,7 +2949,8 @@ Increase this value when unexpected error frequently occurs."
   (aset (cdr news) 6 content))
 
 (defconst mixi-news-category-list '(domestic politics economy area abroad
-                                            sports entertainment IT))
+                                            sports entertainment IT game-anime
+                                            column))
 
 (defmacro mixi-news-category-p (category)
   `(memq ,category mixi-news-category-list))