;; * mixi-get-introductions (broken)
;; * mixi-get-news
;; * mixi-get-releases
+;; * mixi-get-echoes (limited)
+;; * mixi-get-new-echoes (limited)
;;
;; APIs for posting:
;;
;; * mixi-post-topic
;; * mixi-post-comment
;; * mixi-post-message
+;; * mixi-post-echo (limited)
;;
;; Utilities:
;;
;; at run-time.
(eval-when-compile
(defvar w3m-use-cookies)
- (defvar url-request-method)
- (defvar url-request-data)
- (defvar url-request-extra-headers)
- (defvar url-show-status)
(autoload 'w3m-decode-buffer "w3m")
(autoload 'w3m-retrieve "w3m")
(autoload 'url-retrieve-synchronously "url"))
-(defconst mixi-revision "$Revision: 1.184 $")
+(defconst mixi-revision "$Revision: 1.198 $")
(defgroup mixi nil
"API library for accessing to mixi."
¿·¤ÏÀ©¸Â¤µ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤ª¤ê¤Þ¤¹¡£¤´ÌÂÏǤò¤ª¤«¤±¤¤¤¿¤·¤Þ¤¹¤¬¡¢¤·¤Ð¤é¤¯¤ª<br>
ÂÔ¤Á¤¤¤¿¤À¤¤¤Æ¤«¤éÁàºî¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£")
(defconst mixi-warning-continuously-accessing
- "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«<br>
-¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ<br>
-¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
+ "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
(defmacro mixi-retrieve (url &optional post-data)
`(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-retrieve"))
(defun mixi-logout ()
(mixi-retrieve "/logout.pl"))
-(defconst mixi-login-form "<form action=\"/login.pl\" method=\"post\">")
+(defconst mixi-login-form "<form action=\"/login.pl\" method=\"post\" name=\"login_form\">")
(defmacro with-mixi-retrieve (url &rest body)
`(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
(defun mixi-realize-friend (friend)
"Realize a FRIEND."
- ;; FIXME: Check a expiration of cache?
+ ;; FIXME: Check an expiration of cache?
(unless (mixi-object-realized-p friend)
(with-mixi-retrieve (mixi-friend-page friend)
(let ((case-fold-search t))
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
(aset (cdr friend) 13 profile))
-(defmacro mixi-friend-list-page (&optional friend)
- `(concat "/list_friend.pl?page=%d"
- (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
+(defun mixi-my-friend-list-page (&optional dummy)
+ (concat "/list_friend_simple.pl?page=%d"))
+
+(defun mixi-friend-list-page (friend)
+ (concat "/list_friend.pl?page=%d&id=" (mixi-friend-id friend)))
(defconst mixi-friend-list-id-regexp
"<a href=\"?show_friend\\.pl\\?id=\\([0-9]+\\)\"?")
+(defconst mixi-my-friend-list-nick-regexp
+ "<p>\\(.+\\)([0-9]+)</p>")
(defconst mixi-friend-list-nick-regexp
"<span>\\(.+\\)¤µ¤ó([0-9]+)</span>")
(setq range (nth 0 friend-or-range)))
(unless (or (null friend) (mixi-friend-p friend))
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
- mixi-friend-list-id-regexp
- range))
- (nicks (mixi-get-matched-items (mixi-friend-list-page friend)
- mixi-friend-list-nick-regexp
- range)))
- (let ((index 0)
- ret)
- (while (< index (length ids))
- (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
- (nth 0 (nth index nicks))) ret))
- (incf index))
- (reverse ret)))))
+ (let (list-page list-nick-regexp)
+ (if (or (null friend) (equal friend mixi-me))
+ (setq list-page 'mixi-my-friend-list-page
+ list-nick-regexp mixi-my-friend-list-nick-regexp)
+ (setq list-page 'mixi-friend-list-page
+ list-nick-regexp mixi-friend-list-nick-regexp))
+ (let ((ids (mixi-get-matched-items (funcall list-page friend)
+ mixi-friend-list-id-regexp
+ range))
+ (nicks (mixi-get-matched-items (funcall list-page friend)
+ list-nick-regexp
+ range)))
+ (let ((index 0)
+ ret)
+ (while (< index (length ids))
+ (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
+ (nth 0 (nth index nicks))) ret))
+ (incf index))
+ (reverse ret))))))
;; Favorite.
(defmacro mixi-favorite-list-page ()
"&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
(defconst mixi-diary-closed-regexp
- "<td>ͧ¿Í\\(¤Îͧ¿Í\\)?¤Þ¤Ç¸ø³«¤Î¤¿¤áÆɤळ¤È¤¬½ÐÍè¤Þ¤»¤ó¡£</td>")
+ "¤³¤ÎÆüµ¤Ë¥¢¥¯¥»¥¹¤Ç¤¤Þ¤»¤ó¡£°Ê²¼¤Î²ÄǽÀ¤¬¹Í¤¨¤é¤ì¤Þ¤¹¡£<br />")
(defconst mixi-diary-owner-nick-regexp
"<div class=\"diaryTitle\\(Friend\\)? clearfix\">
<h2>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ</h2>")
(defun mixi-realize-diary (diary &optional page)
"Realize a DIARY."
- ;; FIXME: Check a expiration of cache?
+ ;; FIXME: Check an expiration of cache?
(unless (mixi-object-realized-p diary)
(with-mixi-retrieve (or page (mixi-diary-page diary))
(let ((case-fold-search t))
(defconst mixi-new-diary-list-regexp
"<dt>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</dt>
<dd><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\">\\(.+\\)</a> (\\(.*\\))<div ")
+(defconst mixi-new-diary-list-title-regexp
+ "\\(.+\\) (\\([0-9]+\\))")
;;;###autoload
(defun mixi-get-new-diaries (&optional range)
(let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
mixi-new-diary-list-regexp
range)))
- (mapcar (lambda (item)
- (mixi-make-diary (mixi-make-friend (nth 6 item) (nth 8 item))
- (nth 5 item)
- nil
- (encode-time
- 0 (string-to-number (nth 4 item))
- (string-to-number (nth 3 item))
- (string-to-number (nth 2 item))
- (string-to-number (nth 1 item))
- (string-to-number (nth 0 item)))
- (nth 7 item)))
- items)))
+ (delq nil
+ (mapcar (lambda (item)
+ (let ((title (nth 7 item))
+ count)
+ (when (string-match mixi-new-diary-list-title-regexp
+ title)
+ (setq count (string-to-number (match-string 2 title)))
+ (setq title (match-string 1 title)))
+ (let* ((diary (mixi-make-diary
+ (mixi-make-friend (nth 6 item)
+ (nth 8 item))
+ (nth 5 item)))
+ (comment-count (mixi-diary-comment-count diary)))
+ (mixi-diary-set-time diary
+ (encode-time
+ 0 (string-to-number (nth 4 item))
+ (string-to-number (nth 3 item))
+ (string-to-number (nth 2 item))
+ (string-to-number (nth 1 item))
+ (string-to-number (nth 0 item))))
+ (mixi-diary-set-title diary title)
+ (when (or (null comment-count)
+ (< comment-count count))
+ (mixi-diary-set-comment-count diary count)
+ diary))))
+ items))))
(defmacro mixi-search-diary-list-page (keyword)
`(concat "/search_diary.pl?page=%d&submit=search&keyword="
(mixi-url-encode-and-quote-percent-string ,keyword)))
(defconst mixi-search-diary-list-regexp
- "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾ Á°</font></td>
-<td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.*\\)
-
-</td></tr>
-
-<tr>
-<td BGCOLOR=#FDF9F2><font COLOR=#996600>¥¿¥¤¥È¥ë</font></td>
-<td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>
-
-<tr>
-<td BGCOLOR=#FDF9F2><font COLOR=#996600>ËÜ Ê¸</font></td>
-<td COLSPAN=2 BGCOLOR=#FFFFFF width=\"380\">\\(.*\\)</td></tr>
-
-
-<tr>
-<td NOWRAP BGCOLOR=#FDF9F2 WIDTH=80><font COLOR=#996600>ºîÀ®Æü»þ</font></td>
-<td BGCOLOR=#FFFFFF WIDTH=220>\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>
-<td ALIGN=center BGCOLOR=#FDF9F2 width=250><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\"><img src=http://img\\.mixi\\.jp/img/shbtn\\.gif ALT=¾ÜºÙ¤ò¸«¤ë BORDER=0 WIDTH=104 HEIGHT=19></a></td></tr>
-</table>
-</td></tr></table>")
+ "<li>
+<div class=\"listIcon\"><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\"><img src=\".*\" alt=\".*\" /></a>
+<span class=\"name\"><a href=\"view_diary\\.pl\\?id=[0-9]+&owner_id=[0-9]+\">\\(.*\\)</a></span></div>
+<div class=\"listContents\">
+<div class=\"heading\"><a href=\"view_diary\\.pl\\?id=[0-9]+&owner_id=[0-9]+\" class=\"name\">\\(.+\\)</a><span class=\"date\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></div>
+<p class=\"description\">\\(.*\\)
+</div>
+</li>")
;;;###autoload
(defun mixi-search-diaries (keyword &optional range)
(year (nth 5 (decode-time (current-time))))
(month (nth 4 (decode-time (current-time)))))
(mapcar (lambda (item)
- (let ((month-of-item (string-to-number (nth 3 item))))
+ (let ((month-of-item (string-to-number (nth 4 item))))
(when (> month-of-item month)
(decf year))
(setq month month-of-item)
- (mixi-make-diary (mixi-make-friend (nth 8 item) (nth 0 item))
- (nth 7 item)
+ (mixi-make-diary (mixi-make-friend (nth 1 item) (nth 2 item))
+ (nth 0 item)
nil
(encode-time
- 0 (string-to-number (nth 6 item))
+ 0 (string-to-number (nth 7 item))
+ (string-to-number (nth 6 item))
(string-to-number (nth 5 item))
- (string-to-number (nth 4 item))
month year)
- (nth 1 item)
- (nth 2 item))))
+ (nth 3 item)
+ (nth 8 item))))
items)))
(defmacro mixi-post-diary-page ()
(defconst mixi-post-key-regexp
"<input type=\"?hidden\"? name=\"?post_key\"? +value=\"\\([a-z0-9]+\\)\"")
(defconst mixi-post-succeed-regexp
- "<p\\(\\| class=\"messageAlert\"\\)>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É½¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¾¯¡¹¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£</p>")
+ "<p\\(\\| class=\"messageAlert\"\\)>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£</p>")
;; FIXME: Support photos.
;;;###autoload
(defun mixi-realize-community (community)
"Realize a COMMUNITY."
- ;; FIXME: Check a expiration of cache?
+ ;; FIXME: Check an expiration of cache?
(unless (mixi-object-realized-p community)
(with-mixi-retrieve (mixi-community-page community)
(let ((case-fold-search t))
(defun mixi-realize-topic (topic &optional page)
"Realize a TOPIC."
- ;; FIXME: Check a expiration of cache?
+ ;; FIXME: Check an expiration of cache?
(unless (mixi-object-realized-p topic)
(with-mixi-retrieve (or page (mixi-topic-page topic))
(if (re-search-forward mixi-topic-community-regexp nil t)
(defun mixi-realize-event (event &optional page)
"Realize a EVENT."
- ;; FIXME: Check a expiration of cache?
+ ;; FIXME: Check an expiration of cache?
(unless (mixi-object-realized-p event)
(with-mixi-retrieve (or page (mixi-event-page event))
(let ((case-fold-search t))
\\(
| <a href=\"delete_comment\\.pl\\?diary_id=[0-9]+&owner_id=[0-9]+&comment_id=.+&type=comment\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a>
\\|\\)</span>
-
+*
<span class=\"commentTitleDate\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>
</dt>
-+
+*
<dd>
\\(\\(.\\|\r?\n\\)*?\\)
</dd>
mixi-news-cache))
(defconst mixi-news-url-regexp
- "/view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)")
+ "/view_news\\.pl\\?\\(id=\\([0-9]+\\)&media_id=\\([0-9]+\\)\\|media_id=\\([0-9]+\\)&id=\\([0-9]+\\)\\)")
(defun mixi-make-news-from-url (url)
"Return a news object from URL."
(when (string-match mixi-news-url-regexp url)
- (let ((id (match-string 1 url))
- (media-id (match-string 2 url)))
+ (let ((id (or (match-string 2 url) (match-string 5 url)))
+ (media-id (or (match-string 3 url) (match-string 4 url))))
(mixi-make-news media-id id))))
(defmacro mixi-news-p (news)
(defconst mixi-news-content-regexp
"<div class=\"article\">
\\(.+\\)
-
-
++
\\(</div>
</div>\\|<div class=\"additional\">\\)")
(defun mixi-realize-news (news)
"Realize a NEWS."
- ;; FIXME: Check a expiration of cache?
+ ;; FIXME: Check an expiration of cache?
(unless (mixi-object-realized-p news)
(with-mixi-retrieve (mixi-news-page news)
(if (re-search-forward mixi-news-finished-regexp nil t)
(nth 4 item)))
items)))
+;; Echo object.
+(defvar mixi-echo-cache (make-hash-table :test 'equal))
+;; FIXME: Support parent.
+(defun mixi-make-echo (owner post-time &optional content)
+ "Return an echo object."
+ (let ((owner (or owner (mixi-make-me))))
+ (mixi-make-cache (list (mixi-friend-id owner) post-time)
+ (cons 'mixi-echo (vector nil owner post-time content))
+ mixi-echo-cache)))
+
+(defconst mixi-echo-url-regexp
+ "view_echo\\.pl\\?id=\\([0-9]+\\)&post_time=\\([0-9]+\\)")
+
+(defun mixi-make-echo-from-url (url)
+ "Return an echo object from URL."
+ (when (string-match mixi-echo-url-regexp url)
+ (let ((owner-id (match-string 1 url))
+ (post-time (match-string 2 url)))
+ (mixi-make-echo (mixi-make-friend owner-id) post-time))))
+
+(defmacro mixi-echo-p (echo)
+ `(eq (mixi-object-class ,echo) 'mixi-echo))
+
+(defmacro mixi-echo-page (echo)
+ `(concat "/view_echo.pl?id=" (mixi-friend-id (mixi-echo-owner ,echo))
+ "&post_time=" (mixi-echo-post-time ,echo)))
+
+(defconst mixi-echo-owner-nick-regexp
+ "<div id=\"echo_nickname_[0-9]+\" style=\"display: none;\">\\(.*\\)</div>")
+(defconst mixi-echo-content-regexp
+ "<div id=\"echo_body_[0-9]+\" style=\"display: none;\">\\(.+\\)</div>")
+
+(defun mixi-realize-echo (echo)
+ "Realize an ECHO."
+ ;; FIXME: Check an expiration of cache?
+ (unless (mixi-object-realized-p echo)
+ (with-mixi-retrieve (mixi-echo-page echo)
+ (let ((case-fold-search t))
+ (if (re-search-forward mixi-echo-owner-nick-regexp nil t)
+ (mixi-friend-set-nick (mixi-echo-owner echo)
+ (match-string 1))
+ (mixi-realization-error 'cannot-find-owner-nick echo))
+ (if (re-search-forward mixi-echo-content-regexp nil t)
+ (mixi-echo-set-content echo (match-string 1))
+ (mixi-realization-error 'cannot-find-owner-nick echo))))
+ (mixi-object-touch echo)))
+
+(defun mixi-echo-owner (echo)
+ "Return the owner of ECHO."
+ (unless (mixi-echo-p echo)
+ (signal 'wrong-type-argument (list 'mixi-echo-p echo)))
+ (aref (cdr echo) 1))
+
+(defun mixi-echo-post-time (echo)
+ "Return the post-time of ECHO."
+ (unless (mixi-echo-p echo)
+ (signal 'wrong-type-argument (list 'mixi-echo-p echo)))
+ (aref (cdr echo) 2))
+
+(defun mixi-echo-content (echo)
+ "Return the content of ECHO."
+ (unless (mixi-echo-p echo)
+ (signal 'wrong-type-argument (list 'mixi-echo-p echo)))
+ (mixi-realize-echo echo)
+ (aref (cdr echo) 3))
+
+(defun mixi-echo-set-content (echo content)
+ "Set the content of ECHO."
+ (unless (mixi-echo-p echo)
+ (signal 'wrong-type-argument (list 'mixi-echo-p echo)))
+ (aset (cdr echo) 3 content))
+
+(defmacro mixi-echo-list-page (&optional friend)
+ `(concat "/list_echo.pl?page=%d"
+ (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
+
+(defconst mixi-echo-list-regexp
+ "<a href=\"view_echo\\.pl\\?id=\\([0-9]+\\)&post_time=\\([0-9]+\\)\">")
+
+;;;###autoload
+(defun mixi-get-echoes (&rest friend-or-range)
+ "Get echoes of FRIEND."
+ (when (> (length friend-or-range) 2)
+ (signal 'wrong-number-of-arguments
+ (list 'mixi-get-echoes (length friend-or-range))))
+ (let ((friend (nth 0 friend-or-range))
+ (range (nth 1 friend-or-range)))
+ (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
+ (setq friend (nth 1 friend-or-range))
+ (setq range (nth 0 friend-or-range)))
+ (unless (or (null friend) (mixi-friend-p friend))
+ (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
+ (let ((items (mixi-get-matched-items (mixi-echo-list-page friend)
+ mixi-echo-list-regexp
+ range)))
+ (mapcar (lambda (item)
+ (mixi-make-echo friend (nth 1 item)))
+ items))))
+
+(defmacro mixi-new-echo-list-page ()
+ `(concat "/recent_echo.pl?page=%d"))
+
+(defconst mixi-new-echo-list-regexp
+ "<a href=\"view_echo\\.pl\\?id=\\([0-9]+\\)&post_time=\\([0-9]+\\)\">")
+
+;;;###autoload
+(defun mixi-get-new-echoes (&optional range)
+ "Get new echoes."
+ (let ((items (mixi-get-matched-items (mixi-new-echo-list-page)
+ mixi-new-echo-list-regexp
+ range)))
+ (mapcar (lambda (item)
+ (mixi-make-echo (mixi-make-friend (nth 0 item)) (nth 1 item)))
+ items)))
+
+(defmacro mixi-post-echo-page ()
+ `(concat "/add_echo.pl"))
+
+(defconst mixi-echo-post-succeed-regexp mixi-my-id-regexp)
+
+;;;###autoload
+(defun mixi-post-echo (content &optional parent)
+ "Post an echo."
+ (unless (stringp content)
+ (signal 'wrong-type-argument (list 'stringp content)))
+ (unless (or (null parent) (mixi-echo-p parent))
+ (signal 'wrong-type-argument (list 'mixi-echo-p parent)))
+ (let (fields post-key)
+ (with-mixi-retrieve (mixi-post-echo-page)
+ (if (re-search-forward mixi-post-key-regexp nil t)
+ (setq post-key (match-string 1))
+ (mixi-post-error 'cannot-find-key)))
+ (setq fields `(("post_key" . ,post-key)
+ ("redirect" . "home")
+ ("body" . ,content)))
+ (when (mixi-echo-p parent)
+ (setq fields (cons `("parent_member_id" . ,(mixi-friend-id
+ (mixi-echo-owner parent)))
+ fields))
+ (setq fields (cons `("parent_post_time" . ,(mixi-echo-post-time parent))
+ fields)))
+ (with-mixi-post-form (mixi-post-echo-page) fields
+ (unless (re-search-forward mixi-echo-post-succeed-regexp nil t)
+ (mixi-post-error 'cannot-find-succeed)))))
+
(provide 'mixi)
;;; mixi.el ends here