;; mixi.el --- API libraries for accessing to mixi -*- coding: euc-jp -*-
-;; Copyright (C) 2005, 2006, 2007, 2008 OHASHI Akira
+;; Copyright (C) 2005, 2006, 2007, 2008, 2009 OHASHI Akira
;; Author: OHASHI Akira <bg66@koka-in.org>
;; Keywords: hypermedia
;; * mixi-get-friends
;; * mixi-get-favorites
;; * mixi-get-logs
+;; * mixi-get-self-logs
;; * mixi-get-recommended-friends (indies)
;; * mixi-get-diaries
;; * mixi-get-new-diaries
;; 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.195 $")
+(defconst mixi-revision "$Revision: 1.209 $")
(defgroup mixi nil
"API library for accessing to mixi."
:type 'number
:group 'mixi)
+(defcustom mixi-replace-tab-and-space-to-nbsp t
+ "*If non-nil, replace tab and space to for keeping formatted."
+ :type 'boolean
+ :group 'mixi)
+
(defcustom mixi-cache-expires nil
"*Seconds for expiration of a cached object."
:type '(radio (integer :tag "Expired seconds")
(mixi-curl-retrieve url nil (reverse form-data))))
(defconst mixi-my-id-regexp
- "<a href=\"show_profile\\.pl\\?id=\\([0-9]+\\)")
+ "<a href=\"http://mixi.jp/show_profile\\.pl\\?id=\\([0-9]+\\)")
(defun mixi-login (&optional email password)
"Login to mixi."
(setq pos (+ (match-end 0) 1)))
string))
+(defun mixi-replace-tab-and-space-to-nbsp (string)
+ (when mixi-replace-tab-and-space-to-nbsp
+ (let ((pos 0))
+ (while (or (string-match "\t" string pos)
+ (string-match " " string pos))
+ (if (string= (match-string 0 string) "\t")
+ (setq string (replace-match (make-string tab-width ?\ )
+ nil nil string))
+ (setq string (replace-match " " nil nil string))
+ (setq pos (+ (match-end 0) 1))))
+ string)))
+
;; Object.
(defconst mixi-object-prefix "mixi-")
`(eq (mixi-object-class ,friend) 'mixi-friend))
(defmacro mixi-friend-page (friend)
- `(concat "/show_profile.pl?id=" (mixi-friend-id ,friend)))
+ `(concat "/show_friend.pl?id=" (mixi-friend-id ,friend)))
(defconst mixi-friend-nick-regexp
- "<h3>\\(.*\\)¤µ¤ó([0-9]+)</h3>")
+ "<p class=\"name\">\\(.*\\)¤µ¤ó([0-9]+)\n")
(defconst mixi-friend-name-regexp
- "<dt>̾Á°</dt>\n?<dd>\\(.+?\\)\\(<img\\|</dd>\\)")
+ "<th>̾Á°</th>\n+?<td>\\(.+?\\)\\(<img\\|</td>\\)")
(defconst mixi-friend-sex-regexp
- "<dt>ÀÊÌ</dt>\n?<dd>\\([Ã˽÷]\\)À\\(<img\\|</dd>\\)")
+ "<th>ÀÊÌ</th>\n+?<td>\\([Ã˽÷]\\)À\\(<img\\|</td>\\)")
(defconst mixi-friend-address-regexp
- "<dt>¸½½»½ê</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
+ "<th>¸½½»½ê</th>\n+?<td>\\(.+?\\)\\(<img \\|</td>\\)")
(defconst mixi-friend-age-regexp
- "<dt>ǯÎð</dt>\n?<dd>\\([0-9]+\\)ºÐ\\( <img\\|</dd>\\)")
+ "<th>ǯÎð</th>\n+?<td>\\([0-9]+\\)ºÐ\\( <img\\|</td>\\)")
(defconst mixi-friend-birthday-regexp
- "<dt>ÃÂÀ¸Æü</dt>\n?<dd>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(<img \\|</dd>\\)")
+ "<th>ÃÂÀ¸Æü</th>\n+?<td>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(<img \\|</td>\\)")
(defconst mixi-friend-blood-type-regexp
- "<dt>·ì±Õ·¿</dt>\n?<dd>\\([ABO]B?\\)·¿\\(<img \\|</dd>\\)")
+ "<th>·ì±Õ·¿</th>\n+?<td>\\([ABO]B?\\)·¿\\(<img \\|</td>\\)")
(defconst mixi-friend-birthplace-regexp
- "<dt>½Ð¿ÈÃÏ</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
+ "<th>½Ð¿ÈÃÏ</th>\n+?<td>\\(.+?\\)\\(<img \\|</td>\\)")
(defconst mixi-friend-hobby-regexp
- "<dt>¼ñÌ£</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
+ "<th>¼ñÌ£</th>\n+?<td>\\(.+?\\)\\(<img \\|</td>\\)")
(defconst mixi-friend-job-regexp
- "<dt>¿¦¶È</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
+ "<th>¿¦¶È</th>\n+?<td>\\(.+?\\)\\(<img \\|</td>\\)")
(defconst mixi-friend-organization-regexp
- "<dt>½ê°</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
+ "<th>½ê°</th>\n+?<td>\\(.+?\\)\\(<img \\|</td>\\)")
(defconst mixi-friend-profile-regexp
- "<dt>¼«¸Ê¾Ò²ð</dt>\n?<dd class=\"userInput\">\\(.+?\\)</dd>")
+ "<th>¼«¸Ê¾Ò²ð</th>\n+?<td>\\(.+?\\)</td>")
(defun mixi-realize-friend (friend)
"Realize a FRIEND."
(signal 'wrong-type-argument (list 'mixi-log-p log)))
(aref (cdr log) 1))
-(defmacro mixi-log-list-page ()
- `(concat "/show_log.pl"))
+(defconst mixi-log-list-page "/show_log.pl")
(defconst mixi-log-list-regexp
- "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)</a>")
+ "\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span><span class=\"name\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)</a>")
-;;;###autoload
-(defun mixi-get-logs (&optional range)
- "Get logs."
- (let ((items (mixi-get-matched-items (mixi-log-list-page)
+(defun mixi-get-logs-internal (list-page &optional range)
+ (let ((items (mixi-get-matched-items list-page
mixi-log-list-regexp
- range)))
+ range))
+ (year (nth 5 (decode-time (current-time))))
+ (month (nth 4 (decode-time (current-time)))))
(mapcar (lambda (item)
- (mixi-make-log (mixi-make-friend (nth 5 item) (nth 6 item))
- (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)))))
+ (let ((month-of-item (string-to-number (nth 0 item))))
+ (when (> month-of-item month)
+ (decf year))
+ (setq month month-of-item)
+ (mixi-make-log (mixi-make-friend (nth 4 item) (nth 5 item))
+ (encode-time 0
+ (string-to-number (nth 3 item))
+ (string-to-number (nth 2 item))
+ (string-to-number (nth 1 item))
+ month year))))
items)))
+;;;###autoload
+(defun mixi-get-logs (&optional range)
+ "Get logs."
+ (mixi-get-logs-internal mixi-log-list-page range))
+
+(defconst mixi-log-self-list-page "/show_self_log.pl")
+
+;;;###autoload
+(defun mixi-get-self-logs (&optional range)
+ "Get self logs."
+ (mixi-get-logs-internal mixi-log-self-list-page range))
+
;; Recommended friend.
(defmacro mixi-recommended-friend-list-page ()
`(concat "http://indies.mixi.jp/recommend.pl"))
"&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>")
(defconst mixi-diary-title-regexp
"<div class=\"listDiaryTitle\">
-<dl class=\"clearfix\">
+<dl>
<dt>\\([^<\n]+\\)\\(<span>\\)?")
(defconst mixi-diary-time-regexp
"<dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\\([0-9]+\\):\\([0-9]+\\)</dd>")
(setq fields `(("post_key" . ,post-key)
("id" . ,(mixi-friend-id (mixi-make-me)))
("diary_title" . ,title)
- ("diary_body" . ,content)
+ ("diary_body" . ,(mixi-replace-tab-and-space-to-nbsp
+ content))
("submit" . "confirm")))
(with-mixi-post-form (mixi-post-diary-page) fields
(unless (re-search-forward mixi-post-succeed-regexp nil t)
(mixi-post-error 'cannot-find-key community)))
(setq fields `(("post_key" . ,post-key)
("bbs_title" . ,title)
- ("bbs_body" . ,content)
+ ("bbs_body" . ,(mixi-replace-tab-and-space-to-nbsp
+ content))
("submit" . "confirm")))
(with-mixi-post-form (mixi-post-topic-page community) fields
(unless (re-search-forward mixi-post-succeed-regexp nil t)
(setq fields
`(("post_key" . ,post-key)
("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
- ("comment_body" . ,content)
+ ("comment_body" . ,(mixi-replace-tab-and-space-to-nbsp
+ content))
("submit" . "confirm")))
(setq fields `(("post_key" . ,post-key)
- ("comment" . ,content)
+ ("comment" . ,(mixi-replace-tab-and-space-to-nbsp
+ content))
("submit" . "confirm"))))
(with-mixi-post-form (funcall page parent) fields
(unless (re-search-forward mixi-post-succeed-regexp nil t)
(mixi-post-error 'cannot-find-succeed parent)))))
;; Message object.
-(defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
+(defconst mixi-message-box-list
+ '(inbox outbox savebox thrash noticebox)) ; thrash?
(defmacro mixi-message-box-p (box)
`(memq ,box mixi-message-box-list))
`(concat "/view_message.pl?id=" (mixi-message-id ,message)
"&box=" (mixi-message-box ,message)))
-(defconst mixi-message-owner-regexp
- "<font COLOR=#996600>\\(º¹½Ð¿Í\\|°¸ Àè\\)</font> : <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)\\(</a>\\|</td>\\)")
-(defconst mixi-message-time-regexp
-"<font COLOR=#996600>Æü\\(¡¡\\| \\)ÉÕ</font> : \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ ")
(defconst mixi-message-title-regexp
-"<font COLOR=#996600>·ï\\(¡¡\\| \\)̾</font> : \\(.*\\)\n?</td>")
+"<div class=\"messageDetailHead\">
+<h3>\\(.*\\)</h3>")
+(defconst mixi-message-time-regexp
+"<dt>ÆüÉÕ</dt>
+<dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ</dd>")
+(defconst mixi-message-owner-regexp
+ "<dt>º¹½Ð¿Í</dt>
+<dd>\\(<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>\\|mixi</dd>\\)")
(defconst mixi-message-content-regexp
- "<tr><td CLASS=h120 width=\"500\">\\(.*\\)</td></tr>")
+"<div id=\"message_body\" class=\"messageDetailBody[^\"]*\">\\(\\(.\\|\r?\n\\)*?\\)</div>")
(defun mixi-realize-message (message)
"Realize a MESSAGE."
(unless (mixi-object-realized-p message)
(with-mixi-retrieve (mixi-message-page message)
- (if (re-search-forward mixi-message-owner-regexp nil t)
- (mixi-message-set-owner message
- (mixi-make-friend (match-string 2)
- (match-string 3)))
- (mixi-realization-error 'cannot-find-owner message))
+ (if (re-search-forward mixi-message-title-regexp nil t)
+ (mixi-message-set-title message (match-string 1))
+ (mixi-realization-error 'cannot-find-title message))
(if (re-search-forward mixi-message-time-regexp nil t)
(mixi-message-set-time
- message (encode-time 0 (string-to-number (match-string 6))
- (string-to-number (match-string 5))
+ message (encode-time 0 (string-to-number (match-string 5))
(string-to-number (match-string 4))
(string-to-number (match-string 3))
- (string-to-number (match-string 2))))
+ (string-to-number (match-string 2))
+ (string-to-number (match-string 1))))
(mixi-realization-error 'cannot-find-time message))
- (if (re-search-forward mixi-message-title-regexp nil t)
- (mixi-message-set-title message (match-string 2))
- (mixi-realization-error 'cannot-find-title message))
+ (if (re-search-forward mixi-message-owner-regexp nil t)
+ (unless (string= (match-string 1) "mixi</dd>")
+ (mixi-message-set-owner message
+ (mixi-make-friend (match-string 2)
+ (match-string 3))))
+ (mixi-realization-error 'cannot-find-owner message))
(if (re-search-forward mixi-message-content-regexp nil t)
(mixi-message-set-content message (match-string 1))
(mixi-realization-error 'cannot-find-content message)))
(when ,box (concat "&box=" ,box))))
(defconst mixi-message-list-regexp
- "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
+ "<a href=\"view_message\\.pl\\?id=\\(.+\\)&box=\\([^&\"]+\\)")
;;;###autoload
(defun mixi-get-messages (&rest box-or-range)
(mixi-make-message (nth 0 item) (nth 1 item)))
items))))
-(defmacro mixi-post-message-page (friend)
- `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
+(defmacro mixi-post-message-page (&optional friend)
+ `(concat "/send_message.pl"
+ (when ,friend
+ (concat "?id=" (mixi-friend-id ,friend)))))
(defconst mixi-post-message-key-regexp
- "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
+ "<input name=\"?post_key\"? type=\"?hidden\"? value=\"?\\([a-z0-9]+\\)\"? ")
(defconst mixi-post-message-succeed-regexp
- "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
+ "Á÷¿®¤¬´°Î»¤·¤Þ¤·¤¿¡£")
;;;###autoload
(defun mixi-post-message (friend title content)
(if (re-search-forward mixi-post-message-key-regexp nil t)
(setq post-key (match-string 1))
(mixi-post-error 'cannot-find-key friend)))
- (setq fields `(("post_key" . ,post-key)
+ (setq fields `(("from_show_friend" . "")
+ ("mode" . "commit_or_edit")
("subject" . ,title)
- ("body" . ,content)
- ("yes" . "¡¡Á÷¡¡¿®¡¡")
- ("submit" . "confirm")))
- (with-mixi-post-form (mixi-post-message-page friend) fields
+ ("body" . ,(mixi-replace-tab-and-space-to-nbsp content))
+ ("post_key" . ,post-key)
+ ("id" . ,(mixi-friend-id friend))
+ ("original_message_id" . "")
+ ("reply_message_id" . "")
+ ("yes" . "Á÷¿®¤¹¤ë")))
+ (with-mixi-post-form (mixi-post-message-page) fields
(unless (re-search-forward mixi-post-message-succeed-regexp nil t)
(mixi-post-error 'cannot-find-succeed friend)))))
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)
"<p class=\"date\">¡Ê\\(.+\\) - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)¡Ë</p>")
(defconst mixi-news-content-regexp
"<div class=\"article\">
-\\(.+\\)
-+
+\\(\\(.\\|\r?\n\\)*?\\)
\\(</div>
</div>\\|<div class=\"additional\">\\)")
"&post_time=" (mixi-echo-post-time ,echo)))
(defconst mixi-echo-owner-nick-regexp
- "<div id=\"echo_nickname_[0-9]+\" style=\"display: none;\">\\(.*\\)</div>")
+ "<div class=\"echo_nickname\" id=\"echo_nickname_[0-9]+\" style=\"display: none;\">\\(.*\\)</div>")
(defconst mixi-echo-content-regexp
- "<div id=\"echo_body_[0-9]+\" style=\"display: none;\">\\(.+\\)</div>")
+ "<div class=\"echo_body\" id=\"echo_body_[0-9]+\" style=\"display: none;\">\\(.+\\)</div>")
(defun mixi-realize-echo (echo)
"Realize an ECHO."
(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)
+ (with-mixi-retrieve (format (mixi-new-echo-list-page) 1)
(if (re-search-forward mixi-post-key-regexp nil t)
(setq post-key (match-string 1))
(mixi-post-error 'cannot-find-key)))