1 ;; mixi.el --- API library for accessing to mixi
3 ;; Copyright (C) 2005,2006 OHASHI Akira
5 ;; Author: OHASHI Akira <bg66@koka-in.org>
6 ;; Keywords: hypermedia
8 ;; This file is *NOT* a part of Emacs.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; if not, you can either send email to this
22 ;; program's maintainer or write to: The Free Software Foundation,
23 ;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 ;; API for getting contents:
30 ;; * mixi-get-favorites
33 ;; * mixi-get-new-diaries
34 ;; * mixi-get-communities
36 ;; * mixi-get-new-topics
37 ;; * mixi-get-comments
38 ;; * mixi-get-new-comments
39 ;; * mixi-get-messages
43 ;; Display newest 3 diaries like a mail format.
45 ;; (let ((max-numbers 3)
46 ;; (buffer (generate-new-buffer "*temp*"))
47 ;; (format "%Y/%m/%d %H:%M"))
48 ;; (pop-to-buffer buffer)
49 ;; (mapc (lambda (diary)
50 ;; (let ((subject (mixi-diary-title diary))
51 ;; ;; Don't get owner's nick at first for omitting a useless
53 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
54 ;; (date (format-time-string format (mixi-diary-time diary)))
55 ;; (body (mixi-diary-content diary)))
56 ;; (insert "From: " from "\n"
57 ;; "Subject: " subject "\n"
58 ;; "Date: " date "\n\n"
60 ;; (mixi-get-new-diaries max-numbers))
61 ;; (set-buffer-modified-p nil)
62 ;; (setq buffer-read-only t)
63 ;; (goto-char (point-min)))
65 ;; Display newest 3 diaries including newest 3 comments like a mail format.
66 ;; Comments are displayed like a reply mail.
68 ;; (let ((max-numbers 3)
69 ;; (buffer (generate-new-buffer "*temp*"))
70 ;; (format "%Y/%m/%d %H:%M"))
71 ;; (pop-to-buffer buffer)
72 ;; (mapc (lambda (diary)
73 ;; (let ((subject (mixi-diary-title diary))
74 ;; ;; Don't get owner's nick at first for omitting a useless
76 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
77 ;; (date (format-time-string format (mixi-diary-time diary)))
78 ;; (body (mixi-diary-content diary)))
79 ;; (insert "From: " from "\n"
80 ;; "Subject: " subject "\n"
81 ;; "Date: " date "\n\n"
83 ;; (mapc (lambda (comment)
84 ;; (let ((from (mixi-friend-nick
85 ;; (mixi-comment-owner comment)))
86 ;; (subject (concat "Re: " subject))
87 ;; (date (format-time-string
88 ;; format (mixi-comment-time comment)))
89 ;; (body (mixi-comment-content comment)))
90 ;; (insert "From: " from "\n"
91 ;; "Subject: " subject "\n"
92 ;; "Date: " date "\n\n"
94 ;; (mixi-get-comments diary max-numbers))))
95 ;; (mixi-get-new-diaries max-numbers))
96 ;; (set-buffer-modified-p nil)
97 ;; (setq buffer-read-only t)
98 ;; (goto-char (point-min)))
110 (eval-when-compile (require 'cl))
113 "API library for accessing to mixi."
116 (defcustom mixi-url "http://mixi.jp"
121 (defcustom mixi-coding-system 'euc-jp
122 "*Coding system for mixi."
126 (defcustom mixi-retrieve-function
127 (if (fboundp 'url-retrieve-synchronously)
128 'mixi-w3-retrieve 'mixi-w3m-retrieve)
129 "*The function for retrieving."
130 :type '(radio (const :tag "Using w3" mixi-w3-retrieve)
131 (const :tag "Using w3m" mixi-w3m-retrieve)
132 (const :tag "Using curl" mixi-curl-retrieve)
133 (function :format "Other function: %v\n" :size 0))
136 (defcustom mixi-curl-program "curl"
137 "*The program name of `curl'."
141 (defcustom mixi-curl-cookie-file (expand-file-name "~/.mixi-cookies.txt")
142 "*The location of cookie file created by `curl'."
146 (defcustom mixi-default-email nil
147 "*Default E-mail address that is used to login automatically."
148 :type '(radio (string :tag "E-mail address")
149 (const :tag "Asked when it is necessary" nil))
152 (defcustom mixi-default-password nil
153 "*Default password that is used to login automatically."
154 :type '(radio (string :tag "Password")
155 (const :tag "Asked when it is necessary" nil))
158 (defcustom mixi-accept-adult-contents t
159 "*If non-nil, accept to access to the adult contents."
163 (defcustom mixi-continuously-access-interval 4.0
164 "*Time interval between each mixi access.
165 Increase this value when unexpected error frequently occurs."
169 (defcustom mixi-cache-expires 3600
170 "*Seconds for expiration of a cached object."
171 :type '(radio (integer :tag "Expired seconds")
172 (const :tag "Don't expire" nil))
175 ;; FIXME: Not implemented.
176 (defcustom mixi-cache-use-file t
177 "*If non-nil, caches are saved to files."
181 (defcustom mixi-cache-directory (expand-file-name "~/.mixi")
182 "*Where to look for cache files."
189 (defmacro mixi-message (string)
190 `(concat "[mixi] " ,string))
192 (defconst mixi-message-adult-contents
193 "¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
194 ±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
195 (defconst mixi-message-continuously-accessing
196 "°ÂÄꤷ¤Æ¥µ¥¤¥È¤Î±¿±Ä¤ò¤ª¤³¤Ê¤¦°Ù¡¢´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹<br>
197 ¿·¤ÏÀ©¸Â¤µ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤ª¤ê¤Þ¤¹¡£¤´ÌÂÏǤò¤ª¤«¤±¤¤¤¿¤·¤Þ¤¹¤¬¡¢¤·¤Ð¤é¤¯¤ª<br>
198 ÂÔ¤Á¤¤¤¿¤À¤¤¤Æ¤«¤éÁàºî¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£")
199 (defconst mixi-warning-continuously-accessing
200 "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«<br>
201 ¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ<br>
202 ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
204 (defun mixi-retrieve-1 (buffer url &optional post-data)
205 (when (string-match mixi-message-adult-contents buffer)
206 (if mixi-accept-adult-contents
207 (setq buffer (funcall mixi-retrieve-function url "submit=agree"))
208 (setq buffer (funcall mixi-retrieve-function (concat url "?")))))
209 (when (string-match mixi-warning-continuously-accessing buffer)
210 (error (mixi-message "Continuously accessing")))
211 (if (not (string-match mixi-message-continuously-accessing buffer))
213 (message (mixi-message "Waiting for continuously accessing..."))
214 (sit-for mixi-continuously-access-interval)
215 (funcall mixi-retrieve-function url post-data)))
217 (defun mixi-w3-retrieve (url &optional post-data)
218 "Retrieve the URL and return gotten strings."
221 (setq url-request-method "POST")
222 (setq url-request-data post-data))
223 (setq url-request-method "GET")
224 (setq url-request-data nil))
225 (let* ((url (url-expand-file-name url mixi-url))
226 (buffer (url-retrieve-synchronously url))
228 (unless (bufferp buffer)
229 (error (mixi-message "Cannot retrieve")))
230 (with-current-buffer buffer
231 (goto-char (point-min))
232 (if (re-search-forward "HTTP/[0-9.]+ 302 Moved" nil t)
233 (if (re-search-forward
234 (concat "Location: " mixi-url "\\(.+\\)") nil t)
235 (setq ret (mixi-w3-retrieve (match-string 1) post-data))
236 (setq ret (mixi-w3-retrieve "/home.pl" post-data)))
237 (unless (re-search-forward "HTTP/[0-9.]+ 200 OK" nil t)
238 (error (mixi-message "Cannot retrieve")))
239 (search-forward "\n\n")
240 (setq ret (mm-decode-coding-string
241 (buffer-substring-no-properties (point) (point-max))
244 (setq ret (mixi-retrieve-1 ret url post-data))))
247 (defun mixi-w3m-retrieve (url &optional post-data)
248 "Retrieve the URL and return gotten strings."
249 (let ((url (w3m-expand-url url mixi-url)))
251 (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
252 (error (mixi-message "Cannot retrieve"))
253 (w3m-decode-buffer url)
254 (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
255 (mixi-retrieve-1 ret url post-data))))))
257 (defun mixi-curl-retrieve (url &optional post-data)
258 "Retrieve the URL and return gotten strings."
260 (if (fboundp 'set-buffer-multibyte)
261 (set-buffer-multibyte nil))
262 (let ((orig-mode (default-file-modes))
263 (coding-system-for-read 'binary)
264 (coding-system-for-write 'binary)
268 (set-default-file-modes 448)
270 (apply #'start-process "curl" (current-buffer)
272 (append (if post-data '("-d" "@-"))
274 "-b" mixi-curl-cookie-file
275 "-c" mixi-curl-cookie-file
276 (concat mixi-url url)))))
277 (set-process-sentinel process #'ignore))
278 (set-default-file-modes orig-mode))
280 (process-send-string process (concat post-data "\n"))
281 (process-send-eof process))
282 (while (eq (process-status process) 'run)
283 (accept-process-output process 1))
284 (goto-char (point-min))
285 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
286 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
287 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
288 (error (mixi-message "Cannot retrieve")))
289 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
290 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
291 (mixi-retrieve-1 ret url post-data))))
293 (defconst mixi-my-id-regexp
294 "<a href=\"add_diary\\.pl\\?id=\\([0-9]+\\)")
296 (defun mixi-login (&optional email password)
298 (when (and (eq mixi-retrieve-function 'mixi-w3m-retrieve)
299 (not w3m-use-cookies))
302 "Require to accept cookies. Please set `w3m-use-cookies' to t.")))
303 (let ((email (or email mixi-default-email
304 (read-from-minibuffer (mixi-message "Login Email: "))))
305 (password (or password mixi-default-password
306 (read-passwd (mixi-message "Login Password: ")))))
307 (let ((buffer (funcall mixi-retrieve-function "/login.pl"
308 (concat "email=" email
309 "&password=" password
312 (unless (string-match "url=/check\\.pl\\?n=" buffer)
313 (error (mixi-message "Cannot login")))
314 (setq buffer (funcall mixi-retrieve-function "/check.pl?n=home.pl"))
315 (if (string-match mixi-my-id-regexp buffer)
316 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
317 (error (mixi-message "Cannot login"))))))
319 (defun mixi-logout ()
320 (funcall mixi-retrieve-function "/logout.pl"))
322 (defmacro with-mixi-retrieve (url &rest body)
325 (setq buffer (funcall mixi-retrieve-function ,url))
326 (when (string-match "login.pl" buffer)
328 (setq buffer (funcall mixi-retrieve-function ,url))))
330 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
331 (put 'with-mixi-retrieve 'edebug-form-spec '(form body))
333 (defun mixi-get-matched-items (url max-numbers regexp)
334 "Get matched items to REGEXP in URL."
338 (while (or (null max-numbers) (< (length ids) max-numbers))
339 (with-mixi-retrieve (format url page)
341 (while (and (string-match regexp buffer pos)
342 (or (null max-numbers) (< (length ids) max-numbers)))
345 (while (match-string num buffer)
346 (setq list (cons (match-string num buffer) list))
348 (when (member (reverse list) ids)
350 (setq ids (cons (reverse list) ids))
351 (setq pos (match-end (1- num)))))
355 ;; FIXME: Sort? Now order by newest.
358 ;; stolen (and modified) from shimbun.el
359 (defun mixi-remove-markup (string)
360 "Remove markups from STRING."
364 (goto-char (point-min))
365 (while (search-forward "<!--" nil t)
366 (delete-region (match-beginning 0)
367 (or (search-forward "-->" nil t)
369 (goto-char (point-min))
370 (while (re-search-forward "<[^>]+>" nil t)
371 (replace-match "" t t))
372 (goto-char (point-min))
373 (while (re-search-forward "
\r" nil t)
374 (replace-match "\n" t t)))
378 ;; stolen from time-date.el
379 (defun mixi-time-less-p (t1 t2)
380 "Say whether time value T1 is less than time value T2."
381 (unless (numberp (cdr t1))
382 (setq t1 (cons (car t1) (car (cdr t1)))))
383 (unless (numberp (cdr t2))
384 (setq t2 (cons (car t2) (car (cdr t2)))))
385 (or (< (car t1) (car t2))
386 (and (= (car t1) (car t2))
387 (< (cdr t1) (cdr t2)))))
389 (defun mixi-time-add (t1 t2)
390 "Add two time values. One should represent a time difference."
391 (unless (numberp (cdr t1))
392 (setq t1 (cons (car t1) (car (cdr t1)))))
393 (unless (numberp (cdr t2))
394 (setq t2 (cons (car t2) (car (cdr t2)))))
395 (let ((low (+ (cdr t1) (cdr t2))))
396 (cons (+ (car t1) (car t2) (lsh low -16)) low)))
398 ;; stolen from time-date.el
399 (defun mixi-seconds-to-time (seconds)
400 "Convert SECONDS (a floating point number) to a time value."
401 (cons (floor seconds 65536)
402 (floor (mod seconds 65536))))
404 (defun mixi-cache-expired-p (object)
405 "Whether a cache of OBJECT is expired."
406 (let ((timestamp (mixi-object-timestamp object)))
407 (unless (or (null mixi-cache-expires)
410 (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
413 (defun mixi-make-cache (key value table)
414 "Make a cache object and return it."
415 (let ((cache (gethash key table)))
416 (if (and cache (not (mixi-cache-expired-p cache)))
418 (puthash key value table))))
421 (defconst mixi-object-prefix "mixi-")
423 (defmacro mixi-object-class (object)
426 (defmacro mixi-object-p (object)
427 `(eq (string-match (concat "^" mixi-object-prefix)
428 (symbol-name (mixi-object-class ,object))) 0))
430 (defun mixi-object-name (object)
431 "Return the name of OBJECT."
432 (unless (mixi-object-p object)
433 (signal 'wrong-type-argument (list 'mixi-object-p object)))
434 (let ((class (mixi-object-class object)))
435 (substring (symbol-name class) (length mixi-object-prefix))))
437 (defun mixi-object-timestamp (object)
438 "Return the timestamp of OJBECT."
439 (unless (mixi-object-p object)
440 (signal 'wrong-type-argument (list 'mixi-object-p object)))
441 (aref (cdr object) 0))
442 (defalias 'mixi-object-realize-p 'mixi-object-timestamp)
444 (defun mixi-object-id (object)
445 "Return the id of OBJECT."
446 (unless (mixi-object-p object)
447 (signal 'wrong-type-argument (list 'mixi-object-p object)))
448 (let ((func (intern (concat mixi-object-prefix
449 (mixi-object-name object) "-id"))))
450 (funcall func object)))
452 (defun mixi-object-set-timestamp (object timestamp)
453 "Set the timestamp of OBJECT."
454 (unless (mixi-object-p object)
455 (signal 'wrong-type-argument (list 'mixi-object-p object)))
456 (aset (cdr object) 0 timestamp))
458 (defmacro mixi-object-touch (object)
459 `(mixi-object-set-timestamp ,object (current-time)))
462 (defvar mixi-friend-cache (make-hash-table :test 'equal))
463 (defun mixi-make-friend (id &optional nick)
464 "Return a friend object."
465 (mixi-make-cache id (cons 'mixi-friend (vector nil id nick nil nil nil nil
466 nil nil nil nil nil nil nil))
469 (defun mixi-make-me ()
471 (with-mixi-retrieve "/home.pl"
472 (if (string-match mixi-my-id-regexp buffer)
473 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
474 (signal 'error (list 'who-am-i)))))
477 (defmacro mixi-friend-p (friend)
478 `(eq (mixi-object-class ,friend) 'mixi-friend))
480 (defmacro mixi-friend-page (friend)
481 `(concat "/show_friend.pl?id=" (mixi-friend-id ,friend)))
483 (defconst mixi-friend-nick-regexp
484 "<img alt=\"\\*\" src=\"http://img\\.mixi\\.jp/img/dot0\\.gif\" width=\"1\" height=\"5\"><br>\n\\(.*\\)¤µ¤ó([0-9]+)")
485 (defconst mixi-friend-name-sex-regexp
486 "<td BGCOLOR=#F2DDB7 WIDTH=80 NOWRAP><font COLOR=#996600>̾\\( \\| \\)Á°</font></td>\n+<td WIDTH=345>\\([^<]+\\) (\\([Ã˽÷]\\)À)</td>")
487 (defconst mixi-friend-address-regexp
488 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¸½½»½ê</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
489 (defconst mixi-friend-age-regexp
490 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>ǯ\\( \\| \\)Îð</font></td>\n<td>\\([0-9]+\\)ºÐ\\(\n.+\n\\)?</td></tr>")
491 (defconst mixi-friend-birthday-regexp
492 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>ÃÂÀ¸Æü</font></td>\n<td>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(\n.+\n\\)?</td></tr>")
493 (defconst mixi-friend-blood-type-regexp
494 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>·ì±Õ·¿</font></td>\n<td>\\([ABO]B?\\)·¿\\(\n\n\\)?</td></tr>")
495 (defconst mixi-friend-birthplace-regexp
496 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>½Ð¿ÈÃÏ</font>\n?</td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
497 (defconst mixi-friend-hobby-regexp
498 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼ñ\\( \\| \\)Ì£</font></td>\n<td>\\(.+\\)</td></tr>")
499 (defconst mixi-friend-job-regexp
500 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¿¦\\( \\| \\)¶È</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
501 (defconst mixi-friend-organization-regexp
502 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>½ê\\( \\| \\)°</font></td>\n<td[^>]*>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
503 (defconst mixi-friend-profile-regexp
504 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼«¸Ê¾Ò²ð</font></td>\n<td CLASS=h120>\\(.+\\)</td></tr>")
506 (defun mixi-friend-realize (friend)
508 ;; FIXME: Check a expiration of cache?
509 (unless (mixi-object-realize-p friend)
511 (with-mixi-retrieve (mixi-friend-page friend)
513 (if (string-match mixi-friend-nick-regexp buf)
514 (mixi-friend-set-nick friend (match-string 1 buf))
515 (signal 'error (list 'cannot-find-nick friend)))
516 ;; For getting my profile.
517 (unless (string-match mixi-friend-name-sex-regexp buf)
518 (with-mixi-retrieve "/show_profile.pl"
520 (if (string-match mixi-friend-name-sex-regexp buf)
522 (mixi-friend-set-name friend (match-string 2 buf))
523 (mixi-friend-set-sex friend
524 (if (string= (match-string 3 buf) "ÃË")
526 (signal 'error (list 'cannot-find-name-or-sex friend)))
527 (when (string-match mixi-friend-address-regexp buf)
528 (mixi-friend-set-address friend (match-string 1 buf)))
529 (when (string-match mixi-friend-age-regexp buf)
531 friend (string-to-number (match-string 2 buf))))
532 (when (string-match mixi-friend-birthday-regexp buf)
533 (mixi-friend-set-birthday
534 friend (list (string-to-number (match-string 1 buf))
535 (string-to-number (match-string 2 buf)))))
536 (when (string-match mixi-friend-blood-type-regexp buf)
537 (mixi-friend-set-blood-type friend (intern (match-string 1 buf))))
538 (when (string-match mixi-friend-birthplace-regexp buf)
539 (mixi-friend-set-birthplace friend (match-string 1 buf)))
540 (when (string-match mixi-friend-hobby-regexp buf)
541 (mixi-friend-set-hobby
542 friend (split-string (match-string 2 buf) ", ")))
543 (when (string-match mixi-friend-job-regexp buf)
544 (mixi-friend-set-job friend (match-string 2 buf)))
545 (when (string-match mixi-friend-organization-regexp buf)
546 (mixi-friend-set-organization friend (match-string 2 buf)))
547 (when (string-match mixi-friend-profile-regexp buf)
548 (mixi-friend-set-profile
549 friend (mixi-remove-markup (match-string 1 buf)))))
550 (mixi-object-touch friend)))
552 (defun mixi-friend-id (friend)
553 "Return the id of FRIEND."
554 (unless (mixi-friend-p friend)
555 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
556 (aref (cdr friend) 1))
558 (defun mixi-friend-nick (friend)
559 "Return the nick of FRIEND."
560 (unless (mixi-friend-p friend)
561 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
562 (unless (aref (cdr friend) 2)
563 (mixi-friend-realize friend))
564 (aref (cdr friend) 2))
566 (defun mixi-friend-name (friend)
567 "Return the name of FRIEND."
568 (unless (mixi-friend-p friend)
569 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
570 (mixi-friend-realize friend)
571 (aref (cdr friend) 3))
573 (defun mixi-friend-sex (friend)
574 "Return the sex of FRIEND."
575 (unless (mixi-friend-p friend)
576 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
577 (mixi-friend-realize friend)
578 (aref (cdr friend) 4))
580 (defun mixi-friend-address (friend)
581 "Return the address of FRIEND."
582 (unless (mixi-friend-p friend)
583 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
584 (mixi-friend-realize friend)
585 (aref (cdr friend) 5))
587 (defun mixi-friend-age (friend)
588 "Return the age of FRIEND."
589 (unless (mixi-friend-p friend)
590 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
591 (mixi-friend-realize friend)
592 (aref (cdr friend) 6))
594 (defun mixi-friend-birthday (friend)
595 "Return the birthday of FRIEND."
596 (unless (mixi-friend-p friend)
597 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
598 (mixi-friend-realize friend)
599 (aref (cdr friend) 7))
601 (defun mixi-friend-blood-type (friend)
602 "Return the blood type of FRIEND."
603 (unless (mixi-friend-p friend)
604 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
605 (mixi-friend-realize friend)
606 (aref (cdr friend) 8))
608 (defun mixi-friend-birthplace (friend)
609 "Return the birthplace of FRIEND."
610 (unless (mixi-friend-p friend)
611 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
612 (mixi-friend-realize friend)
613 (aref (cdr friend) 9))
615 (defun mixi-friend-hobby (friend)
616 "Return the hobby of FRIEND."
617 (unless (mixi-friend-p friend)
618 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
619 (mixi-friend-realize friend)
620 (aref (cdr friend) 10))
622 (defun mixi-friend-job (friend)
623 "Return the job of FRIEND."
624 (unless (mixi-friend-p friend)
625 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
626 (mixi-friend-realize friend)
627 (aref (cdr friend) 11))
629 (defun mixi-friend-organization (friend)
630 "Return the organization of FRIEND."
631 (unless (mixi-friend-p friend)
632 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
633 (mixi-friend-realize friend)
634 (aref (cdr friend) 12))
636 (defun mixi-friend-profile (friend)
637 "Return the pforile of FRIEND."
638 (unless (mixi-friend-p friend)
639 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
640 (mixi-friend-realize friend)
641 (aref (cdr friend) 13))
643 (defun mixi-friend-set-nick (friend nick)
644 "Set the nick of FRIEND."
645 (unless (mixi-friend-p friend)
646 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
647 (aset (cdr friend) 2 nick))
649 (defun mixi-friend-set-name (friend name)
650 "Set the name of FRIEND."
651 (unless (mixi-friend-p friend)
652 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
653 (aset (cdr friend) 3 name))
655 (defun mixi-friend-set-sex (friend sex)
656 "Set the sex of FRIEND."
657 (unless (mixi-friend-p friend)
658 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
659 (aset (cdr friend) 4 sex))
661 (defun mixi-friend-set-address (friend address)
662 "Set the address of FRIEND."
663 (unless (mixi-friend-p friend)
664 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
665 (aset (cdr friend) 5 address))
667 (defun mixi-friend-set-age (friend age)
668 "Set the age of FRIEND."
669 (unless (mixi-friend-p friend)
670 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
671 (aset (cdr friend) 6 age))
673 (defun mixi-friend-set-birthday (friend birthday)
674 "Set the birthday of FRIEND."
675 (unless (mixi-friend-p friend)
676 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
677 (aset (cdr friend) 7 birthday))
679 (defun mixi-friend-set-blood-type (friend blood-type)
680 "Set the blood type of FRIEND."
681 (unless (mixi-friend-p friend)
682 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
683 (aset (cdr friend) 8 blood-type))
685 (defun mixi-friend-set-birthplace (friend birthplace)
686 "Set the birthplace of FRIEND."
687 (unless (mixi-friend-p friend)
688 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
689 (aset (cdr friend) 9 birthplace))
691 (defun mixi-friend-set-hobby (friend hobby)
692 "Set the hobby of FRIEND."
693 (unless (mixi-friend-p friend)
694 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
695 (aset (cdr friend) 10 hobby))
697 (defun mixi-friend-set-job (friend job)
698 "Set the job of FRIEND."
699 (unless (mixi-friend-p friend)
700 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
701 (aset (cdr friend) 11 job))
703 (defun mixi-friend-set-organization (friend organization)
704 "Set the organization of FRIEND."
705 (unless (mixi-friend-p friend)
706 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
707 (aset (cdr friend) 12 organization))
709 (defun mixi-friend-set-profile (friend profile)
710 "Set the profile of FRIEND."
711 (unless (mixi-friend-p friend)
712 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
713 (aset (cdr friend) 13 profile))
715 (defmacro mixi-friend-list-page (&optional friend)
716 `(concat "/list_friend.pl?page=%d"
717 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
719 (defconst mixi-friend-list-id-regexp
720 "<a href=show_friend\\.pl\\?id=\\([0-9]+\\)")
721 (defconst mixi-friend-list-nick-regexp
722 "<td valign=middle>\\(.+\\)¤µ¤ó([0-9]+)<br />")
724 (defun mixi-get-friends (&rest args)
725 "Get friends of FRIEND."
726 (when (> (length args) 2)
727 (signal 'wrong-number-of-arguments (list 'mixi-get-friends (length args))))
728 (let ((friend (nth 0 args))
729 (max-numbers (nth 1 args)))
730 (when (or (not (mixi-friend-p friend)) (mixi-friend-p max-numbers))
731 (setq friend (nth 1 args))
732 (setq max-numbers (nth 0 args)))
733 (unless (or (null friend) (mixi-friend-p friend))
734 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
735 (let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
737 mixi-friend-list-id-regexp))
738 (nicks (mixi-get-matched-items (mixi-friend-list-page friend)
740 mixi-friend-list-nick-regexp)))
743 (while (< index (length ids))
744 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
745 (nth 0 (nth index nicks))) ret))
750 (defmacro mixi-favorite-list-page ()
751 `(concat "/list_bookmark.pl?page=%d"))
753 (defconst mixi-favorite-list-id-regexp
754 "<td ALIGN=center BGCOLOR=#FDF9F2 width=330><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">")
755 (defconst mixi-favorite-list-nick-regexp
756 "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾ Á°</font></td>
757 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>")
759 (defun mixi-get-favorites (&optional max-numbers)
761 (let ((ids (mixi-get-matched-items (mixi-favorite-list-page)
763 mixi-favorite-list-id-regexp))
764 (nicks (mixi-get-matched-items (mixi-favorite-list-page)
766 mixi-favorite-list-nick-regexp)))
769 (while (< index (length ids))
770 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
771 (nth 0 (nth index nicks))) ret))
776 (defun mixi-make-log (friend time)
777 "Return a log object."
778 (cons 'mixi-log (vector friend time)))
780 (defmacro mixi-log-p (log)
781 `(eq (mixi-object-class ,log) 'mixi-log))
783 (defun mixi-log-friend (log)
784 "Return the friend of LOG."
785 (unless (mixi-log-p log)
786 (signal 'wrong-type-argument (list 'mixi-log-p log)))
789 (defun mixi-log-time (log)
790 "Return the time of LOG."
791 (unless (mixi-log-p log)
792 (signal 'wrong-type-argument (list 'mixi-log-p log)))
795 (defmacro mixi-log-list-page ()
796 `(concat "/show_log.pl"))
798 (defconst mixi-log-list-regexp
799 "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\)</a><br>")
801 (defun mixi-get-logs (&optional max-numbers)
803 (let ((items (mixi-get-matched-items (mixi-log-list-page)
805 mixi-log-list-regexp)))
806 (mapcar (lambda (item)
807 (mixi-make-log (mixi-make-friend (nth 5 item) (nth 6 item))
809 (string-to-number (nth 4 item))
810 (string-to-number (nth 3 item))
811 (string-to-number (nth 2 item))
812 (string-to-number (nth 1 item))
813 (string-to-number (nth 0 item)))))
817 (defvar mixi-diary-cache (make-hash-table :test 'equal))
818 (defun mixi-make-diary (owner id)
819 "Return a diary object."
820 (let ((owner (or owner (mixi-make-me))))
821 (mixi-make-cache (list (mixi-friend-id owner) id)
822 (cons 'mixi-diary (vector nil owner id nil nil nil))
825 (defmacro mixi-diary-p (diary)
826 `(eq (mixi-object-class ,diary) 'mixi-diary))
828 (defmacro mixi-diary-page (diary)
829 `(concat "/view_diary.pl?id=" (mixi-diary-id ,diary)
830 "&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
832 ;; FIXME: Remove `¤µ¤ó'.
833 (defconst mixi-diary-owner-nick-regexp
834 "<td WIDTH=490 background=http://img\\.mixi\\.jp/img/bg_w\\.gif><b><font COLOR=#605048>\\(.+\\)\\(¤µ¤ó\\)?¤ÎÆüµ</font></b></td>")
835 (defconst mixi-diary-time-regexp
836 "<td ALIGN=center ROWSPAN=2 NOWRAP WIDTH=95 bgcolor=#FFD8B0>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</td>")
837 (defconst mixi-diary-title-regexp
838 "<td BGCOLOR=#FFF4E0 WIDTH=430> \\([^<]+\\)</td></tr>")
839 (defconst mixi-diary-content-regexp
840 "<td CLASS=h12>\\(.+\\)</td></tr>")
842 (defun mixi-diary-realize (diary)
844 ;; FIXME: Check a expiration of cache?
845 (unless (mixi-object-realize-p diary)
846 (with-mixi-retrieve (mixi-diary-page diary)
847 (if (string-match mixi-diary-owner-nick-regexp buffer)
848 (mixi-friend-set-nick (mixi-diary-owner diary)
849 (match-string 1 buffer))
850 (signal 'error (list 'cannot-find-owner-nick diary)))
851 (if (string-match mixi-diary-time-regexp buffer)
853 diary (encode-time 0 (string-to-number (match-string 5 buffer))
854 (string-to-number (match-string 4 buffer))
855 (string-to-number (match-string 3 buffer))
856 (string-to-number (match-string 2 buffer))
857 (string-to-number (match-string 1 buffer))))
858 (signal 'error (list 'cannot-find-time diary)))
859 (if (string-match mixi-diary-title-regexp buffer)
860 (mixi-diary-set-title diary (match-string 1 buffer))
861 (signal 'error (list 'cannot-find-title diary)))
862 (if (string-match mixi-diary-content-regexp buffer)
863 (mixi-diary-set-content diary (mixi-remove-markup
864 (match-string 1 buffer)))
865 (signal 'error (list 'cannot-find-content diary))))
866 (mixi-object-touch diary)))
868 (defun mixi-diary-owner (diary)
869 "Return the owner of DIARY."
870 (unless (mixi-diary-p diary)
871 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
872 (aref (cdr diary) 1))
874 (defun mixi-diary-id (diary)
875 "Return the id of DIARY."
876 (unless (mixi-diary-p diary)
877 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
878 (aref (cdr diary) 2))
880 (defun mixi-diary-time (diary)
881 "Return the time of DIARY."
882 (unless (mixi-diary-p diary)
883 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
884 (mixi-diary-realize diary)
885 (aref (cdr diary) 3))
887 (defun mixi-diary-title (diary)
888 "Return the title of DIARY."
889 (unless (mixi-diary-p diary)
890 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
891 (mixi-diary-realize diary)
892 (aref (cdr diary) 4))
894 (defun mixi-diary-content (diary)
895 "Return the content of DIARY."
896 (unless (mixi-diary-p diary)
897 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
898 (mixi-diary-realize diary)
899 (aref (cdr diary) 5))
901 (defun mixi-diary-set-time (diary time)
902 "Set the time of DIARY."
903 (unless (mixi-diary-p diary)
904 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
905 (aset (cdr diary) 3 time))
907 (defun mixi-diary-set-title (diary title)
908 "Set the title of DIARY."
909 (unless (mixi-diary-p diary)
910 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
911 (aset (cdr diary) 4 title))
913 (defun mixi-diary-set-content (diary content)
914 "Set the content of DIARY."
915 (unless (mixi-diary-p diary)
916 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
917 (aset (cdr diary) 5 content))
919 (defmacro mixi-diary-list-page (&optional friend)
920 `(concat "/list_diary.pl?page=%d"
921 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
923 (defconst mixi-diary-list-regexp
924 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">")
926 (defun mixi-get-diaries (&rest args)
927 "Get diaries of FRIEND."
928 (when (> (length args) 2)
929 (signal 'wrong-number-of-arguments (list 'mixi-get-friends (length args))))
930 (let ((friend (nth 0 args))
931 (max-numbers (nth 1 args)))
932 (when (or (not (mixi-friend-p friend)) (mixi-friend-p max-numbers))
933 (setq friend (nth 1 args))
934 (setq max-numbers (nth 0 args)))
935 (unless (or (null friend) (mixi-friend-p friend))
936 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
937 (let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
939 mixi-diary-list-regexp)))
940 (mapcar (lambda (item)
941 (mixi-make-diary friend (nth 0 item)))
944 (defmacro mixi-new-diary-list-page ()
945 `(concat "/new_friend_diary.pl?page=%d"))
947 (defconst mixi-new-diary-list-regexp
948 "<a class=\"new_link\" href=view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)>")
950 (defun mixi-get-new-diaries (&optional max-numbers)
952 (let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
954 mixi-new-diary-list-regexp)))
955 (mapcar (lambda (item)
956 (mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
960 (defvar mixi-community-cache (make-hash-table :test 'equal))
961 (defun mixi-make-community (id &optional name)
962 "Return a community object."
963 (mixi-make-cache id (cons 'mixi-community (vector nil id name nil nil nil
965 mixi-community-cache))
967 (defmacro mixi-community-p (community)
968 `(eq (mixi-object-class ,community) 'mixi-community))
970 (defmacro mixi-community-page (community)
971 `(concat "/view_community.pl?id=" (mixi-community-id ,community)))
973 (defconst mixi-community-nodata-regexp
974 "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
975 (defconst mixi-community-name-regexp
976 "<td WIDTH=345>\\(.*\\)</td></tr>")
977 (defconst mixi-community-birthday-regexp
978 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>³«ÀßÆü</font></td>\n<td>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
979 ;; FIXME: Care when the owner has seceded.
980 (defconst mixi-community-owner-regexp
981 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>´ÉÍý¿Í</font></td>\n<td>\n\n<a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\n\\(.+\\)</a>")
982 (defconst mixi-community-category-regexp
983 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥«¥Æ¥´¥ê</font></td>\n<td>\\([^<]+\\)</td>")
984 (defconst mixi-community-members-regexp
985 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥á¥ó¥Ð¡¼¿ô</font></td>\n<td>\\([0-9]+\\)¿Í</td></tr>")
986 (defconst mixi-community-open-level-regexp
987 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>»²²Ã¾ò·ï¤È<br>¸ø³«¥ì¥Ù¥ë</font></td>
988 <td>\\(.+\\)</td></tr>")
989 (defconst mixi-community-authority-regexp
990 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>\n<td>\\(.+\\)</td></tr>")
991 (defconst mixi-community-description-regexp
992 "<td CLASS=h120>\\(.+\\)</td>")
994 (defun mixi-community-realize (community)
995 "Realize a COMMUNITY."
996 ;; FIXME: Check a expiration of cache?
997 (unless (mixi-object-realize-p community)
998 (with-mixi-retrieve (mixi-community-page community)
999 (if (string-match mixi-community-nodata-regexp buffer)
1000 ;; FIXME: Set all members?
1001 (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1002 (if (string-match mixi-community-name-regexp buffer)
1003 (mixi-community-set-name community (match-string 1 buffer))
1004 (signal 'error (list 'cannot-find-name community)))
1005 (if (string-match mixi-community-birthday-regexp buffer)
1006 (mixi-community-set-birthday
1008 (encode-time 0 0 0 (string-to-number (match-string 3 buffer))
1009 (string-to-number (match-string 2 buffer))
1010 (string-to-number (match-string 1 buffer))))
1011 (signal 'error (list 'cannot-find-birthday community)))
1012 (if (string-match mixi-community-owner-regexp buffer)
1013 (if (string= (match-string 1 buffer) "home.pl")
1014 (mixi-community-set-owner community (mixi-make-me))
1015 (mixi-community-set-owner
1016 community (mixi-make-friend (match-string 2 buffer)
1017 (match-string 3 buffer))))
1018 (signal 'error (list 'cannot-find-owner community)))
1019 (if (string-match mixi-community-category-regexp buffer)
1020 (mixi-community-set-category community (match-string 1 buffer))
1021 (signal 'error (list 'cannot-find-category community)))
1022 (if (string-match mixi-community-members-regexp buffer)
1023 (mixi-community-set-members
1024 community (string-to-number (match-string 1 buffer)))
1025 (signal 'error (list 'cannot-find-members community)))
1026 (if (string-match mixi-community-open-level-regexp buffer)
1027 (mixi-community-set-open-level community (match-string 1 buffer))
1028 (signal 'error (list 'cannot-find-open-level community)))
1029 (if (string-match mixi-community-authority-regexp buffer)
1030 (mixi-community-set-authority community (match-string 1 buffer))
1031 (signal 'error (list 'cannot-find-authority community)))
1032 (if (string-match mixi-community-description-regexp buffer)
1033 (mixi-community-set-description
1034 community (mixi-remove-markup (match-string 1 buffer)))
1035 (signal 'error (list 'cannot-find-description community)))))
1036 (mixi-object-touch community)))
1038 (defun mixi-community-id (community)
1039 "Return the id of COMMUNITY."
1040 (unless (mixi-community-p community)
1041 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1042 (aref (cdr community) 1))
1044 (defun mixi-community-name (community)
1045 "Return the name of COMMUNITY."
1046 (unless (mixi-community-p community)
1047 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1048 (unless (aref (cdr community) 2)
1049 (mixi-community-realize community))
1050 (aref (cdr community) 2))
1052 (defun mixi-community-birthday (community)
1053 "Return the birthday of COMMUNITY."
1054 (unless (mixi-community-p community)
1055 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1056 (mixi-community-realize community)
1057 (aref (cdr community) 3))
1059 (defun mixi-community-owner (community)
1060 "Return the owner of COMMUNITY."
1061 (unless (mixi-community-p community)
1062 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1063 (mixi-community-realize community)
1064 (aref (cdr community) 4))
1066 (defun mixi-community-category (community)
1067 "Return the category of COMMUNITY."
1068 (unless (mixi-community-p community)
1069 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1070 (mixi-community-realize community)
1071 (aref (cdr community) 5))
1073 (defun mixi-community-members (community)
1074 "Return the members of COMMUNITY."
1075 (unless (mixi-community-p community)
1076 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1077 (mixi-community-realize community)
1078 (aref (cdr community) 6))
1080 (defun mixi-community-open-level (community)
1081 "Return the open-level of COMMUNITY."
1082 (unless (mixi-community-p community)
1083 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1084 (mixi-community-realize community)
1085 (aref (cdr community) 7))
1087 (defun mixi-community-authority (community)
1088 "Return the authority of COMMUNITY."
1089 (unless (mixi-community-p community)
1090 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1091 (mixi-community-realize community)
1092 (aref (cdr community) 8))
1094 (defun mixi-community-description (community)
1095 "Return the description of COMMUNITY."
1096 (unless (mixi-community-p community)
1097 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1098 (mixi-community-realize community)
1099 (aref (cdr community) 9))
1101 (defun mixi-community-set-name (community name)
1102 "Set the name of COMMUNITY."
1103 (unless (mixi-community-p community)
1104 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1105 (aset (cdr community) 2 name))
1107 (defun mixi-community-set-birthday (community birthday)
1108 "Set the birthday of COMMUNITY."
1109 (unless (mixi-community-p community)
1110 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1111 (aset (cdr community) 3 birthday))
1113 (defun mixi-community-set-owner (community owner)
1114 "Set the owner of COMMUNITY."
1115 (unless (mixi-community-p community)
1116 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1117 (unless (mixi-friend-p owner)
1118 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1119 (aset (cdr community) 4 owner))
1121 (defun mixi-community-set-category (community category)
1122 "Set the category of COMMUNITY."
1123 (unless (mixi-community-p community)
1124 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1125 (aset (cdr community) 5 category))
1127 (defun mixi-community-set-members (community members)
1128 "Set the name of COMMUNITY."
1129 (unless (mixi-community-p community)
1130 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1131 (aset (cdr community) 6 members))
1133 (defun mixi-community-set-open-level (community open-level)
1134 "Set the name of COMMUNITY."
1135 (unless (mixi-community-p community)
1136 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1137 (aset (cdr community) 7 open-level))
1139 (defun mixi-community-set-authority (community authority)
1140 "Set the name of COMMUNITY."
1141 (unless (mixi-community-p community)
1142 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1143 (aset (cdr community) 8 authority))
1145 (defun mixi-community-set-description (community description)
1146 "Set the name of COMMUNITY."
1147 (unless (mixi-community-p community)
1148 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1149 (aset (cdr community) 9 description))
1151 (defmacro mixi-community-list-page (&optional friend)
1152 `(concat "/list_community.pl?page=%d"
1153 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1155 (defconst mixi-community-list-id-regexp
1156 "<a href=view_community\\.pl\\?id=\\([0-9]+\\)")
1157 (defconst mixi-community-list-name-regexp
1158 "<td valign=middle>\\(.+\\)([0-9]+)</td>")
1160 (defun mixi-get-communities (&rest args)
1161 "Get communities of FRIEND."
1162 (when (> (length args) 2)
1163 (signal 'wrong-number-of-arguments (list 'mixi-get-friends (length args))))
1164 (let ((friend (nth 0 args))
1165 (max-numbers (nth 1 args)))
1166 (when (or (not (mixi-friend-p friend)) (mixi-friend-p max-numbers))
1167 (setq friend (nth 1 args))
1168 (setq max-numbers (nth 0 args)))
1169 (unless (or (null friend) (mixi-friend-p friend))
1170 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1171 (let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
1173 mixi-community-list-id-regexp))
1174 (names (mixi-get-matched-items (mixi-community-list-page friend)
1176 mixi-community-list-name-regexp)))
1179 (while (< index (length ids))
1180 (setq ret (cons (mixi-make-community (nth 0 (nth index ids))
1181 (nth 0 (nth index names))) ret))
1186 (defvar mixi-topic-cache (make-hash-table :test 'equal))
1187 (defun mixi-make-topic (community id)
1188 "Return a topic object."
1189 (mixi-make-cache (list (mixi-community-id community) id)
1190 (cons 'mixi-topic (vector nil community id nil nil nil nil))
1193 (defmacro mixi-topic-p (topic)
1194 `(eq (mixi-object-class ,topic) 'mixi-topic))
1196 (defmacro mixi-topic-page (topic)
1197 `(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
1198 "&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
1200 (defconst mixi-topic-time-regexp
1201 "<td rowspan=\"3\" width=\"110\" bgcolor=\"#ffd8b0\" align=\"center\" valign=\"top\" nowrap>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</td>")
1202 (defconst mixi-topic-title-regexp
1203 "<td bgcolor=\"#fff4e0\"> \\([^<]+\\)</td>")
1204 ;; FIXME: Remove `¤µ¤ó'.
1205 (defconst mixi-topic-owner-regexp
1206 "<td bgcolor=\"#fdf9f2\"> <font color=\"#dfb479\"></font> <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\)\\(¤µ¤ó\\)?</a>")
1207 (defconst mixi-topic-content-regexp
1208 "<td class=\"h120\"><table><tr>\\(.+\\)?</tr></table>\\(.+\\)</td>")
1210 (defun mixi-topic-realize (topic)
1212 ;; FIXME: Check a expiration of cache?
1213 (unless (mixi-object-realize-p topic)
1214 (with-mixi-retrieve (mixi-topic-page topic)
1215 (if (string-match mixi-topic-time-regexp buffer)
1216 (mixi-topic-set-time
1217 topic (encode-time 0 (string-to-number (match-string 5 buffer))
1218 (string-to-number (match-string 4 buffer))
1219 (string-to-number (match-string 3 buffer))
1220 (string-to-number (match-string 2 buffer))
1221 (string-to-number (match-string 1 buffer))))
1222 (signal 'error (list 'cannot-find-time topic)))
1223 (if (string-match mixi-topic-title-regexp buffer)
1224 (mixi-topic-set-title topic (match-string 1 buffer))
1225 (signal 'error (list 'cannot-find-title topic)))
1226 (if (string-match mixi-topic-owner-regexp buffer)
1227 (mixi-topic-set-owner topic
1228 (mixi-make-friend (match-string 1 buffer)
1229 (match-string 2 buffer)))
1230 (signal 'error (list 'cannot-find-owner topic)))
1231 (if (string-match mixi-topic-content-regexp buffer)
1232 (mixi-topic-set-content topic (mixi-remove-markup
1233 (match-string 2 buffer)))
1234 (signal 'error (list 'cannot-find-content topic))))
1235 (mixi-object-touch topic)))
1237 (defun mixi-topic-community (topic)
1238 "Return the community of TOPIC."
1239 (unless (mixi-topic-p topic)
1240 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1241 (aref (cdr topic) 1))
1243 (defun mixi-topic-id (topic)
1244 "Return the id of TOPIC."
1245 (unless (mixi-topic-p topic)
1246 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1247 (aref (cdr topic) 2))
1249 (defun mixi-topic-time (topic)
1250 "Return the time of TOPIC."
1251 (unless (mixi-topic-p topic)
1252 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1253 (mixi-topic-realize topic)
1254 (aref (cdr topic) 3))
1256 (defun mixi-topic-title (topic)
1257 "Return the title of TOPIC."
1258 (unless (mixi-topic-p topic)
1259 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1260 (mixi-topic-realize topic)
1261 (aref (cdr topic) 4))
1263 (defun mixi-topic-owner (topic)
1264 "Return the owner of TOPIC."
1265 (unless (mixi-topic-p topic)
1266 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1267 (mixi-topic-realize topic)
1268 (aref (cdr topic) 5))
1270 (defun mixi-topic-content (topic)
1271 "Return the content of TOPIC."
1272 (unless (mixi-topic-p topic)
1273 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1274 (mixi-topic-realize topic)
1275 (aref (cdr topic) 6))
1277 (defun mixi-topic-set-time (topic time)
1278 "Set the time of TOPIC."
1279 (unless (mixi-topic-p topic)
1280 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1281 (aset (cdr topic) 3 time))
1283 (defun mixi-topic-set-title (topic title)
1284 "Set the title of TOPIC."
1285 (unless (mixi-topic-p topic)
1286 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1287 (aset (cdr topic) 4 title))
1289 (defun mixi-topic-set-owner (topic owner)
1290 "Set the owner of TOPIC."
1291 (unless (mixi-topic-p topic)
1292 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1293 (unless (mixi-friend-p owner)
1294 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1295 (aset (cdr topic) 5 owner))
1297 (defun mixi-topic-set-content (topic content)
1298 "Set the content of TOPIC."
1299 (unless (mixi-topic-p topic)
1300 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1301 (aset (cdr topic) 6 content))
1303 (defmacro mixi-topic-list-page (community)
1304 `(concat "/list_bbs.pl?page=%d"
1305 "&id=" (mixi-community-id ,community)))
1307 (defconst mixi-topic-list-regexp
1308 "<a href=view_bbs\\.pl\\?id=\\([0-9]+\\)")
1310 (defun mixi-get-topics (community &optional max-numbers)
1311 "Get topics of COMMUNITY."
1312 (unless (mixi-community-p community)
1313 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1314 (let ((items (mixi-get-matched-items (mixi-topic-list-page community)
1316 mixi-topic-list-regexp)))
1317 (mapcar (lambda (item)
1318 (mixi-make-topic community (nth 0 item)))
1321 (defmacro mixi-new-topic-list-page ()
1322 `(concat "/new_bbs.pl?page=%d"))
1324 (defconst mixi-new-topic-list-regexp
1325 "<a href=\"view_bbs\\.pl\\?id=\\([0-9]+\\)&comment_count=[0-9]+&comm_id=\\([0-9]+\\)\" class=\"new_link\">")
1327 (defun mixi-get-new-topics (&optional max-numbers)
1329 (let ((items (mixi-get-matched-items (mixi-new-topic-list-page)
1331 mixi-new-topic-list-regexp)))
1332 (mapcar (lambda (item)
1333 (mixi-make-topic (mixi-make-community (nth 1 item))
1338 (defun mixi-make-comment (parent owner time content)
1339 "Return a comment object."
1340 (cons 'mixi-comment (vector parent owner time content)))
1342 (defmacro mixi-comment-p (comment)
1343 `(eq (mixi-object-class ,comment) 'mixi-comment))
1345 (defun mixi-comment-parent (comment)
1346 "Return the parent of COMMENT."
1347 (unless (mixi-comment-p comment)
1348 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
1349 (aref (cdr comment) 0))
1351 (defun mixi-comment-owner (comment)
1352 "Return the owner of COMMENT."
1353 (unless (mixi-comment-p comment)
1354 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
1355 (aref (cdr comment) 1))
1357 (defun mixi-comment-time (comment)
1358 "Return the time of COMMENT."
1359 (unless (mixi-comment-p comment)
1360 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
1361 (aref (cdr comment) 2))
1363 (defun mixi-comment-content (comment)
1364 "Return the content of COMMENT."
1365 (unless (mixi-comment-p comment)
1366 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
1367 (aref (cdr comment) 3))
1369 (defun mixi-diary-comment-list-page (diary)
1370 (concat "/view_diary.pl?page=%d"
1371 "&id=" (mixi-diary-id diary)
1372 "&owner_id=" (mixi-friend-id (mixi-diary-owner diary))))
1374 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
1375 (defconst mixi-diary-comment-list-regexp
1376 "<td rowspan=\"2\" align=\"center\" width=\"95\" bgcolor=\"#f2ddb7\" nowrap>
1377 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)\\(<br>
1378 <input type=checkbox name=comment_id value=\".+\">
1381 <td ALIGN=center BGCOLOR=#FDF9F2 WIDTH=430>
1382 <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"410\">
1385 <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\)</a>
1392 <!-- ËÜʸ : start -->
1394 <td bgcolor=\"#ffffff\">
1395 <table BORDER=0 CELLSPACING=0 CELLPADDING=[35] WIDTH=410>
1399 </td></tr></table>")
1401 (defun mixi-topic-comment-list-page (topic)
1402 (concat "/view_bbs.pl?page=%d"
1403 "&id=" (mixi-topic-id topic)
1404 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
1406 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
1407 (defconst mixi-topic-comment-list-regexp
1408 "<tr valign=\"top\">
1409 <td rowspan=\"2\" width=\"110\" bgcolor=\"#f2ddb7\" align=\"center\" nowrap>
1410 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
1411 \\([0-9]+\\):\\([0-9]+\\)<br>
1413 <td bgcolor=\"#fdf9f2\"> <font color=\"#f8a448\">
1414 <b> [0-9]+</b>:</font>
1416 <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\)</a>
1423 <td bgcolor=\"#ffffff\" align=\"center\">
1424 <table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" width=\"500\">
1435 (defun mixi-get-comments (parent &optional max-numbers)
1436 "Get comments of PARENT."
1437 (unless (mixi-object-p parent)
1438 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
1439 (let* ((name (mixi-object-name parent))
1440 (list-page (intern (concat mixi-object-prefix name
1441 "-comment-list-page")))
1442 (regexp (eval (intern (concat mixi-object-prefix name
1443 "-comment-list-regexp")))))
1444 (let ((items (mixi-get-matched-items
1445 (funcall list-page parent) max-numbers regexp)))
1446 (mapcar (lambda (item)
1447 (mixi-make-comment parent (mixi-make-friend
1448 (nth 6 item) (nth 7 item))
1451 (string-to-number (nth 4 item))
1452 (string-to-number (nth 3 item))
1453 (string-to-number (nth 2 item))
1454 (string-to-number (nth 1 item))
1455 (string-to-number (nth 0 item)))
1456 (mixi-remove-markup (nth 8 item))))
1459 (defmacro mixi-new-comment-list-page ()
1460 `(concat "/new_comment.pl?page=%d"))
1462 (defconst mixi-new-comment-list-regexp
1463 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=[0-9]+\" class=\"new_link\">")
1465 (defun mixi-get-new-comments (&optional max-numbers)
1467 (let ((items (mixi-get-matched-items (mixi-new-comment-list-page)
1469 mixi-new-comment-list-regexp)))
1470 (mapcar (lambda (item)
1471 (let ((diary (mixi-make-diary
1472 (mixi-make-friend (nth 1 item))
1474 (mixi-get-comments diary)))
1478 (defvar mixi-message-cache (make-hash-table :test 'equal))
1479 (defun mixi-make-message (id box)
1480 "Return a message object."
1481 (mixi-make-cache (list id box)
1482 (cons 'mixi-message (vector nil id box nil nil nil nil))
1483 mixi-message-cache))
1485 (defmacro mixi-message-p (message)
1486 `(eq (mixi-object-class ,message) 'mixi-message))
1488 (defmacro mixi-message-page (message)
1489 `(concat "/view_message.pl?id=" (mixi-message-id ,message)
1490 "&box=" (mixi-message-box ,message)))
1492 (defconst mixi-message-owner-regexp
1493 "<font COLOR=#996600>º¹½Ð¿Í</font> : <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\)</a>")
1494 (defconst mixi-message-title-regexp
1495 "<font COLOR=#996600>·ï¡¡Ì¾</font> : \\(.+\\)
1497 (defconst mixi-message-time-regexp
1498 "<font COLOR=#996600>Æü¡¡ÉÕ</font> : \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ ")
1499 (defconst mixi-message-content-regexp
1500 "<tr><td CLASS=h120>\\(.+\\)</td></tr>")
1502 (defun mixi-message-realize (message)
1503 "Realize a MESSAGE."
1504 (unless (mixi-object-realize-p message)
1505 (with-mixi-retrieve (mixi-message-page message)
1506 (if (string-match mixi-message-owner-regexp buffer)
1507 (mixi-message-set-owner message
1508 (mixi-make-friend (match-string 1 buffer)
1509 (match-string 2 buffer)))
1510 (signal 'error (list 'cannot-find-owner message)))
1511 (if (string-match mixi-message-title-regexp buffer)
1512 (mixi-message-set-title message (match-string 1 buffer))
1513 (signal 'error (list 'cannot-find-title message)))
1514 (if (string-match mixi-message-time-regexp buffer)
1515 (mixi-message-set-time
1516 message (encode-time 0 (string-to-number (match-string 5 buffer))
1517 (string-to-number (match-string 4 buffer))
1518 (string-to-number (match-string 3 buffer))
1519 (string-to-number (match-string 2 buffer))
1520 (string-to-number (match-string 1 buffer))))
1521 (signal 'error (list 'cannot-find-time message)))
1522 (if (string-match mixi-message-content-regexp buffer)
1523 (mixi-message-set-content message (mixi-remove-markup
1524 (match-string 1 buffer)))
1525 (signal 'error (list 'cannot-find-content message))))
1526 (mixi-object-touch message)))
1528 (defun mixi-message-id (message)
1529 "Return the id of MESSAGE."
1530 (unless (mixi-message-p message)
1531 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1532 (aref (cdr message) 1))
1534 (defun mixi-message-box (message)
1535 "Return the box of MESSAGE."
1536 (unless (mixi-message-p message)
1537 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1538 (aref (cdr message) 2))
1540 (defun mixi-message-owner (message)
1541 "Return the owner of MESSAGE."
1542 (unless (mixi-message-p message)
1543 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1544 (mixi-message-realize message)
1545 (aref (cdr message) 3))
1547 (defun mixi-message-title (message)
1548 "Return the title of MESSAGE."
1549 (unless (mixi-message-p message)
1550 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1551 (mixi-message-realize message)
1552 (aref (cdr message) 4))
1554 (defun mixi-message-time (message)
1555 "Return the date of MESSAGE."
1556 (unless (mixi-message-p message)
1557 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1558 (mixi-message-realize message)
1559 (aref (cdr message) 5))
1561 (defun mixi-message-content (message)
1562 "Return the content of MESSAGE."
1563 (unless (mixi-message-p message)
1564 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1565 (mixi-message-realize message)
1566 (aref (cdr message) 6))
1568 (defun mixi-message-set-owner (message owner)
1569 "Set the owner of MESSAGE."
1570 (unless (mixi-message-p message)
1571 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1572 (aset (cdr message) 3 owner))
1574 (defun mixi-message-set-title (message title)
1575 "Set the title of MESSAGE."
1576 (unless (mixi-message-p message)
1577 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1578 (aset (cdr message) 4 title))
1580 (defun mixi-message-set-time (message time)
1581 "Set the date of MESSAGE."
1582 (unless (mixi-message-p message)
1583 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1584 (aset (cdr message) 5 time))
1586 (defun mixi-message-set-content (message content)
1587 "Set the content of MESSAGE."
1588 (unless (mixi-message-p message)
1589 (signal 'wrong-type-argument (list 'mixi-message-p message)))
1590 (aset (cdr message) 6 content))
1592 (defmacro mixi-message-list-page (&optional box)
1593 `(concat "/list_message.pl?page=%d"
1594 (when ,box (concat "&box=" ,box))))
1596 (defconst mixi-message-list-regexp
1597 "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
1599 (defun mixi-get-messages (&rest args)
1601 (when (> (length args) 2)
1602 (signal 'wrong-number-of-arguments (list 'mixi-get-messages
1604 (let ((box (nth 0 args))
1605 (max-numbers (nth 1 args)))
1606 (when (or (not (stringp box)) (stringp max-numbers))
1607 (setq box (nth 1 args))
1608 (setq max-numbers (nth 0 args)))
1609 (let ((items (mixi-get-matched-items (mixi-message-list-page box)
1611 mixi-message-list-regexp)))
1612 (mapcar (lambda (item)
1613 (mixi-make-message (nth 0 item) (nth 1 item)))
1618 ;;; mixi.el ends here