1 ;; mixi.el --- API libraries for accessing to mixi -*- coding: euc-jp -*-
3 ;; Copyright (C) 2005, 2006, 2007, 2008 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 GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;; APIs for getting contents:
30 ;; * mixi-get-favorites
32 ;; * mixi-get-recommended-friends (indies)
34 ;; * mixi-get-new-diaries
35 ;; * mixi-search-diaries
36 ;; * mixi-get-communities
37 ;; * mixi-search-communities
38 ;; * mixi-get-recommended-communities (indies)
40 ;; * mixi-get-new-bbses
41 ;; * mixi-search-bbses
42 ;; * mixi-get-comments
43 ;; * mixi-get-new-comments
44 ;; * mixi-get-new-bbs-comments
45 ;; * mixi-get-messages
46 ;; * mixi-get-introductions (broken)
53 ;; * mixi-post-comment
54 ;; * mixi-post-message
58 ;; * mixi-remove-markup (half broken)
62 ;; Display newest 3 diaries like a mail format.
65 ;; (buffer (get-buffer-create "*temp*"))
66 ;; (format "%Y/%m/%d %H:%M"))
67 ;; (pop-to-buffer buffer)
68 ;; (let ((diaries (mixi-get-new-diaries range)))
70 ;; (let* ((diary (car diaries))
71 ;; (subject (mixi-diary-title diary))
72 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
73 ;; (date (format-time-string format (mixi-diary-time diary)))
74 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
75 ;; (insert "From: " from "\n"
76 ;; "Subject: " subject "\n"
77 ;; "Date: " date "\n\n"
79 ;; (setq diaries (cdr diaries))))
80 ;; (set-buffer-modified-p nil)
81 ;; (setq buffer-read-only t)
82 ;; (goto-char (point-min)))
84 ;; Display newest 3 diaries including newest 3 comments like a mail format.
85 ;; Comments are displayed like a reply mail.
88 ;; (buffer (get-buffer-create "*temp*"))
89 ;; (format "%Y/%m/%d %H:%M"))
90 ;; (pop-to-buffer buffer)
91 ;; (let ((diaries (mixi-get-new-diaries range)))
93 ;; (let* ((diary (car diaries))
94 ;; (subject (mixi-diary-title diary))
95 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
96 ;; (date (format-time-string format (mixi-diary-time diary)))
97 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
98 ;; (insert "From: " from "\n"
99 ;; "Subject: " subject "\n"
100 ;; "Date: " date "\n\n"
102 ;; (let ((comments (mixi-get-comments diary range)))
104 ;; (let* ((comment (car comments))
105 ;; (from (mixi-friend-nick (mixi-comment-owner comment)))
106 ;; (subject (concat "Re: " subject))
107 ;; (date (format-time-string format
108 ;; (mixi-comment-time comment)))
109 ;; (body (mixi-remove-markup (mixi-comment-content comment))))
110 ;; (insert "From: " from "\n"
111 ;; "Subject: " subject "\n"
112 ;; "Date: " date "\n\n"
114 ;; (setq comments (cdr comments)))))
115 ;; (setq diaries (cdr diaries))))
116 ;; (set-buffer-modified-p nil)
117 ;; (setq buffer-read-only t)
118 ;; (goto-char (point-min)))
122 ;; If you have bug reports and/or suggestions for improvement, please
123 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
127 (eval-when-compile (require 'cl))
129 ;; Functions and variables which should be defined in the other module
132 (defvar w3m-use-cookies)
133 (defvar url-request-method)
134 (defvar url-request-data)
135 (defvar url-request-extra-headers)
136 (defvar url-show-status)
137 (autoload 'w3m-decode-buffer "w3m")
138 (autoload 'w3m-retrieve "w3m")
139 (autoload 'url-retrieve-synchronously "url"))
141 (defconst mixi-revision "$Revision: 1.182 $")
144 "API library for accessing to mixi."
147 (defcustom mixi-url "http://mixi.jp"
152 (defcustom mixi-directory (expand-file-name "~/.mixi")
153 "*Where to look for mixi files."
157 (defcustom mixi-coding-system 'euc-jp
158 "*Coding system for mixi."
162 (defcustom mixi-curl-program "curl"
163 "*The program name of `curl'."
167 (defcustom mixi-curl-cookie-file (expand-file-name "cookies.txt"
169 "*The location of cookie file created by `curl'."
173 (defcustom mixi-backend
174 (or (condition-case nil
182 (if (fboundp 'url-retrieve-synchronously)
185 (if (and (fboundp 'executable-find)
186 (executable-find mixi-curl-program))
188 (error "Cannot set `mixi-backend'."))
189 "*The backend for accessing to mixi."
190 :type '(radio (const :tag "Use emacs-w3m" w3m)
191 (const :tag "Use url.el" url)
192 (const :tag "Use curl" curl)
193 (symbol :tag "The other backend"))
196 (defcustom mixi-login-use-ssl nil
197 "*If non-ni, login using SSL."
201 (defcustom mixi-default-email nil
202 "*Default E-mail address that is used to login automatically."
203 :type '(radio (string :tag "E-mail address")
204 (const :tag "Asked when it is necessary" nil))
207 (defcustom mixi-default-password nil
208 "*Default password that is used to login automatically."
209 :type '(radio (string :tag "Password")
210 (const :tag "Asked when it is necessary" nil))
213 (defcustom mixi-accept-adult-contents t
214 "*If non-nil, accept to access to the adult contents."
218 (defcustom mixi-continuously-access-interval 4.0
219 "*Time interval between each mixi access.
220 Increase this value when unexpected error frequently occurs."
224 (defcustom mixi-cache-expires nil
225 "*Seconds for expiration of a cached object."
226 :type '(radio (integer :tag "Expired seconds")
227 (const :tag "Don't expire" nil)
228 (const :tag "Don't cache" t))
231 ;; FIXME: Not implemented.
232 (defcustom mixi-cache-use-file t
233 "*If non-nil, caches are saved to files."
237 (defvar mixi-temp-buffer-name " *mixi temp*")
241 (defmacro mixi-message (&rest strings)
242 `(concat "[mixi] " ,@strings))
244 (put 'mixi-realization-error
245 'error-message (mixi-message "Cannot realize object"))
246 (put 'mixi-realization-error
247 'error-conditions '(mixi-realization-error error))
249 (put 'mixi-post-error
250 'error-message (mixi-message "Cannot post"))
251 (put 'mixi-post-error
252 'error-conditions '(mixi-post-error error))
254 (defmacro mixi-realization-error (type object)
255 `(let ((data (if debug-on-error
256 (list ,type ,object (buffer-string))
257 (list ,type ,object))))
258 (signal 'mixi-realization-error data)))
260 (defmacro mixi-post-error (type &optional object)
261 `(let ((data (when debug-on-error (list (buffer-string)))))
263 (setq data (cons ,type (cons ,object data)))
264 (setq data (cons ,type data)))
265 (signal 'mixi-post-error data)))
267 (defconst mixi-message-adult-contents
268 "¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
269 ±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
270 (defconst mixi-message-continuously-accessing
271 "°ÂÄꤷ¤Æ¥µ¥¤¥È¤Î±¿±Ä¤ò¤ª¤³¤Ê¤¦°Ù¡¢´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹<br>
272 ¿·¤ÏÀ©¸Â¤µ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤ª¤ê¤Þ¤¹¡£¤´ÌÂÏǤò¤ª¤«¤±¤¤¤¿¤·¤Þ¤¹¤¬¡¢¤·¤Ð¤é¤¯¤ª<br>
273 ÂÔ¤Á¤¤¤¿¤À¤¤¤Æ¤«¤éÁàºî¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£")
274 (defconst mixi-warning-continuously-accessing
275 "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«<br>
276 ¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ<br>
277 ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
279 (defmacro mixi-retrieve (url &optional post-data)
280 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-retrieve"))
283 (defmacro mixi-post-form (url fields)
284 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-post-form"))
287 (defun mixi-parse-buffer (url buffer &optional post-data)
288 (when (string-match mixi-message-adult-contents buffer)
289 (if mixi-accept-adult-contents
290 (setq buffer (mixi-retrieve url "submit=agree"))
291 (setq buffer (mixi-retrieve (concat url "?")))))
292 (when (string-match mixi-warning-continuously-accessing buffer)
293 (error (mixi-message "Access denied. Please wait a while and increase "
294 "the value of `mixi-continuously-access-interval'.")))
295 (if (not (string-match mixi-message-continuously-accessing buffer))
297 (message (mixi-message "Waiting for continuously accessing..."))
298 (sleep-for mixi-continuously-access-interval)
299 (mixi-retrieve url post-data)))
301 (defmacro mixi-expand-url (url)
302 `(if (string-match "^http" ,url)
304 (concat mixi-url ,url)))
306 ;; FIXME: Support files.
307 (defun mixi-make-form-data (fields)
308 "Make form data and return (CONTENT-TYPE . FORM-DATA)."
309 (let* ((boundary (apply 'format "--_%d_%d_%d" (current-time)))
310 (content-type (concat "multipart/form-data; boundary=" boundary))
314 (concat "--" boundary "\r\n"
315 "Content-Disposition: form-data; name=\""
318 (encode-coding-string (cdr field) mixi-coding-system)))
320 (cons content-type (concat form-data "\r\n--" boundary "--"))))
322 (defun mixi-url-retrieve (url &optional post-data extra-headers)
323 "Retrieve the URL and return gotten strings."
324 (let* ((url-request-method (if post-data "POST" "GET"))
325 (url-request-data post-data)
326 (url-request-extra-headers extra-headers)
327 (url (mixi-expand-url url))
329 (buffer (url-retrieve-synchronously url))
331 (unless (bufferp buffer)
332 (error (mixi-message "Cannot retrieve: " url)))
333 (with-current-buffer buffer
334 (goto-char (point-min))
335 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
336 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
337 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
338 (error (mixi-message "Cannot retrieve: " url)))
339 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
340 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
342 (mixi-parse-buffer url ret post-data))))
344 (defun mixi-url-post-form (url fields)
345 (let* ((form-data (mixi-make-form-data fields))
346 (extra-headers `(("Content-Type" . ,(car form-data)))))
347 (mixi-url-retrieve url (cdr form-data) extra-headers)))
349 (defun mixi-w3m-retrieve (url &optional post-data)
350 "Retrieve the URL and return gotten strings."
351 (let ((url (mixi-expand-url url)))
353 (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
354 (error (mixi-message "Cannot retrieve: " url))
355 (w3m-decode-buffer url)
356 (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
357 (mixi-parse-buffer url ret post-data))))))
359 (defun mixi-w3m-post-form (url fields)
360 (let ((form-data (mixi-make-form-data fields)))
361 (mixi-w3m-retrieve url form-data)))
363 (defun mixi-curl-retrieve (url &optional post-data form-data)
364 "Retrieve the URL and return gotten strings."
366 (if (fboundp 'set-buffer-multibyte)
367 (set-buffer-multibyte nil))
368 (let ((orig-mode (default-file-modes))
369 (coding-system-for-read 'binary)
370 (coding-system-for-write 'binary)
374 (set-default-file-modes 448)
376 (apply #'start-process "curl" (current-buffer)
378 (append (if post-data '("-d" "@-"))
381 "-b" mixi-curl-cookie-file
382 "-c" mixi-curl-cookie-file
383 (mixi-expand-url url)))))
384 (set-process-sentinel process #'ignore))
385 (set-default-file-modes orig-mode))
387 (process-send-string process (concat post-data "\n"))
388 (process-send-eof process))
389 (while (eq (process-status process) 'run)
390 (accept-process-output process 1))
391 (goto-char (point-min))
392 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
393 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
394 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
395 (error (mixi-message "Cannot retrieve: " url)))
396 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
397 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
398 (mixi-parse-buffer url ret post-data))))
400 (defun mixi-curl-post-form (url fields)
402 (mapcar (lambda (field)
403 (push "-F" form-data)
404 (push (concat (car field) "="
405 (encode-coding-string (cdr field)
409 (mixi-curl-retrieve url nil (reverse form-data))))
411 (defconst mixi-my-id-regexp
412 "<a href=\"show_profile\\.pl\\?id=\\([0-9]+\\)")
414 (defun mixi-login (&optional email password)
416 (when (and (eq mixi-backend 'w3m) (not w3m-use-cookies))
417 (error (mixi-message "Require to accept cookies. Please set "
418 "`w3m-use-cookies' to t.")))
419 (let ((email (or email mixi-default-email
420 (read-from-minibuffer (mixi-message "Login Email: "))))
421 (password (or password mixi-default-password
422 (read-passwd (mixi-message "Login Password: ")))))
423 (let ((url (mixi-expand-url "/login.pl")))
424 (when (and mixi-login-use-ssl (string-match "^http:" url))
425 (setq url (replace-match "https:" nil nil url)))
426 (let ((buffer (mixi-retrieve url
427 (concat "email=" email
428 "&password=" password
431 (unless (string-match "url=/check\\.pl\\?n=" buffer)
432 (error (mixi-message "Cannot login")))
433 (setq buffer (mixi-retrieve "/check.pl?n=home.pl"))
434 (if (string-match mixi-my-id-regexp buffer)
435 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
436 (error (mixi-message "Cannot login")))))))
438 (defun mixi-logout ()
439 (mixi-retrieve "/logout.pl"))
441 (defconst mixi-login-form "<form action=\"/login.pl\" method=\"post\">")
443 (defmacro with-mixi-retrieve (url &rest body)
444 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
447 (insert (mixi-retrieve ,url))
448 (goto-char (point-min))
449 (when (search-forward mixi-login-form nil t)
452 (insert (mixi-retrieve ,url))))
453 (goto-char (point-min))
455 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
456 (put 'with-mixi-retrieve 'edebug-form-spec '(body))
458 (defmacro with-mixi-post-form (url fields &rest body)
459 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
462 (insert (mixi-post-form ,url ,fields))
463 (goto-char (point-min))
464 (when (search-forward mixi-login-form nil t)
467 (insert (mixi-post-form ,url ,fields))))
468 (goto-char (point-min))
470 (put 'with-mixi-post-form 'lisp-indent-function 'defun)
471 (put 'with-mixi-post-form 'edebug-form-spec '(body))
473 (defun mixi-get-matched-items (url regexp &optional range reverse)
474 "Get matched items to REGEXP in URL."
478 (while (and (or (null range) (< (length ids) range))
479 (or (= page 1) (and (stringp url) (string-match "%d" url))))
480 (with-mixi-retrieve (when url (format url page))
481 (let ((func (if reverse (progn
482 (goto-char (point-max))
486 (while (and (funcall func regexp nil t)
487 (or (null range) (< (length ids) range)))
490 (while (match-string num)
491 (setq list (cons (match-string num) list))
493 (when (not (member (reverse list) ids))
495 (setq ids (cons (reverse list) ids)))))
501 ;; stolen (and modified) from shimbun.el
502 (defun mixi-remove-markup (string)
503 "Remove markups from STRING."
505 (insert (or string ""))
507 (goto-char (point-min))
508 (while (search-forward "<!--" nil t)
509 (delete-region (match-beginning 0)
510 (or (search-forward "-->" nil t)
512 (goto-char (point-min))
513 (while (re-search-forward "<[^>]+>" nil t)
514 (replace-match "" t t))
515 (goto-char (point-min))
516 (while (re-search-forward "
\r" nil t)
517 (replace-match "\n" t t)))
518 ;; FIXME: Decode entities.
521 ;; stolen (and modified) from w3m.el
522 (defconst mixi-entity-alist '(("gt" . ">")
525 "Alist of html character entities and values.")
527 ;; stolen (and modified) from w3m.el
528 (defun mixi-encode-specials-string (str)
529 "Encode special characters in the string STR."
532 (while (string-match "[<>&]" str pos)
535 (cons (car (rassoc (match-string 0 str) mixi-entity-alist))
537 (cons (substring str pos (match-beginning 0))
541 (apply 'concat (nreverse (cons (substring str pos) buf)))
544 ;; stolen (and modified) from w3m.el
545 (defun mixi-url-encode-string (string)
546 (apply (function concat)
550 ((eq char ?\n) ; newline
552 ((string-match "[-a-zA-Z0-9_:/.]" (char-to-string char)) ; xxx?
553 (char-to-string char)) ; printable
554 ((char-equal char ?\x20) ; space
557 (format "%%%02x" char)))) ; escape
558 ;; Coerce a string into a list of chars.
559 (append (encode-coding-string (or string "") mixi-coding-system)
562 (defun mixi-url-encode-and-quote-percent-string (string)
563 (let ((string (mixi-url-encode-string string))
565 (while (string-match "%" string pos)
566 (setq string (replace-match "%%" nil nil string))
567 (setq pos (+ (match-end 0) 1)))
571 (defconst mixi-object-prefix "mixi-")
573 (defmacro mixi-object-class (object)
576 (defmacro mixi-object-p (object)
577 `(let ((class (mixi-object-class ,object)))
578 (when (symbolp class)
579 (eq (string-match (concat "^" mixi-object-prefix)
580 (symbol-name class)) 0))))
582 (defun mixi-object-name (object)
583 "Return the name of OBJECT."
584 (unless (mixi-object-p object)
585 (signal 'wrong-type-argument (list 'mixi-object-p object)))
586 (let ((class (mixi-object-class object)))
587 (substring (symbol-name class) (length mixi-object-prefix))))
589 (defun mixi-read-object (exp)
590 "Read one Lisp expression as mixi object."
591 (if (mixi-object-p exp)
592 (let ((func (intern (concat mixi-object-prefix "make-"
593 (mixi-object-name exp))))
594 (args (mapcar (lambda (arg)
595 (mixi-read-object arg))
597 (let ((object (apply func (cdr args))))
599 (mixi-object-set-timestamp object (car args)))
603 (defun mixi-object-timestamp (object)
604 "Return the timestamp of OJBECT."
605 (unless (mixi-object-p object)
606 (signal 'wrong-type-argument (list 'mixi-object-p object)))
607 (aref (cdr object) 0))
608 (defalias 'mixi-object-realized-p 'mixi-object-timestamp)
610 (defun mixi-object-owner (object)
611 "Return the owner of OBJECT."
612 (unless (mixi-object-p object)
613 (signal 'wrong-type-argument (list 'mixi-object-p object)))
614 (let ((func (intern (concat mixi-object-prefix
615 (mixi-object-name object) "-owner"))))
616 (funcall func object)))
618 (defun mixi-object-id (object)
619 "Return the id of OBJECT."
620 (unless (mixi-object-p object)
621 (signal 'wrong-type-argument (list 'mixi-object-p object)))
622 (let ((func (intern (concat mixi-object-prefix
623 (mixi-object-name object) "-id"))))
624 (funcall func object)))
626 (defun mixi-object-time (object)
627 "Return the time of OBJECT."
628 (unless (mixi-object-p object)
629 (signal 'wrong-type-argument (list 'mixi-object-p object)))
630 (let ((func (intern (concat mixi-object-prefix
631 (mixi-object-name object) "-time"))))
632 (funcall func object)))
634 (defun mixi-object-title (object)
635 "Return the title of OBJECT."
636 (unless (mixi-object-p object)
637 (signal 'wrong-type-argument (list 'mixi-object-p object)))
638 (let ((func (intern (concat mixi-object-prefix
639 (mixi-object-name object) "-title"))))
640 (funcall func object)))
642 (defun mixi-object-content (object)
643 "Return the content of OBJECT."
644 (unless (mixi-object-p object)
645 (signal 'wrong-type-argument (list 'mixi-object-p object)))
646 (let ((func (intern (concat mixi-object-prefix
647 (mixi-object-name object) "-content"))))
648 (funcall func object)))
650 (defun mixi-object-set-timestamp (object timestamp)
651 "Set the timestamp of OBJECT."
652 (unless (mixi-object-p object)
653 (signal 'wrong-type-argument (list 'mixi-object-p object)))
654 (aset (cdr object) 0 timestamp))
656 (defmacro mixi-object-touch (object)
657 `(mixi-object-set-timestamp ,object (current-time)))
659 (defconst mixi-object-url-regexp
660 "/\\(show\\|view\\)_\\([a-z]+\\)\\.pl")
662 (defun mixi-make-object-from-url (url)
663 "Return a mixi object from URL."
664 (if (string-match mixi-object-url-regexp url)
665 (let ((name (match-string 2 url)))
666 (cond ((string= name "bbs")
668 ((string= name "profile")
669 (setq name "friend")))
670 (let ((func (intern (concat mixi-object-prefix "make-" name
673 (when (string-match "/home\\.pl" url)
674 (mixi-make-friend-from-url url))))
677 ;; stolen from time-date.el
678 (defun mixi-time-less-p (t1 t2)
679 "Say whether time value T1 is less than time value T2."
680 (unless (numberp (cdr t1))
681 (setq t1 (cons (car t1) (car (cdr t1)))))
682 (unless (numberp (cdr t2))
683 (setq t2 (cons (car t2) (car (cdr t2)))))
684 (or (< (car t1) (car t2))
685 (and (= (car t1) (car t2))
686 (< (cdr t1) (cdr t2)))))
688 (defun mixi-time-add (t1 t2)
689 "Add two time values. One should represent a time difference."
690 (unless (numberp (cdr t1))
691 (setq t1 (cons (car t1) (car (cdr t1)))))
692 (unless (numberp (cdr t2))
693 (setq t2 (cons (car t2) (car (cdr t2)))))
694 (let ((low (+ (cdr t1) (cdr t2))))
695 (cons (+ (car t1) (car t2) (lsh low -16)) low)))
697 ;; stolen from time-date.el
698 (defun mixi-seconds-to-time (seconds)
699 "Convert SECONDS (a floating point number) to a time value."
700 (cons (floor seconds 65536)
701 (floor (mod seconds 65536))))
703 (defun mixi-cache-expired-p (object)
704 "Whether a cache of OBJECT is expired."
705 (let ((timestamp (mixi-object-timestamp object)))
706 (unless (or (null mixi-cache-expires)
708 (if (numberp mixi-cache-expires)
710 (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
714 (defun mixi-make-cache (key value table)
715 "Make a cache object and return it."
716 (let ((cache (gethash key table)))
717 (if (and cache (not (mixi-cache-expired-p cache)))
719 (puthash key value table))))
721 (defconst mixi-cache-file-regexp "[a-z]+-cache$")
722 (defconst mixi-cache-regexp (concat mixi-object-prefix
723 mixi-cache-file-regexp))
725 (defun mixi-save-cache ()
726 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
727 (unless (file-directory-p cache-directory)
728 (make-directory cache-directory t))
729 (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
731 (with-temp-file (expand-file-name
732 (substring (symbol-name (car caches))
733 (length mixi-object-prefix))
735 (let ((coding-system-for-write mixi-coding-system)
736 (cache (symbol-value (car caches))))
737 (insert "#s(hash-table size "
738 (number-to-string (hash-table-count cache))
739 " test equal data (\n")
742 (let (print-level print-length)
743 (insert (prin1-to-string key) " "
744 (prin1-to-string value) "\n")))
747 (setq caches (cdr caches))))))
749 ;; stolen (and modified) from lsdb.el
750 (defun mixi-read-cache (&optional marker)
751 "Read one Lisp expression as text from MARKER, return as Lisp object."
754 (if (looking-at "^#s(")
757 (forward-char 2);skip "#s"
758 (forward-sexp);move to the left paren
761 (buffer-disable-undo)
762 (insert-buffer-substring (marker-buffer marker)
764 (goto-char (point-min))
766 (let ((object (read (current-buffer)))
768 (if (eq 'hash-table (car object))
770 (setq data (plist-get (cdr object) 'data))
772 (pop data);throw it away
773 (mixi-read-object (pop data))))
777 (defun mixi-load-cache ()
778 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
779 (when (file-directory-p cache-directory)
780 ;; FIXME: Load friend and community first.
781 (let ((files (directory-files cache-directory t
782 mixi-cache-file-regexp)))
784 (let ((buffer (find-file-noselect (car files))))
788 (goto-char (point-min))
789 (re-search-forward "^#s(")
790 (goto-char (match-beginning 0))
791 (mixi-read-cache (point-marker)))
792 (kill-buffer buffer)))
793 (setq files (cdr files)))))))
796 (defvar mixi-friend-cache (make-hash-table :test 'equal))
797 (defun mixi-make-friend (id &optional nick name sex address age birthday
798 blood-type birthplace hobby job organization
800 "Return a friend object."
801 (mixi-make-cache id (cons 'mixi-friend (vector nil id nick name sex address
802 age birthday blood-type
804 organization profile))
807 (defun mixi-make-me ()
808 "Return a my object."
810 (with-mixi-retrieve "/home.pl"
811 (if (re-search-forward mixi-my-id-regexp nil t)
812 (setq mixi-me (mixi-make-friend (match-string 1)))
813 (signal 'error (list 'who-am-i)))))
816 (defconst mixi-friend-url-regexp
817 "/show_\\(friend\\|profile\\)\\.pl\\?id=\\([0-9]+\\)")
819 (defun mixi-make-friend-from-url (url)
820 "Return a friend object from URL."
821 (if (string-match mixi-friend-url-regexp url)
822 (let ((id (match-string 2 url)))
823 (mixi-make-friend id))
824 (when (string-match "/home\\.pl" url)
827 (defmacro mixi-friend-p (friend)
828 `(eq (mixi-object-class ,friend) 'mixi-friend))
830 (defmacro mixi-friend-page (friend)
831 `(concat "/show_profile.pl?id=" (mixi-friend-id ,friend)))
833 (defconst mixi-friend-nick-regexp
834 "<h3>\\(.*\\)¤µ¤ó([0-9]+)</h3>")
835 (defconst mixi-friend-name-regexp
836 "<dt>̾Á°</dt>\n?<dd>\\(.+?\\)\\(<img\\|</dd>\\)")
837 (defconst mixi-friend-sex-regexp
838 "<dt>ÀÊÌ</dt>\n?<dd>\\([Ã˽÷]\\)À\\(<img\\|</dd>\\)")
839 (defconst mixi-friend-address-regexp
840 "<dt>¸½½»½ê</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
841 (defconst mixi-friend-age-regexp
842 "<dt>ǯÎð</dt>\n?<dd>\\([0-9]+\\)ºÐ\\( <img\\|</dd>\\)")
843 (defconst mixi-friend-birthday-regexp
844 "<dt>ÃÂÀ¸Æü</dt>\n?<dd>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(<img \\|</dd>\\)")
845 (defconst mixi-friend-blood-type-regexp
846 "<dt>·ì±Õ·¿</dt>\n?<dd>\\([ABO]B?\\)·¿\\(<img \\|</dd>\\)")
847 (defconst mixi-friend-birthplace-regexp
848 "<dt>½Ð¿ÈÃÏ</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
849 (defconst mixi-friend-hobby-regexp
850 "<dt>¼ñÌ£</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
851 (defconst mixi-friend-job-regexp
852 "<dt>¿¦¶È</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
853 (defconst mixi-friend-organization-regexp
854 "<dt>½ê°</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
855 (defconst mixi-friend-profile-regexp
856 "<dt>¼«¸Ê¾Ò²ð</dt>\n?<dd class=\"userInput\">\\(.+?\\)</dd>")
858 (defun mixi-realize-friend (friend)
860 ;; FIXME: Check a expiration of cache?
861 (unless (mixi-object-realized-p friend)
862 (with-mixi-retrieve (mixi-friend-page friend)
863 (let ((case-fold-search t))
864 (if (re-search-forward mixi-friend-nick-regexp nil t)
865 (mixi-friend-set-nick friend (match-string 1))
866 (mixi-realization-error 'cannot-find-nick friend))
867 (when (re-search-forward mixi-friend-name-regexp nil t)
868 (mixi-friend-set-name friend (match-string 1)))
869 (when (re-search-forward mixi-friend-sex-regexp nil t)
870 (mixi-friend-set-sex friend (if (string= (match-string 1) "ÃË")
872 (when (re-search-forward mixi-friend-address-regexp nil t)
873 (mixi-friend-set-address friend (match-string 1)))
874 (when (re-search-forward mixi-friend-age-regexp nil t)
875 (mixi-friend-set-age friend (string-to-number (match-string 1))))
876 (when (re-search-forward mixi-friend-birthday-regexp nil t)
877 (mixi-friend-set-birthday
878 friend (list (string-to-number (match-string 1))
879 (string-to-number (match-string 2)))))
880 (when (re-search-forward mixi-friend-blood-type-regexp nil t)
881 (mixi-friend-set-blood-type friend (intern (match-string 1))))
882 (when (re-search-forward mixi-friend-birthplace-regexp nil t)
883 (mixi-friend-set-birthplace friend (match-string 1)))
884 (when (re-search-forward mixi-friend-hobby-regexp nil t)
885 (mixi-friend-set-hobby friend (split-string (match-string 1) ", ")))
886 (when (re-search-forward mixi-friend-job-regexp nil t)
887 (mixi-friend-set-job friend (match-string 1)))
888 (when (re-search-forward mixi-friend-organization-regexp nil t)
889 (mixi-friend-set-organization friend (match-string 1)))
890 (when (re-search-forward mixi-friend-profile-regexp nil t)
891 (mixi-friend-set-profile friend (match-string 1)))))
892 (mixi-object-touch friend)))
894 (defun mixi-friend-id (friend)
895 "Return the id of FRIEND."
896 (unless (mixi-friend-p friend)
897 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
898 (aref (cdr friend) 1))
900 (defun mixi-friend-nick (friend)
901 "Return the nick of FRIEND."
902 (unless (mixi-friend-p friend)
903 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
904 (unless (aref (cdr friend) 2)
905 (mixi-realize-friend friend))
906 (aref (cdr friend) 2))
908 (defun mixi-friend-name (friend)
909 "Return the name of FRIEND."
910 (unless (mixi-friend-p friend)
911 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
912 (mixi-realize-friend friend)
913 (aref (cdr friend) 3))
915 (defun mixi-friend-sex (friend)
916 "Return the sex of FRIEND."
917 (unless (mixi-friend-p friend)
918 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
919 (mixi-realize-friend friend)
920 (aref (cdr friend) 4))
922 (defun mixi-friend-address (friend)
923 "Return the address of FRIEND."
924 (unless (mixi-friend-p friend)
925 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
926 (mixi-realize-friend friend)
927 (aref (cdr friend) 5))
929 (defun mixi-friend-age (friend)
930 "Return the age of FRIEND."
931 (unless (mixi-friend-p friend)
932 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
933 (mixi-realize-friend friend)
934 (aref (cdr friend) 6))
936 (defun mixi-friend-birthday (friend)
937 "Return the birthday of FRIEND."
938 (unless (mixi-friend-p friend)
939 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
940 (mixi-realize-friend friend)
941 (aref (cdr friend) 7))
943 (defun mixi-friend-blood-type (friend)
944 "Return the blood type of FRIEND."
945 (unless (mixi-friend-p friend)
946 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
947 (mixi-realize-friend friend)
948 (aref (cdr friend) 8))
950 (defun mixi-friend-birthplace (friend)
951 "Return the birthplace of FRIEND."
952 (unless (mixi-friend-p friend)
953 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
954 (mixi-realize-friend friend)
955 (aref (cdr friend) 9))
957 (defun mixi-friend-hobby (friend)
958 "Return the hobby of FRIEND."
959 (unless (mixi-friend-p friend)
960 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
961 (mixi-realize-friend friend)
962 (aref (cdr friend) 10))
964 (defun mixi-friend-job (friend)
965 "Return the job of FRIEND."
966 (unless (mixi-friend-p friend)
967 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
968 (mixi-realize-friend friend)
969 (aref (cdr friend) 11))
971 (defun mixi-friend-organization (friend)
972 "Return the organization of FRIEND."
973 (unless (mixi-friend-p friend)
974 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
975 (mixi-realize-friend friend)
976 (aref (cdr friend) 12))
978 (defun mixi-friend-profile (friend)
979 "Return the profile of FRIEND."
980 (unless (mixi-friend-p friend)
981 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
982 (mixi-realize-friend friend)
983 (aref (cdr friend) 13))
985 (defun mixi-friend-set-nick (friend nick)
986 "Set the nick of FRIEND."
987 (unless (mixi-friend-p friend)
988 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
989 (aset (cdr friend) 2 nick))
991 (defun mixi-friend-set-name (friend name)
992 "Set the name of FRIEND."
993 (unless (mixi-friend-p friend)
994 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
995 (aset (cdr friend) 3 name))
997 (defun mixi-friend-set-sex (friend sex)
998 "Set the sex of FRIEND."
999 (unless (mixi-friend-p friend)
1000 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1001 (aset (cdr friend) 4 sex))
1003 (defun mixi-friend-set-address (friend address)
1004 "Set the address of FRIEND."
1005 (unless (mixi-friend-p friend)
1006 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1007 (aset (cdr friend) 5 address))
1009 (defun mixi-friend-set-age (friend age)
1010 "Set the age of FRIEND."
1011 (unless (mixi-friend-p friend)
1012 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1013 (aset (cdr friend) 6 age))
1015 (defun mixi-friend-set-birthday (friend birthday)
1016 "Set the birthday of FRIEND."
1017 (unless (mixi-friend-p friend)
1018 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1019 (aset (cdr friend) 7 birthday))
1021 (defun mixi-friend-set-blood-type (friend blood-type)
1022 "Set the blood type of FRIEND."
1023 (unless (mixi-friend-p friend)
1024 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1025 (aset (cdr friend) 8 blood-type))
1027 (defun mixi-friend-set-birthplace (friend birthplace)
1028 "Set the birthplace of FRIEND."
1029 (unless (mixi-friend-p friend)
1030 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1031 (aset (cdr friend) 9 birthplace))
1033 (defun mixi-friend-set-hobby (friend hobby)
1034 "Set the hobby of FRIEND."
1035 (unless (mixi-friend-p friend)
1036 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1037 (aset (cdr friend) 10 hobby))
1039 (defun mixi-friend-set-job (friend job)
1040 "Set the job of FRIEND."
1041 (unless (mixi-friend-p friend)
1042 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1043 (aset (cdr friend) 11 job))
1045 (defun mixi-friend-set-organization (friend organization)
1046 "Set the organization of FRIEND."
1047 (unless (mixi-friend-p friend)
1048 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1049 (aset (cdr friend) 12 organization))
1051 (defun mixi-friend-set-profile (friend profile)
1052 "Set the profile of FRIEND."
1053 (unless (mixi-friend-p friend)
1054 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1055 (aset (cdr friend) 13 profile))
1057 (defmacro mixi-friend-list-page (&optional friend)
1058 `(concat "/list_friend.pl?page=%d"
1059 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1061 (defconst mixi-friend-list-id-regexp
1062 "<a href=\"?show_friend\\.pl\\?id=\\([0-9]+\\)\"?")
1063 (defconst mixi-friend-list-nick-regexp
1064 "<span>\\(.+\\)¤µ¤ó([0-9]+)</span>")
1067 (defun mixi-get-friends (&rest friend-or-range)
1068 "Get friends of FRIEND."
1069 (when (> (length friend-or-range) 2)
1070 (signal 'wrong-number-of-arguments (list 'mixi-get-friends
1071 (length friend-or-range))))
1072 (let ((friend (nth 0 friend-or-range))
1073 (range (nth 1 friend-or-range)))
1074 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1075 (setq friend (nth 1 friend-or-range))
1076 (setq range (nth 0 friend-or-range)))
1077 (unless (or (null friend) (mixi-friend-p friend))
1078 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1079 (let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
1080 mixi-friend-list-id-regexp
1082 (nicks (mixi-get-matched-items (mixi-friend-list-page friend)
1083 mixi-friend-list-nick-regexp
1087 (while (< index (length ids))
1088 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1089 (nth 0 (nth index nicks))) ret))
1094 (defmacro mixi-favorite-list-page ()
1095 `(concat "/list_bookmark.pl?page=%d"))
1097 (defconst mixi-favorite-list-regexp
1098 "<td bgcolor=\"#FDF9F2\"><font color=\"#996600\">̾Á°</font></td>
1099 <td colspan=\"2\" bgcolor=\"#FFFFFF\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></td>")
1102 (defun mixi-get-favorites (&optional range)
1104 (let ((items (mixi-get-matched-items (mixi-favorite-list-page)
1105 mixi-favorite-list-regexp
1107 (mapcar (lambda (item)
1108 (mixi-make-friend (nth 0 item) (nth 1 item)))
1112 (defun mixi-make-log (friend time)
1113 "Return a log object."
1114 (cons 'mixi-log (vector friend time)))
1116 (defmacro mixi-log-p (log)
1117 `(eq (mixi-object-class ,log) 'mixi-log))
1119 (defun mixi-log-friend (log)
1120 "Return the friend of LOG."
1121 (unless (mixi-log-p log)
1122 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1125 (defun mixi-log-time (log)
1126 "Return the time of LOG."
1127 (unless (mixi-log-p log)
1128 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1131 (defmacro mixi-log-list-page ()
1132 `(concat "/show_log.pl"))
1134 (defconst mixi-log-list-regexp
1135 "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)</a>")
1138 (defun mixi-get-logs (&optional range)
1140 (let ((items (mixi-get-matched-items (mixi-log-list-page)
1141 mixi-log-list-regexp
1143 (mapcar (lambda (item)
1144 (mixi-make-log (mixi-make-friend (nth 5 item) (nth 6 item))
1146 (string-to-number (nth 4 item))
1147 (string-to-number (nth 3 item))
1148 (string-to-number (nth 2 item))
1149 (string-to-number (nth 1 item))
1150 (string-to-number (nth 0 item)))))
1153 ;; Recommended friend.
1154 (defmacro mixi-recommended-friend-list-page ()
1155 `(concat "http://indies.mixi.jp/recommend.pl"))
1157 (defconst mixi-recommended-friend-list-regexp
1158 "<div class=\"iconListImage\"><a href=\"http://mixi\\.jp/show_friend\\.pl\\?id=\\([0-9]+\\)\" [^>]+>.+</a></div><span>\\(.+?\\)¤µ¤ó([0-9]+)</span>")
1161 (defun mixi-get-recommended-friends (&optional range)
1162 "Get recommended friends."
1163 (let ((items (mixi-get-matched-items (mixi-recommended-friend-list-page)
1164 mixi-recommended-friend-list-regexp
1166 (mapcar (lambda (item)
1167 (mixi-make-friend (nth 0 item) (nth 1 item)))
1171 (defvar mixi-diary-cache (make-hash-table :test 'equal))
1172 (defun mixi-make-diary (owner id &optional comment-count time title content)
1173 "Return a diary object."
1174 (let ((owner (or owner (mixi-make-me))))
1175 (mixi-make-cache (list (mixi-friend-id owner) id)
1176 (cons 'mixi-diary (vector nil owner id comment-count time
1180 (defconst mixi-diary-url-regexp
1181 "/view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?")
1183 (defun mixi-make-diary-from-url (url)
1184 "Return a diary object from URL."
1185 (when (string-match mixi-diary-url-regexp url)
1186 (let ((id (match-string 1 url))
1187 (owner-id (match-string 2 url))
1188 (comment-count (match-string 4 url)))
1189 (mixi-make-diary (mixi-make-friend owner-id) id comment-count))))
1191 (defmacro mixi-diary-p (diary)
1192 `(eq (mixi-object-class ,diary) 'mixi-diary))
1194 (defmacro mixi-diary-page (diary)
1195 `(concat "/view_diary.pl?id=" (mixi-diary-id ,diary)
1196 "&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
1198 (defconst mixi-diary-closed-regexp
1199 "<td>ͧ¿Í\\(¤Îͧ¿Í\\)?¤Þ¤Ç¸ø³«¤Î¤¿¤áÆɤळ¤È¤¬½ÐÍè¤Þ¤»¤ó¡£</td>")
1200 (defconst mixi-diary-owner-nick-regexp
1201 "<div class=\"diaryTitle\\(Friend\\)? clearfix\">
1202 <h2>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ</h2>")
1203 (defconst mixi-diary-title-regexp
1204 "<div class=\"listDiaryTitle\">
1205 <dl class=\"clearfix\">
1206 <dt>\\([^<\n]+\\)\\(<span>\\)?")
1207 (defconst mixi-diary-time-regexp
1208 "<dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\\([0-9]+\\):\\([0-9]+\\)</dd>")
1209 (defconst mixi-diary-content-regexp
1210 "<div class=\"txtconfirmArea\">
1211 \\(\\(.\\|\r?\n\\)*?\\)
1212 <!--/viewDiaryBox--></div>")
1214 (defun mixi-realize-diary (diary &optional page)
1216 ;; FIXME: Check a expiration of cache?
1217 (unless (mixi-object-realized-p diary)
1218 (with-mixi-retrieve (or page (mixi-diary-page diary))
1219 (let ((case-fold-search t))
1220 (unless (re-search-forward mixi-diary-closed-regexp nil t)
1221 (if (re-search-forward mixi-diary-owner-nick-regexp nil t)
1222 (mixi-friend-set-nick (mixi-diary-owner diary)
1224 (mixi-realization-error 'cannot-find-owner-nick diary))
1225 (if (re-search-forward mixi-diary-title-regexp nil t)
1226 (mixi-diary-set-title diary (match-string 1))
1227 (mixi-realization-error 'cannot-find-title diary))
1228 (if (re-search-forward mixi-diary-time-regexp nil t)
1229 (mixi-diary-set-time
1230 diary (encode-time 0 (string-to-number (match-string 5))
1231 (string-to-number (match-string 4))
1232 (string-to-number (match-string 3))
1233 (string-to-number (match-string 2))
1234 (string-to-number (match-string 1))))
1235 (mixi-realization-error 'cannot-find-time diary))
1236 (if (re-search-forward mixi-diary-content-regexp nil t)
1237 (mixi-diary-set-content diary (match-string 1))
1238 (mixi-realization-error 'cannot-find-content diary)))))
1239 (mixi-object-touch diary)))
1241 (defun mixi-diary-owner (diary)
1242 "Return the owner of DIARY."
1243 (unless (mixi-diary-p diary)
1244 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1245 (aref (cdr diary) 1))
1247 (defun mixi-diary-id (diary)
1248 "Return the id of DIARY."
1249 (unless (mixi-diary-p diary)
1250 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1251 (aref (cdr diary) 2))
1253 (defun mixi-diary-comment-count (diary)
1254 "Return the comment-count of DIARY."
1255 (unless (mixi-diary-p diary)
1256 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1257 (aref (cdr diary) 3))
1259 (defun mixi-diary-time (diary)
1260 "Return the time of DIARY."
1261 (unless (mixi-diary-p diary)
1262 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1263 (unless (aref (cdr diary) 3)
1264 (mixi-realize-diary diary))
1265 (aref (cdr diary) 4))
1267 (defun mixi-diary-title (diary)
1268 "Return the title of DIARY."
1269 (unless (mixi-diary-p diary)
1270 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1271 (unless (aref (cdr diary) 4)
1272 (mixi-realize-diary diary))
1273 (aref (cdr diary) 5))
1275 (defun mixi-diary-content (diary)
1276 "Return the content of DIARY."
1277 (unless (mixi-diary-p diary)
1278 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1279 (mixi-realize-diary diary)
1280 (aref (cdr diary) 6))
1282 (defun mixi-diary-set-comment-count (diary comment-count)
1283 "Set the comment-count of DIARY."
1284 (unless (mixi-diary-p diary)
1285 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1286 (aset (cdr diary) 3 comment-count))
1288 (defun mixi-diary-set-time (diary time)
1289 "Set the time of DIARY."
1290 (unless (mixi-diary-p diary)
1291 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1292 (aset (cdr diary) 4 time))
1294 (defun mixi-diary-set-title (diary title)
1295 "Set the title of DIARY."
1296 (unless (mixi-diary-p diary)
1297 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1298 (aset (cdr diary) 5 title))
1300 (defun mixi-diary-set-content (diary content)
1301 "Set the content of DIARY."
1302 (unless (mixi-diary-p diary)
1303 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1304 (aset (cdr diary) 6 content))
1306 (defmacro mixi-diary-list-page (&optional friend)
1307 `(concat "/list_diary.pl?page=%d"
1308 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1310 (defconst mixi-diary-list-regexp
1311 "<dt>\\(<input name=\"diary_id\" type=\"checkbox\" value=\"[0-9]+\" />\\|\\)<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">\\(.*\\)</a>\\(<span><a href=\"edit_diary\\.pl\\?id=[0-9]+\">ÊÔ½¸¤¹¤ë</a></span>\\|\\)</dt>
1312 <dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\n?\\([0-9]+\\):\\([0-9]+\\)</dd>
1316 (defun mixi-get-diaries (&rest friend-or-range)
1317 "Get diaries of FRIEND."
1318 (when (> (length friend-or-range) 2)
1319 (signal 'wrong-number-of-arguments
1320 (list 'mixi-get-diaries (length friend-or-range))))
1321 (let ((friend (nth 0 friend-or-range))
1322 (range (nth 1 friend-or-range)))
1323 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1324 (setq friend (nth 1 friend-or-range))
1325 (setq range (nth 0 friend-or-range)))
1326 (unless (or (null friend) (mixi-friend-p friend))
1327 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1328 (let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
1329 mixi-diary-list-regexp
1331 (mapcar (lambda (item)
1332 (mixi-make-diary friend (nth 1 item) nil
1334 0 (string-to-number (nth 8 item))
1335 (string-to-number (nth 7 item))
1336 (string-to-number (nth 6 item))
1337 (string-to-number (nth 5 item))
1338 (string-to-number (nth 4 item)))
1342 (defmacro mixi-new-diary-list-page ()
1343 `(concat "/new_friend_diary.pl?page=%d"))
1345 (defconst mixi-new-diary-list-regexp
1346 "<dt>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</dt>
1347 <dd><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\">\\(.+\\)</a> (\\(.*\\))<div ")
1350 (defun mixi-get-new-diaries (&optional range)
1352 (let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
1353 mixi-new-diary-list-regexp
1355 (mapcar (lambda (item)
1356 (mixi-make-diary (mixi-make-friend (nth 6 item) (nth 8 item))
1360 0 (string-to-number (nth 4 item))
1361 (string-to-number (nth 3 item))
1362 (string-to-number (nth 2 item))
1363 (string-to-number (nth 1 item))
1364 (string-to-number (nth 0 item)))
1368 (defmacro mixi-search-diary-list-page (keyword)
1369 `(concat "/search_diary.pl?page=%d&submit=search&keyword="
1370 (mixi-url-encode-and-quote-percent-string ,keyword)))
1372 (defconst mixi-search-diary-list-regexp
1373 "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾ Á°</font></td>
1374 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.*\\)
1379 <td BGCOLOR=#FDF9F2><font COLOR=#996600>¥¿¥¤¥È¥ë</font></td>
1380 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>
1383 <td BGCOLOR=#FDF9F2><font COLOR=#996600>ËÜ Ê¸</font></td>
1384 <td COLSPAN=2 BGCOLOR=#FFFFFF width=\"380\">\\(.*\\)</td></tr>
1388 <td NOWRAP BGCOLOR=#FDF9F2 WIDTH=80><font COLOR=#996600>ºîÀ®Æü»þ</font></td>
1389 <td BGCOLOR=#FFFFFF WIDTH=220>\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>
1390 <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>
1392 </td></tr></table>")
1395 (defun mixi-search-diaries (keyword &optional range)
1396 (let ((items (mixi-get-matched-items (mixi-search-diary-list-page keyword)
1397 mixi-search-diary-list-regexp
1399 (year (nth 5 (decode-time (current-time))))
1400 (month (nth 4 (decode-time (current-time)))))
1401 (mapcar (lambda (item)
1402 (let ((month-of-item (string-to-number (nth 3 item))))
1403 (when (> month-of-item month)
1405 (setq month month-of-item)
1406 (mixi-make-diary (mixi-make-friend (nth 8 item) (nth 0 item))
1410 0 (string-to-number (nth 6 item))
1411 (string-to-number (nth 5 item))
1412 (string-to-number (nth 4 item))
1418 (defmacro mixi-post-diary-page ()
1419 `(concat "/add_diary.pl"))
1421 (defconst mixi-post-key-regexp
1422 "<input type=\"?hidden\"? name=\"?post_key\"? +value=\"\\([a-z0-9]+\\)\"")
1423 (defconst mixi-post-succeed-regexp
1424 "<p\\(\\| class=\"messageAlert\"\\)>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É½¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¾¯¡¹¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£</p>")
1426 ;; FIXME: Support photos.
1428 (defun mixi-post-diary (title content)
1430 (unless (stringp title)
1431 (signal 'wrong-type-argument (list 'stringp title)))
1432 (unless (stringp content)
1433 (signal 'wrong-type-argument (list 'stringp content)))
1434 (let ((fields `(("id" . ,(mixi-friend-id (mixi-make-me)))
1435 ("diary_title" . ,title)
1436 ("diary_body" . ,content)
1437 ("submit" . "main")))
1439 (with-mixi-post-form (mixi-post-diary-page) fields
1440 (if (re-search-forward mixi-post-key-regexp nil t)
1441 (setq post-key (match-string 1))
1442 (mixi-post-error 'cannot-find-key)))
1443 (setq fields `(("post_key" . ,post-key)
1444 ("id" . ,(mixi-friend-id (mixi-make-me)))
1445 ("diary_title" . ,title)
1446 ("diary_body" . ,content)
1447 ("submit" . "confirm")))
1448 (with-mixi-post-form (mixi-post-diary-page) fields
1449 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1450 (mixi-post-error 'cannot-find-succeed)))))
1452 ;; Community object.
1453 (defvar mixi-community-cache (make-hash-table :test 'equal))
1454 (defun mixi-make-community (id &optional name birthday owner category members
1455 open-level authority description)
1456 "Return a community object."
1457 (mixi-make-cache id (cons 'mixi-community (vector nil id name birthday owner
1459 open-level authority
1461 mixi-community-cache))
1463 (defconst mixi-community-url-regexp
1464 "/view_community\\.pl\\?id=\\([0-9]+\\)")
1466 (defun mixi-make-community-from-url (url)
1467 "Return a community object from URL."
1468 (when (string-match mixi-community-url-regexp url)
1469 (let ((id (match-string 1 url)))
1470 (mixi-make-community id))))
1472 (defmacro mixi-community-p (community)
1473 `(eq (mixi-object-class ,community) 'mixi-community))
1475 (defmacro mixi-community-page (community)
1476 `(concat "/view_community.pl?id=" (mixi-community-id ,community)))
1478 ;; FIXME: Not community specific.
1479 (defconst mixi-community-nodata-regexp
1480 "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1481 (defconst mixi-community-name-regexp
1482 "<div class=\"pageTitle communityTitle002 communityTop\">
1484 (defconst mixi-community-birthday-regexp
1486 <dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br />")
1487 ;; FIXME: Care when the owner has seceded.
1488 (defconst mixi-community-owner-regexp
1491 <a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\\(.*\\)</a>")
1492 (defconst mixi-community-category-regexp
1495 (defconst mixi-community-members-regexp
1496 "<dt>¥á¥ó¥Ð¡¼¿ô</dt>
1497 <dd>\\([0-9]+\\)¿Í</dd>")
1498 (defconst mixi-community-open-level-regexp
1499 "<dt>»²²Ã¾ò·ï¤È<br />¸ø³«¥ì¥Ù¥ë</dt>
1501 (defconst mixi-community-authority-regexp
1502 "<dt>¥È¥Ô¥Ã¥¯¤Î<br />ºîÀ®¸¢¸Â</dt>
1508 (defconst mixi-community-description-regexp
1509 "<div id=\"communityIntro\">
1512 (defun mixi-realize-community (community)
1513 "Realize a COMMUNITY."
1514 ;; FIXME: Check a expiration of cache?
1515 (unless (mixi-object-realized-p community)
1516 (with-mixi-retrieve (mixi-community-page community)
1517 (let ((case-fold-search t))
1518 (if (re-search-forward mixi-community-nodata-regexp nil t)
1519 ;; FIXME: Set all members?
1520 (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1521 (if (re-search-forward mixi-community-name-regexp nil t)
1522 (mixi-community-set-name community (match-string 1))
1523 (mixi-realization-error 'cannot-find-name community))
1524 (if (re-search-forward mixi-community-birthday-regexp nil t)
1525 (mixi-community-set-birthday
1526 community (encode-time 0 0 0
1527 (string-to-number (match-string 3))
1528 (string-to-number (match-string 2))
1529 (string-to-number (match-string 1))))
1530 (mixi-realization-error 'cannot-find-birthday community))
1531 (if (re-search-forward mixi-community-owner-regexp nil t)
1532 (if (string= (match-string 1) "home.pl")
1533 (mixi-community-set-owner community (mixi-make-me))
1534 (mixi-community-set-owner community (mixi-make-friend
1537 (mixi-realization-error 'cannot-find-owner community))
1538 (if (re-search-forward mixi-community-category-regexp nil t)
1539 (mixi-community-set-category community (match-string 1))
1540 (mixi-realization-error 'cannot-find-category community))
1541 (if (re-search-forward mixi-community-members-regexp nil t)
1542 (mixi-community-set-members community
1543 (string-to-number (match-string 1)))
1544 (mixi-realization-error 'cannot-find-members community))
1545 (if (re-search-forward mixi-community-open-level-regexp nil t)
1546 (mixi-community-set-open-level community (match-string 1))
1547 (mixi-realization-error 'cannot-find-open-level community))
1548 (if (re-search-forward mixi-community-authority-regexp nil t)
1549 (mixi-community-set-authority community (match-string 1))
1550 (mixi-realization-error 'cannot-find-authority community))
1551 (if (re-search-forward mixi-community-description-regexp nil t)
1552 (mixi-community-set-description community (match-string 1))
1553 (mixi-realization-error 'cannot-find-description community)))))
1554 (mixi-object-touch community)))
1556 (defun mixi-community-id (community)
1557 "Return the id of COMMUNITY."
1558 (unless (mixi-community-p community)
1559 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1560 (aref (cdr community) 1))
1562 (defun mixi-community-name (community)
1563 "Return the name of COMMUNITY."
1564 (unless (mixi-community-p community)
1565 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1566 (unless (aref (cdr community) 2)
1567 (mixi-realize-community community))
1568 (aref (cdr community) 2))
1570 (defun mixi-community-birthday (community)
1571 "Return the birthday of COMMUNITY."
1572 (unless (mixi-community-p community)
1573 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1574 (mixi-realize-community community)
1575 (aref (cdr community) 3))
1577 (defun mixi-community-owner (community)
1578 "Return the owner of COMMUNITY."
1579 (unless (mixi-community-p community)
1580 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1581 (mixi-realize-community community)
1582 (aref (cdr community) 4))
1584 (defun mixi-community-category (community)
1585 "Return the category of COMMUNITY."
1586 (unless (mixi-community-p community)
1587 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1588 (mixi-realize-community community)
1589 (aref (cdr community) 5))
1591 (defun mixi-community-members (community)
1592 "Return the members of COMMUNITY."
1593 (unless (mixi-community-p community)
1594 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1595 (mixi-realize-community community)
1596 (aref (cdr community) 6))
1598 (defun mixi-community-open-level (community)
1599 "Return the open-level of COMMUNITY."
1600 (unless (mixi-community-p community)
1601 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1602 (mixi-realize-community community)
1603 (aref (cdr community) 7))
1605 (defun mixi-community-authority (community)
1606 "Return the authority of COMMUNITY."
1607 (unless (mixi-community-p community)
1608 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1609 (mixi-realize-community community)
1610 (aref (cdr community) 8))
1612 (defun mixi-community-description (community)
1613 "Return the description of COMMUNITY."
1614 (unless (mixi-community-p community)
1615 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1616 (mixi-realize-community community)
1617 (aref (cdr community) 9))
1619 (defun mixi-community-set-name (community name)
1620 "Set the name of COMMUNITY."
1621 (unless (mixi-community-p community)
1622 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1623 (aset (cdr community) 2 name))
1625 (defun mixi-community-set-birthday (community birthday)
1626 "Set the birthday of COMMUNITY."
1627 (unless (mixi-community-p community)
1628 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1629 (aset (cdr community) 3 birthday))
1631 (defun mixi-community-set-owner (community owner)
1632 "Set the owner of COMMUNITY."
1633 (unless (mixi-community-p community)
1634 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1635 (unless (mixi-friend-p owner)
1636 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1637 (aset (cdr community) 4 owner))
1639 (defun mixi-community-set-category (community category)
1640 "Set the category of COMMUNITY."
1641 (unless (mixi-community-p community)
1642 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1643 (aset (cdr community) 5 category))
1645 (defun mixi-community-set-members (community members)
1646 "Set the name of COMMUNITY."
1647 (unless (mixi-community-p community)
1648 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1649 (aset (cdr community) 6 members))
1651 (defun mixi-community-set-open-level (community open-level)
1652 "Set the name of COMMUNITY."
1653 (unless (mixi-community-p community)
1654 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1655 (aset (cdr community) 7 open-level))
1657 (defun mixi-community-set-authority (community authority)
1658 "Set the name of COMMUNITY."
1659 (unless (mixi-community-p community)
1660 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1661 (aset (cdr community) 8 authority))
1663 (defun mixi-community-set-description (community description)
1664 "Set the name of COMMUNITY."
1665 (unless (mixi-community-p community)
1666 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1667 (aset (cdr community) 9 description))
1669 (defmacro mixi-community-list-page (&optional friend)
1670 `(concat "/list_community.pl?page=%d"
1671 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1673 (defconst mixi-community-list-id-regexp
1674 "<a href=\"?view_community\\.pl\\?id=\\([0-9]+\\)\"?")
1675 (defconst mixi-community-list-name-regexp
1676 "<span>\\(.+\\)([0-9]+)</span>")
1679 (defun mixi-get-communities (&rest friend-or-range)
1680 "Get communities of FRIEND."
1681 (when (> (length friend-or-range) 2)
1682 (signal 'wrong-number-of-arguments
1683 (list 'mixi-get-communities (length friend-or-range))))
1684 (let ((friend (nth 0 friend-or-range))
1685 (range (nth 1 friend-or-range)))
1686 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1687 (setq friend (nth 1 friend-or-range))
1688 (setq range (nth 0 friend-or-range)))
1689 (unless (or (null friend) (mixi-friend-p friend))
1690 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1691 (let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
1692 mixi-community-list-id-regexp
1694 (names (mixi-get-matched-items (mixi-community-list-page friend)
1695 mixi-community-list-name-regexp
1699 (while (< index (length ids))
1700 (setq ret (cons (mixi-make-community (nth 0 (nth index ids))
1701 (nth 0 (nth index names))) ret))
1705 (defmacro mixi-search-community-list-page (keyword)
1706 `(concat "/search_community.pl?page=%d&&sort=date&type=com&submit=main"
1707 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
1710 (defconst mixi-search-community-list-regexp
1711 "<dt class=\"communityTitle\"><a href=\"view_community\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\) ([0-9]+)</a>")
1713 ;; FIXME: Support category.
1715 (defun mixi-search-communities (keyword &optional range)
1716 (let ((items (mixi-get-matched-items (mixi-search-community-list-page
1718 mixi-search-community-list-regexp
1720 (mapcar (lambda (item)
1721 (mixi-make-community (nth 0 item) (nth 1 item)))
1724 ;; Recommended community.
1725 (defalias 'mixi-recommended-community-list-page
1726 'mixi-recommended-friend-list-page)
1728 (defconst mixi-recommended-community-list-regexp
1729 "<div class=\"iconListImage\"><a href=\"http://mixi\\.jp/view_community\\.pl\\?id=\\([0-9]+\\)\" [^>]+>.+</a></div><span>\\(.+\\)([0-9]+)</span>")
1732 (defun mixi-get-recommended-communities (&optional range)
1733 "Get recommended communities."
1734 (let ((items (mixi-get-matched-items (mixi-recommended-community-list-page)
1735 mixi-recommended-community-list-regexp
1737 (mapcar (lambda (item)
1738 (mixi-make-community (nth 0 item) (nth 1 item)))
1742 (defvar mixi-topic-cache (make-hash-table :test 'equal))
1743 (defun mixi-make-topic (community id &optional comment-count time title owner
1745 "Return a topic object."
1746 (mixi-make-cache (list (mixi-community-id community) id)
1747 (cons 'mixi-topic (vector nil community id comment-count
1748 time title owner content))
1751 (defconst mixi-topic-url-regexp
1752 "/view_bbs\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1754 (defun mixi-make-topic-from-url (url)
1755 "Return a topic object from URL."
1756 (when (string-match mixi-topic-url-regexp url)
1757 (let ((id (match-string 1 url))
1758 (comment-count (match-string 3 url))
1759 (community-id (match-string 4 url)))
1760 (mixi-make-topic (mixi-make-community community-id) id comment-count))))
1762 (defmacro mixi-topic-p (topic)
1763 `(eq (mixi-object-class ,topic) 'mixi-topic))
1765 (defmacro mixi-topic-page (topic)
1766 `(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
1767 "&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
1769 (defconst mixi-topic-community-regexp
1770 "<div class=\"pageTitle communityTitle002\">
1771 <h2>\\(.+\\) ¥È¥Ô¥Ã¥¯</h2>")
1772 (defconst mixi-topic-title-regexp
1773 "<span class=\"title\">\\([^<]+\\)</span>")
1774 (defconst mixi-topic-time-regexp
1775 "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>")
1776 (defconst mixi-topic-owner-regexp
1777 "<dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)\\(¤µ¤ó\\)?</a>")
1778 (defconst mixi-topic-content-regexp
1779 "<dd>\\(\\(.\\|\r?\n\\)*?\\)</dd>")
1781 (defun mixi-realize-topic (topic &optional page)
1783 ;; FIXME: Check a expiration of cache?
1784 (unless (mixi-object-realized-p topic)
1785 (with-mixi-retrieve (or page (mixi-topic-page topic))
1786 (if (re-search-forward mixi-topic-community-regexp nil t)
1787 (mixi-community-set-name (mixi-topic-community topic)
1789 (mixi-realization-error 'cannot-find-community topic))
1790 (if (re-search-forward mixi-topic-title-regexp nil t)
1791 (mixi-topic-set-title topic (match-string 1))
1792 (mixi-realization-error 'cannot-find-title topic))
1793 (if (re-search-forward mixi-topic-time-regexp nil t)
1794 (mixi-topic-set-time
1795 topic (encode-time 0 (string-to-number (match-string 5))
1796 (string-to-number (match-string 4))
1797 (string-to-number (match-string 3))
1798 (string-to-number (match-string 2))
1799 (string-to-number (match-string 1))))
1800 (mixi-realization-error 'cannot-find-time topic))
1801 (if (re-search-forward mixi-topic-owner-regexp nil t)
1802 (mixi-topic-set-owner topic (mixi-make-friend (match-string 1)
1804 (mixi-realization-error 'cannot-find-owner topic))
1805 (if (re-search-forward mixi-topic-content-regexp nil t)
1806 (mixi-topic-set-content topic (match-string 1))
1807 (mixi-realization-error 'cannot-find-content topic)))
1808 (mixi-object-touch topic)))
1810 (defun mixi-topic-community (topic)
1811 "Return the community of TOPIC."
1812 (unless (mixi-topic-p topic)
1813 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1814 (aref (cdr topic) 1))
1816 (defun mixi-topic-id (topic)
1817 "Return the id of TOPIC."
1818 (unless (mixi-topic-p topic)
1819 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1820 (aref (cdr topic) 2))
1822 (defun mixi-topic-comment-count (topic)
1823 "Return the comment-count of TOPIC."
1824 (unless (mixi-topic-p topic)
1825 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1826 (aref (cdr topic) 3))
1828 (defun mixi-topic-time (topic)
1829 "Return the time of TOPIC."
1830 (unless (mixi-topic-p topic)
1831 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1832 (mixi-realize-topic topic)
1833 (aref (cdr topic) 4))
1835 (defun mixi-topic-title (topic)
1836 "Return the title of TOPIC."
1837 (unless (mixi-topic-p topic)
1838 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1839 (mixi-realize-topic topic)
1840 (aref (cdr topic) 5))
1842 (defun mixi-topic-owner (topic)
1843 "Return the owner of TOPIC."
1844 (unless (mixi-topic-p topic)
1845 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1846 (mixi-realize-topic topic)
1847 (aref (cdr topic) 6))
1849 (defun mixi-topic-content (topic)
1850 "Return the content of TOPIC."
1851 (unless (mixi-topic-p topic)
1852 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1853 (mixi-realize-topic topic)
1854 (aref (cdr topic) 7))
1856 (defun mixi-topic-set-comment-count (topic comment-count)
1857 "Set the comment-count of TOPIC."
1858 (unless (mixi-topic-p topic)
1859 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1860 (aset (cdr topic) 3 comment-count))
1862 (defun mixi-topic-set-time (topic time)
1863 "Set the time of TOPIC."
1864 (unless (mixi-topic-p topic)
1865 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1866 (aset (cdr topic) 4 time))
1868 (defun mixi-topic-set-title (topic title)
1869 "Set the title of TOPIC."
1870 (unless (mixi-topic-p topic)
1871 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1872 (aset (cdr topic) 5 title))
1874 (defun mixi-topic-set-owner (topic owner)
1875 "Set the owner of TOPIC."
1876 (unless (mixi-topic-p topic)
1877 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1878 (unless (mixi-friend-p owner)
1879 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1880 (aset (cdr topic) 6 owner))
1882 (defun mixi-topic-set-content (topic content)
1883 "Set the content of TOPIC."
1884 (unless (mixi-topic-p topic)
1885 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1886 (aset (cdr topic) 7 content))
1888 (defmacro mixi-post-topic-page (community)
1889 `(concat "/add_bbs.pl?id=" (mixi-community-id community)))
1891 ;; FIXME: Support photos.
1893 (defun mixi-post-topic (community title content)
1894 "Post a topic to COMMUNITY."
1895 (unless (mixi-community-p community)
1896 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1897 (unless (stringp title)
1898 (signal 'wrong-type-argument (list 'stringp title)))
1899 (unless (stringp content)
1900 (signal 'wrong-type-argument (list 'stringp content)))
1901 (let ((fields `(("bbs_title" . ,title)
1902 ("bbs_body" . ,content)
1903 ("submit" . "main")))
1905 (with-mixi-post-form (mixi-post-topic-page community) fields
1906 (if (re-search-forward mixi-post-key-regexp nil t)
1907 (setq post-key (match-string 1))
1908 (mixi-post-error 'cannot-find-key community)))
1909 (setq fields `(("post_key" . ,post-key)
1910 ("bbs_title" . ,title)
1911 ("bbs_body" . ,content)
1912 ("submit" . "confirm")))
1913 (with-mixi-post-form (mixi-post-topic-page community) fields
1914 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1915 (mixi-post-error 'cannot-find-succeed community)))))
1918 (defvar mixi-event-cache (make-hash-table :test 'equal))
1919 (defun mixi-make-event (community id &optional comment-count time title owner
1920 date place detail limit members)
1921 "Return a event object."
1922 (mixi-make-cache (list (mixi-community-id community) id)
1923 (cons 'mixi-event (vector nil community id comment-count
1924 time title owner date place
1925 detail limit members))
1928 (defconst mixi-event-url-regexp
1929 "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1931 (defun mixi-make-event-from-url (url)
1932 "Return a event object from URL."
1933 (when (string-match mixi-event-url-regexp url)
1934 (let ((id (match-string 1 url))
1935 (comment-count (match-string 3 url))
1936 (community-id (match-string 4 url)))
1937 (mixi-make-event (mixi-make-community community-id) id comment-count))))
1939 (defmacro mixi-event-p (event)
1940 `(eq (mixi-object-class ,event) 'mixi-event))
1942 (defmacro mixi-event-page (event)
1943 `(concat "/view_event.pl?id=" (mixi-event-id ,event)
1944 "&comm_id=" (mixi-community-id (mixi-event-community ,event))))
1946 (defconst mixi-event-community-regexp
1947 "<div class=\"pageTitle communityTitle002\">
1948 <h2>\\(.+\\) ¥¤¥Ù¥ó¥È</h2>")
1949 (defconst mixi-event-title-regexp
1950 "<span class=\"title\">\\([^<]+\\)</span>")
1951 (defconst mixi-event-time-regexp
1952 "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>")
1953 (defconst mixi-event-date-regexp
1956 (defconst mixi-event-place-regexp
1959 (defconst mixi-event-owner-regexp
1960 "<dt>\\((mixi Âà²ñºÑ)\\|<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>\\)</dt>")
1961 (defconst mixi-event-owner-seceded-regexp
1963 (defconst mixi-event-detail-regexp
1964 "<dd>\\(\\(.\\|\r?\n\\)*?\\)</dd>
1966 (defconst mixi-event-limit-regexp
1969 (defconst mixi-event-members-regexp
1973 (defun mixi-realize-event (event &optional page)
1975 ;; FIXME: Check a expiration of cache?
1976 (unless (mixi-object-realized-p event)
1977 (with-mixi-retrieve (or page (mixi-event-page event))
1978 (let ((case-fold-search t))
1979 (if (re-search-forward mixi-event-community-regexp nil t)
1980 (mixi-community-set-name (mixi-event-community event)
1982 (mixi-realization-error 'cannot-find-community event))
1983 (if (re-search-forward mixi-event-title-regexp nil t)
1984 (mixi-event-set-title event (match-string 1))
1985 (mixi-realization-error 'cannot-find-title event))
1986 (if (re-search-forward mixi-event-time-regexp nil t)
1987 (mixi-event-set-time
1988 event (encode-time 0 (string-to-number (match-string 5))
1989 (string-to-number (match-string 4))
1990 (string-to-number (match-string 3))
1991 (string-to-number (match-string 2))
1992 (string-to-number (match-string 1))))
1993 (mixi-realization-error 'cannot-find-time event))
1994 (if (re-search-forward mixi-event-date-regexp nil t)
1995 (mixi-event-set-date event (match-string 1))
1996 (mixi-realization-error 'cannot-find-date event))
1997 (if (re-search-forward mixi-event-place-regexp nil t)
1998 (mixi-event-set-place event (match-string 1))
1999 (mixi-realization-error 'cannot-find-place event))
2000 (if (re-search-forward mixi-event-owner-regexp nil t)
2001 (let ((seceded-or-not (match-string 1))
2002 (id (match-string 2))
2003 (nick (match-string 3)))
2004 (if (string= mixi-event-owner-seceded-regexp seceded-or-not)
2005 (mixi-event-set-owner event
2006 (mixi-make-friend nil seceded-or-not))
2007 (mixi-event-set-owner event (mixi-make-friend id nick))))
2008 (mixi-realization-error 'cannot-find-owner event))
2009 (if (re-search-forward mixi-event-detail-regexp nil t)
2010 (mixi-event-set-detail event (match-string 1))
2011 (mixi-realization-error 'cannot-find-detail event))
2012 (if (re-search-forward mixi-event-limit-regexp nil t)
2013 (mixi-event-set-limit event (match-string 1))
2014 (mixi-realization-error 'cannot-find-limit event))
2015 (if (re-search-forward mixi-event-members-regexp nil t)
2016 (mixi-event-set-members event (match-string 1))
2017 (mixi-realization-error 'cannot-find-members event))))
2018 (mixi-object-touch event)))
2020 (defun mixi-event-community (event)
2021 "Return the community of EVENT."
2022 (unless (mixi-event-p event)
2023 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2024 (aref (cdr event) 1))
2026 (defun mixi-event-id (event)
2027 "Return the id of EVENT."
2028 (unless (mixi-event-p event)
2029 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2030 (aref (cdr event) 2))
2032 (defun mixi-event-comment-count (event)
2033 "Return the comment-count of EVENT."
2034 (unless (mixi-event-p event)
2035 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2036 (aref (cdr event) 3))
2038 (defun mixi-event-time (event)
2039 "Return the time 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) 4))
2045 (defun mixi-event-title (event)
2046 "Return the title of EVENT."
2047 (unless (mixi-event-p event)
2048 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2049 (mixi-realize-event event)
2050 (aref (cdr event) 5))
2052 (defun mixi-event-owner (event)
2053 "Return the owner of EVENT."
2054 (unless (mixi-event-p event)
2055 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2056 (mixi-realize-event event)
2057 (aref (cdr event) 6))
2059 (defun mixi-event-date (event)
2060 "Return the date of EVENT."
2061 (unless (mixi-event-p event)
2062 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2063 (mixi-realize-event event)
2064 (aref (cdr event) 7))
2066 (defun mixi-event-place (event)
2067 "Return the place of EVENT."
2068 (unless (mixi-event-p event)
2069 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2070 (mixi-realize-event event)
2071 (aref (cdr event) 8))
2073 (defun mixi-event-detail (event)
2074 "Return the detail of EVENT."
2075 (unless (mixi-event-p event)
2076 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2077 (mixi-realize-event event)
2078 (aref (cdr event) 9))
2080 (defun mixi-event-limit (event)
2081 "Return the limit of EVENT."
2082 (unless (mixi-event-p event)
2083 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2084 (mixi-realize-event event)
2085 (aref (cdr event) 10))
2087 (defun mixi-event-members (event)
2088 "Return the members of EVENT."
2089 (unless (mixi-event-p event)
2090 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2091 (mixi-realize-event event)
2092 (aref (cdr event) 11))
2094 (defun mixi-event-set-comment-count (event comment-count)
2095 "Set the comment-count of EVENT."
2096 (unless (mixi-event-p event)
2097 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2098 (aset (cdr event) 3 comment-count))
2100 (defun mixi-event-set-time (event time)
2101 "Set the time of EVENT."
2102 (unless (mixi-event-p event)
2103 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2104 (aset (cdr event) 4 time))
2106 (defun mixi-event-set-title (event title)
2107 "Set the title of EVENT."
2108 (unless (mixi-event-p event)
2109 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2110 (aset (cdr event) 5 title))
2112 (defun mixi-event-set-owner (event owner)
2113 "Set the owner of EVENT."
2114 (unless (mixi-event-p event)
2115 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2116 (unless (mixi-friend-p owner)
2117 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
2118 (aset (cdr event) 6 owner))
2120 (defun mixi-event-set-date (event date)
2121 "Set the date of EVENT."
2122 (unless (mixi-event-p event)
2123 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2124 (aset (cdr event) 7 date))
2126 (defun mixi-event-set-place (event place)
2127 "Set the place of EVENT."
2128 (unless (mixi-event-p event)
2129 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2130 (aset (cdr event) 8 place))
2132 (defun mixi-event-set-detail (event detail)
2133 "Set the detail of EVENT."
2134 (unless (mixi-event-p event)
2135 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2136 (aset (cdr event) 9 detail))
2138 (defun mixi-event-set-limit (event limit)
2139 "Set the limit of EVENT."
2140 (unless (mixi-event-p event)
2141 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2142 (aset (cdr event) 10 limit))
2144 (defun mixi-event-set-members (event members)
2145 "Set the members of EVENT."
2146 (unless (mixi-event-p event)
2147 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2148 (aset (cdr event) 11 members))
2151 (defconst mixi-bbs-list '(mixi-topic mixi-event))
2153 (defmacro mixi-bbs-p (bbs)
2154 `(memq (mixi-object-class ,bbs) mixi-bbs-list))
2156 (defun mixi-bbs-community (bbs)
2157 "Return the community of BBS."
2158 (unless (mixi-bbs-p bbs)
2159 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2160 (let ((func (intern (concat mixi-object-prefix
2161 (mixi-object-name bbs) "-community"))))
2162 (funcall func bbs)))
2164 (defun mixi-bbs-comment-count (bbs)
2165 "Return the comment-count of BBS."
2166 (unless (mixi-bbs-p bbs)
2167 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2168 (let ((func (intern (concat mixi-object-prefix
2169 (mixi-object-name bbs) "-comment-count"))))
2170 (funcall func bbs)))
2172 (defun mixi-bbs-set-comment-count (bbs count)
2173 "Set the comment-count of BBS."
2174 (unless (mixi-bbs-p bbs)
2175 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2176 (let ((func (intern (concat mixi-object-prefix
2177 (mixi-object-name bbs) "-set-comment-count"))))
2178 (funcall func bbs count)))
2180 (defalias 'mixi-bbs-id 'mixi-object-id)
2181 (defalias 'mixi-bbs-time 'mixi-object-time)
2182 (defalias 'mixi-bbs-title 'mixi-object-title)
2183 (defalias 'mixi-bbs-owner 'mixi-object-owner)
2184 (defalias 'mixi-bbs-content 'mixi-object-content)
2186 (defmacro mixi-bbs-list-page (community)
2187 `(concat "/list_bbs.pl?page=%d"
2188 "&id=" (mixi-community-id ,community)))
2190 (defconst mixi-bbs-list-regexp
2191 "<a href=\"?view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)")
2194 (defun mixi-get-bbses (community &optional range)
2195 "Get bbses of COMMUNITY."
2196 (unless (mixi-community-p community)
2197 (signal 'wrong-type-argument (list 'mixi-community-p community)))
2198 (let ((items (mixi-get-matched-items (mixi-bbs-list-page community)
2199 mixi-bbs-list-regexp
2201 (mapcar (lambda (item)
2202 (let ((name (nth 0 item)))
2203 (when (string= name "bbs")
2204 (setq name "topic"))
2205 (let ((func (intern (concat "mixi-make-" name))))
2206 (funcall func community (nth 1 item)))))
2209 (defmacro mixi-new-bbs-list-page ()
2210 `(concat "/new_bbs.pl?page=%d"))
2212 (defconst mixi-new-bbs-list-regexp
2213 "<dd><a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\">")
2216 (defun mixi-get-new-bbses (&optional range)
2218 (let ((items (mixi-get-matched-items (mixi-new-bbs-list-page)
2219 mixi-new-bbs-list-regexp
2222 (mapcar (lambda (item)
2223 (let ((name (nth 0 item)))
2224 (when (string= name "bbs")
2225 (setq name "topic"))
2226 (let* ((func (intern (concat "mixi-make-" name)))
2228 (mixi-make-community (nth 3 item))
2230 (comment-count (mixi-bbs-comment-count bbs))
2231 (count (string-to-number (nth 2 item))))
2232 (when (or (null comment-count)
2233 (< comment-count count))
2234 (mixi-bbs-set-comment-count bbs count)
2238 (defmacro mixi-search-bbs-list-page (keyword)
2239 `(concat "/search_topic.pl?page=%d&type=top&submit=search"
2240 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
2241 "&community_id=0&category_id=0"))
2243 (defconst mixi-search-bbs-list-regexp
2244 "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\" class=\"title\">")
2246 ;; FIXME: Support community and category.
2248 (defun mixi-search-bbses (keyword &optional range)
2249 (let ((items (mixi-get-matched-items (mixi-search-bbs-list-page keyword)
2250 mixi-search-bbs-list-regexp
2252 (mapcar (lambda (item)
2253 (let ((name (nth 0 item)))
2254 (when (string= name "bbs")
2255 (setq name "topic"))
2256 (let ((func (intern (concat "mixi-make-" name))))
2257 (funcall func (mixi-make-community (nth 2 item))
2262 (defmacro mixi-parent-p (object)
2263 `(or (eq (mixi-object-class ,object) 'mixi-diary)
2264 (mixi-bbs-p ,object)))
2266 (defun mixi-realize-parent (parent &optional page)
2268 (unless (mixi-parent-p parent)
2269 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2270 (let ((func (intern (concat mixi-object-prefix "realize-"
2271 (mixi-object-name parent)))))
2272 (funcall func parent page)))
2275 (defun mixi-make-comment (parent owner time content &optional count)
2276 "Return a comment object."
2277 (cons 'mixi-comment (vector parent owner time content count)))
2279 (defmacro mixi-comment-p (comment)
2280 `(eq (mixi-object-class ,comment) 'mixi-comment))
2282 (defun mixi-comment-parent (comment)
2283 "Return the parent of COMMENT."
2284 (unless (mixi-comment-p comment)
2285 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2286 (aref (cdr comment) 0))
2288 (defun mixi-comment-owner (comment)
2289 "Return the owner of COMMENT."
2290 (unless (mixi-comment-p comment)
2291 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2292 (aref (cdr comment) 1))
2294 (defun mixi-comment-time (comment)
2295 "Return the time of COMMENT."
2296 (unless (mixi-comment-p comment)
2297 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2298 (aref (cdr comment) 2))
2300 (defun mixi-comment-content (comment)
2301 "Return the content of COMMENT."
2302 (unless (mixi-comment-p comment)
2303 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2304 (aref (cdr comment) 3))
2306 (defun mixi-comment-count (comment)
2307 "Return the count of COMMENT."
2308 (unless (mixi-comment-p comment)
2309 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2310 (aref (cdr comment) 4))
2312 (defun mixi-diary-comment-list-page (diary)
2313 (concat "/view_diary.pl?full=1"
2314 "&id=" (mixi-diary-id diary)
2315 "&owner_id=" (mixi-friend-id (mixi-diary-owner diary))))
2317 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2318 (defconst mixi-diary-comment-list-regexp
2319 "<span class=\"commentTitleName\">\\(<input type=\"checkbox\" name=\"comment_id\" value=\".+\" />
2320 \\|\\)<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2322 | <a href=\"delete_comment\\.pl\\?diary_id=[0-9]+&owner_id=[0-9]+&comment_id=.+&type=comment\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a>
2325 <span class=\"commentTitleDate\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>
2329 \\(\\(.\\|\r?\n\\)*?\\)
2334 (defun mixi-topic-comment-list-page (topic)
2335 (concat "/view_bbs.pl?page=all"
2336 "&id=" (mixi-topic-id topic)
2337 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2339 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2340 (defconst mixi-topic-comment-list-regexp
2341 "<dt class=\"commentDate clearfix\"><span class=\"senderId\">\\(<input id=\"commentCheck01\" name=\"comment_id\" type=\"checkbox\" value=\"[0-9]+\" /><label for=\"commentCheck01\">\\|\\)\\([0-9]+\\)\\(<span class=\"deleteTextArea\"><a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a></span>\\|</label>\\|\\)</span>
2342 <span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
2344 <dl class=\"commentContent01\">
2345 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
2347 \\(\\(.\\|\r?\n\\)*?\\)
2350 (defun mixi-event-comment-list-page (event)
2351 (concat "/view_event.pl?page=all"
2352 "&id=" (mixi-event-id event)
2353 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2355 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2356 (defconst mixi-event-comment-list-regexp
2357 "<dt class=\"commentDate clearfix\"><span class=\"senderId\">\\(<input id=\"commentCheck01\" name=\"comment_id\" type=\"checkbox\" value=\"[0-9]+\" /><label for=\"commentCheck01\">\\|\\)\\([0-9]+\\)\\(<span class=\"deleteTextArea\"><a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+&type=event\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a></span>\\|</label>\\|\\)</span>
2358 <span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
2360 <dl class=\"commentContent01\">
2361 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
2363 \\(\\(.\\|\r?\n\\)*?\\)
2367 (defun mixi-get-comments (parent &optional range)
2368 "Get comments of PARENT."
2369 (unless (mixi-parent-p parent)
2370 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2371 (let* ((name (mixi-object-name parent))
2372 (list-page (intern (concat mixi-object-prefix name
2373 "-comment-list-page")))
2374 (regexp (eval (intern (concat mixi-object-prefix name
2375 "-comment-list-regexp"))))
2376 (page (funcall list-page parent)))
2377 (unless (mixi-object-realized-p parent)
2378 (mixi-realize-parent parent page)
2380 (let ((items (mixi-get-matched-items page regexp range t)))
2381 (mapcar (lambda (item)
2382 (let (owner-id owner-nick year month day hour minute content
2384 (if (eq (mixi-object-class parent) 'mixi-diary)
2386 (setq owner-id (nth 1 item))
2387 (setq owner-nick (nth 2 item))
2388 (setq year (nth 4 item))
2389 (setq month (nth 5 item))
2390 (setq day (nth 6 item))
2391 (setq hour (nth 7 item))
2392 (setq minute (nth 8 item))
2393 (setq content (nth 9 item)))
2394 (setq owner-id (nth 8 item))
2395 (setq owner-nick (nth 9 item))
2396 (setq year (nth 3 item))
2397 (setq month (nth 4 item))
2398 (setq day (nth 5 item))
2399 (setq hour (nth 6 item))
2400 (setq minute (nth 7 item))
2401 (setq content (nth 10 item))
2402 (setq count (nth 1 item)))
2403 (mixi-make-comment parent (mixi-make-friend owner-id
2407 (string-to-number minute)
2408 (string-to-number hour)
2409 (string-to-number day)
2410 (string-to-number month)
2411 (string-to-number year))
2415 (defmacro mixi-new-comment-list-page ()
2416 `(concat "/new_comment.pl?page=%d"))
2418 (defconst mixi-new-comment-list-regexp
2419 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)\">")
2422 (defun mixi-get-new-comments (&optional range)
2424 (let ((items (mixi-get-matched-items (mixi-new-comment-list-page)
2425 mixi-new-comment-list-regexp
2428 (mapcar (lambda (item)
2429 (let* ((diary (mixi-make-diary
2430 (mixi-make-friend (nth 1 item))
2432 (comment-count (mixi-diary-comment-count diary))
2433 (count (string-to-number (nth 2 item))))
2434 (when (or (null comment-count)
2435 (< comment-count count))
2436 (mixi-diary-set-comment-count diary count)
2440 (defmacro mixi-new-bbs-comment-list-page ()
2441 `(concat "/new_bbs_comment.pl?page=%d"))
2443 (defconst mixi-new-bbs-comment-list-regexp
2444 "<a href=\"?view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\"?>")
2447 (defun mixi-get-new-bbs-comments (&optional range)
2448 "Get new BBS comments."
2449 (let ((items (mixi-get-matched-items (mixi-new-bbs-comment-list-page)
2450 mixi-new-bbs-comment-list-regexp
2453 (mapcar (lambda (item)
2454 (let ((name (nth 0 item)))
2455 (when (string= name "bbs")
2456 (setq name "topic"))
2457 (let ((make-func (intern (concat "mixi-make-" name)))
2459 (intern (concat "mixi-" name "-comment-count")))
2460 (set-comment-count-func
2461 (intern (concat "mixi-" name
2462 "-set-comment-count"))))
2463 (let* ((bbs (funcall make-func
2464 (mixi-make-community (nth 3 item))
2466 (comment-count (funcall comment-count-func bbs))
2467 (count (string-to-number (nth 2 item))))
2468 (when (or (null comment-count)
2469 (< comment-count count))
2470 (funcall set-comment-count-func bbs count)
2474 (defun mixi-post-diary-comment-page (diary)
2475 (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
2477 (defun mixi-post-topic-comment-page (topic)
2478 (concat "/add_bbs_comment.pl?id=" (mixi-topic-id topic)
2479 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2481 (defun mixi-post-event-comment-page (event)
2482 (concat "/add_event_comment.pl?id=" (mixi-event-id event)
2483 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2485 ;; FIXME: Support photos.
2487 (defun mixi-post-comment (parent content)
2488 "Post a comment to PARENT."
2489 (unless (mixi-object-p parent)
2490 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
2491 (unless (stringp content)
2492 (signal 'wrong-type-argument (list 'stringp content)))
2493 (let* ((name (mixi-object-name parent))
2494 (page (intern (concat mixi-object-prefix "post-" name
2497 (if (mixi-diary-p parent)
2499 `(("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2500 ("comment_body" . ,content)))
2501 (setq fields `(("comment" . ,content))))
2502 (with-mixi-post-form (funcall page parent) fields
2503 (if (re-search-forward mixi-post-key-regexp nil t)
2504 (setq post-key (match-string 1))
2505 (mixi-post-error 'cannot-find-key parent)))
2506 (if (mixi-diary-p parent)
2508 `(("post_key" . ,post-key)
2509 ("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2510 ("comment_body" . ,content)
2511 ("submit" . "confirm")))
2512 (setq fields `(("post_key" . ,post-key)
2513 ("comment" . ,content)
2514 ("submit" . "confirm"))))
2515 (with-mixi-post-form (funcall page parent) fields
2516 (unless (re-search-forward mixi-post-succeed-regexp nil t)
2517 (mixi-post-error 'cannot-find-succeed parent)))))
2520 (defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
2522 (defmacro mixi-message-box-p (box)
2523 `(memq ,box mixi-message-box-list))
2525 (defun mixi-message-box-name (box)
2526 "Return the name of BOX."
2527 (unless (mixi-message-box-p box)
2528 (signal 'wrong-type-argument (list 'mixi-message-box-p box)))
2531 (defvar mixi-message-cache (make-hash-table :test 'equal))
2532 (defun mixi-make-message (id box &optional owner title time content)
2533 "Return a message object."
2534 (mixi-make-cache (list id box)
2535 (cons 'mixi-message (vector nil id box owner title time
2537 mixi-message-cache))
2539 (defconst mixi-message-url-regexp
2540 "/view_message\\.pl\\?id=\\([a-z0-9]+\\)&box=\\([a-z]+\\)")
2542 (defun mixi-make-message-from-url (url)
2543 "Return a message object from URL."
2544 (when (string-match mixi-message-url-regexp url)
2545 (let ((id (match-string 1 url))
2546 (box (match-string 2 url)))
2547 (mixi-make-message id box))))
2549 (defmacro mixi-message-p (message)
2550 `(eq (mixi-object-class ,message) 'mixi-message))
2552 (defmacro mixi-message-page (message)
2553 `(concat "/view_message.pl?id=" (mixi-message-id ,message)
2554 "&box=" (mixi-message-box ,message)))
2556 (defconst mixi-message-owner-regexp
2557 "<font COLOR=#996600>\\(º¹½Ð¿Í\\|°¸ Àè\\)</font> : <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)\\(</a>\\|</td>\\)")
2558 (defconst mixi-message-time-regexp
2559 "<font COLOR=#996600>Æü\\(¡¡\\| \\)ÉÕ</font> : \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ ")
2560 (defconst mixi-message-title-regexp
2561 "<font COLOR=#996600>·ï\\(¡¡\\| \\)̾</font> : \\(.*\\)\n?</td>")
2562 (defconst mixi-message-content-regexp
2563 "<tr><td CLASS=h120 width=\"500\">\\(.*\\)</td></tr>")
2565 (defun mixi-realize-message (message)
2566 "Realize a MESSAGE."
2567 (unless (mixi-object-realized-p message)
2568 (with-mixi-retrieve (mixi-message-page message)
2569 (if (re-search-forward mixi-message-owner-regexp nil t)
2570 (mixi-message-set-owner message
2571 (mixi-make-friend (match-string 2)
2573 (mixi-realization-error 'cannot-find-owner message))
2574 (if (re-search-forward mixi-message-time-regexp nil t)
2575 (mixi-message-set-time
2576 message (encode-time 0 (string-to-number (match-string 6))
2577 (string-to-number (match-string 5))
2578 (string-to-number (match-string 4))
2579 (string-to-number (match-string 3))
2580 (string-to-number (match-string 2))))
2581 (mixi-realization-error 'cannot-find-time message))
2582 (if (re-search-forward mixi-message-title-regexp nil t)
2583 (mixi-message-set-title message (match-string 2))
2584 (mixi-realization-error 'cannot-find-title message))
2585 (if (re-search-forward mixi-message-content-regexp nil t)
2586 (mixi-message-set-content message (match-string 1))
2587 (mixi-realization-error 'cannot-find-content message)))
2588 (mixi-object-touch message)))
2590 (defun mixi-message-id (message)
2591 "Return the id of MESSAGE."
2592 (unless (mixi-message-p message)
2593 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2594 (aref (cdr message) 1))
2596 (defun mixi-message-box (message)
2597 "Return the box of MESSAGE."
2598 (unless (mixi-message-p message)
2599 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2600 (aref (cdr message) 2))
2602 (defun mixi-message-owner (message)
2603 "Return the owner of MESSAGE."
2604 (unless (mixi-message-p message)
2605 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2606 (mixi-realize-message message)
2607 (aref (cdr message) 3))
2609 (defun mixi-message-title (message)
2610 "Return the title of MESSAGE."
2611 (unless (mixi-message-p message)
2612 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2613 (mixi-realize-message message)
2614 (aref (cdr message) 4))
2616 (defun mixi-message-time (message)
2617 "Return the date of MESSAGE."
2618 (unless (mixi-message-p message)
2619 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2620 (mixi-realize-message message)
2621 (aref (cdr message) 5))
2623 (defun mixi-message-content (message)
2624 "Return the content of MESSAGE."
2625 (unless (mixi-message-p message)
2626 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2627 (mixi-realize-message message)
2628 (aref (cdr message) 6))
2630 (defun mixi-message-set-owner (message owner)
2631 "Set the owner of MESSAGE."
2632 (unless (mixi-message-p message)
2633 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2634 (aset (cdr message) 3 owner))
2636 (defun mixi-message-set-title (message title)
2637 "Set the title of MESSAGE."
2638 (unless (mixi-message-p message)
2639 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2640 (aset (cdr message) 4 title))
2642 (defun mixi-message-set-time (message time)
2643 "Set the date of MESSAGE."
2644 (unless (mixi-message-p message)
2645 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2646 (aset (cdr message) 5 time))
2648 (defun mixi-message-set-content (message content)
2649 "Set the content of MESSAGE."
2650 (unless (mixi-message-p message)
2651 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2652 (aset (cdr message) 6 content))
2654 (defmacro mixi-message-list-page (&optional box)
2655 `(concat "/list_message.pl?page=%d"
2656 (when ,box (concat "&box=" ,box))))
2658 (defconst mixi-message-list-regexp
2659 "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
2662 (defun mixi-get-messages (&rest box-or-range)
2663 "Get messages of BOX."
2664 (when (> (length box-or-range) 2)
2665 (signal 'wrong-number-of-arguments
2666 (list 'mixi-get-messages (length box-or-range))))
2667 (let ((box (nth 0 box-or-range))
2668 (range (nth 1 box-or-range)))
2669 (when (or (not (mixi-message-box-p box))
2670 (mixi-message-box-p range))
2671 (setq box (nth 1 box-or-range))
2672 (setq range (nth 0 box-or-range)))
2673 (let ((items (mixi-get-matched-items
2674 (mixi-message-list-page
2675 (when box (mixi-message-box-name box)))
2676 mixi-message-list-regexp
2678 (mapcar (lambda (item)
2679 (mixi-make-message (nth 0 item) (nth 1 item)))
2682 (defmacro mixi-post-message-page (friend)
2683 `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
2685 (defconst mixi-post-message-key-regexp
2686 "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
2688 (defconst mixi-post-message-succeed-regexp
2689 "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
2692 (defun mixi-post-message (friend title content)
2693 "Post a message to FRIEND."
2694 (unless (mixi-friend-p friend)
2695 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2696 (unless (stringp title)
2697 (signal 'wrong-type-argument (list 'stringp title)))
2698 (unless (stringp content)
2699 (signal 'wrong-type-argument (list 'stringp content)))
2700 (let ((fields `(("subject" . ,title)
2702 ("submit" . "main")))
2704 (with-mixi-post-form (mixi-post-message-page friend) fields
2705 (if (re-search-forward mixi-post-message-key-regexp nil t)
2706 (setq post-key (match-string 1))
2707 (mixi-post-error 'cannot-find-key friend)))
2708 (setq fields `(("post_key" . ,post-key)
2709 ("subject" . ,title)
2711 ("yes" . "¡¡Á÷¡¡¿®¡¡")
2712 ("submit" . "confirm")))
2713 (with-mixi-post-form (mixi-post-message-page friend) fields
2714 (unless (re-search-forward mixi-post-message-succeed-regexp nil t)
2715 (mixi-post-error 'cannot-find-succeed friend)))))
2717 ;; Introduction object.
2718 (defun mixi-make-introduction (parent owner content)
2719 "Return a introduction object."
2720 (cons 'mixi-introduction (vector parent owner content)))
2722 (defmacro mixi-introduction-p (introduction)
2723 `(eq (mixi-object-class ,introduction) 'mixi-introduction))
2725 (defun mixi-introduction-parent (introduction)
2726 "Return the parent of INTRODUCTION."
2727 (unless (mixi-introduction-p introduction)
2728 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2729 (aref (cdr introduction) 0))
2731 (defun mixi-introduction-owner (introduction)
2732 "Return the owner of INTRODUCTION."
2733 (unless (mixi-introduction-p introduction)
2734 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2735 (aref (cdr introduction) 1))
2737 (defun mixi-introduction-content (introduction)
2738 "Return the content of INTRODUCTION."
2739 (unless (mixi-introduction-p introduction)
2740 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2741 (aref (cdr introduction) 3))
2743 (defmacro mixi-introduction-list-page (&optional friend)
2744 `(concat "/show_intro.pl?page=%d"
2745 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
2747 (defconst mixi-introduction-list-regexp
2748 "<tr bgcolor=#FFFFFF>
2749 <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>
2756 \\(\\(.\\|\n<br>\\)+\\)\\|
2757 \\(\\(.\\|\n<br>\\)+\\)\\)
2764 (defconst mixi-my-introduction-list-regexp
2765 "<tr bgcolor=#FFFFFF>
2766 <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>
2774 \\(\\(.\\|\n<br>\\)+\\)\\|
2775 \\(\\(.\\|\n<br>\\)+\\)\\)
2779 <a href=\"edit_intro\\.pl\\?id=\\1&type=edit\">¤³¤Îͧ¿Í¤ò¾Ò²ð¤¹¤ë</a>
2783 <a href=\"delete_intro\\.pl\\?id=\\1\">ºï½ü</a>
2789 (defun mixi-get-introductions (&rest friend-or-range)
2790 "Get introductions of FRIEND."
2791 (when (> (length friend-or-range) 2)
2792 (signal 'wrong-number-of-arguments
2793 (list 'mixi-get-introduction (length friend-or-range))))
2794 (let ((friend (nth 0 friend-or-range))
2795 (range (nth 1 friend-or-range)))
2796 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
2797 (setq friend (nth 1 friend-or-range))
2798 (setq range (nth 0 friend-or-range)))
2799 (unless (or (null friend) (mixi-friend-p friend))
2800 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2801 (let* ((regexp (if friend mixi-introduction-list-regexp
2802 mixi-my-introduction-list-regexp))
2803 (items (mixi-get-matched-items (mixi-introduction-list-page friend)
2806 (mapcar (lambda (item)
2807 (mixi-make-introduction (or friend (mixi-make-me))
2808 (mixi-make-friend (nth 0 item)
2814 (defvar mixi-news-cache (make-hash-table :test 'equal))
2815 (defun mixi-make-news (media-id id &optional media time title content)
2816 "Return a news object."
2817 (mixi-make-cache (list media-id id)
2818 (cons 'mixi-news (vector nil media-id id media time title
2822 (defconst mixi-news-url-regexp
2823 "/view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)")
2825 (defun mixi-make-news-from-url (url)
2826 "Return a news object from URL."
2827 (when (string-match mixi-news-url-regexp url)
2828 (let ((id (match-string 1 url))
2829 (media-id (match-string 2 url)))
2830 (mixi-make-news media-id id))))
2832 (defmacro mixi-news-p (news)
2833 `(eq (mixi-object-class ,news) 'mixi-news))
2835 (defmacro mixi-news-page (news)
2836 `(concat "http://news.mixi.jp/view_news.pl?id=" (mixi-news-id ,news)
2837 "&media_id=" (mixi-news-media-id ,news)))
2839 (defconst mixi-news-finished-regexp
2840 "¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤³¤Î¥Ë¥å¡¼¥¹¤Ï·ÇºÜ¤¬½ªÎ»¤·¤¿¤«¡¢URL¤¬´Ö°ã¤Ã¤Æ¤¤¤¤¤ë¤¿¤á¤´Í÷¤¤¤¿¤À¤±¤Þ¤»¤ó¡£</td>")
2841 (defconst mixi-news-title-regexp
2842 "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)\\(
2844 (defconst mixi-news-media-time-regexp
2845 "<td COLSPAN=\"2\" ALIGN=\"right\">(\\(.+\\) - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))</td></tr>")
2846 (defconst mixi-news-content-regexp
2847 "<td CLASS=\"h150\">
2854 \\(</td>\\|<br>\\)")
2856 (defun mixi-realize-news (news)
2858 ;; FIXME: Check a expiration of cache?
2859 (unless (mixi-object-realized-p news)
2860 (with-mixi-retrieve (mixi-news-page news)
2861 (if (re-search-forward mixi-news-finished-regexp nil t)
2862 (mixi-news-set-content news (match-string 0))
2863 (if (re-search-forward mixi-news-title-regexp nil t)
2864 (mixi-news-set-title news (match-string 1))
2865 (mixi-realization-error 'cannot-find-title news))
2866 (if (re-search-forward mixi-news-media-time-regexp nil t)
2868 (mixi-news-set-media news (match-string 1))
2869 (let ((year (nth 5 (decode-time (current-time))))
2870 (month (nth 4 (decode-time (current-time))))
2871 (month-of-item (string-to-number (match-string 2))))
2872 (when (> month-of-item month)
2875 news (encode-time 0 (string-to-number (match-string 5))
2876 (string-to-number (match-string 4))
2877 (string-to-number (match-string 3))
2879 (mixi-realization-error 'cannot-find-media-time news))
2880 (if (re-search-forward mixi-news-content-regexp nil t)
2881 (mixi-news-set-content news (match-string 1))
2882 (mixi-realization-error 'cannot-find-content news))))
2883 (mixi-object-touch news)))
2885 (defun mixi-news-media-id (news)
2886 "Return the media-id of NEWS."
2887 (unless (mixi-news-p news)
2888 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2889 (aref (cdr news) 1))
2891 (defun mixi-news-id (news)
2892 "Return the id of NEWS."
2893 (unless (mixi-news-p news)
2894 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2895 (aref (cdr news) 2))
2897 (defun mixi-news-media (news)
2898 "Return the media of NEWS."
2899 (unless (mixi-news-p news)
2900 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2901 (unless (aref (cdr news) 3)
2902 (mixi-realize-news news))
2903 (aref (cdr news) 3))
2905 (defun mixi-news-time (news)
2906 "Return the time of NEWS."
2907 (unless (mixi-news-p news)
2908 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2909 (unless (aref (cdr news) 4)
2910 (mixi-realize-news news))
2911 (aref (cdr news) 4))
2913 (defun mixi-news-title (news)
2914 "Return the title of NEWS."
2915 (unless (mixi-news-p news)
2916 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2917 (unless (aref (cdr news) 5)
2918 (mixi-realize-news news))
2919 (aref (cdr news) 5))
2921 (defun mixi-news-content (news)
2922 "Return the content of NEWS."
2923 (unless (mixi-news-p news)
2924 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2925 (mixi-realize-news news)
2926 (aref (cdr news) 6))
2928 (defun mixi-news-set-media (news media)
2929 "Set the media of NEWS."
2930 (unless (mixi-news-p news)
2931 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2932 (aset (cdr news) 3 media))
2934 (defun mixi-news-set-time (news time)
2935 "Set the time of NEWS."
2936 (unless (mixi-news-p news)
2937 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2938 (aset (cdr news) 4 time))
2940 (defun mixi-news-set-title (news title)
2941 "Set the title of NEWS."
2942 (unless (mixi-news-p news)
2943 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2944 (aset (cdr news) 5 title))
2946 (defun mixi-news-set-content (news content)
2947 "Set the content of NEWS."
2948 (unless (mixi-news-p news)
2949 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2950 (aset (cdr news) 6 content))
2952 (defconst mixi-news-category-list '(domestic politics economy area abroad
2953 sports entertainment IT game-anime
2956 (defmacro mixi-news-category-p (category)
2957 `(memq ,category mixi-news-category-list))
2959 (defun mixi-news-category-id (category)
2960 "Return the id of CATEGORY."
2961 (unless (mixi-news-category-p category)
2962 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2964 (1+ (- (length mixi-news-category-list)
2965 (length (memq category mixi-news-category-list))))))
2967 (defconst mixi-news-sort-list '(newest pickup))
2969 (defmacro mixi-news-sort-p (sort)
2970 `(memq ,sort mixi-news-sort-list))
2972 (defun mixi-news-sort-id (sort)
2973 "Return the id of SORT."
2974 (unless (mixi-news-sort-p sort)
2975 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
2977 (- (length mixi-news-sort-list)
2978 (length (memq sort mixi-news-sort-list)))))
2980 (defmacro mixi-news-list-page (category sort)
2981 `(concat "http://news.mixi.jp/list_news_category.pl?page=%d"
2982 "&sort=" (mixi-news-sort-id ,sort)
2983 "&id=" (mixi-news-category-id ,category)
2986 (defconst mixi-news-list-regexp
2987 "<tr bgcolor=\"\\(#FCF5EB\\|#FFFFFF\\)\">
2988 <td WIDTH=\"1%\" valign=top CLASS=\"h120\">¡¦</td>
2989 <td WIDTH=\"97%\" CLASS=\"h120\"><A HREF=\"view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)\"class=\"new_link\">\\(.+\\)</A>
2990 \\(<IMG SRC=\"http://img\\.mixi\\.jp/img/news_camera3\\.gif\" WIDTH=\"11\" HEIGHT=\"12\">\\|\\)
2993 <td WIDTH=\"1%\" nowrap CLASS=\"f08\"><A HREF=\"list_news_media\\.pl\\?id=[0-9]+\">\\(.+\\)</A></td>
2994 <td WIDTH=\"1%\" nowrap CLASS=\"f08\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td></tr>")
2997 (defun mixi-get-news (category sort &optional range)
2998 "Get news of CATEGORY and SORT."
2999 (unless (mixi-news-category-p category)
3000 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
3001 (unless (mixi-news-sort-p sort)
3002 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
3003 (let ((items (mixi-get-matched-items (mixi-news-list-page category sort)
3004 mixi-news-list-regexp
3006 (year (nth 5 (decode-time (current-time))))
3007 (month (nth 4 (decode-time (current-time)))))
3008 (mapcar (lambda (item)
3009 (let ((month-of-item (string-to-number (nth 6 item))))
3010 (when (> month-of-item month)
3012 (setq month month-of-item)
3013 (mixi-make-news (nth 2 item) (nth 1 item) (nth 5 item)
3015 0 (string-to-number (nth 9 item))
3016 (string-to-number (nth 8 item))
3017 (string-to-number (nth 7 item))
3024 ;;; mixi.el ends here