1 ;; mixi.el --- API libraries 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 ;; APIs 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
50 ;; * mixi-post-comment
51 ;; * mixi-post-message
55 ;; * mixi-remove-markup
59 ;; Display newest 3 diaries like a mail format.
62 ;; (buffer (get-buffer-create "*temp*"))
63 ;; (format "%Y/%m/%d %H:%M"))
64 ;; (pop-to-buffer buffer)
65 ;; (mapc (lambda (diary)
66 ;; (let ((subject (mixi-diary-title diary))
67 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
68 ;; (date (format-time-string format (mixi-diary-time diary)))
69 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
70 ;; (insert "From: " from "\n"
71 ;; "Subject: " subject "\n"
72 ;; "Date: " date "\n\n"
74 ;; (mixi-get-new-diaries range))
75 ;; (set-buffer-modified-p nil)
76 ;; (setq buffer-read-only t)
77 ;; (goto-char (point-min)))
79 ;; Display newest 3 diaries including newest 3 comments like a mail format.
80 ;; Comments are displayed like a reply mail.
83 ;; (buffer (get-buffer-create "*temp*"))
84 ;; (format "%Y/%m/%d %H:%M"))
85 ;; (pop-to-buffer buffer)
86 ;; (mapc (lambda (diary)
87 ;; (let ((subject (mixi-diary-title diary))
88 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
89 ;; (date (format-time-string format (mixi-diary-time diary)))
90 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
91 ;; (insert "From: " from "\n"
92 ;; "Subject: " subject "\n"
93 ;; "Date: " date "\n\n"
95 ;; (mapc (lambda (comment)
96 ;; (let ((from (mixi-friend-nick
97 ;; (mixi-comment-owner comment)))
98 ;; (subject (concat "Re: " subject))
99 ;; (date (format-time-string
100 ;; format (mixi-comment-time comment)))
101 ;; (body (mixi-remove-markup
102 ;; (mixi-comment-content comment))))
103 ;; (insert "From: " from "\n"
104 ;; "Subject: " subject "\n"
105 ;; "Date: " date "\n\n"
107 ;; (mixi-get-comments diary range))))
108 ;; (mixi-get-new-diaries range))
109 ;; (set-buffer-modified-p nil)
110 ;; (setq buffer-read-only t)
111 ;; (goto-char (point-min)))
115 ;; If you have bug reports and/or suggestions for improvement, please
116 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
120 (eval-when-compile (require 'cl))
122 ;; Functions and variables which should be defined in the other module
125 (defvar w3m-use-cookies)
126 (defvar url-request-method)
127 (defvar url-request-data)
128 (defvar url-request-extra-headers)
129 (defvar url-show-status)
130 (autoload 'w3m-decode-buffer "w3m")
131 (autoload 'w3m-retrieve "w3m")
132 (autoload 'url-retrieve-synchronously "url"))
135 "API library for accessing to mixi."
138 (defcustom mixi-url "http://mixi.jp"
143 (defcustom mixi-directory (expand-file-name "~/.mixi")
144 "*Where to look for mixi files."
148 (defcustom mixi-coding-system 'euc-jp
149 "*Coding system for mixi."
153 (defcustom mixi-curl-program "curl"
154 "*The program name of `curl'."
158 (defcustom mixi-curl-cookie-file (expand-file-name "cookies.txt"
160 "*The location of cookie file created by `curl'."
164 (defcustom mixi-backend
165 (or (condition-case nil
173 (if (fboundp 'url-retrieve-synchronously)
176 (if (and (fboundp 'executable-find)
177 (executable-find mixi-curl-program))
179 (error "Cannot set `mixi-backend'."))
180 "*The backend for accessing to mixi."
181 :type '(radio (const :tag "Use emacs-w3m" w3m)
182 (const :tag "Use url.el" url)
183 (const :tag "Use curl" curl)
184 (symbol :tag "The other backend"))
187 (defcustom mixi-login-use-ssl nil
188 "*If non-ni, login using SSL."
192 (defcustom mixi-default-email nil
193 "*Default E-mail address that is used to login automatically."
194 :type '(radio (string :tag "E-mail address")
195 (const :tag "Asked when it is necessary" nil))
198 (defcustom mixi-default-password nil
199 "*Default password that is used to login automatically."
200 :type '(radio (string :tag "Password")
201 (const :tag "Asked when it is necessary" nil))
204 (defcustom mixi-accept-adult-contents t
205 "*If non-nil, accept to access to the adult contents."
209 (defcustom mixi-continuously-access-interval 4.0
210 "*Time interval between each mixi access.
211 Increase this value when unexpected error frequently occurs."
215 (defcustom mixi-cache-expires nil
216 "*Seconds for expiration of a cached object."
217 :type '(radio (integer :tag "Expired seconds")
218 (const :tag "Don't expire" nil)
219 (const :tag "Don't cache" t))
222 ;; FIXME: Not implemented.
223 (defcustom mixi-cache-use-file t
224 "*If non-nil, caches are saved to files."
228 (defvar mixi-temp-buffer-name " *mixi temp*")
232 (defmacro mixi-message (&rest strings)
233 `(concat "[mixi] " ,@strings))
235 (put 'mixi-realization-error
236 'error-message (mixi-message "Cannot realize object"))
237 (put 'mixi-realization-error
238 'error-conditions '(mixi-realization-error error))
240 (put 'mixi-post-error
241 'error-message (mixi-message "Cannot post"))
242 (put 'mixi-post-error
243 'error-conditions '(mixi-post-error error))
245 (defmacro mixi-realization-error (type object)
246 `(let ((data (if debug-on-error
247 (list ,type ,object (buffer-string))
248 (list ,type ,object))))
249 (signal 'mixi-realization-error data)))
251 (defmacro mixi-post-error (type &optional object)
252 `(let ((data (when debug-on-error (list (buffer-string)))))
254 (setq data (cons ,type (cons ,object data)))
255 (setq data (cons ,type data)))
256 (signal 'mixi-post-error data)))
258 (defconst mixi-message-adult-contents
259 "¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
260 ±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
261 (defconst mixi-message-continuously-accessing
262 "°ÂÄꤷ¤Æ¥µ¥¤¥È¤Î±¿±Ä¤ò¤ª¤³¤Ê¤¦°Ù¡¢´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹<br>
263 ¿·¤ÏÀ©¸Â¤µ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤ª¤ê¤Þ¤¹¡£¤´ÌÂÏǤò¤ª¤«¤±¤¤¤¿¤·¤Þ¤¹¤¬¡¢¤·¤Ð¤é¤¯¤ª<br>
264 ÂÔ¤Á¤¤¤¿¤À¤¤¤Æ¤«¤éÁàºî¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£")
265 (defconst mixi-warning-continuously-accessing
266 "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«<br>
267 ¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ<br>
268 ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
270 (defmacro mixi-retrieve (url &optional post-data)
271 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-retrieve"))
274 (defmacro mixi-post-form (url fields)
275 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-post-form"))
278 (defun mixi-parse-buffer (url buffer &optional post-data)
279 (when (string-match mixi-message-adult-contents buffer)
280 (if mixi-accept-adult-contents
281 (setq buffer (mixi-retrieve url "submit=agree"))
282 (setq buffer (mixi-retrieve (concat url "?")))))
283 (when (string-match mixi-warning-continuously-accessing buffer)
284 (error (mixi-message "Access denied. Please wait a while and increase "
285 "the value of `mixi-continuously-access-interval'.")))
286 (if (not (string-match mixi-message-continuously-accessing buffer))
288 (message (mixi-message "Waiting for continuously accessing..."))
289 (sleep-for mixi-continuously-access-interval)
290 (mixi-retrieve url post-data)))
292 (defmacro mixi-expand-url (url)
293 `(if (string-match "^http" ,url)
295 (concat mixi-url ,url)))
297 ;; FIXME: Support files.
298 (defun mixi-make-form-data (fields)
299 "Make form data and return (CONTENT-TYPE . FORM-DATA)."
300 (let* ((boundary (apply 'format "--_%d_%d_%d" (current-time)))
301 (content-type (concat "multipart/form-data; boundary=" boundary))
305 (concat "--" boundary "\r\n"
306 "Content-Disposition: form-data; name=\""
309 (encode-coding-string (cdr field) mixi-coding-system)))
311 (cons content-type (concat form-data "\r\n--" boundary "--"))))
313 (defun mixi-url-retrieve (url &optional post-data extra-headers)
314 "Retrieve the URL and return gotten strings."
315 (let* ((url-request-method (if post-data "POST" "GET"))
316 (url-request-data post-data)
317 (url-request-extra-headers extra-headers)
318 (url (mixi-expand-url url))
320 (buffer (url-retrieve-synchronously url))
322 (unless (bufferp buffer)
323 (error (mixi-message "Cannot retrieve")))
324 (with-current-buffer buffer
325 (goto-char (point-min))
326 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
327 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
328 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
329 (error (mixi-message "Cannot retrieve")))
330 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
331 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
333 (mixi-parse-buffer url ret post-data))))
335 (defun mixi-url-post-form (url fields)
336 (let* ((form-data (mixi-make-form-data fields))
337 (extra-headers `(("Content-Type" . ,(car form-data)))))
338 (mixi-url-retrieve url (cdr form-data) extra-headers)))
340 (defun mixi-w3m-retrieve (url &optional post-data)
341 "Retrieve the URL and return gotten strings."
342 (let ((url (mixi-expand-url url)))
344 (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
345 (error (mixi-message "Cannot retrieve"))
346 (w3m-decode-buffer url)
347 (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
348 (mixi-parse-buffer url ret post-data))))))
350 (defun mixi-w3m-post-form (url fields)
351 (let ((form-data (mixi-make-form-data fields)))
352 (mixi-w3m-retrieve url form-data)))
354 (defun mixi-curl-retrieve (url &optional post-data form-data)
355 "Retrieve the URL and return gotten strings."
357 (if (fboundp 'set-buffer-multibyte)
358 (set-buffer-multibyte nil))
359 (let ((orig-mode (default-file-modes))
360 (coding-system-for-read 'binary)
361 (coding-system-for-write 'binary)
365 (set-default-file-modes 448)
367 (apply #'start-process "curl" (current-buffer)
369 (append (if post-data '("-d" "@-"))
372 "-b" mixi-curl-cookie-file
373 "-c" mixi-curl-cookie-file
374 (mixi-expand-url url)))))
375 (set-process-sentinel process #'ignore))
376 (set-default-file-modes orig-mode))
378 (process-send-string process (concat post-data "\n"))
379 (process-send-eof process))
380 (while (eq (process-status process) 'run)
381 (accept-process-output process 1))
382 (goto-char (point-min))
383 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
384 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
385 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
386 (error (mixi-message "Cannot retrieve")))
387 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
388 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
389 (mixi-parse-buffer url ret post-data))))
391 (defun mixi-curl-post-form (url fields)
393 (mapcar (lambda (field)
394 (push "-F" form-data)
395 (push (concat (car field) "="
396 (encode-coding-string (cdr field)
400 (mixi-curl-retrieve url nil (reverse form-data))))
402 (defconst mixi-my-id-regexp
403 "<a href=\"add_diary\\.pl\\?id=\\([0-9]+\\)")
405 (defun mixi-login (&optional email password)
407 (when (and (eq mixi-backend 'w3m) (not w3m-use-cookies))
408 (error (mixi-message "Require to accept cookies. Please set "
409 "`w3m-use-cookies' to t.")))
410 (let ((email (or email mixi-default-email
411 (read-from-minibuffer (mixi-message "Login Email: "))))
412 (password (or password mixi-default-password
413 (read-passwd (mixi-message "Login Password: ")))))
414 (let ((url "/login.pl"))
415 (when mixi-login-use-ssl
416 (setq url (concat "https://mixi.jp" url)))
417 (let ((buffer (mixi-retrieve url
418 (concat "email=" email
419 "&password=" password
422 (unless (string-match "url=/check\\.pl\\?n=" buffer)
423 (error (mixi-message "Cannot login")))
424 (setq buffer (mixi-retrieve "/check.pl?n=home.pl"))
425 (if (string-match mixi-my-id-regexp buffer)
426 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
427 (error (mixi-message "Cannot login")))))))
429 (defun mixi-logout ()
430 (mixi-retrieve "/logout.pl"))
432 (defmacro with-mixi-retrieve (url &rest body)
433 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
436 (insert (mixi-retrieve ,url))
437 (goto-char (point-min))
438 (when (search-forward
439 "<form action=\"login.pl\" method=\"post\">" nil t)
442 (insert (mixi-retrieve ,url))))
443 (goto-char (point-min))
445 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
446 (put 'with-mixi-retrieve 'edebug-form-spec '(body))
448 (defmacro with-mixi-post-form (url fields &rest body)
449 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
452 (insert (mixi-post-form ,url ,fields))
453 (goto-char (point-min))
454 (when (search-forward
455 "<form action=\"login.pl\" method=\"post\">" nil t)
458 (insert (mixi-post-form ,url ,fields))))
459 (goto-char (point-min))
461 (put 'with-mixi-post-form 'lisp-indent-function 'defun)
462 (put 'with-mixi-post-form 'edebug-form-spec '(body))
464 (defun mixi-get-matched-items (url regexp &optional range reverse)
465 "Get matched items to REGEXP in URL."
469 (while (or (null range) (< (length ids) range))
470 (with-mixi-retrieve (when url (format url page))
471 (let ((func (if reverse (progn
472 (goto-char (point-max))
476 (while (and (funcall func regexp nil t)
477 (or (null range) (< (length ids) range)))
480 (while (match-string num)
481 (setq list (cons (match-string num) list))
483 (when (not (member (reverse list) ids))
485 (setq ids (cons (reverse list) ids)))))
491 ;; stolen (and modified) from shimbun.el
492 (defun mixi-remove-markup (string)
493 "Remove markups from STRING."
495 (insert (or string ""))
497 (goto-char (point-min))
498 (while (search-forward "<!--" nil t)
499 (delete-region (match-beginning 0)
500 (or (search-forward "-->" nil t)
502 (goto-char (point-min))
503 (while (re-search-forward "<[^>]+>" nil t)
504 (replace-match "" t t))
505 (goto-char (point-min))
506 (while (re-search-forward "
\r" nil t)
507 (replace-match "\n" t t)))
508 ;; FIXME: Decode entities.
511 ;; stolen (and modified) from w3m.el
512 (defun mixi-url-encode-string (string)
513 (apply (function concat)
517 ((eq char ?\n) ; newline
519 ((string-match "[-a-zA-Z0-9_:/.]" (char-to-string char)) ; xxx?
520 (char-to-string char)) ; printable
521 ((char-equal char ?\x20) ; space
524 (format "%%%02x" char)))) ; escape
525 ;; Coerce a string into a list of chars.
526 (append (encode-coding-string (or string "") mixi-coding-system)
529 (defun mixi-url-encode-and-quote-percent-string (string)
530 (let ((string (mixi-url-encode-string string))
532 (while (string-match "%" string pos)
533 (setq string (replace-match "%%" nil nil string))
534 (setq pos (+ (match-end 0) 1)))
538 (defconst mixi-object-prefix "mixi-")
540 (defmacro mixi-object-class (object)
543 (defmacro mixi-object-p (object)
544 `(let ((class (mixi-object-class ,object)))
545 (when (symbolp class)
546 (eq (string-match (concat "^" mixi-object-prefix)
547 (symbol-name class)) 0))))
549 (defun mixi-object-name (object)
550 "Return the name of OBJECT."
551 (unless (mixi-object-p object)
552 (signal 'wrong-type-argument (list 'mixi-object-p object)))
553 (let ((class (mixi-object-class object)))
554 (substring (symbol-name class) (length mixi-object-prefix))))
556 (defun mixi-read-object (exp)
557 "Read one Lisp expression as mixi object."
558 (if (mixi-object-p exp)
559 (let ((func (intern (concat mixi-object-prefix "make-"
560 (mixi-object-name exp))))
561 (args (mapcar (lambda (arg)
562 (mixi-read-object arg))
564 (let ((object (apply func (cdr args))))
566 (mixi-object-set-timestamp object (car args)))
570 (defun mixi-object-timestamp (object)
571 "Return the timestamp of OJBECT."
572 (unless (mixi-object-p object)
573 (signal 'wrong-type-argument (list 'mixi-object-p object)))
574 (aref (cdr object) 0))
575 (defalias 'mixi-object-realized-p 'mixi-object-timestamp)
577 (defun mixi-object-owner (object)
578 "Return the owner of OBJECT."
579 (unless (mixi-object-p object)
580 (signal 'wrong-type-argument (list 'mixi-object-p object)))
581 (let ((func (intern (concat mixi-object-prefix
582 (mixi-object-name object) "-owner"))))
583 (funcall func object)))
585 (defun mixi-object-id (object)
586 "Return the id of OBJECT."
587 (unless (mixi-object-p object)
588 (signal 'wrong-type-argument (list 'mixi-object-p object)))
589 (let ((func (intern (concat mixi-object-prefix
590 (mixi-object-name object) "-id"))))
591 (funcall func object)))
593 (defun mixi-object-time (object)
594 "Return the time of OBJECT."
595 (unless (mixi-object-p object)
596 (signal 'wrong-type-argument (list 'mixi-object-p object)))
597 (let ((func (intern (concat mixi-object-prefix
598 (mixi-object-name object) "-time"))))
599 (funcall func object)))
601 (defun mixi-object-title (object)
602 "Return the title of OBJECT."
603 (unless (mixi-object-p object)
604 (signal 'wrong-type-argument (list 'mixi-object-p object)))
605 (let ((func (intern (concat mixi-object-prefix
606 (mixi-object-name object) "-title"))))
607 (funcall func object)))
609 (defun mixi-object-content (object)
610 "Return the content of OBJECT."
611 (unless (mixi-object-p object)
612 (signal 'wrong-type-argument (list 'mixi-object-p object)))
613 (let ((func (intern (concat mixi-object-prefix
614 (mixi-object-name object) "-content"))))
615 (funcall func object)))
617 (defun mixi-object-set-timestamp (object timestamp)
618 "Set the timestamp of OBJECT."
619 (unless (mixi-object-p object)
620 (signal 'wrong-type-argument (list 'mixi-object-p object)))
621 (aset (cdr object) 0 timestamp))
623 (defmacro mixi-object-touch (object)
624 `(mixi-object-set-timestamp ,object (current-time)))
626 (defconst mixi-object-url-regexp
627 "/\\(show\\|view\\)_\\([a-z]+\\)\\.pl")
629 (defun mixi-make-object-from-url (url)
630 "Return a mixi object from URL."
631 (if (string-match mixi-object-url-regexp url)
632 (let ((name (match-string 2 url)))
633 (cond ((string= name "bbs")
635 ((string= name "profile")
636 (setq name "friend")))
637 (let ((func (intern (concat mixi-object-prefix "make-" name
640 (when (string-match "/home\\.pl" url)
641 (mixi-make-friend-from-url url))))
644 ;; stolen from time-date.el
645 (defun mixi-time-less-p (t1 t2)
646 "Say whether time value T1 is less than time value T2."
647 (unless (numberp (cdr t1))
648 (setq t1 (cons (car t1) (car (cdr t1)))))
649 (unless (numberp (cdr t2))
650 (setq t2 (cons (car t2) (car (cdr t2)))))
651 (or (< (car t1) (car t2))
652 (and (= (car t1) (car t2))
653 (< (cdr t1) (cdr t2)))))
655 (defun mixi-time-add (t1 t2)
656 "Add two time values. One should represent a time difference."
657 (unless (numberp (cdr t1))
658 (setq t1 (cons (car t1) (car (cdr t1)))))
659 (unless (numberp (cdr t2))
660 (setq t2 (cons (car t2) (car (cdr t2)))))
661 (let ((low (+ (cdr t1) (cdr t2))))
662 (cons (+ (car t1) (car t2) (lsh low -16)) low)))
664 ;; stolen from time-date.el
665 (defun mixi-seconds-to-time (seconds)
666 "Convert SECONDS (a floating point number) to a time value."
667 (cons (floor seconds 65536)
668 (floor (mod seconds 65536))))
670 (defun mixi-cache-expired-p (object)
671 "Whether a cache of OBJECT is expired."
672 (let ((timestamp (mixi-object-timestamp object)))
673 (unless (or (null mixi-cache-expires)
675 (if (numberp mixi-cache-expires)
677 (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
681 (defun mixi-make-cache (key value table)
682 "Make a cache object and return it."
683 (let ((cache (gethash key table)))
684 (if (and cache (not (mixi-cache-expired-p cache)))
686 (puthash key value table))))
688 (defconst mixi-cache-file-regexp "[a-z]+-cache$")
689 (defconst mixi-cache-regexp (concat mixi-object-prefix
690 mixi-cache-file-regexp))
692 (defun mixi-save-cache ()
693 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
694 (unless (file-directory-p cache-directory)
695 (make-directory cache-directory t))
696 (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
697 (mapc (lambda (symbol)
698 (with-temp-file (expand-file-name
699 (substring (symbol-name symbol)
700 (length mixi-object-prefix))
702 (let ((coding-system-for-write mixi-coding-system)
703 (cache (symbol-value symbol)))
704 (insert "#s(hash-table size "
705 (number-to-string (hash-table-count cache))
706 " test equal data (\n")
709 (let (print-level print-length)
710 (insert (prin1-to-string key) " "
711 (prin1-to-string value) "\n")))
716 ;; stolen (and modified) from lsdb.el
717 (defun mixi-read-cache (&optional marker)
718 "Read one Lisp expression as text from MARKER, return as Lisp object."
721 (if (looking-at "^#s(")
724 (forward-char 2);skip "#s"
725 (forward-sexp);move to the left paren
728 (buffer-disable-undo)
729 (insert-buffer-substring (marker-buffer marker)
731 (goto-char (point-min))
733 (let ((object (read (current-buffer)))
735 (if (eq 'hash-table (car object))
737 (setq data (plist-get (cdr object) 'data))
739 (pop data);throw it away
740 (mixi-read-object (pop data))))
744 (defun mixi-load-cache ()
745 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
746 (when (file-directory-p cache-directory)
747 ;; FIXME: Load friend and community first.
748 (let ((files (directory-files cache-directory t
749 mixi-cache-file-regexp)))
751 (let ((buffer (find-file-noselect file)))
755 (goto-char (point-min))
756 (re-search-forward "^#s(")
757 (goto-char (match-beginning 0))
758 (mixi-read-cache (point-marker)))
759 (kill-buffer buffer))))
763 (defvar mixi-friend-cache (make-hash-table :test 'equal))
764 (defun mixi-make-friend (id &optional nick name sex address age birthday
765 blood-type birthplace hobby job organization
767 "Return a friend object."
768 (mixi-make-cache id (cons 'mixi-friend (vector nil id nick name sex address
769 age birthday blood-type
771 organization profile))
774 (defun mixi-make-me ()
775 "Return a my object."
777 (with-mixi-retrieve "/home.pl"
778 (if (re-search-forward mixi-my-id-regexp)
779 (setq mixi-me (mixi-make-friend (match-string 1)))
780 (signal 'error (list 'who-am-i)))))
783 (defconst mixi-friend-url-regexp
784 "/show_\\(friend\\|profile\\)\\.pl\\?id=\\([0-9]+\\)")
786 (defun mixi-make-friend-from-url (url)
787 "Return a friend object from URL."
788 (if (string-match mixi-friend-url-regexp url)
789 (let ((id (match-string 2 url)))
790 (mixi-make-friend id))
791 (when (string-match "/home\\.pl" url)
794 (defmacro mixi-friend-p (friend)
795 `(eq (mixi-object-class ,friend) 'mixi-friend))
797 (defmacro mixi-friend-page (friend)
798 `(concat "/show_profile.pl?id=" (mixi-friend-id ,friend)))
800 (defconst mixi-friend-nick-regexp
801 "<img \\(alt=\"\\*\" \\)?src=\"?http://img\\.mixi\\.jp/img/dot0\\.gif\"? width=\"?1\"? height=\"?5\"?\\( /\\)?><br\\( /\\)?>
\r?
802 \\(.*\\)¤µ¤ó([0-9]+)")
803 (defconst mixi-friend-name-regexp
804 "̾\\( \\| \\)Á°</font></td>
806 ?<td width=\"?345\"?>\\(.+?\\)\\(</td>\\| <img\\)")
807 (defconst mixi-friend-sex-regexp
808 "À\\( \\| \\)ÊÌ</font></td>
810 ?<td width=\"?345\"?>\\([Ã˽÷]\\)À\\(</td>\\| <img\\)")
811 (defconst mixi-friend-address-regexp
813 <td>\\(.+?\\)\\(</td>\\| <img\\)")
814 (defconst mixi-friend-age-regexp
815 "ǯ\\( \\| \\)Îð</font></td>\n<td>\\([0-9]+\\)ºÐ\\(</td>\\| <img\\)")
816 (defconst mixi-friend-birthday-regexp
817 "ÃÂÀ¸Æü</font></td>\n<td>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(</td>\\| <img\\)")
818 (defconst mixi-friend-blood-type-regexp
819 "·ì±Õ·¿</font></td>\n<td>\\([ABO]B?\\)·¿\\(</td>\\| <img\\)")
820 (defconst mixi-friend-birthplace-regexp
821 "½Ð¿ÈÃÏ</font>\n?</td>\n<td>\\(.+?\\)\\(</td>\\| <img\\)")
822 (defconst mixi-friend-hobby-regexp
823 "¼ñ\\( \\| \\)Ì£</font></td>\n<td>\\(.+?\\)\\(</td>\\| <img\\)")
824 (defconst mixi-friend-job-regexp
825 "¿¦\\( \\| \\)¶È</font></td>\n<td>\\(.+?\\)\\(</td>\\| <img\\)")
826 (defconst mixi-friend-organization-regexp
827 "½ê\\( \\| \\)°</font></td>\n<td[^>]*>\\(.+?\\)\\(</td>\\| <img\\)")
828 (defconst mixi-friend-profile-regexp
829 "¼«¸Ê¾Ò²ð</font></td>
830 <td class=\"?h120\"?>\\(.+\\)</td></tr>")
832 (defun mixi-realize-friend (friend)
834 ;; FIXME: Check a expiration of cache?
835 (unless (mixi-object-realized-p friend)
836 (with-mixi-retrieve (mixi-friend-page friend)
837 (let ((case-fold-search t))
838 (if (re-search-forward mixi-friend-nick-regexp nil t)
839 (mixi-friend-set-nick friend (match-string 4))
840 (mixi-realization-error 'cannot-find-nick friend))
841 (when (re-search-forward mixi-friend-name-regexp nil t)
842 (mixi-friend-set-name friend (match-string 2)))
843 (when (re-search-forward mixi-friend-sex-regexp nil t)
844 (mixi-friend-set-sex friend (if (string= (match-string 2) "ÃË")
846 (when (re-search-forward mixi-friend-address-regexp nil t)
847 (mixi-friend-set-address friend (match-string 1)))
848 (when (re-search-forward mixi-friend-age-regexp nil t)
849 (mixi-friend-set-age friend (string-to-number (match-string 2))))
850 (when (re-search-forward mixi-friend-birthday-regexp nil t)
851 (mixi-friend-set-birthday
852 friend (list (string-to-number (match-string 1))
853 (string-to-number (match-string 2)))))
854 (when (re-search-forward mixi-friend-blood-type-regexp nil t)
855 (mixi-friend-set-blood-type friend (intern (match-string 1))))
856 (when (re-search-forward mixi-friend-birthplace-regexp nil t)
857 (mixi-friend-set-birthplace friend (match-string 1)))
858 (when (re-search-forward mixi-friend-hobby-regexp nil t)
859 (mixi-friend-set-hobby friend (split-string (match-string 2) ", ")))
860 (when (re-search-forward mixi-friend-job-regexp nil t)
861 (mixi-friend-set-job friend (match-string 2)))
862 (when (re-search-forward mixi-friend-organization-regexp nil t)
863 (mixi-friend-set-organization friend (match-string 2)))
864 (when (re-search-forward mixi-friend-profile-regexp nil t)
865 (mixi-friend-set-profile friend (match-string 1)))))
866 (mixi-object-touch friend)))
868 (defun mixi-friend-id (friend)
869 "Return the id of FRIEND."
870 (unless (mixi-friend-p friend)
871 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
872 (aref (cdr friend) 1))
874 (defun mixi-friend-nick (friend)
875 "Return the nick of FRIEND."
876 (unless (mixi-friend-p friend)
877 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
878 (unless (aref (cdr friend) 2)
879 (mixi-realize-friend friend))
880 (aref (cdr friend) 2))
882 (defun mixi-friend-name (friend)
883 "Return the name of FRIEND."
884 (unless (mixi-friend-p friend)
885 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
886 (mixi-realize-friend friend)
887 (aref (cdr friend) 3))
889 (defun mixi-friend-sex (friend)
890 "Return the sex of FRIEND."
891 (unless (mixi-friend-p friend)
892 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
893 (mixi-realize-friend friend)
894 (aref (cdr friend) 4))
896 (defun mixi-friend-address (friend)
897 "Return the address of FRIEND."
898 (unless (mixi-friend-p friend)
899 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
900 (mixi-realize-friend friend)
901 (aref (cdr friend) 5))
903 (defun mixi-friend-age (friend)
904 "Return the age of FRIEND."
905 (unless (mixi-friend-p friend)
906 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
907 (mixi-realize-friend friend)
908 (aref (cdr friend) 6))
910 (defun mixi-friend-birthday (friend)
911 "Return the birthday of FRIEND."
912 (unless (mixi-friend-p friend)
913 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
914 (mixi-realize-friend friend)
915 (aref (cdr friend) 7))
917 (defun mixi-friend-blood-type (friend)
918 "Return the blood type of FRIEND."
919 (unless (mixi-friend-p friend)
920 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
921 (mixi-realize-friend friend)
922 (aref (cdr friend) 8))
924 (defun mixi-friend-birthplace (friend)
925 "Return the birthplace of FRIEND."
926 (unless (mixi-friend-p friend)
927 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
928 (mixi-realize-friend friend)
929 (aref (cdr friend) 9))
931 (defun mixi-friend-hobby (friend)
932 "Return the hobby of FRIEND."
933 (unless (mixi-friend-p friend)
934 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
935 (mixi-realize-friend friend)
936 (aref (cdr friend) 10))
938 (defun mixi-friend-job (friend)
939 "Return the job of FRIEND."
940 (unless (mixi-friend-p friend)
941 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
942 (mixi-realize-friend friend)
943 (aref (cdr friend) 11))
945 (defun mixi-friend-organization (friend)
946 "Return the organization of FRIEND."
947 (unless (mixi-friend-p friend)
948 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
949 (mixi-realize-friend friend)
950 (aref (cdr friend) 12))
952 (defun mixi-friend-profile (friend)
953 "Return the pforile of FRIEND."
954 (unless (mixi-friend-p friend)
955 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
956 (mixi-realize-friend friend)
957 (aref (cdr friend) 13))
959 (defun mixi-friend-set-nick (friend nick)
960 "Set the nick of FRIEND."
961 (unless (mixi-friend-p friend)
962 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
963 (aset (cdr friend) 2 nick))
965 (defun mixi-friend-set-name (friend name)
966 "Set the name of FRIEND."
967 (unless (mixi-friend-p friend)
968 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
969 (aset (cdr friend) 3 name))
971 (defun mixi-friend-set-sex (friend sex)
972 "Set the sex of FRIEND."
973 (unless (mixi-friend-p friend)
974 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
975 (aset (cdr friend) 4 sex))
977 (defun mixi-friend-set-address (friend address)
978 "Set the address of FRIEND."
979 (unless (mixi-friend-p friend)
980 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
981 (aset (cdr friend) 5 address))
983 (defun mixi-friend-set-age (friend age)
984 "Set the age of FRIEND."
985 (unless (mixi-friend-p friend)
986 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
987 (aset (cdr friend) 6 age))
989 (defun mixi-friend-set-birthday (friend birthday)
990 "Set the birthday of FRIEND."
991 (unless (mixi-friend-p friend)
992 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
993 (aset (cdr friend) 7 birthday))
995 (defun mixi-friend-set-blood-type (friend blood-type)
996 "Set the blood type of FRIEND."
997 (unless (mixi-friend-p friend)
998 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
999 (aset (cdr friend) 8 blood-type))
1001 (defun mixi-friend-set-birthplace (friend birthplace)
1002 "Set the birthplace of FRIEND."
1003 (unless (mixi-friend-p friend)
1004 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1005 (aset (cdr friend) 9 birthplace))
1007 (defun mixi-friend-set-hobby (friend hobby)
1008 "Set the hobby of FRIEND."
1009 (unless (mixi-friend-p friend)
1010 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1011 (aset (cdr friend) 10 hobby))
1013 (defun mixi-friend-set-job (friend job)
1014 "Set the job of FRIEND."
1015 (unless (mixi-friend-p friend)
1016 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1017 (aset (cdr friend) 11 job))
1019 (defun mixi-friend-set-organization (friend organization)
1020 "Set the organization of FRIEND."
1021 (unless (mixi-friend-p friend)
1022 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1023 (aset (cdr friend) 12 organization))
1025 (defun mixi-friend-set-profile (friend profile)
1026 "Set the profile of FRIEND."
1027 (unless (mixi-friend-p friend)
1028 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1029 (aset (cdr friend) 13 profile))
1031 (defmacro mixi-friend-list-page (&optional friend)
1032 `(concat "/list_friend.pl?page=%d"
1033 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1035 (defconst mixi-friend-list-id-regexp
1036 "<a href=show_friend\\.pl\\?id=\\([0-9]+\\)")
1037 (defconst mixi-friend-list-nick-regexp
1038 "<td valign=middle>\\(.+\\)¤µ¤ó([0-9]+)<br />")
1041 (defun mixi-get-friends (&rest friend-or-range)
1042 "Get friends of FRIEND."
1043 (when (> (length friend-or-range) 2)
1044 (signal 'wrong-number-of-arguments (list 'mixi-get-friends
1045 (length friend-or-range))))
1046 (let ((friend (nth 0 friend-or-range))
1047 (range (nth 1 friend-or-range)))
1048 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1049 (setq friend (nth 1 friend-or-range))
1050 (setq range (nth 0 friend-or-range)))
1051 (unless (or (null friend) (mixi-friend-p friend))
1052 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1053 (let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
1054 mixi-friend-list-id-regexp
1056 (nicks (mixi-get-matched-items (mixi-friend-list-page friend)
1057 mixi-friend-list-nick-regexp
1061 (while (< index (length ids))
1062 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1063 (nth 0 (nth index nicks))) ret))
1068 (defmacro mixi-favorite-list-page ()
1069 `(concat "/list_bookmark.pl?page=%d"))
1071 (defconst mixi-favorite-list-id-regexp
1072 "<td ALIGN=center BGCOLOR=#FDF9F2 width=330><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">")
1073 (defconst mixi-favorite-list-nick-regexp
1074 "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾ Á°</font></td>
1075 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>")
1078 (defun mixi-get-favorites (&optional range)
1080 (let ((ids (mixi-get-matched-items (mixi-favorite-list-page)
1081 mixi-favorite-list-id-regexp
1083 (nicks (mixi-get-matched-items (mixi-favorite-list-page)
1084 mixi-favorite-list-nick-regexp
1088 (while (< index (length ids))
1089 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1090 (nth 0 (nth index nicks))) ret))
1095 (defun mixi-make-log (friend time)
1096 "Return a log object."
1097 (cons 'mixi-log (vector friend time)))
1099 (defmacro mixi-log-p (log)
1100 `(eq (mixi-object-class ,log) 'mixi-log))
1102 (defun mixi-log-friend (log)
1103 "Return the friend of LOG."
1104 (unless (mixi-log-p log)
1105 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1108 (defun mixi-log-time (log)
1109 "Return the time of LOG."
1110 (unless (mixi-log-p log)
1111 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1114 (defmacro mixi-log-list-page ()
1115 `(concat "/show_log.pl"))
1117 (defconst mixi-log-list-regexp
1118 "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)</a>")
1121 (defun mixi-get-logs (&optional range)
1123 (let ((items (mixi-get-matched-items (mixi-log-list-page)
1124 mixi-log-list-regexp
1126 (mapcar (lambda (item)
1127 (mixi-make-log (mixi-make-friend (nth 5 item) (nth 6 item))
1129 (string-to-number (nth 4 item))
1130 (string-to-number (nth 3 item))
1131 (string-to-number (nth 2 item))
1132 (string-to-number (nth 1 item))
1133 (string-to-number (nth 0 item)))))
1137 (defvar mixi-diary-cache (make-hash-table :test 'equal))
1138 (defun mixi-make-diary (owner id &optional comment-count time title content)
1139 "Return a diary object."
1140 (let ((owner (or owner (mixi-make-me))))
1141 (mixi-make-cache (list (mixi-friend-id owner) id)
1142 (cons 'mixi-diary (vector nil owner id comment-count time
1146 (defconst mixi-diary-url-regexp
1147 "/view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?")
1149 (defun mixi-make-diary-from-url (url)
1150 "Return a diary object from URL."
1151 (when (string-match mixi-diary-url-regexp url)
1152 (let ((id (match-string 1 url))
1153 (owner-id (match-string 2 url))
1154 (comment-count (match-string 4 url)))
1155 (mixi-make-diary (mixi-make-friend owner-id) id comment-count))))
1157 (defmacro mixi-diary-p (diary)
1158 `(eq (mixi-object-class ,diary) 'mixi-diary))
1160 (defmacro mixi-diary-page (diary)
1161 `(concat "/view_diary.pl?id=" (mixi-diary-id ,diary)
1162 "&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
1164 (defconst mixi-diary-closed-regexp
1165 "<td>ͧ¿Í\\(¤Îͧ¿Í\\)?¤Þ¤Ç¸ø³«¤Î¤¿¤áÆɤळ¤È¤¬½ÐÍè¤Þ¤»¤ó¡£</td></tr>")
1166 (defconst mixi-diary-owner-nick-regexp
1167 "<td WIDTH=490 background=http://img\\.mixi\\.jp/img/bg_w\\.gif><b><font COLOR=#605048>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ</font></b></td>")
1168 (defconst mixi-diary-time-regexp
1169 "<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>")
1170 (defconst mixi-diary-title-regexp
1171 "<td \\(bgcolor\\|BGCOLOR\\)=\"?#FFF4E0\"? width=\"?430\"?> \\([^<]+\\)</td>")
1172 (defconst mixi-diary-content-regexp
1173 "<td \\(class\\|CLASS\\)=\"?h12\"?>\\(.*\\)</td>")
1175 (defun mixi-realize-diary (diary &optional page)
1177 ;; FIXME: Check a expiration of cache?
1178 (unless (mixi-object-realized-p diary)
1179 (with-mixi-retrieve (or page (mixi-diary-page diary))
1180 (unless (re-search-forward mixi-diary-closed-regexp nil t)
1181 (if (re-search-forward mixi-diary-owner-nick-regexp nil t)
1182 (mixi-friend-set-nick (mixi-diary-owner diary) (match-string 1))
1183 (mixi-realization-error 'cannot-find-owner-nick diary))
1184 (if (re-search-forward mixi-diary-time-regexp nil t)
1185 (mixi-diary-set-time
1186 diary (encode-time 0 (string-to-number (match-string 10))
1187 (string-to-number (match-string 9))
1188 (string-to-number (match-string 7))
1189 (string-to-number (match-string 6))
1190 (string-to-number (match-string 5))))
1191 (mixi-realization-error 'cannot-find-time diary))
1192 (if (re-search-forward mixi-diary-title-regexp nil t)
1193 (mixi-diary-set-title diary (match-string 2))
1194 (mixi-realization-error 'cannot-find-title diary))
1195 (if (re-search-forward mixi-diary-content-regexp nil t)
1196 (mixi-diary-set-content diary (match-string 2))
1197 (mixi-realization-error 'cannot-find-content diary))))
1198 (mixi-object-touch diary)))
1200 (defun mixi-diary-owner (diary)
1201 "Return the owner of DIARY."
1202 (unless (mixi-diary-p diary)
1203 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1204 (aref (cdr diary) 1))
1206 (defun mixi-diary-id (diary)
1207 "Return the id of DIARY."
1208 (unless (mixi-diary-p diary)
1209 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1210 (aref (cdr diary) 2))
1212 (defun mixi-diary-comment-count (diary)
1213 "Return the comment-count of DIARY."
1214 (unless (mixi-diary-p diary)
1215 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1216 (aref (cdr diary) 3))
1218 (defun mixi-diary-time (diary)
1219 "Return the time of DIARY."
1220 (unless (mixi-diary-p diary)
1221 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1222 (unless (aref (cdr diary) 3)
1223 (mixi-realize-diary diary))
1224 (aref (cdr diary) 4))
1226 (defun mixi-diary-title (diary)
1227 "Return the title of DIARY."
1228 (unless (mixi-diary-p diary)
1229 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1230 (unless (aref (cdr diary) 4)
1231 (mixi-realize-diary diary))
1232 (aref (cdr diary) 5))
1234 (defun mixi-diary-content (diary)
1235 "Return the content of DIARY."
1236 (unless (mixi-diary-p diary)
1237 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1238 (mixi-realize-diary diary)
1239 (aref (cdr diary) 6))
1241 (defun mixi-diary-set-comment-count (diary comment-count)
1242 "Set the comment-count of DIARY."
1243 (unless (mixi-diary-p diary)
1244 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1245 (aset (cdr diary) 3 comment-count))
1247 (defun mixi-diary-set-time (diary time)
1248 "Set the time of DIARY."
1249 (unless (mixi-diary-p diary)
1250 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1251 (aset (cdr diary) 4 time))
1253 (defun mixi-diary-set-title (diary title)
1254 "Set the title of DIARY."
1255 (unless (mixi-diary-p diary)
1256 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1257 (aset (cdr diary) 5 title))
1259 (defun mixi-diary-set-content (diary content)
1260 "Set the content of DIARY."
1261 (unless (mixi-diary-p diary)
1262 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1263 (aset (cdr diary) 6 content))
1265 (defmacro mixi-diary-list-page (&optional friend)
1266 `(concat "/list_diary.pl?page=%d"
1267 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1269 (defconst mixi-diary-list-regexp
1271 <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>
1272 <td bgcolor=\"#FFF4E0\"> <a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">\\(.*\\)</a></td>")
1275 (defun mixi-get-diaries (&rest friend-or-range)
1276 "Get diaries of FRIEND."
1277 (when (> (length friend-or-range) 2)
1278 (signal 'wrong-number-of-arguments
1279 (list 'mixi-get-diaries (length friend-or-range))))
1280 (let ((friend (nth 0 friend-or-range))
1281 (range (nth 1 friend-or-range)))
1282 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1283 (setq friend (nth 1 friend-or-range))
1284 (setq range (nth 0 friend-or-range)))
1285 (unless (or (null friend) (mixi-friend-p friend))
1286 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1287 (let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
1288 mixi-diary-list-regexp
1290 (year (nth 5 (decode-time (current-time))))
1291 (month (nth 4 (decode-time (current-time)))))
1292 (mapcar (lambda (item)
1293 (let ((month-of-item (string-to-number (nth 0 item))))
1294 (when (> month-of-item month)
1296 (setq month month-of-item)
1297 (mixi-make-diary friend (nth 5 item) nil
1299 0 (string-to-number (nth 3 item))
1300 (string-to-number (nth 2 item))
1301 (string-to-number (nth 1 item))
1306 (defmacro mixi-new-diary-list-page ()
1307 `(concat "/new_friend_diary.pl?page=%d"))
1309 (defconst mixi-new-diary-list-regexp
1310 "<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>
1311 <td WIDTH=450><a class=\"new_link\" href=view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)>\\(.+\\)</a> (\\(.*\\)) ")
1314 (defun mixi-get-new-diaries (&optional range)
1316 (let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
1317 mixi-new-diary-list-regexp
1319 (mapcar (lambda (item)
1320 (mixi-make-diary (mixi-make-friend (nth 6 item) (nth 8 item))
1324 0 (string-to-number (nth 4 item))
1325 (string-to-number (nth 3 item))
1326 (string-to-number (nth 2 item))
1327 (string-to-number (nth 1 item))
1328 (string-to-number (nth 0 item)))
1332 (defmacro mixi-search-diary-list-page (keyword)
1333 `(concat "/search_diary.pl?page=%d&submit=search&keyword="
1334 (mixi-url-encode-and-quote-percent-string ,keyword)))
1336 (defconst mixi-search-diary-list-regexp
1337 "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾ Á°</font></td>
1338 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.*\\)
1343 <td BGCOLOR=#FDF9F2><font COLOR=#996600>¥¿¥¤¥È¥ë</font></td>
1344 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>
1347 <td BGCOLOR=#FDF9F2><font COLOR=#996600>ËÜ Ê¸</font></td>
1348 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.*\\)</td></tr>
1352 <td NOWRAP BGCOLOR=#FDF9F2 WIDTH=80><font COLOR=#996600>ºîÀ®Æü»þ</font></td>
1353 <td BGCOLOR=#FFFFFF WIDTH=220>\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>
1354 <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>
1356 </td></tr></table>")
1359 (defun mixi-search-diaries (keyword &optional range)
1360 (let ((items (mixi-get-matched-items (mixi-search-diary-list-page keyword)
1361 mixi-search-diary-list-regexp
1363 (year (nth 5 (decode-time (current-time))))
1364 (month (nth 4 (decode-time (current-time)))))
1365 (mapcar (lambda (item)
1366 (let ((month-of-item (string-to-number (nth 3 item))))
1367 (when (> month-of-item month)
1369 (setq month month-of-item)
1370 (mixi-make-diary (mixi-make-friend (nth 8 item) (nth 0 item))
1374 0 (string-to-number (nth 6 item))
1375 (string-to-number (nth 5 item))
1376 (string-to-number (nth 4 item))
1382 (defmacro mixi-post-diary-page ()
1383 `(concat "/add_diary.pl"))
1385 (defconst mixi-post-key-regexp
1386 "<input type=\"?hidden\"? name=\"?post_key\"? value=\"\\([a-z0-9]+\\)\">")
1387 (defconst mixi-post-succeed-regexp
1388 "<b>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É½¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¾¯¡¹¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£</b>")
1390 ;; FIXME: Support photos.
1392 (defun mixi-post-diary (title content)
1394 (unless (stringp title)
1395 (signal 'wrong-type-argument (list 'stringp title)))
1396 (unless (stringp content)
1397 (signal 'wrong-type-argument (list 'stringp content)))
1398 (let ((fields `(("id" . ,(mixi-friend-id (mixi-make-me)))
1399 ("diary_title" . ,title)
1400 ("diary_body" . ,content)
1401 ("submit" . "main")))
1403 (with-mixi-post-form (mixi-post-diary-page) fields
1404 (if (re-search-forward mixi-post-key-regexp nil t)
1405 (setq post-key (match-string 1))
1406 (mixi-post-error 'cannot-find-key)))
1407 (setq fields `(("post_key" . ,post-key)
1408 ("id" . ,(mixi-friend-id (mixi-make-me)))
1409 ("diary_title" . ,title)
1410 ("diary_body" . ,content)
1411 ("submit" . "confirm")))
1412 (with-mixi-post-form (mixi-post-diary-page) fields
1413 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1414 (mixi-post-error 'cannot-find-succeed)))))
1416 ;; Community object.
1417 (defvar mixi-community-cache (make-hash-table :test 'equal))
1418 (defun mixi-make-community (id &optional name birthday owner category members
1419 open-level authority description)
1420 "Return a community object."
1421 (mixi-make-cache id (cons 'mixi-community (vector nil id name birthday owner
1423 open-level authority
1425 mixi-community-cache))
1427 (defconst mixi-community-url-regexp
1428 "/view_community\\.pl\\?id=\\([0-9]+\\)")
1430 (defun mixi-make-community-from-url (url)
1431 "Return a community object from URL."
1432 (when (string-match mixi-community-url-regexp url)
1433 (let ((id (match-string 1 url)))
1434 (mixi-make-community id))))
1436 (defmacro mixi-community-p (community)
1437 `(eq (mixi-object-class ,community) 'mixi-community))
1439 (defmacro mixi-community-page (community)
1440 `(concat "/view_community.pl?id=" (mixi-community-id ,community)))
1442 ;; FIXME: Not community specific.
1443 (defconst mixi-community-nodata-regexp
1444 "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1445 (defconst mixi-community-name-regexp
1446 "<td WIDTH=345>\\(.*\\)</td></tr>")
1447 (defconst mixi-community-birthday-regexp
1448 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>³«ÀßÆü</font></td>
\r
1449 <td WIDTH=345>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü")
1450 ;; FIXME: Care when the owner has seceded.
1451 (defconst mixi-community-owner-regexp
1452 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>´ÉÍý¿Í</font></td>
\r
1454 <table style=\"width: 100%;\"><tr><td>
\r
1455 <a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\\(.*\\)</a>")
1456 (defconst mixi-community-category-regexp
1457 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥«¥Æ¥´¥ê</font></td>
\r
1458 <td WIDTH=345>\\([^<]+\\)</td>")
1459 (defconst mixi-community-members-regexp
1460 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥á¥ó¥Ð¡¼¿ô</font></td>
\r
1461 <td WIDTH=345>\\([0-9]+\\)¿Í</td></tr>")
1462 (defconst mixi-community-open-level-regexp
1463 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>»²²Ã¾ò·ï¤È<br>¸ø³«¥ì¥Ù¥ë</font></td>
\r
1464 <td WIDTH=345>\\(.+\\)</td></tr>")
1465 (defconst mixi-community-authority-regexp
1466 "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>
\r
1467 <td WIDTH=345>\\(.+\\)</td></tr>")
1468 (defconst mixi-community-description-regexp
1469 "<td CLASS=h120 WIDTH=345>\\(.+\\)</td>")
1471 (defun mixi-realize-community (community)
1472 "Realize a COMMUNITY."
1473 ;; FIXME: Check a expiration of cache?
1474 (unless (mixi-object-realized-p community)
1475 (with-mixi-retrieve (mixi-community-page community)
1476 (if (re-search-forward mixi-community-nodata-regexp nil t)
1477 ;; FIXME: Set all members?
1478 (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1479 (if (re-search-forward mixi-community-name-regexp nil t)
1480 (mixi-community-set-name community (match-string 1))
1481 (mixi-realization-error 'cannot-find-name community))
1482 (if (re-search-forward mixi-community-birthday-regexp nil t)
1483 (mixi-community-set-birthday
1484 community (encode-time 0 0 0 (string-to-number (match-string 3))
1485 (string-to-number (match-string 2))
1486 (string-to-number (match-string 1))))
1487 (mixi-realization-error 'cannot-find-birthday community))
1488 (if (re-search-forward mixi-community-owner-regexp nil t)
1489 (if (string= (match-string 1) "home.pl")
1490 (mixi-community-set-owner community (mixi-make-me))
1491 (mixi-community-set-owner community
1492 (mixi-make-friend (match-string 2)
1494 (mixi-realization-error 'cannot-find-owner community))
1495 (if (re-search-forward mixi-community-category-regexp nil t)
1496 (mixi-community-set-category community (match-string 1))
1497 (mixi-realization-error 'cannot-find-category community))
1498 (if (re-search-forward mixi-community-members-regexp nil t)
1499 (mixi-community-set-members community
1500 (string-to-number (match-string 1)))
1501 (mixi-realization-error 'cannot-find-members community))
1502 (if (re-search-forward mixi-community-open-level-regexp nil t)
1503 (mixi-community-set-open-level community (match-string 1))
1504 (mixi-realization-error 'cannot-find-open-level community))
1505 (if (re-search-forward mixi-community-authority-regexp nil t)
1506 (mixi-community-set-authority community (match-string 1))
1507 (mixi-realization-error 'cannot-find-authority community))
1508 (if (re-search-forward mixi-community-description-regexp nil t)
1509 (mixi-community-set-description community (match-string 1))
1510 (mixi-realization-error 'cannot-find-description community))))
1511 (mixi-object-touch community)))
1513 (defun mixi-community-id (community)
1514 "Return the id of COMMUNITY."
1515 (unless (mixi-community-p community)
1516 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1517 (aref (cdr community) 1))
1519 (defun mixi-community-name (community)
1520 "Return the name of COMMUNITY."
1521 (unless (mixi-community-p community)
1522 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1523 (unless (aref (cdr community) 2)
1524 (mixi-realize-community community))
1525 (aref (cdr community) 2))
1527 (defun mixi-community-birthday (community)
1528 "Return the birthday of COMMUNITY."
1529 (unless (mixi-community-p community)
1530 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1531 (mixi-realize-community community)
1532 (aref (cdr community) 3))
1534 (defun mixi-community-owner (community)
1535 "Return the owner of COMMUNITY."
1536 (unless (mixi-community-p community)
1537 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1538 (mixi-realize-community community)
1539 (aref (cdr community) 4))
1541 (defun mixi-community-category (community)
1542 "Return the category of COMMUNITY."
1543 (unless (mixi-community-p community)
1544 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1545 (mixi-realize-community community)
1546 (aref (cdr community) 5))
1548 (defun mixi-community-members (community)
1549 "Return the members of COMMUNITY."
1550 (unless (mixi-community-p community)
1551 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1552 (mixi-realize-community community)
1553 (aref (cdr community) 6))
1555 (defun mixi-community-open-level (community)
1556 "Return the open-level of COMMUNITY."
1557 (unless (mixi-community-p community)
1558 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1559 (mixi-realize-community community)
1560 (aref (cdr community) 7))
1562 (defun mixi-community-authority (community)
1563 "Return the authority of COMMUNITY."
1564 (unless (mixi-community-p community)
1565 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1566 (mixi-realize-community community)
1567 (aref (cdr community) 8))
1569 (defun mixi-community-description (community)
1570 "Return the description of COMMUNITY."
1571 (unless (mixi-community-p community)
1572 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1573 (mixi-realize-community community)
1574 (aref (cdr community) 9))
1576 (defun mixi-community-set-name (community name)
1577 "Set the name of COMMUNITY."
1578 (unless (mixi-community-p community)
1579 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1580 (aset (cdr community) 2 name))
1582 (defun mixi-community-set-birthday (community birthday)
1583 "Set the birthday of COMMUNITY."
1584 (unless (mixi-community-p community)
1585 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1586 (aset (cdr community) 3 birthday))
1588 (defun mixi-community-set-owner (community owner)
1589 "Set the owner of COMMUNITY."
1590 (unless (mixi-community-p community)
1591 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1592 (unless (mixi-friend-p owner)
1593 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1594 (aset (cdr community) 4 owner))
1596 (defun mixi-community-set-category (community category)
1597 "Set the category of COMMUNITY."
1598 (unless (mixi-community-p community)
1599 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1600 (aset (cdr community) 5 category))
1602 (defun mixi-community-set-members (community members)
1603 "Set the name of COMMUNITY."
1604 (unless (mixi-community-p community)
1605 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1606 (aset (cdr community) 6 members))
1608 (defun mixi-community-set-open-level (community open-level)
1609 "Set the name of COMMUNITY."
1610 (unless (mixi-community-p community)
1611 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1612 (aset (cdr community) 7 open-level))
1614 (defun mixi-community-set-authority (community authority)
1615 "Set the name of COMMUNITY."
1616 (unless (mixi-community-p community)
1617 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1618 (aset (cdr community) 8 authority))
1620 (defun mixi-community-set-description (community description)
1621 "Set the name of COMMUNITY."
1622 (unless (mixi-community-p community)
1623 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1624 (aset (cdr community) 9 description))
1626 (defmacro mixi-community-list-page (&optional friend)
1627 `(concat "/list_community.pl?page=%d"
1628 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1630 (defconst mixi-community-list-id-regexp
1631 "<a href=view_community\\.pl\\?id=\\([0-9]+\\)")
1632 (defconst mixi-community-list-name-regexp
1633 "<td valign=middle>\\(.+\\)([0-9]+)</td>")
1636 (defun mixi-get-communities (&rest friend-or-range)
1637 "Get communities of FRIEND."
1638 (when (> (length friend-or-range) 2)
1639 (signal 'wrong-number-of-arguments
1640 (list 'mixi-get-communities (length friend-or-range))))
1641 (let ((friend (nth 0 friend-or-range))
1642 (range (nth 1 friend-or-range)))
1643 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1644 (setq friend (nth 1 friend-or-range))
1645 (setq range (nth 0 friend-or-range)))
1646 (unless (or (null friend) (mixi-friend-p friend))
1647 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1648 (let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
1649 mixi-community-list-id-regexp
1651 (names (mixi-get-matched-items (mixi-community-list-page friend)
1652 mixi-community-list-name-regexp
1656 (while (< index (length ids))
1657 (setq ret (cons (mixi-make-community (nth 0 (nth index ids))
1658 (nth 0 (nth index names))) ret))
1662 (defmacro mixi-search-community-list-page (keyword)
1663 `(concat "/search_community.pl?page=%d&&sort=date&type=com&submit=main"
1664 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
1667 (defconst mixi-search-community-list-regexp
1668 "<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>
1669 <td NOWRAP WIDTH=90 BGCOLOR=#FDF9F2><font COLOR=#996600>¥³¥ß¥å¥Ë¥Æ¥£Ì¾</font></td>
1670 <td COLSPAN=2 WIDTH=370 BGCOLOR=#FFFFFF>\\([^<]+\\)</td></tr>")
1672 ;; FIXME: Support category.
1674 (defun mixi-search-communities (keyword &optional range)
1675 (let ((items (mixi-get-matched-items (mixi-search-community-list-page
1677 mixi-search-community-list-regexp
1679 (mapcar (lambda (item)
1680 (mixi-make-community (nth 0 item) (nth 1 item)))
1684 (defvar mixi-topic-cache (make-hash-table :test 'equal))
1685 (defun mixi-make-topic (community id &optional comment-count time title owner
1687 "Return a topic object."
1688 (mixi-make-cache (list (mixi-community-id community) id)
1689 (cons 'mixi-topic (vector nil community id comment-count
1690 time title owner content))
1693 (defconst mixi-topic-url-regexp
1694 "/view_bbs\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1696 (defun mixi-make-topic-from-url (url)
1697 "Return a topic object from URL."
1698 (when (string-match mixi-topic-url-regexp url)
1699 (let ((id (match-string 1 url))
1700 (comment-count (match-string 3 url))
1701 (community-id (match-string 4 url)))
1702 (mixi-make-topic (mixi-make-community community-id) id comment-count))))
1704 (defmacro mixi-topic-p (topic)
1705 `(eq (mixi-object-class ,topic) 'mixi-topic))
1707 (defmacro mixi-topic-page (topic)
1708 `(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
1709 "&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
1711 (defconst mixi-topic-community-regexp
1712 "<td width=\"595\" background=\"http://img\\.mixi\\.jp/img/bg_w\\.gif\"><b>\\[\\(.+\\)\\] ¥È¥Ô¥Ã¥¯</b></td>")
1713 (defconst mixi-topic-time-regexp
1714 "<td rowspan=\"3\" width=\"110\" bgcolor=\"#ffd8b0\" align=\"center\" valign=\"top\" nowrap>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</td>")
1715 (defconst mixi-topic-title-regexp
1716 "<td bgcolor=\"#fff4e0\"> \\([^<]+\\)</td>")
1717 (defconst mixi-topic-owner-regexp
1718 "<td bgcolor=\"#fdf9f2\"> <font color=\"#dfb479\"></font> <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)\\(¤µ¤ó\\)?</a>")
1719 (defconst mixi-topic-content-regexp
1720 "<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>")
1722 (defun mixi-realize-topic (topic &optional page)
1724 ;; FIXME: Check a expiration of cache?
1725 (unless (mixi-object-realized-p topic)
1726 (with-mixi-retrieve (or page (mixi-topic-page topic))
1727 (if (re-search-forward mixi-topic-community-regexp nil t)
1728 (mixi-community-set-name (mixi-topic-community topic)
1730 (mixi-realization-error 'cannot-find-community topic))
1731 (if (re-search-forward mixi-topic-time-regexp nil t)
1732 (mixi-topic-set-time
1733 topic (encode-time 0 (string-to-number (match-string 5))
1734 (string-to-number (match-string 4))
1735 (string-to-number (match-string 3))
1736 (string-to-number (match-string 2))
1737 (string-to-number (match-string 1))))
1738 (mixi-realization-error 'cannot-find-time topic))
1739 (if (re-search-forward mixi-topic-title-regexp nil t)
1740 (mixi-topic-set-title topic (match-string 1))
1741 (mixi-realization-error 'cannot-find-title topic))
1742 (if (re-search-forward mixi-topic-owner-regexp nil t)
1743 (mixi-topic-set-owner topic (mixi-make-friend (match-string 1)
1745 (mixi-realization-error 'cannot-find-owner topic))
1746 (if (re-search-forward mixi-topic-content-regexp nil t)
1747 (mixi-topic-set-content topic (match-string 2))
1748 (mixi-realization-error 'cannot-find-content topic)))
1749 (mixi-object-touch topic)))
1751 (defun mixi-topic-community (topic)
1752 "Return the community of TOPIC."
1753 (unless (mixi-topic-p topic)
1754 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1755 (aref (cdr topic) 1))
1757 (defun mixi-topic-id (topic)
1758 "Return the id of TOPIC."
1759 (unless (mixi-topic-p topic)
1760 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1761 (aref (cdr topic) 2))
1763 (defun mixi-topic-comment-count (topic)
1764 "Return the comment-count of TOPIC."
1765 (unless (mixi-topic-p topic)
1766 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1767 (aref (cdr topic) 3))
1769 (defun mixi-topic-time (topic)
1770 "Return the time of TOPIC."
1771 (unless (mixi-topic-p topic)
1772 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1773 (mixi-realize-topic topic)
1774 (aref (cdr topic) 4))
1776 (defun mixi-topic-title (topic)
1777 "Return the title of TOPIC."
1778 (unless (mixi-topic-p topic)
1779 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1780 (mixi-realize-topic topic)
1781 (aref (cdr topic) 5))
1783 (defun mixi-topic-owner (topic)
1784 "Return the owner of TOPIC."
1785 (unless (mixi-topic-p topic)
1786 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1787 (mixi-realize-topic topic)
1788 (aref (cdr topic) 6))
1790 (defun mixi-topic-content (topic)
1791 "Return the content of TOPIC."
1792 (unless (mixi-topic-p topic)
1793 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1794 (mixi-realize-topic topic)
1795 (aref (cdr topic) 7))
1797 (defun mixi-topic-set-comment-count (topic comment-count)
1798 "Set the comment-count of TOPIC."
1799 (unless (mixi-topic-p topic)
1800 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1801 (aset (cdr topic) 3 comment-count))
1803 (defun mixi-topic-set-time (topic time)
1804 "Set the time of TOPIC."
1805 (unless (mixi-topic-p topic)
1806 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1807 (aset (cdr topic) 4 time))
1809 (defun mixi-topic-set-title (topic title)
1810 "Set the title of TOPIC."
1811 (unless (mixi-topic-p topic)
1812 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1813 (aset (cdr topic) 5 title))
1815 (defun mixi-topic-set-owner (topic owner)
1816 "Set the owner of TOPIC."
1817 (unless (mixi-topic-p topic)
1818 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1819 (unless (mixi-friend-p owner)
1820 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1821 (aset (cdr topic) 6 owner))
1823 (defun mixi-topic-set-content (topic content)
1824 "Set the content of TOPIC."
1825 (unless (mixi-topic-p topic)
1826 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1827 (aset (cdr topic) 7 content))
1829 (defmacro mixi-post-topic-page (community)
1830 `(concat "/add_bbs.pl?id=" (mixi-community-id community)))
1832 ;; FIXME: Support photos.
1834 (defun mixi-post-topic (community title content)
1835 "Post a topic to COMMUNITY."
1836 (unless (mixi-community-p community)
1837 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1838 (unless (stringp title)
1839 (signal 'wrong-type-argument (list 'stringp title)))
1840 (unless (stringp content)
1841 (signal 'wrong-type-argument (list 'stringp content)))
1842 (let ((fields `(("bbs_title" . ,title)
1843 ("bbs_body" . ,content)
1844 ("submit" . "main")))
1846 (with-mixi-post-form (mixi-post-topic-page community) fields
1847 (if (re-search-forward mixi-post-key-regexp nil t)
1848 (setq post-key (match-string 1))
1849 (mixi-post-error 'cannot-find-key community)))
1850 (setq fields `(("post_key" . ,post-key)
1851 ("bbs_title" . ,title)
1852 ("bbs_body" . ,content)
1853 ("submit" . "confirm")))
1854 (with-mixi-post-form (mixi-post-topic-page community) fields
1855 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1856 (mixi-post-error 'cannot-find-succeed community)))))
1859 (defvar mixi-event-cache (make-hash-table :test 'equal))
1860 (defun mixi-make-event (community id &optional comment-count time title owner
1861 date place detail limit members)
1862 "Return a event object."
1863 (mixi-make-cache (list (mixi-community-id community) id)
1864 (cons 'mixi-event (vector nil community id comment-count
1865 time title owner date place
1866 detail limit members))
1869 (defconst mixi-event-url-regexp
1870 "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1872 (defun mixi-make-event-from-url (url)
1873 "Return a event object from URL."
1874 (when (string-match mixi-event-url-regexp url)
1875 (let ((id (match-string 1 url))
1876 (comment-count (match-string 3 url))
1877 (community-id (match-string 4 url)))
1878 (mixi-make-event (mixi-make-community community-id) id comment-count))))
1880 (defmacro mixi-event-p (event)
1881 `(eq (mixi-object-class ,event) 'mixi-event))
1883 (defmacro mixi-event-page (event)
1884 `(concat "/view_event.pl?id=" (mixi-event-id ,event)
1885 "&comm_id=" (mixi-community-id (mixi-event-community ,event))))
1887 (defconst mixi-event-community-regexp
1888 "<td WIDTH=595 background=http://img\\.mixi\\.jp/img/bg_w\\.gif><b>\\[\\(.+\\)\\] ¥¤¥Ù¥ó¥È</b></td>")
1889 (defconst mixi-event-time-regexp
1890 "<td ROWSPAN=11 \\(BGCOLOR\\|bgcolor\\)=#FFD8B0 \\(ALIGN\\|align\\)=center \\(VALIGN\\|Valign\\)=top WIDTH=110>
1891 ?\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
1892 ?\\([0-9]+\\):\\([0-9]+\\)</td>")
1893 (defconst mixi-event-title-regexp
1894 "<td bgcolor=#FFF4E0\\( width=410\\)?> \\([^<]+\\)</td>")
1895 (defconst mixi-event-owner-regexp
1896 "<td \\(BGCOLOR\\|bgcolor\\)=#FDF9F2> <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>")
1897 (defconst mixi-event-owner-seceded-regexp
1898 "<td \\(BGCOLOR\\|bgcolor\\)=#FDF9F2> \\((mixi Âà²ñºÑ)\\)")
1899 (defconst mixi-event-date-regexp
1900 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>³«ºÅÆü»þ</td>
1901 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
1904 (defconst mixi-event-place-regexp
1905 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>³«ºÅ¾ì½ê</td>
1906 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
1909 (defconst mixi-event-detail-regexp
1910 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>¾ÜºÙ</td>
1911 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)><table BORDER=0 CELLSPACING=0 CELLPADDING=5><tr><td CLASS=h120>\\(.+\\)</td></tr></table></td>")
1912 (defconst mixi-event-limit-regexp
1913 "<td \\(BGCOLOR\\|bgcolor\\)=\"?#\\(FFFFFF\\|ffffff\\)\"? \\(ALIGN\\|align\\)=\"?center\"? NOWRAP>Ê罸´ü¸Â</td>
1914 ?<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)> \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
1915 (defconst mixi-event-members-regexp
1916 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>»²²Ã¼Ô</td>
1917 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
1920 ?<table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>
1923 ?<td> \\(.+\\)</td>")
1925 (defun mixi-realize-event (event &optional page)
1927 ;; FIXME: Check a expiration of cache?
1928 (unless (mixi-object-realized-p event)
1929 (with-mixi-retrieve (or page (mixi-event-page event))
1930 (if (re-search-forward mixi-event-community-regexp nil t)
1931 (mixi-community-set-name (mixi-event-community event)
1933 (mixi-realization-error 'cannot-find-community event))
1934 (if (re-search-forward mixi-event-time-regexp nil t)
1935 (mixi-event-set-time
1936 event (encode-time 0 (string-to-number (match-string 8))
1937 (string-to-number (match-string 7))
1938 (string-to-number (match-string 6))
1939 (string-to-number (match-string 5))
1940 (string-to-number (match-string 4))))
1941 (mixi-realization-error 'cannot-find-time event))
1942 (if (re-search-forward mixi-event-title-regexp nil t)
1943 (mixi-event-set-title event (match-string 2))
1944 (mixi-realization-error 'cannot-find-title event))
1945 (if (re-search-forward mixi-event-owner-regexp nil t)
1946 (mixi-event-set-owner event (mixi-make-friend (match-string 2)
1948 (if (re-search-forward mixi-event-owner-seceded-regexp nil t)
1949 (mixi-event-set-owner event
1950 (mixi-make-friend nil (match-string 2)))
1951 (mixi-realization-error 'cannot-find-owner event)))
1952 (if (re-search-forward mixi-event-date-regexp nil t)
1953 (mixi-event-set-date event (match-string 6))
1954 (mixi-realization-error 'cannot-find-date event))
1955 (if (re-search-forward mixi-event-place-regexp nil t)
1956 (mixi-event-set-place event (match-string 6))
1957 (mixi-realization-error 'cannot-find-place event))
1958 (if (re-search-forward mixi-event-detail-regexp nil t)
1959 (mixi-event-set-detail event (match-string 6))
1960 (mixi-realization-error 'cannot-find-detail event))
1961 (when (re-search-forward mixi-event-limit-regexp nil t)
1962 (mixi-event-set-limit
1963 event (encode-time 0 0 0 (string-to-number (match-string 8))
1964 (string-to-number (match-string 7))
1965 (string-to-number (match-string 6)))))
1966 (if (re-search-forward mixi-event-members-regexp nil t)
1967 (mixi-event-set-members event (match-string 6))
1968 (mixi-realization-error 'cannot-find-members event)))
1969 (mixi-object-touch event)))
1971 (defun mixi-event-community (event)
1972 "Return the community of EVENT."
1973 (unless (mixi-event-p event)
1974 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1975 (aref (cdr event) 1))
1977 (defun mixi-event-id (event)
1978 "Return the id of EVENT."
1979 (unless (mixi-event-p event)
1980 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1981 (aref (cdr event) 2))
1983 (defun mixi-event-comment-count (event)
1984 "Return the comment-count of EVENT."
1985 (unless (mixi-event-p event)
1986 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1987 (aref (cdr event) 3))
1989 (defun mixi-event-time (event)
1990 "Return the time of EVENT."
1991 (unless (mixi-event-p event)
1992 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1993 (mixi-realize-event event)
1994 (aref (cdr event) 4))
1996 (defun mixi-event-title (event)
1997 "Return the title of EVENT."
1998 (unless (mixi-event-p event)
1999 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2000 (mixi-realize-event event)
2001 (aref (cdr event) 5))
2003 (defun mixi-event-owner (event)
2004 "Return the owner of EVENT."
2005 (unless (mixi-event-p event)
2006 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2007 (mixi-realize-event event)
2008 (aref (cdr event) 6))
2010 (defun mixi-event-date (event)
2011 "Return the date of EVENT."
2012 (unless (mixi-event-p event)
2013 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2014 (mixi-realize-event event)
2015 (aref (cdr event) 7))
2017 (defun mixi-event-place (event)
2018 "Return the place of EVENT."
2019 (unless (mixi-event-p event)
2020 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2021 (mixi-realize-event event)
2022 (aref (cdr event) 8))
2024 (defun mixi-event-detail (event)
2025 "Return the detail of EVENT."
2026 (unless (mixi-event-p event)
2027 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2028 (mixi-realize-event event)
2029 (aref (cdr event) 9))
2031 (defun mixi-event-limit (event)
2032 "Return the limit of EVENT."
2033 (unless (mixi-event-p event)
2034 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2035 (mixi-realize-event event)
2036 (aref (cdr event) 10))
2038 (defun mixi-event-members (event)
2039 "Return the members of EVENT."
2040 (unless (mixi-event-p event)
2041 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2042 (mixi-realize-event event)
2043 (aref (cdr event) 11))
2045 (defun mixi-event-set-comment-count (event comment-count)
2046 "Set the comment-count of EVENT."
2047 (unless (mixi-event-p event)
2048 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2049 (aset (cdr event) 3 comment-count))
2051 (defun mixi-event-set-time (event time)
2052 "Set the time of EVENT."
2053 (unless (mixi-event-p event)
2054 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2055 (aset (cdr event) 4 time))
2057 (defun mixi-event-set-title (event title)
2058 "Set the title of EVENT."
2059 (unless (mixi-event-p event)
2060 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2061 (aset (cdr event) 5 title))
2063 (defun mixi-event-set-owner (event owner)
2064 "Set the owner of EVENT."
2065 (unless (mixi-event-p event)
2066 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2067 (unless (mixi-friend-p owner)
2068 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
2069 (aset (cdr event) 6 owner))
2071 (defun mixi-event-set-date (event date)
2072 "Set the date of EVENT."
2073 (unless (mixi-event-p event)
2074 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2075 (aset (cdr event) 7 date))
2077 (defun mixi-event-set-place (event place)
2078 "Set the place of EVENT."
2079 (unless (mixi-event-p event)
2080 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2081 (aset (cdr event) 8 place))
2083 (defun mixi-event-set-detail (event detail)
2084 "Set the detail of EVENT."
2085 (unless (mixi-event-p event)
2086 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2087 (aset (cdr event) 9 detail))
2089 (defun mixi-event-set-limit (event limit)
2090 "Set the limit of EVENT."
2091 (unless (mixi-event-p event)
2092 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2093 (aset (cdr event) 10 limit))
2095 (defun mixi-event-set-members (event members)
2096 "Set the members of EVENT."
2097 (unless (mixi-event-p event)
2098 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2099 (aset (cdr event) 11 members))
2102 (defconst mixi-bbs-list '(mixi-topic mixi-event))
2104 (defmacro mixi-bbs-p (bbs)
2105 `(memq (mixi-object-class ,bbs) mixi-bbs-list))
2107 (defun mixi-bbs-community (bbs)
2108 "Return the community of BBS."
2109 (unless (mixi-bbs-p bbs)
2110 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2111 (let ((func (intern (concat mixi-object-prefix
2112 (mixi-object-name bbs) "-community"))))
2113 (funcall func bbs)))
2115 (defun mixi-bbs-comment-count (bbs)
2116 "Return the comment-count of BBS."
2117 (unless (mixi-bbs-p bbs)
2118 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2119 (let ((func (intern (concat mixi-object-prefix
2120 (mixi-object-name bbs) "-comment-count"))))
2121 (funcall func bbs)))
2123 (defun mixi-bbs-set-comment-count (bbs count)
2124 "Set the comment-count of BBS."
2125 (unless (mixi-bbs-p bbs)
2126 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2127 (let ((func (intern (concat mixi-object-prefix
2128 (mixi-object-name bbs) "-set-comment-count"))))
2129 (funcall func bbs count)))
2131 (defalias 'mixi-bbs-id 'mixi-object-id)
2132 (defalias 'mixi-bbs-time 'mixi-object-time)
2133 (defalias 'mixi-bbs-title 'mixi-object-title)
2134 (defalias 'mixi-bbs-owner 'mixi-object-owner)
2135 (defalias 'mixi-bbs-content 'mixi-object-content)
2137 (defmacro mixi-bbs-list-page (community)
2138 `(concat "/list_bbs.pl?page=%d"
2139 "&id=" (mixi-community-id ,community)))
2141 (defconst mixi-bbs-list-regexp
2142 "<a href=view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)")
2145 (defun mixi-get-bbses (community &optional range)
2146 "Get bbese of COMMUNITY."
2147 (unless (mixi-community-p community)
2148 (signal 'wrong-type-argument (list 'mixi-community-p community)))
2149 (let ((items (mixi-get-matched-items (mixi-bbs-list-page community)
2150 mixi-bbs-list-regexp
2152 (mapcar (lambda (item)
2153 (let ((name (nth 0 item)))
2154 (when (string= name "bbs")
2155 (setq name "topic"))
2156 (let ((func (intern (concat "mixi-make-" name))))
2157 (funcall func community (nth 1 item)))))
2160 (defmacro mixi-new-bbs-list-page ()
2161 `(concat "/new_bbs.pl?page=%d"))
2163 (defconst mixi-new-bbs-list-regexp
2164 "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\" class=\"new_link\">")
2167 (defun mixi-get-new-bbses (&optional range)
2169 (let ((items (mixi-get-matched-items (mixi-new-bbs-list-page)
2170 mixi-new-bbs-list-regexp
2173 (mapcar (lambda (item)
2174 (let ((name (nth 0 item)))
2175 (when (string= name "bbs")
2176 (setq name "topic"))
2177 (let* ((func (intern (concat "mixi-make-" name)))
2179 (mixi-make-community (nth 3 item))
2181 (comment-count (mixi-bbs-comment-count bbs))
2182 (count (string-to-number (nth 2 item))))
2183 (when (or (null comment-count)
2184 (< comment-count count))
2185 (mixi-bbs-set-comment-count bbs count)
2189 (defmacro mixi-search-bbs-list-page (keyword)
2190 `(concat "/search_topic.pl?page=%d&type=top&submit=search"
2191 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
2192 "&community_id=0&category_id=0"))
2194 (defconst mixi-search-bbs-list-regexp
2195 "<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>")
2197 ;; FIXME: Support community and category.
2199 (defun mixi-search-bbses (keyword &optional range)
2200 (let ((items (mixi-get-matched-items (mixi-search-bbs-list-page keyword)
2201 mixi-search-bbs-list-regexp
2203 (mapcar (lambda (item)
2204 (let ((name (nth 0 item)))
2205 (when (string= name "bbs")
2206 (setq name "topic"))
2207 (let ((func (intern (concat "mixi-make-" name))))
2208 (funcall func (mixi-make-community (nth 2 item))
2213 (defmacro mixi-parent-p (object)
2214 `(or (eq (mixi-object-class ,object) 'mixi-diary)
2215 (mixi-bbs-p ,object)))
2217 (defun mixi-realize-parent (parent &optional page)
2219 (unless (mixi-parent-p parent)
2220 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2221 (let ((func (intern (concat mixi-object-prefix "realize-"
2222 (mixi-object-name parent)))))
2223 (funcall func parent page)))
2226 (defun mixi-make-comment (parent owner time content)
2227 "Return a comment object."
2228 (cons 'mixi-comment (vector parent owner time content)))
2230 (defmacro mixi-comment-p (comment)
2231 `(eq (mixi-object-class ,comment) 'mixi-comment))
2233 (defun mixi-comment-parent (comment)
2234 "Return the parent of COMMENT."
2235 (unless (mixi-comment-p comment)
2236 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2237 (aref (cdr comment) 0))
2239 (defun mixi-comment-owner (comment)
2240 "Return the owner of COMMENT."
2241 (unless (mixi-comment-p comment)
2242 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2243 (aref (cdr comment) 1))
2245 (defun mixi-comment-time (comment)
2246 "Return the time of COMMENT."
2247 (unless (mixi-comment-p comment)
2248 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2249 (aref (cdr comment) 2))
2251 (defun mixi-comment-content (comment)
2252 "Return the content of COMMENT."
2253 (unless (mixi-comment-p comment)
2254 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2255 (aref (cdr comment) 3))
2257 (defun mixi-diary-comment-list-page (diary)
2258 (concat "/view_diary.pl?full=1"
2259 "&id=" (mixi-diary-id diary)
2260 "&owner_id=" (mixi-friend-id (mixi-diary-owner diary))))
2262 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2263 (defconst mixi-diary-comment-list-regexp
2264 "<td rowspan=\"2\" align=\"center\" width=\"95\" bgcolor=\"#f2ddb7\" nowrap>
2265 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)\\(<br>
2266 <input type=checkbox name=comment_id value=\".+\">
2269 <td ALIGN=center BGCOLOR=#FDF9F2 WIDTH=430>
2270 <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"410\">
2273 <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2275 \\(<font color=\"#f2ddb7\">|</font> <a href=[^>]+>ºï½ü</a>
2282 <!-- [^ ]+ : start -->
2284 <td bgcolor=\"#ffffff\">
2285 <table BORDER=0 CELLSPACING=0 CELLPADDING=[35] WIDTH=410>
2289 </td></tr></table>")
2291 (defun mixi-topic-comment-list-page (topic)
2292 (concat "/view_bbs.pl?page=all"
2293 "&id=" (mixi-topic-id topic)
2294 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2296 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2297 (defconst mixi-topic-comment-list-regexp
2298 "<tr valign=\"top\">
2299 <td rowspan=\"2\" width=\"110\" bgcolor=\"#f2ddb7\" align=\"center\" nowrap>
2300 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
2301 \\([0-9]+\\):\\([0-9]+\\)<br>
2302 \\(<input type=\"checkbox\" name=\"comment_id\" value=\".+\">
2304 <td bgcolor=\"#fdf9f2\"> <font color=\"#f8a448\">
2305 <b>[^<]+</b>:</font>
2307 \\|\\) *<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2311 \\|<font color=\"#f2ddb7\">| </font><a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+\">ºï½ü</a>
2315 <td bgcolor=\"#ffffff\" align=\"center\">
2316 <table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" width=\"500\">
2327 (defun mixi-event-comment-list-page (event)
2328 (concat "/view_event.pl?page=all"
2329 "&id=" (mixi-event-id event)
2330 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2332 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2333 (defconst mixi-event-comment-list-regexp
2335 <td ROWSPAN=2 ALIGN=center BGCOLOR=#F2DDB7 WIDTH=110>
2336 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
2337 \\([0-9]+\\):\\([0-9]+\\)<br>
2339 \\(<td BGCOLOR=#FDF9F2>\\)
2340 <font COLOR=#F8A448><b>[^<]+</b> :</font>
2341 <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2343 \\(<font COLOR=#F2DDB7>|</font>
2344 <a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+&type=event\">ºï½ü</a>
2349 <td ALIGN=center BGCOLOR=#FFFFFF>
2350 <table BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=500>
2351 <tr><td CLASS=h120>\\(.+\\)</td></tr>
2357 (defun mixi-get-comments (parent &optional range)
2358 "Get comments of PARENT."
2359 (unless (mixi-parent-p parent)
2360 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2361 (let* ((name (mixi-object-name parent))
2362 (list-page (intern (concat mixi-object-prefix name
2363 "-comment-list-page")))
2364 (regexp (eval (intern (concat mixi-object-prefix name
2365 "-comment-list-regexp"))))
2366 (page (funcall list-page parent)))
2367 (unless (mixi-object-realized-p parent)
2368 (mixi-realize-parent parent page)
2370 (let ((items (mixi-get-matched-items page regexp range t)))
2371 (mapcar (lambda (item)
2372 (mixi-make-comment parent (mixi-make-friend
2373 (nth 7 item) (nth 8 item))
2376 (string-to-number (nth 4 item))
2377 (string-to-number (nth 3 item))
2378 (string-to-number (nth 2 item))
2379 (string-to-number (nth 1 item))
2380 (string-to-number (nth 0 item)))
2384 (defmacro mixi-new-comment-list-page ()
2385 `(concat "/new_comment.pl?page=%d"))
2387 (defconst mixi-new-comment-list-regexp
2388 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)\" class=\"new_link\">")
2391 (defun mixi-get-new-comments (&optional range)
2393 (let ((items (mixi-get-matched-items (mixi-new-comment-list-page)
2394 mixi-new-comment-list-regexp
2397 (mapcar (lambda (item)
2398 (let* ((diary (mixi-make-diary
2399 (mixi-make-friend (nth 1 item))
2401 (comment-count (mixi-diary-comment-count diary))
2402 (count (string-to-number (nth 2 item))))
2403 (when (or (null comment-count)
2404 (< comment-count count))
2405 (mixi-diary-set-comment-count diary count)
2409 (defun mixi-post-diary-comment-page (diary)
2410 (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
2412 (defun mixi-post-topic-comment-page (topic)
2413 (concat "/add_bbs_comment.pl?id=" (mixi-topic-id topic)
2414 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2416 (defun mixi-post-event-comment-page (event)
2417 (concat "/add_event_comment.pl?id=" (mixi-event-id event)
2418 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2420 ;; FIXME: Support photos.
2422 (defun mixi-post-comment (parent content)
2423 "Post a comment to PARENT."
2424 (unless (mixi-object-p parent)
2425 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
2426 (unless (stringp content)
2427 (signal 'wrong-type-argument (list 'stringp content)))
2428 (let* ((name (mixi-object-name parent))
2429 (page (intern (concat mixi-object-prefix "post-" name
2432 (if (mixi-diary-p parent)
2434 `(("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2435 ("comment_body" . ,content)))
2436 (setq fields `(("comment" . ,content))))
2437 (with-mixi-post-form (funcall page parent) fields
2438 (if (re-search-forward mixi-post-key-regexp nil t)
2439 (setq post-key (match-string 1))
2440 (mixi-post-error 'cannot-find-key parent)))
2441 (if (mixi-diary-p parent)
2443 `(("post_key" . ,post-key)
2444 ("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2445 ("comment_body" . ,content)
2446 ("submit" . "confirm")))
2447 (setq fields `(("post_key" . ,post-key)
2448 ("comment" . ,content)
2449 ("submit" . "confirm"))))
2450 (with-mixi-post-form (funcall page parent) fields
2451 (unless (re-search-forward mixi-post-succeed-regexp nil t)
2452 (mixi-post-error 'cannot-find-succeed parent)))))
2455 (defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
2457 (defmacro mixi-message-box-p (box)
2458 `(memq ,box mixi-message-box-list))
2460 (defun mixi-message-box-name (box)
2461 "Return the name of BOX."
2462 (unless (mixi-message-box-p box)
2463 (signal 'wrong-type-argument (list 'mixi-message-box-p box)))
2466 (defvar mixi-message-cache (make-hash-table :test 'equal))
2467 (defun mixi-make-message (id box &optional owner title time content)
2468 "Return a message object."
2469 (mixi-make-cache (list id box)
2470 (cons 'mixi-message (vector nil id box owner title time
2472 mixi-message-cache))
2474 (defconst mixi-message-url-regexp
2475 "/view_message\\.pl\\?id=\\([a-z0-9]+\\)&box=\\([a-z]+\\)")
2477 (defun mixi-make-message-from-url (url)
2478 "Return a message object from URL."
2479 (when (string-match mixi-message-url-regexp url)
2480 (let ((id (match-string 1 url))
2481 (box (match-string 2 url)))
2482 (mixi-make-message id box))))
2484 (defmacro mixi-message-p (message)
2485 `(eq (mixi-object-class ,message) 'mixi-message))
2487 (defmacro mixi-message-page (message)
2488 `(concat "/view_message.pl?id=" (mixi-message-id ,message)
2489 "&box=" (mixi-message-box ,message)))
2491 (defconst mixi-message-owner-regexp
2492 "<font COLOR=#996600>\\(º¹½Ð¿Í\\|°¸ Àè\\)</font> : <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)\\(</a>\\|</td>\\)")
2493 (defconst mixi-message-time-regexp
2494 "<font COLOR=#996600>Æü\\(¡¡\\| \\)ÉÕ</font> : \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ ")
2495 (defconst mixi-message-title-regexp
2496 "<font COLOR=#996600>·ï\\(¡¡\\| \\)̾</font> : \\(.*\\)\n?</td>")
2497 (defconst mixi-message-content-regexp
2498 "<tr><td CLASS=h120>\\(.*\\)</td></tr>")
2500 (defun mixi-realize-message (message)
2501 "Realize a MESSAGE."
2502 (unless (mixi-object-realized-p message)
2503 (with-mixi-retrieve (mixi-message-page message)
2504 (if (re-search-forward mixi-message-owner-regexp nil t)
2505 (mixi-message-set-owner message
2506 (mixi-make-friend (match-string 2)
2508 (mixi-realization-error 'cannot-find-owner message))
2509 (if (re-search-forward mixi-message-time-regexp nil t)
2510 (mixi-message-set-time
2511 message (encode-time 0 (string-to-number (match-string 6))
2512 (string-to-number (match-string 5))
2513 (string-to-number (match-string 4))
2514 (string-to-number (match-string 3))
2515 (string-to-number (match-string 2))))
2516 (mixi-realization-error 'cannot-find-time message))
2517 (if (re-search-forward mixi-message-title-regexp nil t)
2518 (mixi-message-set-title message (match-string 2))
2519 (mixi-realization-error 'cannot-find-title message))
2520 (if (re-search-forward mixi-message-content-regexp nil t)
2521 (mixi-message-set-content message (match-string 1))
2522 (mixi-realization-error 'cannot-find-content message)))
2523 (mixi-object-touch message)))
2525 (defun mixi-message-id (message)
2526 "Return the id of MESSAGE."
2527 (unless (mixi-message-p message)
2528 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2529 (aref (cdr message) 1))
2531 (defun mixi-message-box (message)
2532 "Return the box of MESSAGE."
2533 (unless (mixi-message-p message)
2534 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2535 (aref (cdr message) 2))
2537 (defun mixi-message-owner (message)
2538 "Return the owner of MESSAGE."
2539 (unless (mixi-message-p message)
2540 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2541 (mixi-realize-message message)
2542 (aref (cdr message) 3))
2544 (defun mixi-message-title (message)
2545 "Return the title of MESSAGE."
2546 (unless (mixi-message-p message)
2547 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2548 (mixi-realize-message message)
2549 (aref (cdr message) 4))
2551 (defun mixi-message-time (message)
2552 "Return the date of MESSAGE."
2553 (unless (mixi-message-p message)
2554 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2555 (mixi-realize-message message)
2556 (aref (cdr message) 5))
2558 (defun mixi-message-content (message)
2559 "Return the content of MESSAGE."
2560 (unless (mixi-message-p message)
2561 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2562 (mixi-realize-message message)
2563 (aref (cdr message) 6))
2565 (defun mixi-message-set-owner (message owner)
2566 "Set the owner of MESSAGE."
2567 (unless (mixi-message-p message)
2568 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2569 (aset (cdr message) 3 owner))
2571 (defun mixi-message-set-title (message title)
2572 "Set the title of MESSAGE."
2573 (unless (mixi-message-p message)
2574 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2575 (aset (cdr message) 4 title))
2577 (defun mixi-message-set-time (message time)
2578 "Set the date of MESSAGE."
2579 (unless (mixi-message-p message)
2580 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2581 (aset (cdr message) 5 time))
2583 (defun mixi-message-set-content (message content)
2584 "Set the content of MESSAGE."
2585 (unless (mixi-message-p message)
2586 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2587 (aset (cdr message) 6 content))
2589 (defmacro mixi-message-list-page (&optional box)
2590 `(concat "/list_message.pl?page=%d"
2591 (when ,box (concat "&box=" ,box))))
2593 (defconst mixi-message-list-regexp
2594 "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
2597 (defun mixi-get-messages (&rest box-or-range)
2598 "Get messages of BOX."
2599 (when (> (length box-or-range) 2)
2600 (signal 'wrong-number-of-arguments
2601 (list 'mixi-get-messages (length box-or-range))))
2602 (let ((box (nth 0 box-or-range))
2603 (range (nth 1 box-or-range)))
2604 (when (or (not (mixi-message-box-p box))
2605 (mixi-message-box-p range))
2606 (setq box (nth 1 box-or-range))
2607 (setq range (nth 0 box-or-range)))
2608 (let ((items (mixi-get-matched-items
2609 (mixi-message-list-page
2610 (when box (mixi-message-box-name box)))
2611 mixi-message-list-regexp
2613 (mapcar (lambda (item)
2614 (mixi-make-message (nth 0 item) (nth 1 item)))
2617 (defmacro mixi-post-message-page (friend)
2618 `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
2620 (defconst mixi-post-message-key-regexp
2621 "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
2623 (defconst mixi-post-message-succeed-regexp
2624 "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
2627 (defun mixi-post-message (friend title content)
2628 "Post a message to FRIEND."
2629 (unless (mixi-friend-p friend)
2630 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2631 (unless (stringp title)
2632 (signal 'wrong-type-argument (list 'stringp title)))
2633 (unless (stringp content)
2634 (signal 'wrong-type-argument (list 'stringp content)))
2635 (let ((fields `(("subject" . ,title)
2637 ("submit" . "main")))
2639 (with-mixi-post-form (mixi-post-message-page friend) fields
2640 (if (re-search-forward mixi-post-message-key-regexp nil t)
2641 (setq post-key (match-string 1))
2642 (mixi-post-error 'cannot-find-key friend)))
2643 (setq fields `(("post_key" . ,post-key)
2644 ("subject" . ,title)
2646 ("yes" . "¡¡Á÷¡¡¿®¡¡")
2647 ("submit" . "confirm")))
2648 (with-mixi-post-form (mixi-post-message-page friend) fields
2649 (unless (re-search-forward mixi-post-message-succeed-regexp nil t)
2650 (mixi-post-error 'cannot-find-succeed friend)))))
2652 ;; Introduction object.
2653 (defun mixi-make-introduction (parent owner content)
2654 "Return a introduction object."
2655 (cons 'mixi-introduction (vector parent owner content)))
2657 (defmacro mixi-introduction-p (introduction)
2658 `(eq (mixi-object-class ,introduction) 'mixi-introduction))
2660 (defun mixi-introduction-parent (introduction)
2661 "Return the parent of INTRODUCTION."
2662 (unless (mixi-introduction-p introduction)
2663 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2664 (aref (cdr introduction) 0))
2666 (defun mixi-introduction-owner (introduction)
2667 "Return the owner of INTRODUCTION."
2668 (unless (mixi-introduction-p introduction)
2669 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2670 (aref (cdr introduction) 1))
2672 (defun mixi-introduction-content (introduction)
2673 "Return the content of INTRODUCTION."
2674 (unless (mixi-introduction-p introduction)
2675 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2676 (aref (cdr introduction) 3))
2678 (defmacro mixi-introduction-list-page (&optional friend)
2679 `(concat "/show_intro.pl?page=%d"
2680 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
2682 (defconst mixi-introduction-list-regexp
2683 "<tr bgcolor=#FFFFFF>
2684 <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>
2691 \\(\\(.\\|\n<br>\\)+\\)\\|
2692 \\(\\(.\\|\n<br>\\)+\\)\\)
2699 (defconst mixi-my-introduction-list-regexp
2700 "<tr bgcolor=#FFFFFF>
2701 <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>
2709 \\(\\(.\\|\n<br>\\)+\\)\\|
2710 \\(\\(.\\|\n<br>\\)+\\)\\)
2714 <a href=\"edit_intro\\.pl\\?id=\\1&type=edit\">¤³¤Îͧ¿Í¤ò¾Ò²ð¤¹¤ë</a>
2718 <a href=\"delete_intro\\.pl\\?id=\\1\">ºï½ü</a>
2724 (defun mixi-get-introductions (&rest friend-or-range)
2725 "Get introductions of FRIEND."
2726 (when (> (length friend-or-range) 2)
2727 (signal 'wrong-number-of-arguments
2728 (list 'mixi-get-introduction (length friend-or-range))))
2729 (let ((friend (nth 0 friend-or-range))
2730 (range (nth 1 friend-or-range)))
2731 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
2732 (setq friend (nth 1 friend-or-range))
2733 (setq range (nth 0 friend-or-range)))
2734 (unless (or (null friend) (mixi-friend-p friend))
2735 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2736 (let* ((regexp (if friend mixi-introduction-list-regexp
2737 mixi-my-introduction-list-regexp))
2738 (items (mixi-get-matched-items (mixi-introduction-list-page friend)
2741 (mapcar (lambda (item)
2742 (mixi-make-introduction (or friend (mixi-make-me))
2743 (mixi-make-friend (nth 0 item)
2749 (defvar mixi-news-cache (make-hash-table :test 'equal))
2750 (defun mixi-make-news (media-id id &optional media time title content)
2751 "Return a news object."
2752 (mixi-make-cache (list media-id id)
2753 (cons 'mixi-news (vector nil media-id id media time title
2757 (defconst mixi-news-url-regexp
2758 "/view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)")
2760 (defun mixi-make-news-from-url (url)
2761 "Return a news object from URL."
2762 (when (string-match mixi-news-url-regexp url)
2763 (let ((id (match-string 1 url))
2764 (media-id (match-string 2 url)))
2765 (mixi-make-news media-id id))))
2767 (defmacro mixi-news-p (news)
2768 `(eq (mixi-object-class ,news) 'mixi-news))
2770 (defmacro mixi-news-page (news)
2771 `(concat "http://news.mixi.jp/view_news.pl?id=" (mixi-news-id ,news)
2772 "&media_id=" (mixi-news-media-id ,news)))
2775 (defconst mixi-news-finished-regexp
2776 "<td ALIGN=center background=http://img\\.mixi\\.jp/img/bg_line\\.gif> ¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤³¤Î¥Ë¥å¡¼¥¹¤Ï·ÇºÜ½ªÎ»¤·¤Þ¤·¤¿¡£</td>")
2777 (defconst mixi-news-title-regexp
2778 "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)\\(
\r
2780 (defconst mixi-news-media-time-regexp
2781 "<td COLSPAN=\"2\" ALIGN=\"right\">(\\(.+\\) - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))</td></tr>")
2782 (defconst mixi-news-content-regexp
2783 "<td CLASS=\"h150\">
2790 \\(</td>\\|<br>\\)")
2792 (defun mixi-realize-news (news)
2794 ;; FIXME: Check a expiration of cache?
2795 (unless (mixi-object-realized-p news)
2796 (with-mixi-retrieve (mixi-news-page news)
2797 (if (re-search-forward mixi-news-finished-regexp nil t)
2798 (mixi-news-set-content news (match-string 0))
2799 (if (re-search-forward mixi-news-title-regexp nil t)
2800 (mixi-news-set-title news (match-string 1))
2801 (mixi-realization-error 'cannot-find-title news))
2802 (if (re-search-forward mixi-news-media-time-regexp nil t)
2804 (mixi-news-set-media news (match-string 1))
2805 (let ((year (nth 5 (decode-time (current-time))))
2806 (month (nth 4 (decode-time (current-time))))
2807 (month-of-item (string-to-number (match-string 2))))
2808 (when (> month-of-item month)
2811 news (encode-time 0 (string-to-number (match-string 5))
2812 (string-to-number (match-string 4))
2813 (string-to-number (match-string 3))
2815 (mixi-realization-error 'cannot-find-media-time news))
2816 (if (re-search-forward mixi-news-content-regexp nil t)
2817 (mixi-news-set-content news (match-string 1))
2818 (mixi-realization-error 'cannot-find-content news))))
2819 (mixi-object-touch news)))
2821 (defun mixi-news-media-id (news)
2822 "Return the media-id of NEWS."
2823 (unless (mixi-news-p news)
2824 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2825 (aref (cdr news) 1))
2827 (defun mixi-news-id (news)
2828 "Return the id of NEWS."
2829 (unless (mixi-news-p news)
2830 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2831 (aref (cdr news) 2))
2833 (defun mixi-news-media (news)
2834 "Return the media of NEWS."
2835 (unless (mixi-news-p news)
2836 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2837 (unless (aref (cdr news) 3)
2838 (mixi-realize-news news))
2839 (aref (cdr news) 3))
2841 (defun mixi-news-time (news)
2842 "Return the time of NEWS."
2843 (unless (mixi-news-p news)
2844 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2845 (unless (aref (cdr news) 4)
2846 (mixi-realize-news news))
2847 (aref (cdr news) 4))
2849 (defun mixi-news-title (news)
2850 "Return the title of NEWS."
2851 (unless (mixi-news-p news)
2852 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2853 (unless (aref (cdr news) 5)
2854 (mixi-realize-news news))
2855 (aref (cdr news) 5))
2857 (defun mixi-news-content (news)
2858 "Return the content of NEWS."
2859 (unless (mixi-news-p news)
2860 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2861 (mixi-realize-news news)
2862 (aref (cdr news) 6))
2864 (defun mixi-news-set-media (news media)
2865 "Set the media of NEWS."
2866 (unless (mixi-news-p news)
2867 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2868 (aset (cdr news) 3 media))
2870 (defun mixi-news-set-time (news time)
2871 "Set the time of NEWS."
2872 (unless (mixi-news-p news)
2873 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2874 (aset (cdr news) 4 time))
2876 (defun mixi-news-set-title (news title)
2877 "Set the title of NEWS."
2878 (unless (mixi-news-p news)
2879 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2880 (aset (cdr news) 5 title))
2882 (defun mixi-news-set-content (news content)
2883 "Set the content of NEWS."
2884 (unless (mixi-news-p news)
2885 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2886 (aset (cdr news) 6 content))
2888 (defconst mixi-news-category-list '(domestic politics economy area abroad
2889 sports entertainment IT))
2891 (defmacro mixi-news-category-p (category)
2892 `(memq ,category mixi-news-category-list))
2894 (defun mixi-news-category-id (category)
2895 "Return the id of CATEGORY."
2896 (unless (mixi-news-category-p category)
2897 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2899 (1+ (- (length mixi-news-category-list)
2900 (length (memq category mixi-news-category-list))))))
2902 (defconst mixi-news-sort-list '(newest pickup))
2904 (defmacro mixi-news-sort-p (sort)
2905 `(memq ,sort mixi-news-sort-list))
2907 (defun mixi-news-sort-id (sort)
2908 "Return the id of SORT."
2909 (unless (mixi-news-sort-p sort)
2910 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
2912 (- (length mixi-news-sort-list)
2913 (length (memq sort mixi-news-sort-list)))))
2915 (defmacro mixi-news-list-page (category sort)
2916 `(concat "http://news.mixi.jp/list_news_category.pl?page=%d"
2917 "&sort=" (mixi-news-sort-id ,sort)
2918 "&id=" (mixi-news-category-id ,category)
2921 (defconst mixi-news-list-regexp
2922 "<tr bgcolor=\"\\(#FCF5EB\\|#FFFFFF\\)\">
2923 <td WIDTH=\"1%\" valign=top CLASS=\"h120\">¡¦</td>
2924 <td WIDTH=\"97%\" CLASS=\"h120\"><A HREF=\"view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)\"class=\"new_link\">\\(.+\\)</A>
2925 \\(<IMG SRC=\"http://img\\.mixi\\.jp/img/news_camera3\\.gif\" WIDTH=\"11\" HEIGHT=\"12\">\\|\\)
2928 <td WIDTH=\"1%\" nowrap CLASS=\"f08\"><A HREF=\"list_news_media\\.pl\\?id=[0-9]+\">\\(.+\\)</A></td>
2929 <td WIDTH=\"1%\" nowrap CLASS=\"f08\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td></tr>")
2932 (defun mixi-get-news (category sort &optional range)
2933 "Get news of CATEGORY and SORT."
2934 (unless (mixi-news-category-p category)
2935 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2936 (unless (mixi-news-sort-p sort)
2937 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
2938 (let ((items (mixi-get-matched-items (mixi-news-list-page category sort)
2939 mixi-news-list-regexp
2941 (year (nth 5 (decode-time (current-time))))
2942 (month (nth 4 (decode-time (current-time)))))
2943 (mapcar (lambda (item)
2944 (let ((month-of-item (string-to-number (nth 6 item))))
2945 (when (> month-of-item month)
2947 (setq month month-of-item)
2948 (mixi-make-news (nth 2 item) (nth 1 item) (nth 5 item)
2950 0 (string-to-number (nth 9 item))
2951 (string-to-number (nth 8 item))
2952 (string-to-number (nth 7 item))
2959 ;;; mixi.el ends here