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-search-diaries
35 ;; * mixi-get-communities
36 ;; * mixi-search-communities
38 ;; * mixi-get-new-bbses
39 ;; * mixi-search-bbses
40 ;; * mixi-get-comments
41 ;; * mixi-get-new-comments
42 ;; * mixi-get-messages
43 ;; * mixi-get-introductions
49 ;; * mixi-post-comment
50 ;; * mixi-post-message
54 ;; * mixi-remove-markup
58 ;; Display newest 3 diaries like a mail format.
61 ;; (buffer (get-buffer-create "*temp*"))
62 ;; (format "%Y/%m/%d %H:%M"))
63 ;; (pop-to-buffer buffer)
64 ;; (mapc (lambda (diary)
65 ;; (let ((subject (mixi-diary-title diary))
66 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
67 ;; (date (format-time-string format (mixi-diary-time diary)))
68 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
69 ;; (insert "From: " from "\n"
70 ;; "Subject: " subject "\n"
71 ;; "Date: " date "\n\n"
73 ;; (mixi-get-new-diaries range))
74 ;; (set-buffer-modified-p nil)
75 ;; (setq buffer-read-only t)
76 ;; (goto-char (point-min)))
78 ;; Display newest 3 diaries including newest 3 comments like a mail format.
79 ;; Comments are displayed like a reply mail.
82 ;; (buffer (get-buffer-create "*temp*"))
83 ;; (format "%Y/%m/%d %H:%M"))
84 ;; (pop-to-buffer buffer)
85 ;; (mapc (lambda (diary)
86 ;; (let ((subject (mixi-diary-title diary))
87 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
88 ;; (date (format-time-string format (mixi-diary-time diary)))
89 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
90 ;; (insert "From: " from "\n"
91 ;; "Subject: " subject "\n"
92 ;; "Date: " date "\n\n"
94 ;; (mapc (lambda (comment)
95 ;; (let ((from (mixi-friend-nick
96 ;; (mixi-comment-owner comment)))
97 ;; (subject (concat "Re: " subject))
98 ;; (date (format-time-string
99 ;; format (mixi-comment-time comment)))
100 ;; (body (mixi-remove-markup
101 ;; (mixi-comment-content comment))))
102 ;; (insert "From: " from "\n"
103 ;; "Subject: " subject "\n"
104 ;; "Date: " date "\n\n"
106 ;; (mixi-get-comments diary range))))
107 ;; (mixi-get-new-diaries range))
108 ;; (set-buffer-modified-p nil)
109 ;; (setq buffer-read-only t)
110 ;; (goto-char (point-min)))
114 ;; If you have bug reports and/or suggestions for improvement, please
115 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
119 (eval-when-compile (require 'cl))
122 "API library for accessing to mixi."
125 (defcustom mixi-url "http://mixi.jp"
130 (defcustom mixi-directory (expand-file-name "~/.mixi")
131 "*Where to look for mixi files."
135 (defcustom mixi-coding-system 'euc-jp
136 "*Coding system for mixi."
140 (defcustom mixi-curl-program "curl"
141 "*The program name of `curl'."
145 (defcustom mixi-curl-cookie-file (expand-file-name "cookies.txt"
147 "*The location of cookie file created by `curl'."
151 (defcustom mixi-backend
152 (or (condition-case nil
160 (if (fboundp 'url-retrieve-synchronously)
163 (if (and (fboundp 'executable-find)
164 (executable-find mixi-curl-program))
166 (error "Cannot set `mixi-backend'."))
167 "*The backend for accessing to mixi."
168 :type '(radio (const :tag "Use emacs-w3m" w3m)
169 (const :tag "Use url.el" url)
170 (const :tag "Use curl" curl)
171 (symbol :tag "The other backend"))
174 (defcustom mixi-default-email nil
175 "*Default E-mail address that is used to login automatically."
176 :type '(radio (string :tag "E-mail address")
177 (const :tag "Asked when it is necessary" nil))
180 (defcustom mixi-default-password nil
181 "*Default password that is used to login automatically."
182 :type '(radio (string :tag "Password")
183 (const :tag "Asked when it is necessary" nil))
186 (defcustom mixi-accept-adult-contents t
187 "*If non-nil, accept to access to the adult contents."
191 (defcustom mixi-continuously-access-interval 4.0
192 "*Time interval between each mixi access.
193 Increase this value when unexpected error frequently occurs."
197 (defcustom mixi-cache-expires nil
198 "*Seconds for expiration of a cached object."
199 :type '(radio (integer :tag "Expired seconds")
200 (const :tag "Don't expire" nil)
201 (const :tag "Don't cache" t))
204 ;; FIXME: Not implemented.
205 (defcustom mixi-cache-use-file t
206 "*If non-nil, caches are saved to files."
213 (defmacro mixi-message (&rest strings)
214 `(concat "[mixi] " ,@strings))
216 (put 'mixi-realization-error
217 'error-message (mixi-message "Cannot realize object"))
218 (put 'mixi-realization-error
219 'error-conditions '(mixi-realization-error error))
221 (put 'mixi-post-error
222 'error-message (mixi-message "Cannot post"))
223 (put 'mixi-post-error
224 'error-conditions '(mixi-post-error error))
226 (defmacro mixi-realization-error (type object)
227 `(let ((data (if (and (boundp 'buffer) debug-on-error)
228 (list ,type ,object buffer)
229 (list ,type ,object))))
230 (signal 'mixi-realization-error data)))
232 (defmacro mixi-post-error (type &optional object)
233 `(let ((data (when (and (boundp 'buffer) debug-on-error)
236 (setq data (cons ,type (cons ,object data)))
237 (setq data (cons ,type data)))
238 (signal 'mixi-post-error data)))
240 (defconst mixi-message-adult-contents
241 "¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
242 ±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
243 (defconst mixi-message-continuously-accessing
244 "°ÂÄꤷ¤Æ¥µ¥¤¥È¤Î±¿±Ä¤ò¤ª¤³¤Ê¤¦°Ù¡¢´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹<br>
245 ¿·¤ÏÀ©¸Â¤µ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤ª¤ê¤Þ¤¹¡£¤´ÌÂÏǤò¤ª¤«¤±¤¤¤¿¤·¤Þ¤¹¤¬¡¢¤·¤Ð¤é¤¯¤ª<br>
246 ÂÔ¤Á¤¤¤¿¤À¤¤¤Æ¤«¤éÁàºî¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£")
247 (defconst mixi-warning-continuously-accessing
248 "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«<br>
249 ¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ<br>
250 ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
252 (defmacro mixi-retrieve (url &optional post-data)
253 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-retrieve"))
256 (defmacro mixi-post-form (url fields)
257 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-post-form"))
260 (defun mixi-parse-buffer (url buffer &optional post-data)
261 (when (string-match mixi-message-adult-contents buffer)
262 (if mixi-accept-adult-contents
263 (setq buffer (mixi-retrieve url "submit=agree"))
264 (setq buffer (mixi-retrieve (concat url "?")))))
265 (when (string-match mixi-warning-continuously-accessing buffer)
266 (error (mixi-message "Access denied. Please wait a while and increase "
267 "the value of `mixi-continuously-access-interval'.")))
268 (if (not (string-match mixi-message-continuously-accessing buffer))
270 (message (mixi-message "Waiting for continuously accessing..."))
271 (sleep-for mixi-continuously-access-interval)
272 (mixi-retrieve url post-data)))
274 (defmacro mixi-expand-url (url)
275 `(if (string-match "^http" ,url)
277 (concat mixi-url ,url)))
279 ;; FIXME: Support file, checkbox and so on.
280 (defun mixi-make-form-data (fields)
281 "Make form data and return (CONTENT-TYPE . FORM-DATA)."
282 (let* ((boundary (apply 'format "--_%d_%d_%d" (current-time)))
283 (content-type (concat "multipart/form-data; boundary=" boundary))
287 (concat "--" boundary "\r\n"
288 "Content-Disposition: form-data; name=\""
291 (encode-coding-string (cdr field) mixi-coding-system)))
293 (cons content-type (concat form-data "\r\n--" boundary "--"))))
295 (defun mixi-url-retrieve (url &optional post-data extra-headers)
296 "Retrieve the URL and return gotten strings."
297 (let* ((url-request-method (if post-data "POST" "GET"))
298 (url-request-data post-data)
299 (url-request-extra-headers extra-headers)
300 (url (mixi-expand-url url))
301 (buffer (url-retrieve-synchronously url))
303 (unless (bufferp buffer)
304 (error (mixi-message "Cannot retrieve")))
305 (with-current-buffer buffer
306 (goto-char (point-min))
307 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
308 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
309 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
310 (error (mixi-message "Cannot retrieve")))
311 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
312 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
314 (mixi-parse-buffer url ret post-data))))
316 (defun mixi-url-post-form (url fields)
317 (let* ((form-data (mixi-make-form-data fields))
318 (extra-headers `(("Content-Type" . ,(car form-data)))))
319 (mixi-url-retrieve url (cdr form-data) extra-headers)))
321 (defun mixi-w3m-retrieve (url &optional post-data)
322 "Retrieve the URL and return gotten strings."
323 (let ((url (mixi-expand-url url)))
325 (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
326 (error (mixi-message "Cannot retrieve"))
327 (w3m-decode-buffer url)
328 (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
329 (mixi-parse-buffer url ret post-data))))))
331 (defun mixi-w3m-post-form (url fields)
332 (let ((form-data (mixi-make-form-data fields)))
333 (mixi-w3m-retrieve url form-data)))
335 (defun mixi-curl-retrieve (url &optional post-data)
336 "Retrieve the URL and return gotten strings."
338 (if (fboundp 'set-buffer-multibyte)
339 (set-buffer-multibyte nil))
340 (let ((orig-mode (default-file-modes))
341 (coding-system-for-read 'binary)
342 (coding-system-for-write 'binary)
346 (set-default-file-modes 448)
348 (apply #'start-process "curl" (current-buffer)
350 (append (if post-data '("-d" "@-"))
352 "-b" mixi-curl-cookie-file
353 "-c" mixi-curl-cookie-file
354 (mixi-expand-url url)))))
355 (set-process-sentinel process #'ignore))
356 (set-default-file-modes orig-mode))
358 (process-send-string process (concat post-data "\n"))
359 (process-send-eof process))
360 (while (eq (process-status process) 'run)
361 (accept-process-output process 1))
362 (goto-char (point-min))
363 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
364 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
365 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
366 (error (mixi-message "Cannot retrieve")))
367 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
368 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
369 (mixi-parse-buffer url ret post-data))))
371 (defconst mixi-my-id-regexp
372 "<a href=\"add_diary\\.pl\\?id=\\([0-9]+\\)")
374 (defun mixi-login (&optional email password)
376 (when (and (eq mixi-backend 'w3m) (not w3m-use-cookies))
377 (error (mixi-message "Require to accept cookies. Please set "
378 "`w3m-use-cookies' to t.")))
379 (let ((email (or email mixi-default-email
380 (read-from-minibuffer (mixi-message "Login Email: "))))
381 (password (or password mixi-default-password
382 (read-passwd (mixi-message "Login Password: ")))))
383 (let ((buffer (mixi-retrieve "/login.pl"
384 (concat "email=" email
385 "&password=" password
388 (unless (string-match "url=/check\\.pl\\?n=" buffer)
389 (error (mixi-message "Cannot login")))
390 (setq buffer (mixi-retrieve "/check.pl?n=home.pl"))
391 (if (string-match mixi-my-id-regexp buffer)
392 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
393 (error (mixi-message "Cannot login"))))))
395 (defun mixi-logout ()
396 (mixi-retrieve "/logout.pl"))
398 (defmacro with-mixi-retrieve (url &rest body)
401 (setq buffer (mixi-retrieve ,url))
402 (when (string-match "<form action=\"login\\.pl\" method=\"post\">"
405 (setq buffer (mixi-retrieve ,url))))
407 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
408 (put 'with-mixi-retrieve 'edebug-form-spec '(form body))
410 (defmacro with-mixi-post-form (url fields &rest body)
413 (setq buffer (mixi-post-form ,url ,fields))
414 (when (string-match "<form action=\"login\\.pl\" method=\"post\">"
417 (setq buffer (mixi-post-form ,url ,fields))))
419 (put 'with-mixi-post-form 'lisp-indent-function 'defun)
420 (put 'with-mixi-post-form 'edebug-form-spec '(form body))
422 (defun mixi-get-matched-items (url regexp &optional range)
423 "Get matched items to REGEXP in URL."
427 (while (or (null range) (< (length ids) range))
428 (with-mixi-retrieve (format url page)
431 (while (and (string-match regexp buffer pos)
432 (or (null range) (< (length ids) range)))
435 (while (match-string num buffer)
436 (setq list (cons (match-string num buffer) list))
438 (when (not (member (reverse list) ids))
440 (setq ids (cons (reverse list) ids)))
441 (setq pos (match-end (1- num)))))
447 ;; stolen (and modified) from shimbun.el
448 (defun mixi-remove-markup (string)
449 "Remove markups from STRING."
451 (insert (or string ""))
453 (goto-char (point-min))
454 (while (search-forward "<!--" nil t)
455 (delete-region (match-beginning 0)
456 (or (search-forward "-->" nil t)
458 (goto-char (point-min))
459 (while (re-search-forward "<[^>]+>" nil t)
460 (replace-match "" t t))
461 (goto-char (point-min))
462 (while (re-search-forward "
\r" nil t)
463 (replace-match "\n" t t)))
464 ;; FIXME: Decode entities.
467 ;; stolen (and modified) from w3m.el
469 (defun mixi-url-encode-and-quote-percent-string (string)
470 (apply (function concat)
474 ((eq char ?\n) ; newline
476 ((string-match "[-a-zA-Z0-9_:/.]" (char-to-string char)) ; xxx?
477 (char-to-string char)) ; printable
478 ((char-equal char ?\x20) ; space
481 (format "%%%%%02x" char)))) ; escape
482 ;; Coerce a string into a list of chars.
483 (append (encode-coding-string (or string "") mixi-coding-system)
487 (defconst mixi-object-prefix "mixi-")
489 (defmacro mixi-object-class (object)
492 (defmacro mixi-object-p (object)
493 `(let ((class (mixi-object-class ,object)))
494 (when (symbolp class)
495 (eq (string-match (concat "^" mixi-object-prefix)
496 (symbol-name class)) 0))))
498 (defun mixi-object-name (object)
499 "Return the name of OBJECT."
500 (unless (mixi-object-p object)
501 (signal 'wrong-type-argument (list 'mixi-object-p object)))
502 (let ((class (mixi-object-class object)))
503 (substring (symbol-name class) (length mixi-object-prefix))))
505 (defun mixi-read-object (exp)
506 "Read one Lisp expression as mixi object."
507 (if (mixi-object-p exp)
508 (let ((func (intern (concat mixi-object-prefix "make-"
509 (mixi-object-name exp))))
510 (args (mapcar (lambda (arg)
511 (mixi-read-object arg))
513 (let ((object (apply func (cdr args))))
515 (mixi-object-set-timestamp object (car args)))
519 (defun mixi-object-timestamp (object)
520 "Return the timestamp of OJBECT."
521 (unless (mixi-object-p object)
522 (signal 'wrong-type-argument (list 'mixi-object-p object)))
523 (aref (cdr object) 0))
524 (defalias 'mixi-object-realized-p 'mixi-object-timestamp)
526 (defun mixi-object-owner (object)
527 "Return the owner of OBJECT."
528 (unless (mixi-object-p object)
529 (signal 'wrong-type-argument (list 'mixi-object-p object)))
530 (let ((func (intern (concat mixi-object-prefix
531 (mixi-object-name object) "-owner"))))
532 (funcall func object)))
534 (defun mixi-object-id (object)
535 "Return the id of OBJECT."
536 (unless (mixi-object-p object)
537 (signal 'wrong-type-argument (list 'mixi-object-p object)))
538 (let ((func (intern (concat mixi-object-prefix
539 (mixi-object-name object) "-id"))))
540 (funcall func object)))
542 (defun mixi-object-time (object)
543 "Return the time of OBJECT."
544 (unless (mixi-object-p object)
545 (signal 'wrong-type-argument (list 'mixi-object-p object)))
546 (let ((func (intern (concat mixi-object-prefix
547 (mixi-object-name object) "-time"))))
548 (funcall func object)))
550 (defun mixi-object-title (object)
551 "Return the title of OBJECT."
552 (unless (mixi-object-p object)
553 (signal 'wrong-type-argument (list 'mixi-object-p object)))
554 (let ((func (intern (concat mixi-object-prefix
555 (mixi-object-name object) "-title"))))
556 (funcall func object)))
558 (defun mixi-object-content (object)
559 "Return the content of OBJECT."
560 (unless (mixi-object-p object)
561 (signal 'wrong-type-argument (list 'mixi-object-p object)))
562 (let ((func (intern (concat mixi-object-prefix
563 (mixi-object-name object) "-content"))))
564 (funcall func object)))
566 (defun mixi-object-set-timestamp (object timestamp)
567 "Set the timestamp of OBJECT."
568 (unless (mixi-object-p object)
569 (signal 'wrong-type-argument (list 'mixi-object-p object)))
570 (aset (cdr object) 0 timestamp))
572 (defmacro mixi-object-touch (object)
573 `(mixi-object-set-timestamp ,object (current-time)))
575 (defconst mixi-object-url-regexp
576 "/\\(show\\|view\\)_\\([a-z]+\\)\\.pl")
578 (defun mixi-make-object-from-url (url)
579 "Return a mixi object from URL."
580 (if (string-match mixi-object-url-regexp url)
581 (let ((name (match-string 2 url)))
582 (when (string= name "bbs")
584 (let ((func (intern (concat mixi-object-prefix "make-" name
587 (when (string-match "/home\\.pl" url)
588 (mixi-make-friend-from-url url))))
591 ;; stolen from time-date.el
592 (defun mixi-time-less-p (t1 t2)
593 "Say whether time value T1 is less than time value T2."
594 (unless (numberp (cdr t1))
595 (setq t1 (cons (car t1) (car (cdr t1)))))
596 (unless (numberp (cdr t2))
597 (setq t2 (cons (car t2) (car (cdr t2)))))
598 (or (< (car t1) (car t2))
599 (and (= (car t1) (car t2))
600 (< (cdr t1) (cdr t2)))))
602 (defun mixi-time-add (t1 t2)
603 "Add two time values. One should represent a time difference."
604 (unless (numberp (cdr t1))
605 (setq t1 (cons (car t1) (car (cdr t1)))))
606 (unless (numberp (cdr t2))
607 (setq t2 (cons (car t2) (car (cdr t2)))))
608 (let ((low (+ (cdr t1) (cdr t2))))
609 (cons (+ (car t1) (car t2) (lsh low -16)) low)))
611 ;; stolen from time-date.el
612 (defun mixi-seconds-to-time (seconds)
613 "Convert SECONDS (a floating point number) to a time value."
614 (cons (floor seconds 65536)
615 (floor (mod seconds 65536))))
617 (defun mixi-cache-expired-p (object)
618 "Whether a cache of OBJECT is expired."
619 (let ((timestamp (mixi-object-timestamp object)))
620 (unless (or (null mixi-cache-expires)
622 (if (numberp mixi-cache-expires)
624 (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
628 (defun mixi-make-cache (key value table)
629 "Make a cache object and return it."
630 (let ((cache (gethash key table)))
631 (if (and cache (not (mixi-cache-expired-p cache)))
633 (puthash key value table))))
635 (defconst mixi-cache-file-regexp "[a-z]+-cache$")
636 (defconst mixi-cache-regexp (concat mixi-object-prefix
637 mixi-cache-file-regexp))
639 (defun mixi-save-cache ()
640 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
641 (unless (file-directory-p cache-directory)
642 (make-directory cache-directory t))
643 (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
644 (mapc (lambda (symbol)
645 (with-temp-file (expand-file-name
646 (substring (symbol-name symbol)
647 (length mixi-object-prefix))
649 (let ((coding-system-for-write mixi-coding-system)
650 (cache (symbol-value symbol)))
651 (insert "#s(hash-table size "
652 (number-to-string (hash-table-count cache))
653 " test equal data (\n")
656 (let (print-level print-length)
657 (insert (prin1-to-string key) " "
658 (prin1-to-string value) "\n")))
663 ;; stolen (and modified) from lsdb.el
664 (defun mixi-read-cache (&optional marker)
665 "Read one Lisp expression as text from MARKER, return as Lisp object."
668 (if (looking-at "^#s(")
671 (forward-char 2);skip "#s"
672 (forward-sexp);move to the left paren
675 (buffer-disable-undo)
676 (insert-buffer-substring (marker-buffer marker)
678 (goto-char (point-min))
680 (let ((object (read (current-buffer)))
682 (if (eq 'hash-table (car object))
684 (setq data (plist-get (cdr object) 'data))
686 (pop data);throw it away
687 (mixi-read-object (pop data))))
691 (defun mixi-load-cache ()
692 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
693 (when (file-directory-p cache-directory)
694 ;; FIXME: Load friend and community first.
695 (let ((files (directory-files cache-directory t
696 mixi-cache-file-regexp)))
698 (let ((buffer (find-file-noselect file)))
702 (goto-char (point-min))
703 (re-search-forward "^#s(")
704 (goto-char (match-beginning 0))
705 (mixi-read-cache (point-marker)))
706 (kill-buffer buffer))))
710 (defvar mixi-friend-cache (make-hash-table :test 'equal))
711 (defun mixi-make-friend (id &optional nick name sex address age birthday
712 blood-type birthplace hobby job organization
714 "Return a friend object."
715 (mixi-make-cache id (cons 'mixi-friend (vector nil id nick name sex address
716 age birthday blood-type
718 organization profile))
721 (defun mixi-make-me ()
722 "Return a my object."
724 (with-mixi-retrieve "/home.pl"
725 (if (string-match mixi-my-id-regexp buffer)
726 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
727 (signal 'error (list 'who-am-i)))))
730 (defconst mixi-friend-url-regexp
731 "/show_friend\\.pl\\?id=\\([0-9]+\\)")
733 (defun mixi-make-friend-from-url (url)
734 "Return a friend object from URL."
735 (if (string-match mixi-friend-url-regexp url)
736 (let ((id (match-string 1 url)))
737 (mixi-make-friend id))
738 (when (string-match "/home\\.pl" url)
741 (defmacro mixi-friend-p (friend)
742 `(eq (mixi-object-class ,friend) 'mixi-friend))
744 (defmacro mixi-friend-page (friend)
745 `(concat "/show_friend.pl?id=" (mixi-friend-id ,friend)))
747 (defconst mixi-friend-nick-regexp
748 "<img alt=\"\\*\" src=\"http://img\\.mixi\\.jp/img/dot0\\.gif\" width=\"1\" height=\"5\"><br>
\r?
749 \\(.*\\)¤µ¤ó([0-9]+)")
750 (defconst mixi-friend-name-regexp
751 "<td BGCOLOR=#F2DDB7 WIDTH=80 NOWRAP><font COLOR=#996600>̾\\( \\| \\)Á°</font></td>
753 ?<td WIDTH=345>\\(.+?\\)\\(</td>\\|<img\\)")
754 (defconst mixi-friend-sex-regexp
755 "<td BGCOLOR=#F2DDB7\\( WIDTH=80 NOWRAP\\)?><font COLOR=#996600>À\\( \\| \\)ÊÌ</font></td>
757 ?<td WIDTH=345>\\([Ã˽÷]\\)À\\(</td>\\|<img\\)")
758 (defconst mixi-friend-address-regexp
759 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¸½½»½ê</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
760 (defconst mixi-friend-age-regexp
761 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>ǯ\\( \\| \\)Îð</font></td>\n<td>\\([0-9]+\\)ºÐ\\(\n.+\n\\)?</td></tr>")
762 (defconst mixi-friend-birthday-regexp
763 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>ÃÂÀ¸Æü</font></td>\n<td>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(\n.+\n\\)?</td></tr>")
764 (defconst mixi-friend-blood-type-regexp
765 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>·ì±Õ·¿</font></td>\n<td>\\([ABO]B?\\)·¿\\(\n\n\\)?</td></tr>")
766 (defconst mixi-friend-birthplace-regexp
767 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>½Ð¿ÈÃÏ</font>\n?</td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
768 (defconst mixi-friend-hobby-regexp
769 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼ñ\\( \\| \\)Ì£</font></td>\n<td>\\(.+?\\)\\(</td>\\|<img\\)")
770 (defconst mixi-friend-job-regexp
771 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¿¦\\( \\| \\)¶È</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
772 (defconst mixi-friend-organization-regexp
773 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>½ê\\( \\| \\)°</font></td>\n<td[^>]*>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
774 (defconst mixi-friend-profile-regexp
775 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼«¸Ê¾Ò²ð</font></td>\n<td CLASS=h120>\\(.+\\)</td></tr>")
777 (defun mixi-realize-friend (friend)
779 ;; FIXME: Check a expiration of cache?
780 (unless (mixi-object-realized-p friend)
782 (with-mixi-retrieve (mixi-friend-page friend)
784 (if (string-match mixi-friend-nick-regexp buf)
785 (mixi-friend-set-nick friend (match-string 1 buf))
786 (mixi-realization-error 'cannot-find-nick friend))
787 ;; For getting my profile.
788 (unless (string-match mixi-friend-name-regexp buf)
789 (with-mixi-retrieve (concat "/show_profile.pl?id="
790 (mixi-friend-id friend))
792 (if (string-match mixi-friend-name-regexp buf)
793 (mixi-friend-set-name friend (match-string 2 buf))
794 (mixi-realization-error 'cannot-find-name friend))
795 (if (string-match mixi-friend-sex-regexp buf)
796 (mixi-friend-set-sex friend
797 (if (string= (match-string 3 buf) "ÃË")
799 (mixi-realization-error 'cannot-find-sex friend))
800 (when (string-match mixi-friend-address-regexp buf)
801 (mixi-friend-set-address friend (match-string 1 buf)))
802 (when (string-match mixi-friend-age-regexp buf)
804 friend (string-to-number (match-string 2 buf))))
805 (when (string-match mixi-friend-birthday-regexp buf)
806 (mixi-friend-set-birthday
807 friend (list (string-to-number (match-string 1 buf))
808 (string-to-number (match-string 2 buf)))))
809 (when (string-match mixi-friend-blood-type-regexp buf)
810 (mixi-friend-set-blood-type friend (intern (match-string 1 buf))))
811 (when (string-match mixi-friend-birthplace-regexp buf)
812 (mixi-friend-set-birthplace friend (match-string 1 buf)))
813 (when (string-match mixi-friend-hobby-regexp buf)
814 (mixi-friend-set-hobby
815 friend (split-string (match-string 2 buf) ", ")))
816 (when (string-match mixi-friend-job-regexp buf)
817 (mixi-friend-set-job friend (match-string 2 buf)))
818 (when (string-match mixi-friend-organization-regexp buf)
819 (mixi-friend-set-organization friend (match-string 2 buf)))
820 (when (string-match mixi-friend-profile-regexp buf)
821 (mixi-friend-set-profile friend (match-string 1 buf))))
822 (mixi-object-touch friend)))
824 (defun mixi-friend-id (friend)
825 "Return the id of FRIEND."
826 (unless (mixi-friend-p friend)
827 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
828 (aref (cdr friend) 1))
830 (defun mixi-friend-nick (friend)
831 "Return the nick of FRIEND."
832 (unless (mixi-friend-p friend)
833 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
834 (unless (aref (cdr friend) 2)
835 (mixi-realize-friend friend))
836 (aref (cdr friend) 2))
838 (defun mixi-friend-name (friend)
839 "Return the name of FRIEND."
840 (unless (mixi-friend-p friend)
841 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
842 (mixi-realize-friend friend)
843 (aref (cdr friend) 3))
845 (defun mixi-friend-sex (friend)
846 "Return the sex of FRIEND."
847 (unless (mixi-friend-p friend)
848 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
849 (mixi-realize-friend friend)
850 (aref (cdr friend) 4))
852 (defun mixi-friend-address (friend)
853 "Return the address of FRIEND."
854 (unless (mixi-friend-p friend)
855 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
856 (mixi-realize-friend friend)
857 (aref (cdr friend) 5))
859 (defun mixi-friend-age (friend)
860 "Return the age of FRIEND."
861 (unless (mixi-friend-p friend)
862 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
863 (mixi-realize-friend friend)
864 (aref (cdr friend) 6))
866 (defun mixi-friend-birthday (friend)
867 "Return the birthday of FRIEND."
868 (unless (mixi-friend-p friend)
869 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
870 (mixi-realize-friend friend)
871 (aref (cdr friend) 7))
873 (defun mixi-friend-blood-type (friend)
874 "Return the blood type of FRIEND."
875 (unless (mixi-friend-p friend)
876 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
877 (mixi-realize-friend friend)
878 (aref (cdr friend) 8))
880 (defun mixi-friend-birthplace (friend)
881 "Return the birthplace of FRIEND."
882 (unless (mixi-friend-p friend)
883 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
884 (mixi-realize-friend friend)
885 (aref (cdr friend) 9))
887 (defun mixi-friend-hobby (friend)
888 "Return the hobby of FRIEND."
889 (unless (mixi-friend-p friend)
890 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
891 (mixi-realize-friend friend)
892 (aref (cdr friend) 10))
894 (defun mixi-friend-job (friend)
895 "Return the job of FRIEND."
896 (unless (mixi-friend-p friend)
897 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
898 (mixi-realize-friend friend)
899 (aref (cdr friend) 11))
901 (defun mixi-friend-organization (friend)
902 "Return the organization of FRIEND."
903 (unless (mixi-friend-p friend)
904 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
905 (mixi-realize-friend friend)
906 (aref (cdr friend) 12))
908 (defun mixi-friend-profile (friend)
909 "Return the pforile of FRIEND."
910 (unless (mixi-friend-p friend)
911 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
912 (mixi-realize-friend friend)
913 (aref (cdr friend) 13))
915 (defun mixi-friend-set-nick (friend nick)
916 "Set the nick of FRIEND."
917 (unless (mixi-friend-p friend)
918 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
919 (aset (cdr friend) 2 nick))
921 (defun mixi-friend-set-name (friend name)
922 "Set the name of FRIEND."
923 (unless (mixi-friend-p friend)
924 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
925 (aset (cdr friend) 3 name))
927 (defun mixi-friend-set-sex (friend sex)
928 "Set the sex of FRIEND."
929 (unless (mixi-friend-p friend)
930 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
931 (aset (cdr friend) 4 sex))
933 (defun mixi-friend-set-address (friend address)
934 "Set the address of FRIEND."
935 (unless (mixi-friend-p friend)
936 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
937 (aset (cdr friend) 5 address))
939 (defun mixi-friend-set-age (friend age)
940 "Set the age of FRIEND."
941 (unless (mixi-friend-p friend)
942 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
943 (aset (cdr friend) 6 age))
945 (defun mixi-friend-set-birthday (friend birthday)
946 "Set the birthday of FRIEND."
947 (unless (mixi-friend-p friend)
948 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
949 (aset (cdr friend) 7 birthday))
951 (defun mixi-friend-set-blood-type (friend blood-type)
952 "Set the blood type of FRIEND."
953 (unless (mixi-friend-p friend)
954 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
955 (aset (cdr friend) 8 blood-type))
957 (defun mixi-friend-set-birthplace (friend birthplace)
958 "Set the birthplace of FRIEND."
959 (unless (mixi-friend-p friend)
960 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
961 (aset (cdr friend) 9 birthplace))
963 (defun mixi-friend-set-hobby (friend hobby)
964 "Set the hobby of FRIEND."
965 (unless (mixi-friend-p friend)
966 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
967 (aset (cdr friend) 10 hobby))
969 (defun mixi-friend-set-job (friend job)
970 "Set the job of FRIEND."
971 (unless (mixi-friend-p friend)
972 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
973 (aset (cdr friend) 11 job))
975 (defun mixi-friend-set-organization (friend organization)
976 "Set the organization of FRIEND."
977 (unless (mixi-friend-p friend)
978 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
979 (aset (cdr friend) 12 organization))
981 (defun mixi-friend-set-profile (friend profile)
982 "Set the profile of FRIEND."
983 (unless (mixi-friend-p friend)
984 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
985 (aset (cdr friend) 13 profile))
987 (defmacro mixi-friend-list-page (&optional friend)
988 `(concat "/list_friend.pl?page=%d"
989 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
991 (defconst mixi-friend-list-id-regexp
992 "<a href=show_friend\\.pl\\?id=\\([0-9]+\\)")
993 (defconst mixi-friend-list-nick-regexp
994 "<td valign=middle>\\(.+\\)¤µ¤ó([0-9]+)<br />")
996 (defun mixi-get-friends (&rest friend-or-range)
997 "Get friends of FRIEND."
998 (when (> (length friend-or-range) 2)
999 (signal 'wrong-number-of-arguments (list 'mixi-get-friends
1000 (length friend-or-range))))
1001 (let ((friend (nth 0 friend-or-range))
1002 (range (nth 1 friend-or-range)))
1003 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1004 (setq friend (nth 1 friend-or-range))
1005 (setq range (nth 0 friend-or-range)))
1006 (unless (or (null friend) (mixi-friend-p friend))
1007 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1008 (let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
1009 mixi-friend-list-id-regexp
1011 (nicks (mixi-get-matched-items (mixi-friend-list-page friend)
1012 mixi-friend-list-nick-regexp
1016 (while (< index (length ids))
1017 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1018 (nth 0 (nth index nicks))) ret))
1023 (defmacro mixi-favorite-list-page ()
1024 `(concat "/list_bookmark.pl?page=%d"))
1026 (defconst mixi-favorite-list-id-regexp
1027 "<td ALIGN=center BGCOLOR=#FDF9F2 width=330><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">")
1028 (defconst mixi-favorite-list-nick-regexp
1029 "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾ Á°</font></td>
1030 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>")
1032 (defun mixi-get-favorites (&optional range)
1034 (let ((ids (mixi-get-matched-items (mixi-favorite-list-page)
1035 mixi-favorite-list-id-regexp
1037 (nicks (mixi-get-matched-items (mixi-favorite-list-page)
1038 mixi-favorite-list-nick-regexp
1042 (while (< index (length ids))
1043 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1044 (nth 0 (nth index nicks))) ret))
1049 (defun mixi-make-log (friend time)
1050 "Return a log object."
1051 (cons 'mixi-log (vector friend time)))
1053 (defmacro mixi-log-p (log)
1054 `(eq (mixi-object-class ,log) 'mixi-log))
1056 (defun mixi-log-friend (log)
1057 "Return the friend of LOG."
1058 (unless (mixi-log-p log)
1059 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1062 (defun mixi-log-time (log)
1063 "Return the time of LOG."
1064 (unless (mixi-log-p log)
1065 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1068 (defmacro mixi-log-list-page ()
1069 `(concat "/show_log.pl"))
1071 (defconst mixi-log-list-regexp
1072 "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></li>")
1074 (defun mixi-get-logs (&optional range)
1076 (let ((items (mixi-get-matched-items (mixi-log-list-page)
1077 mixi-log-list-regexp
1079 (mapcar (lambda (item)
1080 (mixi-make-log (mixi-make-friend (nth 5 item) (nth 6 item))
1082 (string-to-number (nth 4 item))
1083 (string-to-number (nth 3 item))
1084 (string-to-number (nth 2 item))
1085 (string-to-number (nth 1 item))
1086 (string-to-number (nth 0 item)))))
1090 (defvar mixi-diary-cache (make-hash-table :test 'equal))
1091 (defun mixi-make-diary (owner id &optional time title content)
1092 "Return a diary object."
1093 (let ((owner (or owner (mixi-make-me))))
1094 (mixi-make-cache (list (mixi-friend-id owner) id)
1095 (cons 'mixi-diary (vector nil owner id time title
1099 (defconst mixi-diary-url-regexp
1100 "/view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)")
1102 (defun mixi-make-diary-from-url (url)
1103 "Return a diary object from URL."
1104 (when (string-match mixi-diary-url-regexp url)
1105 (let ((id (match-string 1 url))
1106 (owner-id (match-string 2 url)))
1107 (mixi-make-diary (mixi-make-friend owner-id) id))))
1109 (defmacro mixi-diary-p (diary)
1110 `(eq (mixi-object-class ,diary) 'mixi-diary))
1112 (defmacro mixi-diary-page (diary)
1113 `(concat "/view_diary.pl?id=" (mixi-diary-id ,diary)
1114 "&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
1116 (defconst mixi-diary-closed-regexp
1117 "<td>ͧ¿Í\\(¤Îͧ¿Í\\)?¤Þ¤Ç¸ø³«¤Î¤¿¤áÆɤळ¤È¤¬½ÐÍè¤Þ¤»¤ó¡£</td></tr>")
1118 (defconst mixi-diary-owner-nick-regexp
1119 "<td WIDTH=490 background=http://img\\.mixi\\.jp/img/bg_w\\.gif><b><font COLOR=#605048>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ</font></b></td>")
1120 (defconst mixi-diary-time-regexp
1121 "<td \\(align\\|ALIGN\\)=\"?center\"? \\(rowspan\\|ROWSPAN\\)=\"?[23]\"? \\(nowrap=\"nowrap\"\\|NOWRAP\\) \\(width\\|WIDTH\\)=\"?95\"? bgcolor=\"?#FFD8B0\"?>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(<br />\\|<br>\\)\\([0-9]+\\):\\([0-9]+\\)</td>")
1122 (defconst mixi-diary-title-regexp
1123 "<td \\(bgcolor\\|BGCOLOR\\)=\"?#FFF4E0\"? width=\"?430\"?> \\([^<]+\\)</td>")
1124 (defconst mixi-diary-content-regexp
1125 "<td \\(class\\|CLASS\\)=\"?h12\"?>\\(.*\\)</td>")
1127 (defun mixi-realize-diary (diary)
1129 ;; FIXME: Check a expiration of cache?
1130 (unless (mixi-object-realized-p diary)
1131 (with-mixi-retrieve (mixi-diary-page diary)
1132 (unless (string-match mixi-diary-closed-regexp buffer)
1133 (if (string-match mixi-diary-owner-nick-regexp buffer)
1134 (mixi-friend-set-nick (mixi-diary-owner diary)
1135 (match-string 1 buffer))
1136 (mixi-realization-error 'cannot-find-owner-nick diary))
1137 (if (string-match mixi-diary-time-regexp buffer)
1138 (mixi-diary-set-time
1139 diary (encode-time 0 (string-to-number (match-string 10 buffer))
1140 (string-to-number (match-string 9 buffer))
1141 (string-to-number (match-string 7 buffer))
1142 (string-to-number (match-string 6 buffer))
1143 (string-to-number (match-string 5 buffer))))
1144 (mixi-realization-error 'cannot-find-time diary))
1145 (if (string-match mixi-diary-title-regexp buffer)
1146 (mixi-diary-set-title diary (match-string 2 buffer))
1147 (mixi-realization-error 'cannot-find-title diary))
1148 (if (string-match mixi-diary-content-regexp buffer)
1149 (mixi-diary-set-content diary (match-string 2 buffer))
1150 (mixi-realization-error 'cannot-find-content diary))))
1151 (mixi-object-touch diary)))
1153 (defun mixi-diary-owner (diary)
1154 "Return the owner of DIARY."
1155 (unless (mixi-diary-p diary)
1156 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1157 (aref (cdr diary) 1))
1159 (defun mixi-diary-id (diary)
1160 "Return the id of DIARY."
1161 (unless (mixi-diary-p diary)
1162 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1163 (aref (cdr diary) 2))
1165 (defun mixi-diary-time (diary)
1166 "Return the time of DIARY."
1167 (unless (mixi-diary-p diary)
1168 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1169 (unless (aref (cdr diary) 3)
1170 (mixi-realize-diary diary))
1171 (aref (cdr diary) 3))
1173 (defun mixi-diary-title (diary)
1174 "Return the title of DIARY."
1175 (unless (mixi-diary-p diary)
1176 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1177 (unless (aref (cdr diary) 4)
1178 (mixi-realize-diary diary))
1179 (aref (cdr diary) 4))
1181 (defun mixi-diary-content (diary)
1182 "Return the content of DIARY."
1183 (unless (mixi-diary-p diary)
1184 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1185 (mixi-realize-diary diary)
1186 (aref (cdr diary) 5))
1188 (defun mixi-diary-set-time (diary time)
1189 "Set the time of DIARY."
1190 (unless (mixi-diary-p diary)
1191 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1192 (aset (cdr diary) 3 time))
1194 (defun mixi-diary-set-title (diary title)
1195 "Set the title of DIARY."
1196 (unless (mixi-diary-p diary)
1197 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1198 (aset (cdr diary) 4 title))
1200 (defun mixi-diary-set-content (diary content)
1201 "Set the content of DIARY."
1202 (unless (mixi-diary-p diary)
1203 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1204 (aset (cdr diary) 5 content))
1206 (defmacro mixi-diary-list-page (&optional friend)
1207 `(concat "/list_diary.pl?page=%d"
1208 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1210 (defconst mixi-diary-list-regexp
1212 <td ALIGN=center ROWSPAN=3 NOWRAP bgcolor=#F2DDB7><font COLOR=#996600>\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</font>\\(<br><input type=\"checkbox\" name=\"diary_id\" value=\"[0-9]+\">\\|\\)</td>
1213 <td bgcolor=\"#FFF4E0\"> <a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">\\(.*\\)</a></td>
1216 <td ALIGN=center BGCOLOR=#FFFFFF>
1217 <table BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH=410>
1229 (defun mixi-get-diaries (&rest friend-or-range)
1230 "Get diaries of FRIEND."
1231 (when (> (length friend-or-range) 2)
1232 (signal 'wrong-number-of-arguments
1233 (list 'mixi-get-diaries (length friend-or-range))))
1234 (let ((friend (nth 0 friend-or-range))
1235 (range (nth 1 friend-or-range)))
1236 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1237 (setq friend (nth 1 friend-or-range))
1238 (setq range (nth 0 friend-or-range)))
1239 (unless (or (null friend) (mixi-friend-p friend))
1240 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1241 (let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
1242 mixi-diary-list-regexp
1244 (year (nth 5 (decode-time (current-time))))
1245 (month (nth 4 (decode-time (current-time)))))
1246 (mapcar (lambda (item)
1247 (let ((month-of-item (string-to-number (nth 0 item))))
1248 (when (> month-of-item month)
1250 (setq month month-of-item)
1251 (mixi-make-diary friend (nth 5 item)
1253 0 (string-to-number (nth 3 item))
1254 (string-to-number (nth 2 item))
1255 (string-to-number (nth 1 item))
1257 (nth 6 item) (nth 7 item))))
1260 (defmacro mixi-new-diary-list-page ()
1261 `(concat "/new_friend_diary.pl?page=%d"))
1263 (defconst mixi-new-diary-list-regexp
1264 "<td WIDTH=180><img src=http://img\\.mixi\\.jp/img/pen\\.gif ALIGN=left WIDTH=14 HEIGHT=16>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>
1265 <td WIDTH=450><a class=\"new_link\" href=view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)>\\(.+\\)</a> (\\(.*\\)) ")
1267 (defun mixi-get-new-diaries (&optional range)
1269 (let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
1270 mixi-new-diary-list-regexp
1272 (mapcar (lambda (item)
1273 (mixi-make-diary (mixi-make-friend (nth 6 item) (nth 8 item))
1276 0 (string-to-number (nth 4 item))
1277 (string-to-number (nth 3 item))
1278 (string-to-number (nth 2 item))
1279 (string-to-number (nth 1 item))
1280 (string-to-number (nth 0 item)))
1284 (defmacro mixi-search-diary-list-page (keyword)
1285 `(concat "/search_diary.pl?page=%d&submit=search&keyword="
1286 (mixi-url-encode-and-quote-percent-string ,keyword)))
1288 (defconst mixi-search-diary-list-regexp
1289 "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾ Á°</font></td>
1290 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.*\\)
1295 <td BGCOLOR=#FDF9F2><font COLOR=#996600>¥¿¥¤¥È¥ë</font></td>
1296 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>
1299 <td BGCOLOR=#FDF9F2><font COLOR=#996600>ËÜ Ê¸</font></td>
1300 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.*\\)</td></tr>
1304 <td NOWRAP BGCOLOR=#FDF9F2 WIDTH=80><font COLOR=#996600>ºîÀ®Æü»þ</font></td>
1305 <td BGCOLOR=#FFFFFF WIDTH=220>\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>
1306 <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>
1308 </td></tr></table>")
1310 (defun mixi-search-diaries (keyword &optional range)
1311 (let ((items (mixi-get-matched-items (mixi-search-diary-list-page keyword)
1312 mixi-search-diary-list-regexp
1314 (year (nth 5 (decode-time (current-time))))
1315 (month (nth 4 (decode-time (current-time)))))
1316 (mapcar (lambda (item)
1317 (let ((month-of-item (string-to-number (nth 3 item))))
1318 (when (> month-of-item month)
1320 (setq month month-of-item)
1321 (mixi-make-diary (mixi-make-friend (nth 8 item) (nth 0 item))
1324 0 (string-to-number (nth 6 item))
1325 (string-to-number (nth 5 item))
1326 (string-to-number (nth 4 item))
1332 (defmacro mixi-post-diary-page ()
1333 `(concat "/add_diary.pl"))
1335 (defconst mixi-post-key-regexp
1336 "<input type=\"?hidden\"? name=\"?post_key\"? value=\"\\([a-z0-9]+\\)\">")
1337 (defconst mixi-post-succeed-regexp
1338 "<b>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É½¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¾¯¡¹¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£</b>")
1340 ;; FIXME: Support photos.
1341 (defun mixi-post-diary (title content)
1343 (unless (stringp title)
1344 (signal 'wrong-type-argument (list 'stringp title)))
1345 (unless (stringp content)
1346 (signal 'wrong-type-argument (list 'stringp content)))
1347 (let ((fields `(("id" . ,(mixi-friend-id (mixi-make-me)))
1348 ("diary_title" . ,title)
1349 ("diary_body" . ,content)
1350 ("submit" . "main")))
1352 (with-mixi-post-form (mixi-post-diary-page) fields
1353 (if (string-match mixi-post-key-regexp buffer)
1354 (setq post-key (match-string 1 buffer))
1355 (mixi-post-error 'cannot-find-key)))
1356 (setq fields `(("post_key" . ,post-key)
1357 ("id" . ,(mixi-friend-id (mixi-make-me)))
1358 ("diary_title" . ,title)
1359 ("diary_body" . ,content)
1360 ("submit" . "confirm")))
1361 (with-mixi-post-form (mixi-post-diary-page) fields
1362 (unless (string-match mixi-post-succeed-regexp buffer)
1363 (mixi-post-error 'cannot-find-succeed)))))
1365 ;; Community object.
1366 (defvar mixi-community-cache (make-hash-table :test 'equal))
1367 (defun mixi-make-community (id &optional name birthday owner category members
1368 open-level authority description)
1369 "Return a community object."
1370 (mixi-make-cache id (cons 'mixi-community (vector nil id name birthday owner
1372 open-level authority
1374 mixi-community-cache))
1376 (defconst mixi-community-url-regexp
1377 "/view_community\\.pl\\?id=\\([0-9]+\\)")
1379 (defun mixi-make-community-from-url (url)
1380 "Return a community object from URL."
1381 (when (string-match mixi-community-url-regexp url)
1382 (let ((id (match-string 1 url)))
1383 (mixi-make-community id))))
1385 (defmacro mixi-community-p (community)
1386 `(eq (mixi-object-class ,community) 'mixi-community))
1388 (defmacro mixi-community-page (community)
1389 `(concat "/view_community.pl?id=" (mixi-community-id ,community)))
1391 ;; FIXME: Not community specific.
1392 (defconst mixi-community-nodata-regexp
1393 "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1394 (defconst mixi-community-name-regexp
1395 "<td WIDTH=345>\\(.*\\)</td></tr>")
1396 (defconst mixi-community-birthday-regexp
1397 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>³«ÀßÆü</font></td>
\r
1398 <td WIDTH=345>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
1399 ;; FIXME: Care when the owner has seceded.
1400 (defconst mixi-community-owner-regexp
1401 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>´ÉÍý¿Í</font></td>
\r
1403 <table style=\"width: 100%;\"><tr><td>
\r
1404 <a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\\(.*\\)</a>")
1405 (defconst mixi-community-category-regexp
1406 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥«¥Æ¥´¥ê</font></td>
\r
1407 <td WIDTH=345>\\([^<]+\\)</td>")
1408 (defconst mixi-community-members-regexp
1409 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥á¥ó¥Ð¡¼¿ô</font></td>
\r
1410 <td WIDTH=345>\\([0-9]+\\)¿Í</td></tr>")
1411 (defconst mixi-community-open-level-regexp
1412 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>»²²Ã¾ò·ï¤È<br>¸ø³«¥ì¥Ù¥ë</font></td>
\r
1413 <td WIDTH=345>\\(.+\\)</td></tr>")
1414 (defconst mixi-community-authority-regexp
1415 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>
\r
1416 <td WIDTH=345>\\(.+\\)</td></tr>")
1417 (defconst mixi-community-description-regexp
1418 "<td CLASS=h120 WIDTH=345>\\(.+\\)</td>")
1420 (defun mixi-realize-community (community)
1421 "Realize a COMMUNITY."
1422 ;; FIXME: Check a expiration of cache?
1423 (unless (mixi-object-realized-p community)
1424 (with-mixi-retrieve (mixi-community-page community)
1425 (if (string-match mixi-community-nodata-regexp buffer)
1426 ;; FIXME: Set all members?
1427 (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1428 (if (string-match mixi-community-name-regexp buffer)
1429 (mixi-community-set-name community (match-string 1 buffer))
1430 (mixi-realization-error 'cannot-find-name community))
1431 (if (string-match mixi-community-birthday-regexp buffer)
1432 (mixi-community-set-birthday
1434 (encode-time 0 0 0 (string-to-number (match-string 3 buffer))
1435 (string-to-number (match-string 2 buffer))
1436 (string-to-number (match-string 1 buffer))))
1437 (mixi-realization-error 'cannot-find-birthday community))
1438 (if (string-match mixi-community-owner-regexp buffer)
1439 (if (string= (match-string 1 buffer) "home.pl")
1440 (mixi-community-set-owner community (mixi-make-me))
1441 (mixi-community-set-owner
1442 community (mixi-make-friend (match-string 2 buffer)
1443 (match-string 3 buffer))))
1444 (mixi-realization-error 'cannot-find-owner community))
1445 (if (string-match mixi-community-category-regexp buffer)
1446 (mixi-community-set-category community (match-string 1 buffer))
1447 (mixi-realization-error 'cannot-find-category community))
1448 (if (string-match mixi-community-members-regexp buffer)
1449 (mixi-community-set-members
1450 community (string-to-number (match-string 1 buffer)))
1451 (mixi-realization-error 'cannot-find-members community))
1452 (if (string-match mixi-community-open-level-regexp buffer)
1453 (mixi-community-set-open-level community (match-string 1 buffer))
1454 (mixi-realization-error 'cannot-find-open-level community))
1455 (if (string-match mixi-community-authority-regexp buffer)
1456 (mixi-community-set-authority community (match-string 1 buffer))
1457 (mixi-realization-error 'cannot-find-authority community))
1458 (if (string-match mixi-community-description-regexp buffer)
1459 (mixi-community-set-description community (match-string 1 buffer))
1460 (mixi-realization-error 'cannot-find-description community))))
1461 (mixi-object-touch community)))
1463 (defun mixi-community-id (community)
1464 "Return the id of COMMUNITY."
1465 (unless (mixi-community-p community)
1466 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1467 (aref (cdr community) 1))
1469 (defun mixi-community-name (community)
1470 "Return the name of COMMUNITY."
1471 (unless (mixi-community-p community)
1472 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1473 (unless (aref (cdr community) 2)
1474 (mixi-realize-community community))
1475 (aref (cdr community) 2))
1477 (defun mixi-community-birthday (community)
1478 "Return the birthday of COMMUNITY."
1479 (unless (mixi-community-p community)
1480 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1481 (mixi-realize-community community)
1482 (aref (cdr community) 3))
1484 (defun mixi-community-owner (community)
1485 "Return the owner of COMMUNITY."
1486 (unless (mixi-community-p community)
1487 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1488 (mixi-realize-community community)
1489 (aref (cdr community) 4))
1491 (defun mixi-community-category (community)
1492 "Return the category of COMMUNITY."
1493 (unless (mixi-community-p community)
1494 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1495 (mixi-realize-community community)
1496 (aref (cdr community) 5))
1498 (defun mixi-community-members (community)
1499 "Return the members of COMMUNITY."
1500 (unless (mixi-community-p community)
1501 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1502 (mixi-realize-community community)
1503 (aref (cdr community) 6))
1505 (defun mixi-community-open-level (community)
1506 "Return the open-level of COMMUNITY."
1507 (unless (mixi-community-p community)
1508 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1509 (mixi-realize-community community)
1510 (aref (cdr community) 7))
1512 (defun mixi-community-authority (community)
1513 "Return the authority of COMMUNITY."
1514 (unless (mixi-community-p community)
1515 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1516 (mixi-realize-community community)
1517 (aref (cdr community) 8))
1519 (defun mixi-community-description (community)
1520 "Return the description of COMMUNITY."
1521 (unless (mixi-community-p community)
1522 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1523 (mixi-realize-community community)
1524 (aref (cdr community) 9))
1526 (defun mixi-community-set-name (community name)
1527 "Set the name of COMMUNITY."
1528 (unless (mixi-community-p community)
1529 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1530 (aset (cdr community) 2 name))
1532 (defun mixi-community-set-birthday (community birthday)
1533 "Set the birthday of COMMUNITY."
1534 (unless (mixi-community-p community)
1535 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1536 (aset (cdr community) 3 birthday))
1538 (defun mixi-community-set-owner (community owner)
1539 "Set the owner of COMMUNITY."
1540 (unless (mixi-community-p community)
1541 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1542 (unless (mixi-friend-p owner)
1543 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1544 (aset (cdr community) 4 owner))
1546 (defun mixi-community-set-category (community category)
1547 "Set the category of COMMUNITY."
1548 (unless (mixi-community-p community)
1549 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1550 (aset (cdr community) 5 category))
1552 (defun mixi-community-set-members (community members)
1553 "Set the name of COMMUNITY."
1554 (unless (mixi-community-p community)
1555 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1556 (aset (cdr community) 6 members))
1558 (defun mixi-community-set-open-level (community open-level)
1559 "Set the name of COMMUNITY."
1560 (unless (mixi-community-p community)
1561 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1562 (aset (cdr community) 7 open-level))
1564 (defun mixi-community-set-authority (community authority)
1565 "Set the name of COMMUNITY."
1566 (unless (mixi-community-p community)
1567 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1568 (aset (cdr community) 8 authority))
1570 (defun mixi-community-set-description (community description)
1571 "Set the name of COMMUNITY."
1572 (unless (mixi-community-p community)
1573 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1574 (aset (cdr community) 9 description))
1576 (defmacro mixi-community-list-page (&optional friend)
1577 `(concat "/list_community.pl?page=%d"
1578 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1580 (defconst mixi-community-list-id-regexp
1581 "<a href=view_community\\.pl\\?id=\\([0-9]+\\)")
1582 (defconst mixi-community-list-name-regexp
1583 "<td valign=middle>\\(.+\\)([0-9]+)</td>")
1585 (defun mixi-get-communities (&rest friend-or-range)
1586 "Get communities of FRIEND."
1587 (when (> (length friend-or-range) 2)
1588 (signal 'wrong-number-of-arguments
1589 (list 'mixi-get-communities (length friend-or-range))))
1590 (let ((friend (nth 0 friend-or-range))
1591 (range (nth 1 friend-or-range)))
1592 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1593 (setq friend (nth 1 friend-or-range))
1594 (setq range (nth 0 friend-or-range)))
1595 (unless (or (null friend) (mixi-friend-p friend))
1596 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1597 (let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
1598 mixi-community-list-id-regexp
1600 (names (mixi-get-matched-items (mixi-community-list-page friend)
1601 mixi-community-list-name-regexp
1605 (while (< index (length ids))
1606 (setq ret (cons (mixi-make-community (nth 0 (nth index ids))
1607 (nth 0 (nth index names))) ret))
1611 (defmacro mixi-search-community-list-page (keyword)
1612 `(concat "/search_community.pl?page=%d&&sort=date&type=com&submit=main"
1613 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
1616 (defconst mixi-search-community-list-regexp
1617 "<td WIDTH=90 VALIGN=top ROWSPAN=4 ALIGN=center background=http://img\\.mixi\\.jp/img/bg_line\\.gif><a href=\"view_community\\.pl\\?id=\\([0-9]+\\)\"><img SRC=\"http://img-c[0-9]+\\.mixi\\.jp/photo/comm/[^.]+\\.jpg\" VSPACE=3 border=0></a></td>
1618 <td NOWRAP WIDTH=90 BGCOLOR=#FDF9F2><font COLOR=#996600>¥³¥ß¥å¥Ë¥Æ¥£Ì¾</font></td>
1619 <td COLSPAN=2 WIDTH=370 BGCOLOR=#FFFFFF>\\([^<]+\\)</td></tr>")
1621 ;; FIXME: Support category.
1622 (defun mixi-search-communities (keyword &optional range)
1623 (let ((items (mixi-get-matched-items (mixi-search-community-list-page
1625 mixi-search-community-list-regexp
1627 (mapcar (lambda (item)
1628 (mixi-make-community (nth 0 item) (nth 1 item)))
1632 (defvar mixi-topic-cache (make-hash-table :test 'equal))
1633 (defun mixi-make-topic (community id &optional time title owner content)
1634 "Return a topic object."
1635 (mixi-make-cache (list (mixi-community-id community) id)
1636 (cons 'mixi-topic (vector nil community id time title owner
1640 (defconst mixi-topic-url-regexp
1641 "/view_bbs\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=[0-9]+\\)?&comm_id=\\([0-9]+\\)")
1643 (defun mixi-make-topic-from-url (url)
1644 "Return a topic object from URL."
1645 (when (string-match mixi-topic-url-regexp url)
1646 (let ((id (match-string 1 url))
1647 (community-id (match-string 3 url)))
1648 (mixi-make-topic (mixi-make-community community-id) id))))
1650 (defmacro mixi-topic-p (topic)
1651 `(eq (mixi-object-class ,topic) 'mixi-topic))
1653 (defmacro mixi-topic-page (topic)
1654 `(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
1655 "&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
1657 (defconst mixi-topic-community-regexp
1658 "<td width=\"595\" background=\"http://img\\.mixi\\.jp/img/bg_w\\.gif\"><b>\\[\\(.+\\)\\] ¥È¥Ô¥Ã¥¯</b></td>")
1659 (defconst mixi-topic-time-regexp
1660 "<td rowspan=\"3\" width=\"110\" bgcolor=\"#ffd8b0\" align=\"center\" valign=\"top\" nowrap>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</td>")
1661 (defconst mixi-topic-title-regexp
1662 "<td bgcolor=\"#fff4e0\"> \\([^<]+\\)</td>")
1663 (defconst mixi-topic-owner-regexp
1664 "<td bgcolor=\"#fdf9f2\"> <font color=\"#dfb479\"></font> <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)\\(¤µ¤ó\\)?</a>")
1665 (defconst mixi-topic-content-regexp
1666 "<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"><tr><td class=\"h120\"><table><tr>\\(<td width=\"130\" height=\"140\" align=\"center\" valign=\"middle\"><a href=\"javascript:void(0)\" onClick=\"MM_openBrWindow('show_bbs_picture\\.pl\\?id=[0-9]+&comm_id=[0-9]+&number=[0-9]+','pict','width=680,height=660,toolbar=no,scrollbars=yes,left=5,top=5')\"><img src=\"http://ic[0-9]+\\.mixi\\.jp/[^.]+\\.jpg\" border=\"0\"></a></td>\n\\)*</tr></table>\\(.+\\)</td></tr></table>")
1668 (defun mixi-realize-topic (topic)
1670 ;; FIXME: Check a expiration of cache?
1671 (unless (mixi-object-realized-p topic)
1672 (with-mixi-retrieve (mixi-topic-page topic)
1673 (if (string-match mixi-topic-community-regexp buffer)
1674 (mixi-community-set-name (mixi-topic-community topic)
1675 (match-string 1 buffer))
1676 (mixi-realization-error 'cannot-find-community topic))
1677 (if (string-match mixi-topic-time-regexp buffer)
1678 (mixi-topic-set-time
1679 topic (encode-time 0 (string-to-number (match-string 5 buffer))
1680 (string-to-number (match-string 4 buffer))
1681 (string-to-number (match-string 3 buffer))
1682 (string-to-number (match-string 2 buffer))
1683 (string-to-number (match-string 1 buffer))))
1684 (mixi-realization-error 'cannot-find-time topic))
1685 (if (string-match mixi-topic-title-regexp buffer)
1686 (mixi-topic-set-title topic (match-string 1 buffer))
1687 (mixi-realization-error 'cannot-find-title topic))
1688 (if (string-match mixi-topic-owner-regexp buffer)
1689 (mixi-topic-set-owner topic
1690 (mixi-make-friend (match-string 1 buffer)
1691 (match-string 2 buffer)))
1692 (mixi-realization-error 'cannot-find-owner topic))
1693 (if (string-match mixi-topic-content-regexp buffer)
1694 (mixi-topic-set-content topic (match-string 2 buffer))
1695 (mixi-realization-error 'cannot-find-content topic)))
1696 (mixi-object-touch topic)))
1698 (defun mixi-topic-community (topic)
1699 "Return the community of TOPIC."
1700 (unless (mixi-topic-p topic)
1701 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1702 (aref (cdr topic) 1))
1704 (defun mixi-topic-id (topic)
1705 "Return the id of TOPIC."
1706 (unless (mixi-topic-p topic)
1707 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1708 (aref (cdr topic) 2))
1710 (defun mixi-topic-time (topic)
1711 "Return the time of TOPIC."
1712 (unless (mixi-topic-p topic)
1713 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1714 (mixi-realize-topic topic)
1715 (aref (cdr topic) 3))
1717 (defun mixi-topic-title (topic)
1718 "Return the title of TOPIC."
1719 (unless (mixi-topic-p topic)
1720 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1721 (mixi-realize-topic topic)
1722 (aref (cdr topic) 4))
1724 (defun mixi-topic-owner (topic)
1725 "Return the owner of TOPIC."
1726 (unless (mixi-topic-p topic)
1727 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1728 (mixi-realize-topic topic)
1729 (aref (cdr topic) 5))
1731 (defun mixi-topic-content (topic)
1732 "Return the content of TOPIC."
1733 (unless (mixi-topic-p topic)
1734 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1735 (mixi-realize-topic topic)
1736 (aref (cdr topic) 6))
1738 (defun mixi-topic-set-time (topic time)
1739 "Set the time of TOPIC."
1740 (unless (mixi-topic-p topic)
1741 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1742 (aset (cdr topic) 3 time))
1744 (defun mixi-topic-set-title (topic title)
1745 "Set the title of TOPIC."
1746 (unless (mixi-topic-p topic)
1747 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1748 (aset (cdr topic) 4 title))
1750 (defun mixi-topic-set-owner (topic owner)
1751 "Set the owner of TOPIC."
1752 (unless (mixi-topic-p topic)
1753 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1754 (unless (mixi-friend-p owner)
1755 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1756 (aset (cdr topic) 5 owner))
1758 (defun mixi-topic-set-content (topic content)
1759 "Set the content of TOPIC."
1760 (unless (mixi-topic-p topic)
1761 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1762 (aset (cdr topic) 6 content))
1764 (defmacro mixi-post-topic-page (community)
1765 `(concat "/add_bbs.pl?id=" (mixi-community-id community)))
1767 ;; FIXME: Support photos.
1768 (defun mixi-post-topic (community title content)
1769 "Post a topic to COMMUNITY."
1770 (unless (mixi-community-p community)
1771 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1772 (unless (stringp title)
1773 (signal 'wrong-type-argument (list 'stringp title)))
1774 (unless (stringp content)
1775 (signal 'wrong-type-argument (list 'stringp content)))
1776 (let ((fields `(("bbs_title" . ,title)
1777 ("bbs_body" . ,content)
1778 ("submit" . "main")))
1780 (with-mixi-post-form (mixi-post-topic-page community) fields
1781 (if (string-match mixi-post-key-regexp buffer)
1782 (setq post-key (match-string 1 buffer))
1783 (mixi-post-error 'cannot-find-key community)))
1784 (setq fields `(("post_key" . ,post-key)
1785 ("bbs_title" . ,title)
1786 ("bbs_body" . ,content)
1787 ("submit" . "confirm")))
1788 (with-mixi-post-form (mixi-post-topic-page community) fields
1789 (unless (string-match mixi-post-succeed-regexp buffer)
1790 (mixi-post-error 'cannot-find-succeed community)))))
1793 (defvar mixi-event-cache (make-hash-table :test 'equal))
1794 (defun mixi-make-event (community id &optional time title owner date place
1795 detail limit members)
1796 "Return a event object."
1797 (mixi-make-cache (list (mixi-community-id community) id)
1798 (cons 'mixi-event (vector nil community id time title owner
1799 date place detail limit members))
1802 (defconst mixi-event-url-regexp
1803 "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=[0-9]+\\)?&comm_id=\\([0-9]+\\)")
1805 (defun mixi-make-event-from-url (url)
1806 "Return a event object from URL."
1807 (when (string-match mixi-event-url-regexp url)
1808 (let ((id (match-string 1 url))
1809 (community-id (match-string 3 url)))
1810 (mixi-make-event (mixi-make-community community-id) id))))
1812 (defmacro mixi-event-p (event)
1813 `(eq (mixi-object-class ,event) 'mixi-event))
1815 (defmacro mixi-event-page (event)
1816 `(concat "/view_event.pl?id=" (mixi-event-id ,event)
1817 "&comm_id=" (mixi-community-id (mixi-event-community ,event))))
1819 (defconst mixi-event-community-regexp
1820 "<td WIDTH=595 background=http://img\\.mixi\\.jp/img/bg_w\\.gif><b>\\[\\(.+\\)\\] ¥¤¥Ù¥ó¥È</b></td>")
1821 (defconst mixi-event-time-regexp
1822 "<td ROWSPAN=11 \\(BGCOLOR\\|bgcolor\\)=#FFD8B0 \\(ALIGN\\|align\\)=center \\(VALIGN\\|Valign\\)=top WIDTH=110>
1823 ?\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
1824 ?\\([0-9]+\\):\\([0-9]+\\)</td>")
1825 (defconst mixi-event-title-regexp
1826 "<td bgcolor=#FFF4E0\\( width=410\\)?> \\([^<]+\\)</td>")
1827 (defconst mixi-event-owner-regexp
1828 "<td \\(BGCOLOR\\|bgcolor\\)=#FDF9F2> <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>")
1829 (defconst mixi-event-owner-seceded-regexp
1830 "<td \\(BGCOLOR\\|bgcolor\\)=#FDF9F2> \\((mixi Âà²ñºÑ)\\)")
1831 (defconst mixi-event-date-regexp
1832 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>³«ºÅÆü»þ</td>
1833 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
1836 (defconst mixi-event-place-regexp
1837 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>³«ºÅ¾ì½ê</td>
1838 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
1841 (defconst mixi-event-detail-regexp
1842 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>¾ÜºÙ</td>
1843 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)><table BORDER=0 CELLSPACING=0 CELLPADDING=5><tr><td CLASS=h120>\\(.+\\)</td></tr></table></td>")
1844 (defconst mixi-event-limit-regexp
1845 "<td \\(BGCOLOR\\|bgcolor\\)=\"?#\\(FFFFFF\\|ffffff\\)\"? \\(ALIGN\\|align\\)=\"?center\"? NOWRAP>Ê罸´ü¸Â</td>
1846 ?<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)> \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
1847 (defconst mixi-event-members-regexp
1848 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>»²²Ã¼Ô</td>
1849 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
1852 ?<table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>
1855 ?<td> \\(.+\\)</td>")
1857 (defun mixi-realize-event (event)
1859 ;; FIXME: Check a expiration of cache?
1860 (unless (mixi-object-realized-p event)
1861 (with-mixi-retrieve (mixi-event-page event)
1862 (if (string-match mixi-event-community-regexp buffer)
1863 (mixi-community-set-name (mixi-event-community event)
1864 (match-string 1 buffer))
1865 (mixi-realization-error 'cannot-find-community event))
1866 (if (string-match mixi-event-time-regexp buffer)
1867 (mixi-event-set-time
1868 event (encode-time 0 (string-to-number (match-string 8 buffer))
1869 (string-to-number (match-string 7 buffer))
1870 (string-to-number (match-string 6 buffer))
1871 (string-to-number (match-string 5 buffer))
1872 (string-to-number (match-string 4 buffer))))
1873 (mixi-realization-error 'cannot-find-time event))
1874 (if (string-match mixi-event-title-regexp buffer)
1875 (mixi-event-set-title event (match-string 2 buffer))
1876 (mixi-realization-error 'cannot-find-title event))
1877 (if (string-match mixi-event-owner-regexp buffer)
1878 (mixi-event-set-owner event
1879 (mixi-make-friend (match-string 2 buffer)
1880 (match-string 3 buffer)))
1881 (if (string-match mixi-event-owner-seceded-regexp buffer)
1882 (mixi-event-set-owner event
1883 (mixi-make-friend nil
1884 (match-string 2 buffer)))
1885 (mixi-realization-error 'cannot-find-owner event)))
1886 (if (string-match mixi-event-date-regexp buffer)
1887 (mixi-event-set-date event (match-string 6 buffer))
1888 (mixi-realization-error 'cannot-find-date event))
1889 (if (string-match mixi-event-place-regexp buffer)
1890 (mixi-event-set-place event (match-string 6 buffer))
1891 (mixi-realization-error 'cannot-find-place event))
1892 (if (string-match mixi-event-detail-regexp buffer)
1893 (mixi-event-set-detail event (match-string 6 buffer))
1894 (mixi-realization-error 'cannot-find-detail event))
1895 (when (string-match mixi-event-limit-regexp buffer)
1896 (mixi-event-set-limit
1897 event (encode-time 0 0 0 (string-to-number (match-string 8 buffer))
1898 (string-to-number (match-string 7 buffer))
1899 (string-to-number (match-string 6 buffer)))))
1900 (if (string-match mixi-event-members-regexp buffer)
1901 (mixi-event-set-members event (match-string 6 buffer))
1902 (mixi-realization-error 'cannot-find-members event)))
1903 (mixi-object-touch event)))
1905 (defun mixi-event-community (event)
1906 "Return the community of EVENT."
1907 (unless (mixi-event-p event)
1908 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1909 (aref (cdr event) 1))
1911 (defun mixi-event-id (event)
1912 "Return the id of EVENT."
1913 (unless (mixi-event-p event)
1914 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1915 (aref (cdr event) 2))
1917 (defun mixi-event-time (event)
1918 "Return the time of EVENT."
1919 (unless (mixi-event-p event)
1920 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1921 (mixi-realize-event event)
1922 (aref (cdr event) 3))
1924 (defun mixi-event-title (event)
1925 "Return the title of EVENT."
1926 (unless (mixi-event-p event)
1927 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1928 (mixi-realize-event event)
1929 (aref (cdr event) 4))
1931 (defun mixi-event-owner (event)
1932 "Return the owner of EVENT."
1933 (unless (mixi-event-p event)
1934 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1935 (mixi-realize-event event)
1936 (aref (cdr event) 5))
1938 (defun mixi-event-date (event)
1939 "Return the date of EVENT."
1940 (unless (mixi-event-p event)
1941 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1942 (mixi-realize-event event)
1943 (aref (cdr event) 6))
1945 (defun mixi-event-place (event)
1946 "Return the place of EVENT."
1947 (unless (mixi-event-p event)
1948 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1949 (mixi-realize-event event)
1950 (aref (cdr event) 7))
1952 (defun mixi-event-detail (event)
1953 "Return the detail of EVENT."
1954 (unless (mixi-event-p event)
1955 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1956 (mixi-realize-event event)
1957 (aref (cdr event) 8))
1959 (defun mixi-event-limit (event)
1960 "Return the limit of EVENT."
1961 (unless (mixi-event-p event)
1962 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1963 (mixi-realize-event event)
1964 (aref (cdr event) 9))
1966 (defun mixi-event-members (event)
1967 "Return the members of EVENT."
1968 (unless (mixi-event-p event)
1969 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1970 (mixi-realize-event event)
1971 (aref (cdr event) 10))
1973 (defun mixi-event-set-time (event time)
1974 "Set the time of EVENT."
1975 (unless (mixi-event-p event)
1976 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1977 (aset (cdr event) 3 time))
1979 (defun mixi-event-set-title (event title)
1980 "Set the title of EVENT."
1981 (unless (mixi-event-p event)
1982 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1983 (aset (cdr event) 4 title))
1985 (defun mixi-event-set-owner (event owner)
1986 "Set the owner of EVENT."
1987 (unless (mixi-event-p event)
1988 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1989 (unless (mixi-friend-p owner)
1990 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1991 (aset (cdr event) 5 owner))
1993 (defun mixi-event-set-date (event date)
1994 "Set the date of EVENT."
1995 (unless (mixi-event-p event)
1996 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1997 (aset (cdr event) 6 date))
1999 (defun mixi-event-set-place (event place)
2000 "Set the place of EVENT."
2001 (unless (mixi-event-p event)
2002 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2003 (aset (cdr event) 7 place))
2005 (defun mixi-event-set-detail (event detail)
2006 "Set the detail of EVENT."
2007 (unless (mixi-event-p event)
2008 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2009 (aset (cdr event) 8 detail))
2011 (defun mixi-event-set-limit (event limit)
2012 "Set the limit of EVENT."
2013 (unless (mixi-event-p event)
2014 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2015 (aset (cdr event) 9 limit))
2017 (defun mixi-event-set-members (event members)
2018 "Set the members of EVENT."
2019 (unless (mixi-event-p event)
2020 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2021 (aset (cdr event) 10 members))
2024 (defconst mixi-bbs-list '(mixi-topic mixi-event))
2026 (defmacro mixi-bbs-p (object)
2027 `(when (memq (mixi-object-class ,object) mixi-bbs-list)
2030 (defun mixi-bbs-community (object)
2031 "Return the community of OBJECT."
2032 (unless (mixi-bbs-p object)
2033 (signal 'wrong-type-argument (list 'mixi-bbs-p object)))
2034 (let ((func (intern (concat mixi-object-prefix
2035 (mixi-object-name object) "-community"))))
2036 (funcall func object)))
2038 (defalias 'mixi-bbs-id 'mixi-object-id)
2039 (defalias 'mixi-bbs-time 'mixi-object-time)
2040 (defalias 'mixi-bbs-title 'mixi-object-title)
2041 (defalias 'mixi-bbs-owner 'mixi-object-owner)
2042 (defalias 'mixi-bbs-content 'mixi-object-content)
2044 (defmacro mixi-bbs-list-page (community)
2045 `(concat "/list_bbs.pl?page=%d"
2046 "&id=" (mixi-community-id ,community)))
2048 (defconst mixi-bbs-list-regexp
2049 "<a href=view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)")
2051 (defun mixi-get-bbses (community &optional range)
2052 "Get bbese of COMMUNITY."
2053 (unless (mixi-community-p community)
2054 (signal 'wrong-type-argument (list 'mixi-community-p community)))
2055 (let ((items (mixi-get-matched-items (mixi-bbs-list-page community)
2056 mixi-bbs-list-regexp
2058 (mapcar (lambda (item)
2059 (let ((name (nth 0 item)))
2060 (when (string= name "bbs")
2061 (setq name "topic"))
2062 (let ((func (intern (concat "mixi-make-" name))))
2063 (funcall func community (nth 1 item)))))
2066 (defmacro mixi-new-bbs-list-page ()
2067 `(concat "/new_bbs.pl?page=%d"))
2069 (defconst mixi-new-bbs-list-regexp
2070 "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=[0-9]+&comm_id=\\([0-9]+\\)\" class=\"new_link\">")
2072 (defun mixi-get-new-bbses (&optional range)
2074 (let ((items (mixi-get-matched-items (mixi-new-bbs-list-page)
2075 mixi-new-bbs-list-regexp
2077 (mapcar (lambda (item)
2078 (let ((name (nth 0 item)))
2079 (when (string= name "bbs")
2080 (setq name "topic"))
2081 (let ((func (intern (concat "mixi-make-" name))))
2082 (funcall func (mixi-make-community (nth 2 item))
2086 (defmacro mixi-search-bbs-list-page (keyword)
2087 `(concat "/search_topic.pl?page=%d&type=top&submit=search"
2088 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
2089 "&community_id=0&category_id=0"))
2091 (defconst mixi-search-bbs-list-regexp
2092 "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\"><img src=http://img\\.mixi\\.jp/img/shbtn\\.gif ALT=¾ÜºÙ¤ò¸«¤ë BORDER=0 WIDTH=104 HEIGHT=19></a>")
2094 ;; FIXME: Support community and category.
2095 (defun mixi-search-bbses (keyword &optional range)
2096 (let ((items (mixi-get-matched-items (mixi-search-bbs-list-page keyword)
2097 mixi-search-bbs-list-regexp
2099 (mapcar (lambda (item)
2100 (let ((name (nth 0 item)))
2101 (when (string= name "bbs")
2102 (setq name "topic"))
2103 (let ((func (intern (concat "mixi-make-" name))))
2104 (funcall func (mixi-make-community (nth 2 item))
2109 (defun mixi-make-comment (parent owner time content)
2110 "Return a comment object."
2111 (cons 'mixi-comment (vector parent owner time content)))
2113 (defmacro mixi-comment-p (comment)
2114 `(eq (mixi-object-class ,comment) 'mixi-comment))
2116 (defun mixi-comment-parent (comment)
2117 "Return the parent of COMMENT."
2118 (unless (mixi-comment-p comment)
2119 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2120 (aref (cdr comment) 0))
2122 (defun mixi-comment-owner (comment)
2123 "Return the owner of COMMENT."
2124 (unless (mixi-comment-p comment)
2125 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2126 (aref (cdr comment) 1))
2128 (defun mixi-comment-time (comment)
2129 "Return the time of COMMENT."
2130 (unless (mixi-comment-p comment)
2131 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2132 (aref (cdr comment) 2))
2134 (defun mixi-comment-content (comment)
2135 "Return the content of COMMENT."
2136 (unless (mixi-comment-p comment)
2137 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2138 (aref (cdr comment) 3))
2140 (defun mixi-diary-comment-list-page (diary)
2141 (concat "/view_diary.pl?full=1"
2142 "&id=" (mixi-diary-id diary)
2143 "&owner_id=" (mixi-friend-id (mixi-diary-owner diary))))
2145 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2146 (defconst mixi-diary-comment-list-regexp
2147 "<td rowspan=\"2\" align=\"center\" width=\"95\" bgcolor=\"#f2ddb7\" nowrap>
2148 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)\\(<br>
2149 <input type=checkbox name=comment_id value=\".+\">
2152 <td ALIGN=center BGCOLOR=#FDF9F2 WIDTH=430>
2153 <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"410\">
2156 <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2158 \\(<font color=\"#f2ddb7\">|</font> <a href=[^>]+>ºï½ü</a>
2165 <!-- [^ ]+ : start -->
2167 <td bgcolor=\"#ffffff\">
2168 <table BORDER=0 CELLSPACING=0 CELLPADDING=[35] WIDTH=410>
2172 </td></tr></table>")
2174 (defun mixi-topic-comment-list-page (topic)
2175 (concat "/view_bbs.pl?page=all"
2176 "&id=" (mixi-topic-id topic)
2177 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2179 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2180 (defconst mixi-topic-comment-list-regexp
2181 "<tr valign=\"top\">
2182 <td rowspan=\"2\" width=\"110\" bgcolor=\"#f2ddb7\" align=\"center\" nowrap>
2183 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
2184 \\([0-9]+\\):\\([0-9]+\\)<br>
2185 \\(<input type=\"checkbox\" name=\"comment_id\" value=\".+\">
2187 <td bgcolor=\"#fdf9f2\"> <font color=\"#f8a448\">
2188 <b>[^<]+</b>:</font>
2190 \\|\\) *<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2194 \\|<font color=\"#f2ddb7\">| </font><a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+\">ºï½ü</a>
2198 <td bgcolor=\"#ffffff\" align=\"center\">
2199 <table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" width=\"500\">
2210 (defun mixi-event-comment-list-page (event)
2211 (concat "/view_event.pl?page=all"
2212 "&id=" (mixi-event-id event)
2213 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2215 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2216 (defconst mixi-event-comment-list-regexp
2218 <td ROWSPAN=2 ALIGN=center BGCOLOR=#F2DDB7 WIDTH=110>
2219 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
2220 \\([0-9]+\\):\\([0-9]+\\)<br>
2222 \\(<td BGCOLOR=#FDF9F2>\\)
2223 <font COLOR=#F8A448><b>[^<]+</b> :</font>
2224 <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2226 \\(<font COLOR=#F2DDB7>|</font>
2227 <a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+&type=event\">ºï½ü</a>
2232 <td ALIGN=center BGCOLOR=#FFFFFF>
2233 <table BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=500>
2234 <tr><td CLASS=h120>\\(.+\\)</td></tr>
2239 (defun mixi-get-comments (parent &optional range)
2240 "Get comments of PARENT."
2241 (unless (mixi-object-p parent)
2242 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
2243 (let* ((name (mixi-object-name parent))
2244 (list-page (intern (concat mixi-object-prefix name
2245 "-comment-list-page")))
2246 (regexp (eval (intern (concat mixi-object-prefix name
2247 "-comment-list-regexp")))))
2248 (let ((items (mixi-get-matched-items
2249 (funcall list-page parent) regexp)))
2252 (mapc (lambda (item)
2253 (when (and (numberp range)
2254 (>= (length list) range))
2256 (setq list (cons item list)))
2258 (setq items (reverse list)))
2259 (mapcar (lambda (item)
2260 (mixi-make-comment parent (mixi-make-friend
2261 (nth 7 item) (nth 8 item))
2264 (string-to-number (nth 4 item))
2265 (string-to-number (nth 3 item))
2266 (string-to-number (nth 2 item))
2267 (string-to-number (nth 1 item))
2268 (string-to-number (nth 0 item)))
2272 (defmacro mixi-new-comment-list-page ()
2273 `(concat "/new_comment.pl?page=%d"))
2275 (defconst mixi-new-comment-list-regexp
2276 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=[0-9]+\" class=\"new_link\">")
2278 (defun mixi-get-new-comments (&optional range)
2280 (let ((items (mixi-get-matched-items (mixi-new-comment-list-page)
2281 mixi-new-comment-list-regexp
2283 (mapcar (lambda (item)
2284 (mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
2287 (defun mixi-post-diary-comment-page (diary)
2288 (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
2290 (defun mixi-post-topic-comment-page (topic)
2291 (concat "/add_bbs_comment.pl?id=" (mixi-topic-id topic)
2292 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2294 (defun mixi-post-event-comment-page (event)
2295 (concat "/add_event_comment.pl?id=" (mixi-event-id event)
2296 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2298 ;; FIXME: Support photos.
2299 (defun mixi-post-comment (parent content)
2300 "Post a comment to PARENT."
2301 (unless (mixi-object-p parent)
2302 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
2303 (unless (stringp content)
2304 (signal 'wrong-type-argument (list 'stringp content)))
2305 (let* ((name (mixi-object-name parent))
2306 (page (intern (concat mixi-object-prefix "post-" name
2309 (if (mixi-diary-p parent)
2311 `(("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2312 ("comment_body" . ,content)))
2313 (setq fields `(("comment" . ,content))))
2314 (with-mixi-post-form (funcall page parent) fields
2315 (if (string-match mixi-post-key-regexp buffer)
2316 (setq post-key (match-string 1 buffer))
2317 (mixi-post-error 'cannot-find-key parent)))
2318 (if (mixi-diary-p parent)
2320 `(("post_key" . ,post-key)
2321 ("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2322 ("comment_body" . ,content)
2323 ("submit" . "confirm")))
2324 (setq fields `(("post_key" . ,post-key)
2325 ("comment" . ,content)
2326 ("submit" . "confirm"))))
2327 (with-mixi-post-form (funcall page parent) fields
2328 (unless (string-match mixi-post-succeed-regexp buffer)
2329 (mixi-post-error 'cannot-find-succeed parent)))))
2332 (defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
2334 (defmacro mixi-message-box-p (box)
2335 `(when (memq ,box mixi-message-box-list)
2338 (defun mixi-message-box-name (box)
2339 "Return the name of BOX."
2340 (unless (mixi-message-box-p box)
2341 (signal 'wrong-type-argument (list 'mixi-message-box-p box)))
2344 (defvar mixi-message-cache (make-hash-table :test 'equal))
2345 (defun mixi-make-message (id box &optional owner title time content)
2346 "Return a message object."
2347 (mixi-make-cache (list id box)
2348 (cons 'mixi-message (vector nil id box owner title time
2350 mixi-message-cache))
2352 (defconst mixi-message-url-regexp
2353 "/view_message\\.pl\\?id=\\([a-z0-9]+\\)&box=\\([a-z]+\\)")
2355 (defun mixi-make-message-from-url (url)
2356 "Return a message object from URL."
2357 (when (string-match mixi-message-url-regexp url)
2358 (let ((id (match-string 1 url))
2359 (box (match-string 2 url)))
2360 (mixi-make-message id box))))
2362 (defmacro mixi-message-p (message)
2363 `(eq (mixi-object-class ,message) 'mixi-message))
2365 (defmacro mixi-message-page (message)
2366 `(concat "/view_message.pl?id=" (mixi-message-id ,message)
2367 "&box=" (mixi-message-box ,message)))
2369 (defconst mixi-message-owner-regexp
2370 "<font COLOR=#996600>\\(º¹½Ð¿Í\\|°¸ Àè\\)</font> : <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)\\(</a>\\|</td>\\)")
2371 (defconst mixi-message-title-regexp
2372 "<font COLOR=#996600>·ï\\(¡¡\\| \\)̾</font> : \\(.+\\)\n?</td>")
2373 (defconst mixi-message-time-regexp
2374 "<font COLOR=#996600>Æü\\(¡¡\\| \\)ÉÕ</font> : \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ ")
2375 (defconst mixi-message-content-regexp
2376 "<tr><td CLASS=h120>\\(.+\\)</td></tr>")
2378 (defun mixi-realize-message (message)
2379 "Realize a MESSAGE."
2380 (unless (mixi-object-realized-p message)
2381 (with-mixi-retrieve (mixi-message-page message)
2382 (if (string-match mixi-message-owner-regexp buffer)
2383 (mixi-message-set-owner message
2384 (mixi-make-friend (match-string 2 buffer)
2385 (match-string 3 buffer)))
2386 (mixi-realization-error 'cannot-find-owner message))
2387 (if (string-match mixi-message-title-regexp buffer)
2388 (mixi-message-set-title message (match-string 2 buffer))
2389 (mixi-realization-error 'cannot-find-title message))
2390 (if (string-match mixi-message-time-regexp buffer)
2391 (mixi-message-set-time
2392 message (encode-time 0 (string-to-number (match-string 6 buffer))
2393 (string-to-number (match-string 5 buffer))
2394 (string-to-number (match-string 4 buffer))
2395 (string-to-number (match-string 3 buffer))
2396 (string-to-number (match-string 2 buffer))))
2397 (mixi-realization-error 'cannot-find-time message))
2398 (if (string-match mixi-message-content-regexp buffer)
2399 (mixi-message-set-content message (match-string 1 buffer))
2400 (mixi-realization-error 'cannot-find-content message)))
2401 (mixi-object-touch message)))
2403 (defun mixi-message-id (message)
2404 "Return the id of MESSAGE."
2405 (unless (mixi-message-p message)
2406 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2407 (aref (cdr message) 1))
2409 (defun mixi-message-box (message)
2410 "Return the box of MESSAGE."
2411 (unless (mixi-message-p message)
2412 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2413 (aref (cdr message) 2))
2415 (defun mixi-message-owner (message)
2416 "Return the owner of MESSAGE."
2417 (unless (mixi-message-p message)
2418 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2419 (mixi-realize-message message)
2420 (aref (cdr message) 3))
2422 (defun mixi-message-title (message)
2423 "Return the title of MESSAGE."
2424 (unless (mixi-message-p message)
2425 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2426 (mixi-realize-message message)
2427 (aref (cdr message) 4))
2429 (defun mixi-message-time (message)
2430 "Return the date of MESSAGE."
2431 (unless (mixi-message-p message)
2432 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2433 (mixi-realize-message message)
2434 (aref (cdr message) 5))
2436 (defun mixi-message-content (message)
2437 "Return the content of MESSAGE."
2438 (unless (mixi-message-p message)
2439 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2440 (mixi-realize-message message)
2441 (aref (cdr message) 6))
2443 (defun mixi-message-set-owner (message owner)
2444 "Set the owner of MESSAGE."
2445 (unless (mixi-message-p message)
2446 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2447 (aset (cdr message) 3 owner))
2449 (defun mixi-message-set-title (message title)
2450 "Set the title of MESSAGE."
2451 (unless (mixi-message-p message)
2452 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2453 (aset (cdr message) 4 title))
2455 (defun mixi-message-set-time (message time)
2456 "Set the date of MESSAGE."
2457 (unless (mixi-message-p message)
2458 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2459 (aset (cdr message) 5 time))
2461 (defun mixi-message-set-content (message content)
2462 "Set the content of MESSAGE."
2463 (unless (mixi-message-p message)
2464 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2465 (aset (cdr message) 6 content))
2467 (defmacro mixi-message-list-page (&optional box)
2468 `(concat "/list_message.pl?page=%d"
2469 (when ,box (concat "&box=" ,box))))
2471 (defconst mixi-message-list-regexp
2472 "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
2474 (defun mixi-get-messages (&rest box-or-range)
2475 "Get messages of BOX."
2476 (when (> (length box-or-range) 2)
2477 (signal 'wrong-number-of-arguments
2478 (list 'mixi-get-messages (length box-or-range))))
2479 (let ((box (nth 0 box-or-range))
2480 (range (nth 1 box-or-range)))
2481 (when (or (not (mixi-message-box-p box))
2482 (mixi-message-box-p range))
2483 (setq box (nth 1 box-or-range))
2484 (setq range (nth 0 box-or-range)))
2485 (let ((items (mixi-get-matched-items
2486 (mixi-message-list-page
2487 (when box (mixi-message-box-name box)))
2488 mixi-message-list-regexp
2490 (mapcar (lambda (item)
2491 (mixi-make-message (nth 0 item) (nth 1 item)))
2494 (defmacro mixi-post-message-page (friend)
2495 `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
2497 (defconst mixi-post-message-key-regexp
2498 "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
2500 (defconst mixi-post-message-succeed-regexp
2501 "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
2503 (defun mixi-post-message (friend title content)
2504 "Post a message to FRIEND."
2505 (unless (mixi-friend-p friend)
2506 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2507 (unless (stringp title)
2508 (signal 'wrong-type-argument (list 'stringp title)))
2509 (unless (stringp content)
2510 (signal 'wrong-type-argument (list 'stringp content)))
2511 (let ((fields `(("subject" . ,title)
2513 ("submit" . "main")))
2515 (with-mixi-post-form (mixi-post-message-page friend) fields
2516 (if (string-match mixi-post-message-key-regexp buffer)
2517 (setq post-key (match-string 1 buffer))
2518 (mixi-post-error 'cannot-find-key friend)))
2519 (setq fields `(("post_key" . ,post-key)
2520 ("subject" . ,title)
2522 ("yes" . "¡¡Á÷¡¡¿®¡¡")
2523 ("submit" . "confirm")))
2524 (with-mixi-post-form (mixi-post-message-page friend) fields
2525 (unless (string-match mixi-post-message-succeed-regexp buffer)
2526 (mixi-post-error 'cannot-find-succeed friend)))))
2528 ;; Introduction object.
2529 (defun mixi-make-introduction (parent owner content)
2530 "Return a introduction object."
2531 (cons 'mixi-introduction (vector parent owner content)))
2533 (defmacro mixi-introduction-p (introduction)
2534 `(eq (mixi-object-class ,introduction) 'mixi-introduction))
2536 (defun mixi-introduction-parent (introduction)
2537 "Return the parent of INTRODUCTION."
2538 (unless (mixi-introduction-p introduction)
2539 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2540 (aref (cdr introduction) 0))
2542 (defun mixi-introduction-owner (introduction)
2543 "Return the owner of INTRODUCTION."
2544 (unless (mixi-introduction-p introduction)
2545 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2546 (aref (cdr introduction) 1))
2548 (defun mixi-introduction-content (introduction)
2549 "Return the content of INTRODUCTION."
2550 (unless (mixi-introduction-p introduction)
2551 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2552 (aref (cdr introduction) 3))
2554 (defmacro mixi-introduction-list-page (&optional friend)
2555 `(concat "/show_intro.pl?page=%d"
2556 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
2558 (defconst mixi-introduction-list-regexp
2559 "<tr bgcolor=#FFFFFF>
2560 <td WIDTH=150 background=http://img\\.mixi\\.jp/img/bg_line\\.gif align=\"center\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\"><img src=\".+\" border=0><br>
2567 \\(\\(.\\|\n<br>\\)+\\)\\|
2568 \\(\\(.\\|\n<br>\\)+\\)\\)
2575 (defconst mixi-my-introduction-list-regexp
2576 "<tr bgcolor=#FFFFFF>
2577 <td WIDTH=150 background=http://img\\.mixi\\.jp/img/bg_line\\.gif align=\"center\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\"><img src=\".+\" border=0><br>
2585 \\(\\(.\\|\n<br>\\)+\\)\\|
2586 \\(\\(.\\|\n<br>\\)+\\)\\)
2590 <a href=\"edit_intro\\.pl\\?id=\\1&type=edit\">¤³¤Îͧ¿Í¤ò¾Ò²ð¤¹¤ë</a>
2594 <a href=\"delete_intro\\.pl\\?id=\\1\">ºï½ü</a>
2599 (defun mixi-get-introductions (&rest friend-or-range)
2600 "Get introductions of FRIEND."
2601 (when (> (length friend-or-range) 2)
2602 (signal 'wrong-number-of-arguments
2603 (list 'mixi-get-introduction (length friend-or-range))))
2604 (let ((friend (nth 0 friend-or-range))
2605 (range (nth 1 friend-or-range)))
2606 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
2607 (setq friend (nth 1 friend-or-range))
2608 (setq range (nth 0 friend-or-range)))
2609 (unless (or (null friend) (mixi-friend-p friend))
2610 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2611 (let* ((regexp (if friend mixi-introduction-list-regexp
2612 mixi-my-introduction-list-regexp))
2613 (items (mixi-get-matched-items (mixi-introduction-list-page friend)
2616 (mapcar (lambda (item)
2617 (mixi-make-introduction (or friend (mixi-make-me))
2618 (mixi-make-friend (nth 0 item)
2624 (defvar mixi-news-cache (make-hash-table :test 'equal))
2625 (defun mixi-make-news (media-id id &optional time title content)
2626 "Return a news object."
2627 (mixi-make-cache (list media-id id)
2628 (cons 'mixi-news (vector nil media-id id time title
2632 (defconst mixi-news-url-regexp
2633 "/view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)")
2635 (defun mixi-make-news-from-url (url)
2636 "Return a news object from URL."
2637 (when (string-match mixi-news-url-regexp url)
2638 (let ((id (match-string 1 url))
2639 (media-id (match-string 2 url)))
2640 (mixi-make-news media-id id))))
2642 (defmacro mixi-news-p (news)
2643 `(eq (mixi-object-class ,news) 'mixi-news))
2645 (defmacro mixi-news-page (news)
2646 `(concat "http://news.mixi.jp/view_news.pl?id=" (mixi-news-id ,news)
2647 "&media_id=" (mixi-news-media-id ,news)))
2649 (defconst mixi-news-title-regexp
2650 "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)</td>")
2651 (defconst mixi-news-time-regexp
2652 "<td COLSPAN=\"2\" ALIGN=\"right\">(.+ - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))</td></tr>")
2653 (defconst mixi-news-content-regexp
2654 "<td CLASS=\"h150\">
2663 (defun mixi-realize-news (news)
2665 ;; FIXME: Check a expiration of cache?
2666 (unless (mixi-object-realized-p news)
2667 (with-mixi-retrieve (mixi-news-page news)
2668 (if (string-match mixi-news-title-regexp buffer)
2669 (mixi-news-set-title news (match-string 1 buffer))
2670 (mixi-realization-error 'cannot-find-title news))
2671 (if (string-match mixi-news-time-regexp buffer)
2672 (let ((year (nth 5 (decode-time (current-time))))
2673 (month (nth 4 (decode-time (current-time))))
2674 (month-of-item (string-to-number (match-string 1 buffer))))
2675 (when (> month-of-item month)
2678 news (encode-time 0 (string-to-number (match-string 4 buffer))
2679 (string-to-number (match-string 3 buffer))
2680 (string-to-number (match-string 2 buffer))
2682 (mixi-realization-error 'cannot-find-time news))
2683 (if (string-match mixi-news-content-regexp buffer)
2684 (mixi-news-set-content news (match-string 1 buffer))
2685 (mixi-realization-error 'cannot-find-content news)))
2686 (mixi-object-touch news)))
2688 (defun mixi-news-media-id (news)
2689 "Return the media-id of NEWS."
2690 (unless (mixi-news-p news)
2691 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2692 (aref (cdr news) 1))
2694 (defun mixi-news-id (news)
2695 "Return the id of NEWS."
2696 (unless (mixi-news-p news)
2697 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2698 (aref (cdr news) 2))
2700 (defun mixi-news-time (news)
2701 "Return the time of NEWS."
2702 (unless (mixi-news-p news)
2703 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2704 (unless (aref (cdr news) 3)
2705 (mixi-realize-news news))
2706 (aref (cdr news) 3))
2708 (defun mixi-news-title (news)
2709 "Return the title of NEWS."
2710 (unless (mixi-news-p news)
2711 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2712 (unless (aref (cdr news) 4)
2713 (mixi-realize-news news))
2714 (aref (cdr news) 4))
2716 (defun mixi-news-content (news)
2717 "Return the content of NEWS."
2718 (unless (mixi-news-p news)
2719 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2720 (mixi-realize-news news)
2721 (aref (cdr news) 5))
2723 (defun mixi-news-set-time (news time)
2724 "Set the time of NEWS."
2725 (unless (mixi-news-p news)
2726 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2727 (aset (cdr news) 3 time))
2729 (defun mixi-news-set-title (news title)
2730 "Set the title of NEWS."
2731 (unless (mixi-news-p news)
2732 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2733 (aset (cdr news) 4 title))
2735 (defun mixi-news-set-content (news content)
2736 "Set the content of NEWS."
2737 (unless (mixi-news-p news)
2738 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2739 (aset (cdr news) 5 content))
2741 (defconst mixi-news-category-list '(domestic politics economy area abroad
2742 sports entertainment IT))
2744 (defmacro mixi-news-category-p (category)
2745 `(when (memq ,category mixi-news-category-list)
2748 (defun mixi-news-category-id (category)
2749 "Return the id of CATEGORY."
2750 (unless (mixi-news-category-p category)
2751 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2753 (1+ (- (length mixi-news-category-list)
2754 (length (memq category mixi-news-category-list))))))
2756 (defmacro mixi-news-list-page (category)
2757 `(concat "http://news.mixi.jp/list_news_category.pl?page=%d&sort=1"
2758 (concat "&id=" (mixi-news-category-id category) "&type=bn")))
2760 (defconst mixi-news-list-regexp
2761 "<tr bgcolor=\"\\(#FCF5EB\\|#FFFFFF\\)\">
2762 <td WIDTH=\"1%\" valign=top CLASS=\"h120\">¡¦</td>
2763 <td WIDTH=\"97%\" CLASS=\"h120\"><A HREF=\"view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)\"class=\"new_link\">\\(.+\\)</A>
2764 \\(<IMG SRC=\"http://img\\.mixi\\.jp/img/news_camera3\\.gif\" WIDTH=\"11\" HEIGHT=\"12\">\\|\\)
2767 <td WIDTH=\"1%\" nowrap CLASS=\"f08\"><A HREF=\"list_news_media\\.pl\\?id=[0-9]+\">.+</A></td>
2768 <td WIDTH=\"1%\" nowrap CLASS=\"f08\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td></tr>")
2770 (defun mixi-get-news (category &optional range)
2771 "Get news of CATEGORY."
2772 (unless (mixi-news-category-p category)
2773 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2774 (let ((items (mixi-get-matched-items (mixi-news-list-page category)
2775 mixi-news-list-regexp
2777 (year (nth 5 (decode-time (current-time))))
2778 (month (nth 4 (decode-time (current-time)))))
2779 (mapcar (lambda (item)
2780 (let ((month-of-item (string-to-number (nth 5 item))))
2781 (when (> month-of-item month)
2783 (setq month month-of-item)
2784 (mixi-make-news (nth 2 item) (nth 1 item)
2786 0 (string-to-number (nth 8 item))
2787 (string-to-number (nth 7 item))
2788 (string-to-number (nth 6 item))
2795 ;;; mixi.el ends here