1 ;; mixi.el --- API libraries for accessing to mixi -*- coding: euc-jp -*-
3 ;; Copyright (C) 2005, 2006, 2007 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
33 ;; * mixi-get-new-diaries
34 ;; * mixi-search-diaries
35 ;; * mixi-get-communities
36 ;; * mixi-search-communities
38 ;; * mixi-get-new-bbses
39 ;; * mixi-search-bbses
40 ;; * mixi-get-comments
41 ;; * mixi-get-new-comments
42 ;; * mixi-get-new-bbs-comments
43 ;; * mixi-get-messages
44 ;; * mixi-get-introductions (broken)
51 ;; * mixi-post-comment
52 ;; * mixi-post-message
56 ;; * mixi-remove-markup (half broken)
60 ;; Display newest 3 diaries like a mail format.
63 ;; (buffer (get-buffer-create "*temp*"))
64 ;; (format "%Y/%m/%d %H:%M"))
65 ;; (pop-to-buffer buffer)
66 ;; (let ((diaries (mixi-get-new-diaries range)))
68 ;; (let* ((diary (car diaries))
69 ;; (subject (mixi-diary-title diary))
70 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
71 ;; (date (format-time-string format (mixi-diary-time diary)))
72 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
73 ;; (insert "From: " from "\n"
74 ;; "Subject: " subject "\n"
75 ;; "Date: " date "\n\n"
77 ;; (setq diaries (cdr diaries))))
78 ;; (set-buffer-modified-p nil)
79 ;; (setq buffer-read-only t)
80 ;; (goto-char (point-min)))
82 ;; Display newest 3 diaries including newest 3 comments like a mail format.
83 ;; Comments are displayed like a reply mail.
86 ;; (buffer (get-buffer-create "*temp*"))
87 ;; (format "%Y/%m/%d %H:%M"))
88 ;; (pop-to-buffer buffer)
89 ;; (let ((diaries (mixi-get-new-diaries range)))
91 ;; (let* ((diary (car diaries))
92 ;; (subject (mixi-diary-title diary))
93 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
94 ;; (date (format-time-string format (mixi-diary-time diary)))
95 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
96 ;; (insert "From: " from "\n"
97 ;; "Subject: " subject "\n"
98 ;; "Date: " date "\n\n"
100 ;; (let ((comments (mixi-get-comments diary range)))
102 ;; (let* ((comment (car comments))
103 ;; (from (mixi-friend-nick (mixi-comment-owner comment)))
104 ;; (subject (concat "Re: " subject))
105 ;; (date (format-time-string format
106 ;; (mixi-comment-time comment)))
107 ;; (body (mixi-remove-markup (mixi-comment-content comment))))
108 ;; (insert "From: " from "\n"
109 ;; "Subject: " subject "\n"
110 ;; "Date: " date "\n\n"
112 ;; (setq comments (cdr comments)))))
113 ;; (setq diaries (cdr diaries))))
114 ;; (set-buffer-modified-p nil)
115 ;; (setq buffer-read-only t)
116 ;; (goto-char (point-min)))
120 ;; If you have bug reports and/or suggestions for improvement, please
121 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
125 (eval-when-compile (require 'cl))
127 ;; Functions and variables which should be defined in the other module
130 (defvar w3m-use-cookies)
131 (defvar url-request-method)
132 (defvar url-request-data)
133 (defvar url-request-extra-headers)
134 (defvar url-show-status)
135 (autoload 'w3m-decode-buffer "w3m")
136 (autoload 'w3m-retrieve "w3m")
137 (autoload 'url-retrieve-synchronously "url"))
139 (defconst mixi-revision "$Revision: 1.176 $")
142 "API library for accessing to mixi."
145 (defcustom mixi-url "http://mixi.jp"
150 (defcustom mixi-directory (expand-file-name "~/.mixi")
151 "*Where to look for mixi files."
155 (defcustom mixi-coding-system 'euc-jp
156 "*Coding system for mixi."
160 (defcustom mixi-curl-program "curl"
161 "*The program name of `curl'."
165 (defcustom mixi-curl-cookie-file (expand-file-name "cookies.txt"
167 "*The location of cookie file created by `curl'."
171 (defcustom mixi-backend
172 (or (condition-case nil
180 (if (fboundp 'url-retrieve-synchronously)
183 (if (and (fboundp 'executable-find)
184 (executable-find mixi-curl-program))
186 (error "Cannot set `mixi-backend'."))
187 "*The backend for accessing to mixi."
188 :type '(radio (const :tag "Use emacs-w3m" w3m)
189 (const :tag "Use url.el" url)
190 (const :tag "Use curl" curl)
191 (symbol :tag "The other backend"))
194 (defcustom mixi-login-use-ssl nil
195 "*If non-ni, login using SSL."
199 (defcustom mixi-default-email nil
200 "*Default E-mail address that is used to login automatically."
201 :type '(radio (string :tag "E-mail address")
202 (const :tag "Asked when it is necessary" nil))
205 (defcustom mixi-default-password nil
206 "*Default password that is used to login automatically."
207 :type '(radio (string :tag "Password")
208 (const :tag "Asked when it is necessary" nil))
211 (defcustom mixi-accept-adult-contents t
212 "*If non-nil, accept to access to the adult contents."
216 (defcustom mixi-continuously-access-interval 4.0
217 "*Time interval between each mixi access.
218 Increase this value when unexpected error frequently occurs."
222 (defcustom mixi-cache-expires nil
223 "*Seconds for expiration of a cached object."
224 :type '(radio (integer :tag "Expired seconds")
225 (const :tag "Don't expire" nil)
226 (const :tag "Don't cache" t))
229 ;; FIXME: Not implemented.
230 (defcustom mixi-cache-use-file t
231 "*If non-nil, caches are saved to files."
235 (defvar mixi-temp-buffer-name " *mixi temp*")
239 (defmacro mixi-message (&rest strings)
240 `(concat "[mixi] " ,@strings))
242 (put 'mixi-realization-error
243 'error-message (mixi-message "Cannot realize object"))
244 (put 'mixi-realization-error
245 'error-conditions '(mixi-realization-error error))
247 (put 'mixi-post-error
248 'error-message (mixi-message "Cannot post"))
249 (put 'mixi-post-error
250 'error-conditions '(mixi-post-error error))
252 (defmacro mixi-realization-error (type object)
253 `(let ((data (if debug-on-error
254 (list ,type ,object (buffer-string))
255 (list ,type ,object))))
256 (signal 'mixi-realization-error data)))
258 (defmacro mixi-post-error (type &optional object)
259 `(let ((data (when debug-on-error (list (buffer-string)))))
261 (setq data (cons ,type (cons ,object data)))
262 (setq data (cons ,type data)))
263 (signal 'mixi-post-error data)))
265 (defconst mixi-message-adult-contents
266 "¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
267 ±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
268 (defconst mixi-message-continuously-accessing
269 "°ÂÄꤷ¤Æ¥µ¥¤¥È¤Î±¿±Ä¤ò¤ª¤³¤Ê¤¦°Ù¡¢´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹<br>
270 ¿·¤ÏÀ©¸Â¤µ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤ª¤ê¤Þ¤¹¡£¤´ÌÂÏǤò¤ª¤«¤±¤¤¤¿¤·¤Þ¤¹¤¬¡¢¤·¤Ð¤é¤¯¤ª<br>
271 ÂÔ¤Á¤¤¤¿¤À¤¤¤Æ¤«¤éÁàºî¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£")
272 (defconst mixi-warning-continuously-accessing
273 "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«<br>
274 ¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ<br>
275 ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
277 (defmacro mixi-retrieve (url &optional post-data)
278 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-retrieve"))
281 (defmacro mixi-post-form (url fields)
282 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-post-form"))
285 (defun mixi-parse-buffer (url buffer &optional post-data)
286 (when (string-match mixi-message-adult-contents buffer)
287 (if mixi-accept-adult-contents
288 (setq buffer (mixi-retrieve url "submit=agree"))
289 (setq buffer (mixi-retrieve (concat url "?")))))
290 (when (string-match mixi-warning-continuously-accessing buffer)
291 (error (mixi-message "Access denied. Please wait a while and increase "
292 "the value of `mixi-continuously-access-interval'.")))
293 (if (not (string-match mixi-message-continuously-accessing buffer))
295 (message (mixi-message "Waiting for continuously accessing..."))
296 (sleep-for mixi-continuously-access-interval)
297 (mixi-retrieve url post-data)))
299 (defmacro mixi-expand-url (url)
300 `(if (string-match "^http" ,url)
302 (concat mixi-url ,url)))
304 ;; FIXME: Support files.
305 (defun mixi-make-form-data (fields)
306 "Make form data and return (CONTENT-TYPE . FORM-DATA)."
307 (let* ((boundary (apply 'format "--_%d_%d_%d" (current-time)))
308 (content-type (concat "multipart/form-data; boundary=" boundary))
312 (concat "--" boundary "\r\n"
313 "Content-Disposition: form-data; name=\""
316 (encode-coding-string (cdr field) mixi-coding-system)))
318 (cons content-type (concat form-data "\r\n--" boundary "--"))))
320 (defun mixi-url-retrieve (url &optional post-data extra-headers)
321 "Retrieve the URL and return gotten strings."
322 (let* ((url-request-method (if post-data "POST" "GET"))
323 (url-request-data post-data)
324 (url-request-extra-headers extra-headers)
325 (url (mixi-expand-url url))
327 (buffer (url-retrieve-synchronously url))
329 (unless (bufferp buffer)
330 (error (mixi-message "Cannot retrieve: " url)))
331 (with-current-buffer buffer
332 (goto-char (point-min))
333 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
334 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
335 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
336 (error (mixi-message "Cannot retrieve: " url)))
337 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
338 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
340 (mixi-parse-buffer url ret post-data))))
342 (defun mixi-url-post-form (url fields)
343 (let* ((form-data (mixi-make-form-data fields))
344 (extra-headers `(("Content-Type" . ,(car form-data)))))
345 (mixi-url-retrieve url (cdr form-data) extra-headers)))
347 (defun mixi-w3m-retrieve (url &optional post-data)
348 "Retrieve the URL and return gotten strings."
349 (let ((url (mixi-expand-url url)))
351 (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
352 (error (mixi-message "Cannot retrieve: " url))
353 (w3m-decode-buffer url)
354 (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
355 (mixi-parse-buffer url ret post-data))))))
357 (defun mixi-w3m-post-form (url fields)
358 (let ((form-data (mixi-make-form-data fields)))
359 (mixi-w3m-retrieve url form-data)))
361 (defun mixi-curl-retrieve (url &optional post-data form-data)
362 "Retrieve the URL and return gotten strings."
364 (if (fboundp 'set-buffer-multibyte)
365 (set-buffer-multibyte nil))
366 (let ((orig-mode (default-file-modes))
367 (coding-system-for-read 'binary)
368 (coding-system-for-write 'binary)
372 (set-default-file-modes 448)
374 (apply #'start-process "curl" (current-buffer)
376 (append (if post-data '("-d" "@-"))
379 "-b" mixi-curl-cookie-file
380 "-c" mixi-curl-cookie-file
381 (mixi-expand-url url)))))
382 (set-process-sentinel process #'ignore))
383 (set-default-file-modes orig-mode))
385 (process-send-string process (concat post-data "\n"))
386 (process-send-eof process))
387 (while (eq (process-status process) 'run)
388 (accept-process-output process 1))
389 (goto-char (point-min))
390 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
391 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
392 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
393 (error (mixi-message "Cannot retrieve: " url)))
394 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
395 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
396 (mixi-parse-buffer url ret post-data))))
398 (defun mixi-curl-post-form (url fields)
400 (mapcar (lambda (field)
401 (push "-F" form-data)
402 (push (concat (car field) "="
403 (encode-coding-string (cdr field)
407 (mixi-curl-retrieve url nil (reverse form-data))))
409 (defconst mixi-my-id-regexp
410 "<a href=\"show_profile\\.pl\\?id=\\([0-9]+\\)")
412 (defun mixi-login (&optional email password)
414 (when (and (eq mixi-backend 'w3m) (not w3m-use-cookies))
415 (error (mixi-message "Require to accept cookies. Please set "
416 "`w3m-use-cookies' to t.")))
417 (let ((email (or email mixi-default-email
418 (read-from-minibuffer (mixi-message "Login Email: "))))
419 (password (or password mixi-default-password
420 (read-passwd (mixi-message "Login Password: ")))))
421 (let ((url (mixi-expand-url "/login.pl")))
422 (when (and mixi-login-use-ssl (string-match "^http:" url))
423 (setq url (replace-match "https:" nil nil url)))
424 (let ((buffer (mixi-retrieve url
425 (concat "email=" email
426 "&password=" password
429 (unless (string-match "url=/check\\.pl\\?n=" buffer)
430 (error (mixi-message "Cannot login")))
431 (setq buffer (mixi-retrieve "/check.pl?n=home.pl"))
432 (if (string-match mixi-my-id-regexp buffer)
433 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
434 (error (mixi-message "Cannot login")))))))
436 (defun mixi-logout ()
437 (mixi-retrieve "/logout.pl"))
439 (defconst mixi-login-form "<form action=\"/login.pl\" method=\"post\">")
441 (defmacro with-mixi-retrieve (url &rest body)
442 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
445 (insert (mixi-retrieve ,url))
446 (goto-char (point-min))
447 (when (search-forward mixi-login-form nil t)
450 (insert (mixi-retrieve ,url))))
451 (goto-char (point-min))
453 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
454 (put 'with-mixi-retrieve 'edebug-form-spec '(body))
456 (defmacro with-mixi-post-form (url fields &rest body)
457 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
460 (insert (mixi-post-form ,url ,fields))
461 (goto-char (point-min))
462 (when (search-forward mixi-login-form nil t)
465 (insert (mixi-post-form ,url ,fields))))
466 (goto-char (point-min))
468 (put 'with-mixi-post-form 'lisp-indent-function 'defun)
469 (put 'with-mixi-post-form 'edebug-form-spec '(body))
471 (defun mixi-get-matched-items (url regexp &optional range reverse)
472 "Get matched items to REGEXP in URL."
476 (while (or (null range) (< (length ids) range))
477 (with-mixi-retrieve (when url (format url page))
478 (let ((func (if reverse (progn
479 (goto-char (point-max))
483 (while (and (funcall func regexp nil t)
484 (or (null range) (< (length ids) range)))
487 (while (match-string num)
488 (setq list (cons (match-string num) list))
490 (when (not (member (reverse list) ids))
492 (setq ids (cons (reverse list) ids)))))
498 ;; stolen (and modified) from shimbun.el
499 (defun mixi-remove-markup (string)
500 "Remove markups from STRING."
502 (insert (or string ""))
504 (goto-char (point-min))
505 (while (search-forward "<!--" nil t)
506 (delete-region (match-beginning 0)
507 (or (search-forward "-->" nil t)
509 (goto-char (point-min))
510 (while (re-search-forward "<[^>]+>" nil t)
511 (replace-match "" t t))
512 (goto-char (point-min))
513 (while (re-search-forward "
\r" nil t)
514 (replace-match "\n" t t)))
515 ;; FIXME: Decode entities.
518 ;; stolen (and modified) from w3m.el
519 (defconst mixi-entity-alist '(("gt" . ">")
522 "Alist of html character entities and values.")
524 ;; stolen (and modified) from w3m.el
525 (defun mixi-encode-specials-string (str)
526 "Encode special characters in the string STR."
529 (while (string-match "[<>&]" str pos)
532 (cons (car (rassoc (match-string 0 str) mixi-entity-alist))
534 (cons (substring str pos (match-beginning 0))
538 (apply 'concat (nreverse (cons (substring str pos) buf)))
541 ;; stolen (and modified) from w3m.el
542 (defun mixi-url-encode-string (string)
543 (apply (function concat)
547 ((eq char ?\n) ; newline
549 ((string-match "[-a-zA-Z0-9_:/.]" (char-to-string char)) ; xxx?
550 (char-to-string char)) ; printable
551 ((char-equal char ?\x20) ; space
554 (format "%%%02x" char)))) ; escape
555 ;; Coerce a string into a list of chars.
556 (append (encode-coding-string (or string "") mixi-coding-system)
559 (defun mixi-url-encode-and-quote-percent-string (string)
560 (let ((string (mixi-url-encode-string string))
562 (while (string-match "%" string pos)
563 (setq string (replace-match "%%" nil nil string))
564 (setq pos (+ (match-end 0) 1)))
568 (defconst mixi-object-prefix "mixi-")
570 (defmacro mixi-object-class (object)
573 (defmacro mixi-object-p (object)
574 `(let ((class (mixi-object-class ,object)))
575 (when (symbolp class)
576 (eq (string-match (concat "^" mixi-object-prefix)
577 (symbol-name class)) 0))))
579 (defun mixi-object-name (object)
580 "Return the name of OBJECT."
581 (unless (mixi-object-p object)
582 (signal 'wrong-type-argument (list 'mixi-object-p object)))
583 (let ((class (mixi-object-class object)))
584 (substring (symbol-name class) (length mixi-object-prefix))))
586 (defun mixi-read-object (exp)
587 "Read one Lisp expression as mixi object."
588 (if (mixi-object-p exp)
589 (let ((func (intern (concat mixi-object-prefix "make-"
590 (mixi-object-name exp))))
591 (args (mapcar (lambda (arg)
592 (mixi-read-object arg))
594 (let ((object (apply func (cdr args))))
596 (mixi-object-set-timestamp object (car args)))
600 (defun mixi-object-timestamp (object)
601 "Return the timestamp of OJBECT."
602 (unless (mixi-object-p object)
603 (signal 'wrong-type-argument (list 'mixi-object-p object)))
604 (aref (cdr object) 0))
605 (defalias 'mixi-object-realized-p 'mixi-object-timestamp)
607 (defun mixi-object-owner (object)
608 "Return the owner of OBJECT."
609 (unless (mixi-object-p object)
610 (signal 'wrong-type-argument (list 'mixi-object-p object)))
611 (let ((func (intern (concat mixi-object-prefix
612 (mixi-object-name object) "-owner"))))
613 (funcall func object)))
615 (defun mixi-object-id (object)
616 "Return the id of OBJECT."
617 (unless (mixi-object-p object)
618 (signal 'wrong-type-argument (list 'mixi-object-p object)))
619 (let ((func (intern (concat mixi-object-prefix
620 (mixi-object-name object) "-id"))))
621 (funcall func object)))
623 (defun mixi-object-time (object)
624 "Return the time of OBJECT."
625 (unless (mixi-object-p object)
626 (signal 'wrong-type-argument (list 'mixi-object-p object)))
627 (let ((func (intern (concat mixi-object-prefix
628 (mixi-object-name object) "-time"))))
629 (funcall func object)))
631 (defun mixi-object-title (object)
632 "Return the title of OBJECT."
633 (unless (mixi-object-p object)
634 (signal 'wrong-type-argument (list 'mixi-object-p object)))
635 (let ((func (intern (concat mixi-object-prefix
636 (mixi-object-name object) "-title"))))
637 (funcall func object)))
639 (defun mixi-object-content (object)
640 "Return the content of OBJECT."
641 (unless (mixi-object-p object)
642 (signal 'wrong-type-argument (list 'mixi-object-p object)))
643 (let ((func (intern (concat mixi-object-prefix
644 (mixi-object-name object) "-content"))))
645 (funcall func object)))
647 (defun mixi-object-set-timestamp (object timestamp)
648 "Set the timestamp of OBJECT."
649 (unless (mixi-object-p object)
650 (signal 'wrong-type-argument (list 'mixi-object-p object)))
651 (aset (cdr object) 0 timestamp))
653 (defmacro mixi-object-touch (object)
654 `(mixi-object-set-timestamp ,object (current-time)))
656 (defconst mixi-object-url-regexp
657 "/\\(show\\|view\\)_\\([a-z]+\\)\\.pl")
659 (defun mixi-make-object-from-url (url)
660 "Return a mixi object from URL."
661 (if (string-match mixi-object-url-regexp url)
662 (let ((name (match-string 2 url)))
663 (cond ((string= name "bbs")
665 ((string= name "profile")
666 (setq name "friend")))
667 (let ((func (intern (concat mixi-object-prefix "make-" name
670 (when (string-match "/home\\.pl" url)
671 (mixi-make-friend-from-url url))))
674 ;; stolen from time-date.el
675 (defun mixi-time-less-p (t1 t2)
676 "Say whether time value T1 is less than time value T2."
677 (unless (numberp (cdr t1))
678 (setq t1 (cons (car t1) (car (cdr t1)))))
679 (unless (numberp (cdr t2))
680 (setq t2 (cons (car t2) (car (cdr t2)))))
681 (or (< (car t1) (car t2))
682 (and (= (car t1) (car t2))
683 (< (cdr t1) (cdr t2)))))
685 (defun mixi-time-add (t1 t2)
686 "Add two time values. One should represent a time difference."
687 (unless (numberp (cdr t1))
688 (setq t1 (cons (car t1) (car (cdr t1)))))
689 (unless (numberp (cdr t2))
690 (setq t2 (cons (car t2) (car (cdr t2)))))
691 (let ((low (+ (cdr t1) (cdr t2))))
692 (cons (+ (car t1) (car t2) (lsh low -16)) low)))
694 ;; stolen from time-date.el
695 (defun mixi-seconds-to-time (seconds)
696 "Convert SECONDS (a floating point number) to a time value."
697 (cons (floor seconds 65536)
698 (floor (mod seconds 65536))))
700 (defun mixi-cache-expired-p (object)
701 "Whether a cache of OBJECT is expired."
702 (let ((timestamp (mixi-object-timestamp object)))
703 (unless (or (null mixi-cache-expires)
705 (if (numberp mixi-cache-expires)
707 (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
711 (defun mixi-make-cache (key value table)
712 "Make a cache object and return it."
713 (let ((cache (gethash key table)))
714 (if (and cache (not (mixi-cache-expired-p cache)))
716 (puthash key value table))))
718 (defconst mixi-cache-file-regexp "[a-z]+-cache$")
719 (defconst mixi-cache-regexp (concat mixi-object-prefix
720 mixi-cache-file-regexp))
722 (defun mixi-save-cache ()
723 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
724 (unless (file-directory-p cache-directory)
725 (make-directory cache-directory t))
726 (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
728 (with-temp-file (expand-file-name
729 (substring (symbol-name (car caches))
730 (length mixi-object-prefix))
732 (let ((coding-system-for-write mixi-coding-system)
733 (cache (symbol-value (car caches))))
734 (insert "#s(hash-table size "
735 (number-to-string (hash-table-count cache))
736 " test equal data (\n")
739 (let (print-level print-length)
740 (insert (prin1-to-string key) " "
741 (prin1-to-string value) "\n")))
744 (setq caches (cdr caches))))))
746 ;; stolen (and modified) from lsdb.el
747 (defun mixi-read-cache (&optional marker)
748 "Read one Lisp expression as text from MARKER, return as Lisp object."
751 (if (looking-at "^#s(")
754 (forward-char 2);skip "#s"
755 (forward-sexp);move to the left paren
758 (buffer-disable-undo)
759 (insert-buffer-substring (marker-buffer marker)
761 (goto-char (point-min))
763 (let ((object (read (current-buffer)))
765 (if (eq 'hash-table (car object))
767 (setq data (plist-get (cdr object) 'data))
769 (pop data);throw it away
770 (mixi-read-object (pop data))))
774 (defun mixi-load-cache ()
775 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
776 (when (file-directory-p cache-directory)
777 ;; FIXME: Load friend and community first.
778 (let ((files (directory-files cache-directory t
779 mixi-cache-file-regexp)))
781 (let ((buffer (find-file-noselect (car files))))
785 (goto-char (point-min))
786 (re-search-forward "^#s(")
787 (goto-char (match-beginning 0))
788 (mixi-read-cache (point-marker)))
789 (kill-buffer buffer)))
790 (setq files (cdr files)))))))
793 (defvar mixi-friend-cache (make-hash-table :test 'equal))
794 (defun mixi-make-friend (id &optional nick name sex address age birthday
795 blood-type birthplace hobby job organization
797 "Return a friend object."
798 (mixi-make-cache id (cons 'mixi-friend (vector nil id nick name sex address
799 age birthday blood-type
801 organization profile))
804 (defun mixi-make-me ()
805 "Return a my object."
807 (with-mixi-retrieve "/home.pl"
808 (if (re-search-forward mixi-my-id-regexp nil t)
809 (setq mixi-me (mixi-make-friend (match-string 1)))
810 (signal 'error (list 'who-am-i)))))
813 (defconst mixi-friend-url-regexp
814 "/show_\\(friend\\|profile\\)\\.pl\\?id=\\([0-9]+\\)")
816 (defun mixi-make-friend-from-url (url)
817 "Return a friend object from URL."
818 (if (string-match mixi-friend-url-regexp url)
819 (let ((id (match-string 2 url)))
820 (mixi-make-friend id))
821 (when (string-match "/home\\.pl" url)
824 (defmacro mixi-friend-p (friend)
825 `(eq (mixi-object-class ,friend) 'mixi-friend))
827 (defmacro mixi-friend-page (friend)
828 `(concat "/show_profile.pl?id=" (mixi-friend-id ,friend)))
830 (defconst mixi-friend-nick-regexp
831 "<h3>\\(.*\\)¤µ¤ó([0-9]+)</h3>")
832 (defconst mixi-friend-name-regexp
833 "<dt>̾Á°</dt>\n?<dd>\\(.+?\\)\\(<img\\|</dd>\\)")
834 (defconst mixi-friend-sex-regexp
835 "<dt>ÀÊÌ</dt>\n?<dd>\\([Ã˽÷]\\)À\\(<img\\|</dd>\\)")
836 (defconst mixi-friend-address-regexp
837 "<dt>¸½½»½ê</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
838 (defconst mixi-friend-age-regexp
839 "<dt>ǯÎð</dt>\n?<dd>\\([0-9]+\\)ºÐ\\( <img\\|</dd>\\)")
840 (defconst mixi-friend-birthday-regexp
841 "<dt>ÃÂÀ¸Æü</dt>\n?<dd>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(<img \\|</dd>\\)")
842 (defconst mixi-friend-blood-type-regexp
843 "<dt>·ì±Õ·¿</dt>\n?<dd>\\([ABO]B?\\)·¿\\(<img \\|</dd>\\)")
844 (defconst mixi-friend-birthplace-regexp
845 "<dt>½Ð¿ÈÃÏ</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
846 (defconst mixi-friend-hobby-regexp
847 "<dt>¼ñÌ£</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
848 (defconst mixi-friend-job-regexp
849 "<dt>¿¦¶È</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
850 (defconst mixi-friend-organization-regexp
851 "<dt>½ê°</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
852 (defconst mixi-friend-profile-regexp
853 "<dt>¼«¸Ê¾Ò²ð</dt>\n?<dd class=\"userInput\">\\(.+?\\)</dd>")
855 (defun mixi-realize-friend (friend)
857 ;; FIXME: Check a expiration of cache?
858 (unless (mixi-object-realized-p friend)
859 (with-mixi-retrieve (mixi-friend-page friend)
860 (let ((case-fold-search t))
861 (if (re-search-forward mixi-friend-nick-regexp nil t)
862 (mixi-friend-set-nick friend (match-string 1))
863 (mixi-realization-error 'cannot-find-nick friend))
864 (when (re-search-forward mixi-friend-name-regexp nil t)
865 (mixi-friend-set-name friend (match-string 1)))
866 (when (re-search-forward mixi-friend-sex-regexp nil t)
867 (mixi-friend-set-sex friend (if (string= (match-string 1) "ÃË")
869 (when (re-search-forward mixi-friend-address-regexp nil t)
870 (mixi-friend-set-address friend (match-string 1)))
871 (when (re-search-forward mixi-friend-age-regexp nil t)
872 (mixi-friend-set-age friend (string-to-number (match-string 1))))
873 (when (re-search-forward mixi-friend-birthday-regexp nil t)
874 (mixi-friend-set-birthday
875 friend (list (string-to-number (match-string 1))
876 (string-to-number (match-string 2)))))
877 (when (re-search-forward mixi-friend-blood-type-regexp nil t)
878 (mixi-friend-set-blood-type friend (intern (match-string 1))))
879 (when (re-search-forward mixi-friend-birthplace-regexp nil t)
880 (mixi-friend-set-birthplace friend (match-string 1)))
881 (when (re-search-forward mixi-friend-hobby-regexp nil t)
882 (mixi-friend-set-hobby friend (split-string (match-string 1) ", ")))
883 (when (re-search-forward mixi-friend-job-regexp nil t)
884 (mixi-friend-set-job friend (match-string 1)))
885 (when (re-search-forward mixi-friend-organization-regexp nil t)
886 (mixi-friend-set-organization friend (match-string 1)))
887 (when (re-search-forward mixi-friend-profile-regexp nil t)
888 (mixi-friend-set-profile friend (match-string 1)))))
889 (mixi-object-touch friend)))
891 (defun mixi-friend-id (friend)
892 "Return the id of FRIEND."
893 (unless (mixi-friend-p friend)
894 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
895 (aref (cdr friend) 1))
897 (defun mixi-friend-nick (friend)
898 "Return the nick of FRIEND."
899 (unless (mixi-friend-p friend)
900 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
901 (unless (aref (cdr friend) 2)
902 (mixi-realize-friend friend))
903 (aref (cdr friend) 2))
905 (defun mixi-friend-name (friend)
906 "Return the name of FRIEND."
907 (unless (mixi-friend-p friend)
908 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
909 (mixi-realize-friend friend)
910 (aref (cdr friend) 3))
912 (defun mixi-friend-sex (friend)
913 "Return the sex of FRIEND."
914 (unless (mixi-friend-p friend)
915 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
916 (mixi-realize-friend friend)
917 (aref (cdr friend) 4))
919 (defun mixi-friend-address (friend)
920 "Return the address of FRIEND."
921 (unless (mixi-friend-p friend)
922 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
923 (mixi-realize-friend friend)
924 (aref (cdr friend) 5))
926 (defun mixi-friend-age (friend)
927 "Return the age of FRIEND."
928 (unless (mixi-friend-p friend)
929 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
930 (mixi-realize-friend friend)
931 (aref (cdr friend) 6))
933 (defun mixi-friend-birthday (friend)
934 "Return the birthday of FRIEND."
935 (unless (mixi-friend-p friend)
936 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
937 (mixi-realize-friend friend)
938 (aref (cdr friend) 7))
940 (defun mixi-friend-blood-type (friend)
941 "Return the blood type of FRIEND."
942 (unless (mixi-friend-p friend)
943 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
944 (mixi-realize-friend friend)
945 (aref (cdr friend) 8))
947 (defun mixi-friend-birthplace (friend)
948 "Return the birthplace of FRIEND."
949 (unless (mixi-friend-p friend)
950 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
951 (mixi-realize-friend friend)
952 (aref (cdr friend) 9))
954 (defun mixi-friend-hobby (friend)
955 "Return the hobby of FRIEND."
956 (unless (mixi-friend-p friend)
957 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
958 (mixi-realize-friend friend)
959 (aref (cdr friend) 10))
961 (defun mixi-friend-job (friend)
962 "Return the job of FRIEND."
963 (unless (mixi-friend-p friend)
964 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
965 (mixi-realize-friend friend)
966 (aref (cdr friend) 11))
968 (defun mixi-friend-organization (friend)
969 "Return the organization of FRIEND."
970 (unless (mixi-friend-p friend)
971 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
972 (mixi-realize-friend friend)
973 (aref (cdr friend) 12))
975 (defun mixi-friend-profile (friend)
976 "Return the profile of FRIEND."
977 (unless (mixi-friend-p friend)
978 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
979 (mixi-realize-friend friend)
980 (aref (cdr friend) 13))
982 (defun mixi-friend-set-nick (friend nick)
983 "Set the nick of FRIEND."
984 (unless (mixi-friend-p friend)
985 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
986 (aset (cdr friend) 2 nick))
988 (defun mixi-friend-set-name (friend name)
989 "Set the name of FRIEND."
990 (unless (mixi-friend-p friend)
991 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
992 (aset (cdr friend) 3 name))
994 (defun mixi-friend-set-sex (friend sex)
995 "Set the sex of FRIEND."
996 (unless (mixi-friend-p friend)
997 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
998 (aset (cdr friend) 4 sex))
1000 (defun mixi-friend-set-address (friend address)
1001 "Set the address of FRIEND."
1002 (unless (mixi-friend-p friend)
1003 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1004 (aset (cdr friend) 5 address))
1006 (defun mixi-friend-set-age (friend age)
1007 "Set the age of FRIEND."
1008 (unless (mixi-friend-p friend)
1009 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1010 (aset (cdr friend) 6 age))
1012 (defun mixi-friend-set-birthday (friend birthday)
1013 "Set the birthday of FRIEND."
1014 (unless (mixi-friend-p friend)
1015 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1016 (aset (cdr friend) 7 birthday))
1018 (defun mixi-friend-set-blood-type (friend blood-type)
1019 "Set the blood type of FRIEND."
1020 (unless (mixi-friend-p friend)
1021 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1022 (aset (cdr friend) 8 blood-type))
1024 (defun mixi-friend-set-birthplace (friend birthplace)
1025 "Set the birthplace of FRIEND."
1026 (unless (mixi-friend-p friend)
1027 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1028 (aset (cdr friend) 9 birthplace))
1030 (defun mixi-friend-set-hobby (friend hobby)
1031 "Set the hobby of FRIEND."
1032 (unless (mixi-friend-p friend)
1033 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1034 (aset (cdr friend) 10 hobby))
1036 (defun mixi-friend-set-job (friend job)
1037 "Set the job of FRIEND."
1038 (unless (mixi-friend-p friend)
1039 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1040 (aset (cdr friend) 11 job))
1042 (defun mixi-friend-set-organization (friend organization)
1043 "Set the organization of FRIEND."
1044 (unless (mixi-friend-p friend)
1045 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1046 (aset (cdr friend) 12 organization))
1048 (defun mixi-friend-set-profile (friend profile)
1049 "Set the profile of FRIEND."
1050 (unless (mixi-friend-p friend)
1051 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1052 (aset (cdr friend) 13 profile))
1054 (defmacro mixi-friend-list-page (&optional friend)
1055 `(concat "/list_friend.pl?page=%d"
1056 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1058 (defconst mixi-friend-list-id-regexp
1059 "<a href=\"?show_friend\\.pl\\?id=\\([0-9]+\\)\"?")
1060 (defconst mixi-friend-list-nick-regexp
1061 "<span>\\(.+\\)¤µ¤ó([0-9]+)</span>")
1064 (defun mixi-get-friends (&rest friend-or-range)
1065 "Get friends of FRIEND."
1066 (when (> (length friend-or-range) 2)
1067 (signal 'wrong-number-of-arguments (list 'mixi-get-friends
1068 (length friend-or-range))))
1069 (let ((friend (nth 0 friend-or-range))
1070 (range (nth 1 friend-or-range)))
1071 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1072 (setq friend (nth 1 friend-or-range))
1073 (setq range (nth 0 friend-or-range)))
1074 (unless (or (null friend) (mixi-friend-p friend))
1075 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1076 (let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
1077 mixi-friend-list-id-regexp
1079 (nicks (mixi-get-matched-items (mixi-friend-list-page friend)
1080 mixi-friend-list-nick-regexp
1084 (while (< index (length ids))
1085 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1086 (nth 0 (nth index nicks))) ret))
1091 (defmacro mixi-favorite-list-page ()
1092 `(concat "/list_bookmark.pl?page=%d"))
1094 (defconst mixi-favorite-list-regexp
1095 "<td bgcolor=\"#FDF9F2\"><font color=\"#996600\">̾Á°</font></td>
1096 <td colspan=\"2\" bgcolor=\"#FFFFFF\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></td>")
1099 (defun mixi-get-favorites (&optional range)
1101 (let ((items (mixi-get-matched-items (mixi-favorite-list-page)
1102 mixi-favorite-list-regexp
1104 (mapcar (lambda (item)
1105 (mixi-make-friend (nth 0 item) (nth 1 item)))
1109 (defun mixi-make-log (friend time)
1110 "Return a log object."
1111 (cons 'mixi-log (vector friend time)))
1113 (defmacro mixi-log-p (log)
1114 `(eq (mixi-object-class ,log) 'mixi-log))
1116 (defun mixi-log-friend (log)
1117 "Return the friend of LOG."
1118 (unless (mixi-log-p log)
1119 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1122 (defun mixi-log-time (log)
1123 "Return the time of LOG."
1124 (unless (mixi-log-p log)
1125 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1128 (defmacro mixi-log-list-page ()
1129 `(concat "/show_log.pl"))
1131 (defconst mixi-log-list-regexp
1132 "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)</a>")
1135 (defun mixi-get-logs (&optional range)
1137 (let ((items (mixi-get-matched-items (mixi-log-list-page)
1138 mixi-log-list-regexp
1140 (mapcar (lambda (item)
1141 (mixi-make-log (mixi-make-friend (nth 5 item) (nth 6 item))
1143 (string-to-number (nth 4 item))
1144 (string-to-number (nth 3 item))
1145 (string-to-number (nth 2 item))
1146 (string-to-number (nth 1 item))
1147 (string-to-number (nth 0 item)))))
1151 (defvar mixi-diary-cache (make-hash-table :test 'equal))
1152 (defun mixi-make-diary (owner id &optional comment-count time title content)
1153 "Return a diary object."
1154 (let ((owner (or owner (mixi-make-me))))
1155 (mixi-make-cache (list (mixi-friend-id owner) id)
1156 (cons 'mixi-diary (vector nil owner id comment-count time
1160 (defconst mixi-diary-url-regexp
1161 "/view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?")
1163 (defun mixi-make-diary-from-url (url)
1164 "Return a diary object from URL."
1165 (when (string-match mixi-diary-url-regexp url)
1166 (let ((id (match-string 1 url))
1167 (owner-id (match-string 2 url))
1168 (comment-count (match-string 4 url)))
1169 (mixi-make-diary (mixi-make-friend owner-id) id comment-count))))
1171 (defmacro mixi-diary-p (diary)
1172 `(eq (mixi-object-class ,diary) 'mixi-diary))
1174 (defmacro mixi-diary-page (diary)
1175 `(concat "/view_diary.pl?id=" (mixi-diary-id ,diary)
1176 "&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
1178 (defconst mixi-diary-closed-regexp
1179 "<td>ͧ¿Í\\(¤Îͧ¿Í\\)?¤Þ¤Ç¸ø³«¤Î¤¿¤áÆɤळ¤È¤¬½ÐÍè¤Þ¤»¤ó¡£</td>")
1180 (defconst mixi-diary-owner-nick-regexp
1181 "<div class=\"diaryTitle\\(Friend\\)? clearfix\">
1182 <h2>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ</h2>")
1183 (defconst mixi-diary-title-regexp
1184 "<div class=\"listDiaryTitle\">
1185 <dl class=\"clearfix\">
1186 <dt>\\([^<\n]+\\)\\(<span>\\)?")
1187 (defconst mixi-diary-time-regexp
1188 "<dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\\([0-9]+\\):\\([0-9]+\\)</dd>")
1189 (defconst mixi-diary-content-regexp
1190 "<div class=\"txtconfirmArea\">
1191 \\(\\(.\\|\r?\n\\)*?\\)
1192 <!--/viewDiaryBox--></div>")
1194 (defun mixi-realize-diary (diary &optional page)
1196 ;; FIXME: Check a expiration of cache?
1197 (unless (mixi-object-realized-p diary)
1198 (with-mixi-retrieve (or page (mixi-diary-page diary))
1199 (let ((case-fold-search t))
1200 (unless (re-search-forward mixi-diary-closed-regexp nil t)
1201 (if (re-search-forward mixi-diary-owner-nick-regexp nil t)
1202 (mixi-friend-set-nick (mixi-diary-owner diary)
1204 (mixi-realization-error 'cannot-find-owner-nick diary))
1205 (if (re-search-forward mixi-diary-title-regexp nil t)
1206 (mixi-diary-set-title diary (match-string 1))
1207 (mixi-realization-error 'cannot-find-title diary))
1208 (if (re-search-forward mixi-diary-time-regexp nil t)
1209 (mixi-diary-set-time
1210 diary (encode-time 0 (string-to-number (match-string 5))
1211 (string-to-number (match-string 4))
1212 (string-to-number (match-string 3))
1213 (string-to-number (match-string 2))
1214 (string-to-number (match-string 1))))
1215 (mixi-realization-error 'cannot-find-time diary))
1216 (if (re-search-forward mixi-diary-content-regexp nil t)
1217 (mixi-diary-set-content diary (match-string 1))
1218 (mixi-realization-error 'cannot-find-content diary)))))
1219 (mixi-object-touch diary)))
1221 (defun mixi-diary-owner (diary)
1222 "Return the owner of DIARY."
1223 (unless (mixi-diary-p diary)
1224 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1225 (aref (cdr diary) 1))
1227 (defun mixi-diary-id (diary)
1228 "Return the id of DIARY."
1229 (unless (mixi-diary-p diary)
1230 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1231 (aref (cdr diary) 2))
1233 (defun mixi-diary-comment-count (diary)
1234 "Return the comment-count of DIARY."
1235 (unless (mixi-diary-p diary)
1236 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1237 (aref (cdr diary) 3))
1239 (defun mixi-diary-time (diary)
1240 "Return the time of DIARY."
1241 (unless (mixi-diary-p diary)
1242 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1243 (unless (aref (cdr diary) 3)
1244 (mixi-realize-diary diary))
1245 (aref (cdr diary) 4))
1247 (defun mixi-diary-title (diary)
1248 "Return the title of DIARY."
1249 (unless (mixi-diary-p diary)
1250 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1251 (unless (aref (cdr diary) 4)
1252 (mixi-realize-diary diary))
1253 (aref (cdr diary) 5))
1255 (defun mixi-diary-content (diary)
1256 "Return the content of DIARY."
1257 (unless (mixi-diary-p diary)
1258 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1259 (mixi-realize-diary diary)
1260 (aref (cdr diary) 6))
1262 (defun mixi-diary-set-comment-count (diary comment-count)
1263 "Set the comment-count of DIARY."
1264 (unless (mixi-diary-p diary)
1265 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1266 (aset (cdr diary) 3 comment-count))
1268 (defun mixi-diary-set-time (diary time)
1269 "Set the time of DIARY."
1270 (unless (mixi-diary-p diary)
1271 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1272 (aset (cdr diary) 4 time))
1274 (defun mixi-diary-set-title (diary title)
1275 "Set the title of DIARY."
1276 (unless (mixi-diary-p diary)
1277 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1278 (aset (cdr diary) 5 title))
1280 (defun mixi-diary-set-content (diary content)
1281 "Set the content of DIARY."
1282 (unless (mixi-diary-p diary)
1283 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1284 (aset (cdr diary) 6 content))
1286 (defmacro mixi-diary-list-page (&optional friend)
1287 `(concat "/list_diary.pl?page=%d"
1288 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1290 (defconst mixi-diary-list-regexp
1291 "<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>
1292 <dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\n?\\([0-9]+\\):\\([0-9]+\\)</dd>
1296 (defun mixi-get-diaries (&rest friend-or-range)
1297 "Get diaries of FRIEND."
1298 (when (> (length friend-or-range) 2)
1299 (signal 'wrong-number-of-arguments
1300 (list 'mixi-get-diaries (length friend-or-range))))
1301 (let ((friend (nth 0 friend-or-range))
1302 (range (nth 1 friend-or-range)))
1303 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1304 (setq friend (nth 1 friend-or-range))
1305 (setq range (nth 0 friend-or-range)))
1306 (unless (or (null friend) (mixi-friend-p friend))
1307 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1308 (let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
1309 mixi-diary-list-regexp
1311 (mapcar (lambda (item)
1312 (mixi-make-diary friend (nth 1 item) nil
1314 0 (string-to-number (nth 8 item))
1315 (string-to-number (nth 7 item))
1316 (string-to-number (nth 6 item))
1317 (string-to-number (nth 5 item))
1318 (string-to-number (nth 4 item)))
1322 (defmacro mixi-new-diary-list-page ()
1323 `(concat "/new_friend_diary.pl?page=%d"))
1325 (defconst mixi-new-diary-list-regexp
1326 "<dt>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</dt>
1327 <dd><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\">\\(.+\\)</a> (\\(.*\\))<div ")
1330 (defun mixi-get-new-diaries (&optional range)
1332 (let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
1333 mixi-new-diary-list-regexp
1335 (mapcar (lambda (item)
1336 (mixi-make-diary (mixi-make-friend (nth 6 item) (nth 8 item))
1340 0 (string-to-number (nth 4 item))
1341 (string-to-number (nth 3 item))
1342 (string-to-number (nth 2 item))
1343 (string-to-number (nth 1 item))
1344 (string-to-number (nth 0 item)))
1348 (defmacro mixi-search-diary-list-page (keyword)
1349 `(concat "/search_diary.pl?page=%d&submit=search&keyword="
1350 (mixi-url-encode-and-quote-percent-string ,keyword)))
1352 (defconst mixi-search-diary-list-regexp
1353 "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾ Á°</font></td>
1354 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.*\\)
1359 <td BGCOLOR=#FDF9F2><font COLOR=#996600>¥¿¥¤¥È¥ë</font></td>
1360 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>
1363 <td BGCOLOR=#FDF9F2><font COLOR=#996600>ËÜ Ê¸</font></td>
1364 <td COLSPAN=2 BGCOLOR=#FFFFFF width=\"380\">\\(.*\\)</td></tr>
1368 <td NOWRAP BGCOLOR=#FDF9F2 WIDTH=80><font COLOR=#996600>ºîÀ®Æü»þ</font></td>
1369 <td BGCOLOR=#FFFFFF WIDTH=220>\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>
1370 <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>
1372 </td></tr></table>")
1375 (defun mixi-search-diaries (keyword &optional range)
1376 (let ((items (mixi-get-matched-items (mixi-search-diary-list-page keyword)
1377 mixi-search-diary-list-regexp
1379 (year (nth 5 (decode-time (current-time))))
1380 (month (nth 4 (decode-time (current-time)))))
1381 (mapcar (lambda (item)
1382 (let ((month-of-item (string-to-number (nth 3 item))))
1383 (when (> month-of-item month)
1385 (setq month month-of-item)
1386 (mixi-make-diary (mixi-make-friend (nth 8 item) (nth 0 item))
1390 0 (string-to-number (nth 6 item))
1391 (string-to-number (nth 5 item))
1392 (string-to-number (nth 4 item))
1398 (defmacro mixi-post-diary-page ()
1399 `(concat "/add_diary.pl"))
1401 (defconst mixi-post-key-regexp
1402 "<input type=\"?hidden\"? name=\"?post_key\"? +value=\"\\([a-z0-9]+\\)\"")
1403 (defconst mixi-post-succeed-regexp
1404 "<p\\(\\| class=\"messageAlert\"\\)>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É½¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¾¯¡¹¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£</p>")
1406 ;; FIXME: Support photos.
1408 (defun mixi-post-diary (title content)
1410 (unless (stringp title)
1411 (signal 'wrong-type-argument (list 'stringp title)))
1412 (unless (stringp content)
1413 (signal 'wrong-type-argument (list 'stringp content)))
1414 (let ((fields `(("id" . ,(mixi-friend-id (mixi-make-me)))
1415 ("diary_title" . ,title)
1416 ("diary_body" . ,content)
1417 ("submit" . "main")))
1419 (with-mixi-post-form (mixi-post-diary-page) fields
1420 (if (re-search-forward mixi-post-key-regexp nil t)
1421 (setq post-key (match-string 1))
1422 (mixi-post-error 'cannot-find-key)))
1423 (setq fields `(("post_key" . ,post-key)
1424 ("id" . ,(mixi-friend-id (mixi-make-me)))
1425 ("diary_title" . ,title)
1426 ("diary_body" . ,content)
1427 ("submit" . "confirm")))
1428 (with-mixi-post-form (mixi-post-diary-page) fields
1429 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1430 (mixi-post-error 'cannot-find-succeed)))))
1432 ;; Community object.
1433 (defvar mixi-community-cache (make-hash-table :test 'equal))
1434 (defun mixi-make-community (id &optional name birthday owner category members
1435 open-level authority description)
1436 "Return a community object."
1437 (mixi-make-cache id (cons 'mixi-community (vector nil id name birthday owner
1439 open-level authority
1441 mixi-community-cache))
1443 (defconst mixi-community-url-regexp
1444 "/view_community\\.pl\\?id=\\([0-9]+\\)")
1446 (defun mixi-make-community-from-url (url)
1447 "Return a community object from URL."
1448 (when (string-match mixi-community-url-regexp url)
1449 (let ((id (match-string 1 url)))
1450 (mixi-make-community id))))
1452 (defmacro mixi-community-p (community)
1453 `(eq (mixi-object-class ,community) 'mixi-community))
1455 (defmacro mixi-community-page (community)
1456 `(concat "/view_community.pl?id=" (mixi-community-id ,community)))
1458 ;; FIXME: Not community specific.
1459 (defconst mixi-community-nodata-regexp
1460 "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1461 (defconst mixi-community-name-regexp
1462 "<div class=\"pageTitle communityTitle002 communityTop\">
1464 (defconst mixi-community-birthday-regexp
1466 <dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br />")
1467 ;; FIXME: Care when the owner has seceded.
1468 (defconst mixi-community-owner-regexp
1471 <a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\\(.*\\)</a>")
1472 (defconst mixi-community-category-regexp
1475 (defconst mixi-community-members-regexp
1476 "<dt>¥á¥ó¥Ð¡¼¿ô</dt>
1477 <dd>\\([0-9]+\\)¿Í</dd>")
1478 (defconst mixi-community-open-level-regexp
1479 "<dt>»²²Ã¾ò·ï¤È<br />¸ø³«¥ì¥Ù¥ë</dt>
1481 (defconst mixi-community-authority-regexp
1482 "<dt>¥È¥Ô¥Ã¥¯¤Î<br />ºîÀ®¸¢¸Â</dt>
1488 (defconst mixi-community-description-regexp
1489 "<div id=\"communityIntro\">
1492 (defun mixi-realize-community (community)
1493 "Realize a COMMUNITY."
1494 ;; FIXME: Check a expiration of cache?
1495 (unless (mixi-object-realized-p community)
1496 (with-mixi-retrieve (mixi-community-page community)
1497 (let ((case-fold-search t))
1498 (if (re-search-forward mixi-community-nodata-regexp nil t)
1499 ;; FIXME: Set all members?
1500 (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1501 (if (re-search-forward mixi-community-name-regexp nil t)
1502 (mixi-community-set-name community (match-string 1))
1503 (mixi-realization-error 'cannot-find-name community))
1504 (if (re-search-forward mixi-community-birthday-regexp nil t)
1505 (mixi-community-set-birthday
1506 community (encode-time 0 0 0
1507 (string-to-number (match-string 3))
1508 (string-to-number (match-string 2))
1509 (string-to-number (match-string 1))))
1510 (mixi-realization-error 'cannot-find-birthday community))
1511 (if (re-search-forward mixi-community-owner-regexp nil t)
1512 (if (string= (match-string 1) "home.pl")
1513 (mixi-community-set-owner community (mixi-make-me))
1514 (mixi-community-set-owner community (mixi-make-friend
1517 (mixi-realization-error 'cannot-find-owner community))
1518 (if (re-search-forward mixi-community-category-regexp nil t)
1519 (mixi-community-set-category community (match-string 1))
1520 (mixi-realization-error 'cannot-find-category community))
1521 (if (re-search-forward mixi-community-members-regexp nil t)
1522 (mixi-community-set-members community
1523 (string-to-number (match-string 1)))
1524 (mixi-realization-error 'cannot-find-members community))
1525 (if (re-search-forward mixi-community-open-level-regexp nil t)
1526 (mixi-community-set-open-level community (match-string 1))
1527 (mixi-realization-error 'cannot-find-open-level community))
1528 (if (re-search-forward mixi-community-authority-regexp nil t)
1529 (mixi-community-set-authority community (match-string 1))
1530 (mixi-realization-error 'cannot-find-authority community))
1531 (if (re-search-forward mixi-community-description-regexp nil t)
1532 (mixi-community-set-description community (match-string 1))
1533 (mixi-realization-error 'cannot-find-description community)))))
1534 (mixi-object-touch community)))
1536 (defun mixi-community-id (community)
1537 "Return the id of COMMUNITY."
1538 (unless (mixi-community-p community)
1539 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1540 (aref (cdr community) 1))
1542 (defun mixi-community-name (community)
1543 "Return the name of COMMUNITY."
1544 (unless (mixi-community-p community)
1545 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1546 (unless (aref (cdr community) 2)
1547 (mixi-realize-community community))
1548 (aref (cdr community) 2))
1550 (defun mixi-community-birthday (community)
1551 "Return the birthday of COMMUNITY."
1552 (unless (mixi-community-p community)
1553 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1554 (mixi-realize-community community)
1555 (aref (cdr community) 3))
1557 (defun mixi-community-owner (community)
1558 "Return the owner of COMMUNITY."
1559 (unless (mixi-community-p community)
1560 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1561 (mixi-realize-community community)
1562 (aref (cdr community) 4))
1564 (defun mixi-community-category (community)
1565 "Return the category of COMMUNITY."
1566 (unless (mixi-community-p community)
1567 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1568 (mixi-realize-community community)
1569 (aref (cdr community) 5))
1571 (defun mixi-community-members (community)
1572 "Return the members of COMMUNITY."
1573 (unless (mixi-community-p community)
1574 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1575 (mixi-realize-community community)
1576 (aref (cdr community) 6))
1578 (defun mixi-community-open-level (community)
1579 "Return the open-level of COMMUNITY."
1580 (unless (mixi-community-p community)
1581 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1582 (mixi-realize-community community)
1583 (aref (cdr community) 7))
1585 (defun mixi-community-authority (community)
1586 "Return the authority of COMMUNITY."
1587 (unless (mixi-community-p community)
1588 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1589 (mixi-realize-community community)
1590 (aref (cdr community) 8))
1592 (defun mixi-community-description (community)
1593 "Return the description of COMMUNITY."
1594 (unless (mixi-community-p community)
1595 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1596 (mixi-realize-community community)
1597 (aref (cdr community) 9))
1599 (defun mixi-community-set-name (community name)
1600 "Set the name of COMMUNITY."
1601 (unless (mixi-community-p community)
1602 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1603 (aset (cdr community) 2 name))
1605 (defun mixi-community-set-birthday (community birthday)
1606 "Set the birthday of COMMUNITY."
1607 (unless (mixi-community-p community)
1608 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1609 (aset (cdr community) 3 birthday))
1611 (defun mixi-community-set-owner (community owner)
1612 "Set the owner of COMMUNITY."
1613 (unless (mixi-community-p community)
1614 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1615 (unless (mixi-friend-p owner)
1616 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1617 (aset (cdr community) 4 owner))
1619 (defun mixi-community-set-category (community category)
1620 "Set the category of COMMUNITY."
1621 (unless (mixi-community-p community)
1622 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1623 (aset (cdr community) 5 category))
1625 (defun mixi-community-set-members (community members)
1626 "Set the name of COMMUNITY."
1627 (unless (mixi-community-p community)
1628 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1629 (aset (cdr community) 6 members))
1631 (defun mixi-community-set-open-level (community open-level)
1632 "Set the name of COMMUNITY."
1633 (unless (mixi-community-p community)
1634 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1635 (aset (cdr community) 7 open-level))
1637 (defun mixi-community-set-authority (community authority)
1638 "Set the name of COMMUNITY."
1639 (unless (mixi-community-p community)
1640 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1641 (aset (cdr community) 8 authority))
1643 (defun mixi-community-set-description (community description)
1644 "Set the name of COMMUNITY."
1645 (unless (mixi-community-p community)
1646 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1647 (aset (cdr community) 9 description))
1649 (defmacro mixi-community-list-page (&optional friend)
1650 `(concat "/list_community.pl?page=%d"
1651 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1653 (defconst mixi-community-list-id-regexp
1654 "<a href=\"?view_community\\.pl\\?id=\\([0-9]+\\)\"?")
1655 (defconst mixi-community-list-name-regexp
1656 "<span>\\(.+\\)([0-9]+)</span>")
1659 (defun mixi-get-communities (&rest friend-or-range)
1660 "Get communities of FRIEND."
1661 (when (> (length friend-or-range) 2)
1662 (signal 'wrong-number-of-arguments
1663 (list 'mixi-get-communities (length friend-or-range))))
1664 (let ((friend (nth 0 friend-or-range))
1665 (range (nth 1 friend-or-range)))
1666 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1667 (setq friend (nth 1 friend-or-range))
1668 (setq range (nth 0 friend-or-range)))
1669 (unless (or (null friend) (mixi-friend-p friend))
1670 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1671 (let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
1672 mixi-community-list-id-regexp
1674 (names (mixi-get-matched-items (mixi-community-list-page friend)
1675 mixi-community-list-name-regexp
1679 (while (< index (length ids))
1680 (setq ret (cons (mixi-make-community (nth 0 (nth index ids))
1681 (nth 0 (nth index names))) ret))
1685 (defmacro mixi-search-community-list-page (keyword)
1686 `(concat "/search_community.pl?page=%d&&sort=date&type=com&submit=main"
1687 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
1690 (defconst mixi-search-community-list-regexp
1691 "<dt class=\"communityTitle\"><a href=\"view_community\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\) ([0-9]+)</a>")
1693 ;; FIXME: Support category.
1695 (defun mixi-search-communities (keyword &optional range)
1696 (let ((items (mixi-get-matched-items (mixi-search-community-list-page
1698 mixi-search-community-list-regexp
1700 (mapcar (lambda (item)
1701 (mixi-make-community (nth 0 item) (nth 1 item)))
1705 (defvar mixi-topic-cache (make-hash-table :test 'equal))
1706 (defun mixi-make-topic (community id &optional comment-count time title owner
1708 "Return a topic object."
1709 (mixi-make-cache (list (mixi-community-id community) id)
1710 (cons 'mixi-topic (vector nil community id comment-count
1711 time title owner content))
1714 (defconst mixi-topic-url-regexp
1715 "/view_bbs\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1717 (defun mixi-make-topic-from-url (url)
1718 "Return a topic object from URL."
1719 (when (string-match mixi-topic-url-regexp url)
1720 (let ((id (match-string 1 url))
1721 (comment-count (match-string 3 url))
1722 (community-id (match-string 4 url)))
1723 (mixi-make-topic (mixi-make-community community-id) id comment-count))))
1725 (defmacro mixi-topic-p (topic)
1726 `(eq (mixi-object-class ,topic) 'mixi-topic))
1728 (defmacro mixi-topic-page (topic)
1729 `(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
1730 "&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
1732 (defconst mixi-topic-community-regexp
1733 "<div class=\"pageTitle communityTitle002\">
1734 <h2>\\(.+\\) ¥È¥Ô¥Ã¥¯</h2>")
1735 (defconst mixi-topic-title-regexp
1736 "<span class=\"title\">\\([^<]+\\)</span>")
1737 (defconst mixi-topic-time-regexp
1738 "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>")
1739 (defconst mixi-topic-owner-regexp
1740 "<dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)\\(¤µ¤ó\\)?</a>")
1741 (defconst mixi-topic-content-regexp
1742 "<dd>\\(\\(.\\|\r?\n\\)*?\\)</dd>")
1744 (defun mixi-realize-topic (topic &optional page)
1746 ;; FIXME: Check a expiration of cache?
1747 (unless (mixi-object-realized-p topic)
1748 (with-mixi-retrieve (or page (mixi-topic-page topic))
1749 (if (re-search-forward mixi-topic-community-regexp nil t)
1750 (mixi-community-set-name (mixi-topic-community topic)
1752 (mixi-realization-error 'cannot-find-community topic))
1753 (if (re-search-forward mixi-topic-title-regexp nil t)
1754 (mixi-topic-set-title topic (match-string 1))
1755 (mixi-realization-error 'cannot-find-title topic))
1756 (if (re-search-forward mixi-topic-time-regexp nil t)
1757 (mixi-topic-set-time
1758 topic (encode-time 0 (string-to-number (match-string 5))
1759 (string-to-number (match-string 4))
1760 (string-to-number (match-string 3))
1761 (string-to-number (match-string 2))
1762 (string-to-number (match-string 1))))
1763 (mixi-realization-error 'cannot-find-time topic))
1764 (if (re-search-forward mixi-topic-owner-regexp nil t)
1765 (mixi-topic-set-owner topic (mixi-make-friend (match-string 1)
1767 (mixi-realization-error 'cannot-find-owner topic))
1768 (if (re-search-forward mixi-topic-content-regexp nil t)
1769 (mixi-topic-set-content topic (match-string 1))
1770 (mixi-realization-error 'cannot-find-content topic)))
1771 (mixi-object-touch topic)))
1773 (defun mixi-topic-community (topic)
1774 "Return the community of TOPIC."
1775 (unless (mixi-topic-p topic)
1776 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1777 (aref (cdr topic) 1))
1779 (defun mixi-topic-id (topic)
1780 "Return the id of TOPIC."
1781 (unless (mixi-topic-p topic)
1782 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1783 (aref (cdr topic) 2))
1785 (defun mixi-topic-comment-count (topic)
1786 "Return the comment-count of TOPIC."
1787 (unless (mixi-topic-p topic)
1788 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1789 (aref (cdr topic) 3))
1791 (defun mixi-topic-time (topic)
1792 "Return the time of TOPIC."
1793 (unless (mixi-topic-p topic)
1794 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1795 (mixi-realize-topic topic)
1796 (aref (cdr topic) 4))
1798 (defun mixi-topic-title (topic)
1799 "Return the title of TOPIC."
1800 (unless (mixi-topic-p topic)
1801 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1802 (mixi-realize-topic topic)
1803 (aref (cdr topic) 5))
1805 (defun mixi-topic-owner (topic)
1806 "Return the owner of TOPIC."
1807 (unless (mixi-topic-p topic)
1808 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1809 (mixi-realize-topic topic)
1810 (aref (cdr topic) 6))
1812 (defun mixi-topic-content (topic)
1813 "Return the content of TOPIC."
1814 (unless (mixi-topic-p topic)
1815 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1816 (mixi-realize-topic topic)
1817 (aref (cdr topic) 7))
1819 (defun mixi-topic-set-comment-count (topic comment-count)
1820 "Set the comment-count of TOPIC."
1821 (unless (mixi-topic-p topic)
1822 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1823 (aset (cdr topic) 3 comment-count))
1825 (defun mixi-topic-set-time (topic time)
1826 "Set the time of TOPIC."
1827 (unless (mixi-topic-p topic)
1828 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1829 (aset (cdr topic) 4 time))
1831 (defun mixi-topic-set-title (topic title)
1832 "Set the title of TOPIC."
1833 (unless (mixi-topic-p topic)
1834 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1835 (aset (cdr topic) 5 title))
1837 (defun mixi-topic-set-owner (topic owner)
1838 "Set the owner of TOPIC."
1839 (unless (mixi-topic-p topic)
1840 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1841 (unless (mixi-friend-p owner)
1842 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1843 (aset (cdr topic) 6 owner))
1845 (defun mixi-topic-set-content (topic content)
1846 "Set the content of TOPIC."
1847 (unless (mixi-topic-p topic)
1848 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1849 (aset (cdr topic) 7 content))
1851 (defmacro mixi-post-topic-page (community)
1852 `(concat "/add_bbs.pl?id=" (mixi-community-id community)))
1854 ;; FIXME: Support photos.
1856 (defun mixi-post-topic (community title content)
1857 "Post a topic to COMMUNITY."
1858 (unless (mixi-community-p community)
1859 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1860 (unless (stringp title)
1861 (signal 'wrong-type-argument (list 'stringp title)))
1862 (unless (stringp content)
1863 (signal 'wrong-type-argument (list 'stringp content)))
1864 (let ((fields `(("bbs_title" . ,title)
1865 ("bbs_body" . ,content)
1866 ("submit" . "main")))
1868 (with-mixi-post-form (mixi-post-topic-page community) fields
1869 (if (re-search-forward mixi-post-key-regexp nil t)
1870 (setq post-key (match-string 1))
1871 (mixi-post-error 'cannot-find-key community)))
1872 (setq fields `(("post_key" . ,post-key)
1873 ("bbs_title" . ,title)
1874 ("bbs_body" . ,content)
1875 ("submit" . "confirm")))
1876 (with-mixi-post-form (mixi-post-topic-page community) fields
1877 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1878 (mixi-post-error 'cannot-find-succeed community)))))
1881 (defvar mixi-event-cache (make-hash-table :test 'equal))
1882 (defun mixi-make-event (community id &optional comment-count time title owner
1883 date place detail limit members)
1884 "Return a event object."
1885 (mixi-make-cache (list (mixi-community-id community) id)
1886 (cons 'mixi-event (vector nil community id comment-count
1887 time title owner date place
1888 detail limit members))
1891 (defconst mixi-event-url-regexp
1892 "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1894 (defun mixi-make-event-from-url (url)
1895 "Return a event object from URL."
1896 (when (string-match mixi-event-url-regexp url)
1897 (let ((id (match-string 1 url))
1898 (comment-count (match-string 3 url))
1899 (community-id (match-string 4 url)))
1900 (mixi-make-event (mixi-make-community community-id) id comment-count))))
1902 (defmacro mixi-event-p (event)
1903 `(eq (mixi-object-class ,event) 'mixi-event))
1905 (defmacro mixi-event-page (event)
1906 `(concat "/view_event.pl?id=" (mixi-event-id ,event)
1907 "&comm_id=" (mixi-community-id (mixi-event-community ,event))))
1909 (defconst mixi-event-community-regexp
1910 "<div class=\"pageTitle communityTitle002\">
1911 <h2>\\(.+\\) ¥¤¥Ù¥ó¥È</h2>")
1912 (defconst mixi-event-title-regexp
1913 "<span class=\"title\">\\([^<]+\\)</span>")
1914 (defconst mixi-event-time-regexp
1915 "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>")
1916 (defconst mixi-event-date-regexp
1919 (defconst mixi-event-place-regexp
1922 (defconst mixi-event-owner-regexp
1923 "<dt>\\((mixi Âà²ñºÑ)\\|<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>\\)</dt>")
1924 (defconst mixi-event-owner-seceded-regexp
1926 (defconst mixi-event-detail-regexp
1927 "<dd>\\(\\(.\\|\r?\n\\)*?\\)</dd>
1929 (defconst mixi-event-limit-regexp
1932 (defconst mixi-event-members-regexp
1936 (defun mixi-realize-event (event &optional page)
1938 ;; FIXME: Check a expiration of cache?
1939 (unless (mixi-object-realized-p event)
1940 (with-mixi-retrieve (or page (mixi-event-page event))
1941 (let ((case-fold-search t))
1942 (if (re-search-forward mixi-event-community-regexp nil t)
1943 (mixi-community-set-name (mixi-event-community event)
1945 (mixi-realization-error 'cannot-find-community event))
1946 (if (re-search-forward mixi-event-title-regexp nil t)
1947 (mixi-event-set-title event (match-string 1))
1948 (mixi-realization-error 'cannot-find-title event))
1949 (if (re-search-forward mixi-event-time-regexp nil t)
1950 (mixi-event-set-time
1951 event (encode-time 0 (string-to-number (match-string 5))
1952 (string-to-number (match-string 4))
1953 (string-to-number (match-string 3))
1954 (string-to-number (match-string 2))
1955 (string-to-number (match-string 1))))
1956 (mixi-realization-error 'cannot-find-time event))
1957 (if (re-search-forward mixi-event-date-regexp nil t)
1958 (mixi-event-set-date event (match-string 1))
1959 (mixi-realization-error 'cannot-find-date event))
1960 (if (re-search-forward mixi-event-place-regexp nil t)
1961 (mixi-event-set-place event (match-string 1))
1962 (mixi-realization-error 'cannot-find-place event))
1963 (if (re-search-forward mixi-event-owner-regexp nil t)
1964 (let ((seceded-or-not (match-string 1))
1965 (id (match-string 2))
1966 (nick (match-string 3)))
1967 (if (string= mixi-event-owner-seceded-regexp seceded-or-not)
1968 (mixi-event-set-owner event
1969 (mixi-make-friend nil seceded-or-not))
1970 (mixi-event-set-owner event (mixi-make-friend id nick))))
1971 (mixi-realization-error 'cannot-find-owner event))
1972 (if (re-search-forward mixi-event-detail-regexp nil t)
1973 (mixi-event-set-detail event (match-string 1))
1974 (mixi-realization-error 'cannot-find-detail event))
1975 (if (re-search-forward mixi-event-limit-regexp nil t)
1976 (mixi-event-set-limit event (match-string 1))
1977 (mixi-realization-error 'cannot-find-limit event))
1978 (if (re-search-forward mixi-event-members-regexp nil t)
1979 (mixi-event-set-members event (match-string 1))
1980 (mixi-realization-error 'cannot-find-members event))))
1981 (mixi-object-touch event)))
1983 (defun mixi-event-community (event)
1984 "Return the community of EVENT."
1985 (unless (mixi-event-p event)
1986 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1987 (aref (cdr event) 1))
1989 (defun mixi-event-id (event)
1990 "Return the id of EVENT."
1991 (unless (mixi-event-p event)
1992 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1993 (aref (cdr event) 2))
1995 (defun mixi-event-comment-count (event)
1996 "Return the comment-count of EVENT."
1997 (unless (mixi-event-p event)
1998 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1999 (aref (cdr event) 3))
2001 (defun mixi-event-time (event)
2002 "Return the time of EVENT."
2003 (unless (mixi-event-p event)
2004 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2005 (mixi-realize-event event)
2006 (aref (cdr event) 4))
2008 (defun mixi-event-title (event)
2009 "Return the title of EVENT."
2010 (unless (mixi-event-p event)
2011 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2012 (mixi-realize-event event)
2013 (aref (cdr event) 5))
2015 (defun mixi-event-owner (event)
2016 "Return the owner of EVENT."
2017 (unless (mixi-event-p event)
2018 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2019 (mixi-realize-event event)
2020 (aref (cdr event) 6))
2022 (defun mixi-event-date (event)
2023 "Return the date of EVENT."
2024 (unless (mixi-event-p event)
2025 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2026 (mixi-realize-event event)
2027 (aref (cdr event) 7))
2029 (defun mixi-event-place (event)
2030 "Return the place of EVENT."
2031 (unless (mixi-event-p event)
2032 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2033 (mixi-realize-event event)
2034 (aref (cdr event) 8))
2036 (defun mixi-event-detail (event)
2037 "Return the detail of EVENT."
2038 (unless (mixi-event-p event)
2039 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2040 (mixi-realize-event event)
2041 (aref (cdr event) 9))
2043 (defun mixi-event-limit (event)
2044 "Return the limit of EVENT."
2045 (unless (mixi-event-p event)
2046 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2047 (mixi-realize-event event)
2048 (aref (cdr event) 10))
2050 (defun mixi-event-members (event)
2051 "Return the members of EVENT."
2052 (unless (mixi-event-p event)
2053 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2054 (mixi-realize-event event)
2055 (aref (cdr event) 11))
2057 (defun mixi-event-set-comment-count (event comment-count)
2058 "Set the comment-count of EVENT."
2059 (unless (mixi-event-p event)
2060 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2061 (aset (cdr event) 3 comment-count))
2063 (defun mixi-event-set-time (event time)
2064 "Set the time of EVENT."
2065 (unless (mixi-event-p event)
2066 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2067 (aset (cdr event) 4 time))
2069 (defun mixi-event-set-title (event title)
2070 "Set the title of EVENT."
2071 (unless (mixi-event-p event)
2072 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2073 (aset (cdr event) 5 title))
2075 (defun mixi-event-set-owner (event owner)
2076 "Set the owner of EVENT."
2077 (unless (mixi-event-p event)
2078 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2079 (unless (mixi-friend-p owner)
2080 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
2081 (aset (cdr event) 6 owner))
2083 (defun mixi-event-set-date (event date)
2084 "Set the date of EVENT."
2085 (unless (mixi-event-p event)
2086 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2087 (aset (cdr event) 7 date))
2089 (defun mixi-event-set-place (event place)
2090 "Set the place of EVENT."
2091 (unless (mixi-event-p event)
2092 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2093 (aset (cdr event) 8 place))
2095 (defun mixi-event-set-detail (event detail)
2096 "Set the detail of EVENT."
2097 (unless (mixi-event-p event)
2098 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2099 (aset (cdr event) 9 detail))
2101 (defun mixi-event-set-limit (event limit)
2102 "Set the limit of EVENT."
2103 (unless (mixi-event-p event)
2104 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2105 (aset (cdr event) 10 limit))
2107 (defun mixi-event-set-members (event members)
2108 "Set the members of EVENT."
2109 (unless (mixi-event-p event)
2110 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2111 (aset (cdr event) 11 members))
2114 (defconst mixi-bbs-list '(mixi-topic mixi-event))
2116 (defmacro mixi-bbs-p (bbs)
2117 `(memq (mixi-object-class ,bbs) mixi-bbs-list))
2119 (defun mixi-bbs-community (bbs)
2120 "Return the community of BBS."
2121 (unless (mixi-bbs-p bbs)
2122 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2123 (let ((func (intern (concat mixi-object-prefix
2124 (mixi-object-name bbs) "-community"))))
2125 (funcall func bbs)))
2127 (defun mixi-bbs-comment-count (bbs)
2128 "Return the comment-count of BBS."
2129 (unless (mixi-bbs-p bbs)
2130 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2131 (let ((func (intern (concat mixi-object-prefix
2132 (mixi-object-name bbs) "-comment-count"))))
2133 (funcall func bbs)))
2135 (defun mixi-bbs-set-comment-count (bbs count)
2136 "Set the comment-count of BBS."
2137 (unless (mixi-bbs-p bbs)
2138 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2139 (let ((func (intern (concat mixi-object-prefix
2140 (mixi-object-name bbs) "-set-comment-count"))))
2141 (funcall func bbs count)))
2143 (defalias 'mixi-bbs-id 'mixi-object-id)
2144 (defalias 'mixi-bbs-time 'mixi-object-time)
2145 (defalias 'mixi-bbs-title 'mixi-object-title)
2146 (defalias 'mixi-bbs-owner 'mixi-object-owner)
2147 (defalias 'mixi-bbs-content 'mixi-object-content)
2149 (defmacro mixi-bbs-list-page (community)
2150 `(concat "/list_bbs.pl?page=%d"
2151 "&id=" (mixi-community-id ,community)))
2153 (defconst mixi-bbs-list-regexp
2154 "<a href=\"?view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)")
2157 (defun mixi-get-bbses (community &optional range)
2158 "Get bbese of COMMUNITY."
2159 (unless (mixi-community-p community)
2160 (signal 'wrong-type-argument (list 'mixi-community-p community)))
2161 (let ((items (mixi-get-matched-items (mixi-bbs-list-page community)
2162 mixi-bbs-list-regexp
2164 (mapcar (lambda (item)
2165 (let ((name (nth 0 item)))
2166 (when (string= name "bbs")
2167 (setq name "topic"))
2168 (let ((func (intern (concat "mixi-make-" name))))
2169 (funcall func community (nth 1 item)))))
2172 (defmacro mixi-new-bbs-list-page ()
2173 `(concat "/new_bbs.pl?page=%d"))
2175 (defconst mixi-new-bbs-list-regexp
2176 "<dd><a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\">")
2179 (defun mixi-get-new-bbses (&optional range)
2181 (let ((items (mixi-get-matched-items (mixi-new-bbs-list-page)
2182 mixi-new-bbs-list-regexp
2185 (mapcar (lambda (item)
2186 (let ((name (nth 0 item)))
2187 (when (string= name "bbs")
2188 (setq name "topic"))
2189 (let* ((func (intern (concat "mixi-make-" name)))
2191 (mixi-make-community (nth 3 item))
2193 (comment-count (mixi-bbs-comment-count bbs))
2194 (count (string-to-number (nth 2 item))))
2195 (when (or (null comment-count)
2196 (< comment-count count))
2197 (mixi-bbs-set-comment-count bbs count)
2201 (defmacro mixi-search-bbs-list-page (keyword)
2202 `(concat "/search_topic.pl?page=%d&type=top&submit=search"
2203 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
2204 "&community_id=0&category_id=0"))
2206 (defconst mixi-search-bbs-list-regexp
2207 "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\" class=\"title\">")
2209 ;; FIXME: Support community and category.
2211 (defun mixi-search-bbses (keyword &optional range)
2212 (let ((items (mixi-get-matched-items (mixi-search-bbs-list-page keyword)
2213 mixi-search-bbs-list-regexp
2215 (mapcar (lambda (item)
2216 (let ((name (nth 0 item)))
2217 (when (string= name "bbs")
2218 (setq name "topic"))
2219 (let ((func (intern (concat "mixi-make-" name))))
2220 (funcall func (mixi-make-community (nth 2 item))
2225 (defmacro mixi-parent-p (object)
2226 `(or (eq (mixi-object-class ,object) 'mixi-diary)
2227 (mixi-bbs-p ,object)))
2229 (defun mixi-realize-parent (parent &optional page)
2231 (unless (mixi-parent-p parent)
2232 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2233 (let ((func (intern (concat mixi-object-prefix "realize-"
2234 (mixi-object-name parent)))))
2235 (funcall func parent page)))
2238 (defun mixi-make-comment (parent owner time content &optional count)
2239 "Return a comment object."
2240 (cons 'mixi-comment (vector parent owner time content count)))
2242 (defmacro mixi-comment-p (comment)
2243 `(eq (mixi-object-class ,comment) 'mixi-comment))
2245 (defun mixi-comment-parent (comment)
2246 "Return the parent of COMMENT."
2247 (unless (mixi-comment-p comment)
2248 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2249 (aref (cdr comment) 0))
2251 (defun mixi-comment-owner (comment)
2252 "Return the owner of COMMENT."
2253 (unless (mixi-comment-p comment)
2254 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2255 (aref (cdr comment) 1))
2257 (defun mixi-comment-time (comment)
2258 "Return the time of COMMENT."
2259 (unless (mixi-comment-p comment)
2260 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2261 (aref (cdr comment) 2))
2263 (defun mixi-comment-content (comment)
2264 "Return the content of COMMENT."
2265 (unless (mixi-comment-p comment)
2266 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2267 (aref (cdr comment) 3))
2269 (defun mixi-comment-count (comment)
2270 "Return the count of COMMENT."
2271 (unless (mixi-comment-p comment)
2272 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2273 (aref (cdr comment) 4))
2275 (defun mixi-diary-comment-list-page (diary)
2276 (concat "/view_diary.pl?full=1"
2277 "&id=" (mixi-diary-id diary)
2278 "&owner_id=" (mixi-friend-id (mixi-diary-owner diary))))
2280 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2281 (defconst mixi-diary-comment-list-regexp
2282 "<span class=\"commentTitleName\">\\(<input type=\"checkbox\" name=\"comment_id\" value=\".+\" />
2283 \\|\\)<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2285 | <a href=\"delete_comment\\.pl\\?diary_id=[0-9]+&owner_id=[0-9]+&comment_id=.+&type=comment\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a>
2288 <span class=\"commentTitleDate\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>
2294 \\(\\(.\\|\r?\n\\)*?\\)
2299 (defun mixi-topic-comment-list-page (topic)
2300 (concat "/view_bbs.pl?page=all"
2301 "&id=" (mixi-topic-id topic)
2302 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2304 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2305 (defconst mixi-topic-comment-list-regexp
2306 "<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>
2307 <span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
2309 <dl class=\"commentContent01\">
2310 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
2312 \\(\\(.\\|\r?\n\\)*?\\)
2315 (defun mixi-event-comment-list-page (event)
2316 (concat "/view_event.pl?page=all"
2317 "&id=" (mixi-event-id event)
2318 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2320 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2321 (defconst mixi-event-comment-list-regexp
2322 "<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>
2323 <span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
2325 <dl class=\"commentContent01\">
2326 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
2328 \\(\\(.\\|\r?\n\\)*?\\)
2332 (defun mixi-get-comments (parent &optional range)
2333 "Get comments of PARENT."
2334 (unless (mixi-parent-p parent)
2335 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2336 (let* ((name (mixi-object-name parent))
2337 (list-page (intern (concat mixi-object-prefix name
2338 "-comment-list-page")))
2339 (regexp (eval (intern (concat mixi-object-prefix name
2340 "-comment-list-regexp"))))
2341 (page (funcall list-page parent)))
2342 (unless (mixi-object-realized-p parent)
2343 (mixi-realize-parent parent page)
2345 (let ((items (mixi-get-matched-items page regexp range t)))
2346 (mapcar (lambda (item)
2347 (let (owner-id owner-nick year month day hour minute content
2349 (if (eq (mixi-object-class parent) 'mixi-diary)
2351 (setq owner-id (nth 1 item))
2352 (setq owner-nick (nth 2 item))
2353 (setq year (nth 4 item))
2354 (setq month (nth 5 item))
2355 (setq day (nth 6 item))
2356 (setq hour (nth 7 item))
2357 (setq minute (nth 8 item))
2358 (setq content (nth 9 item)))
2359 (setq owner-id (nth 8 item))
2360 (setq owner-nick (nth 9 item))
2361 (setq year (nth 3 item))
2362 (setq month (nth 4 item))
2363 (setq day (nth 5 item))
2364 (setq hour (nth 6 item))
2365 (setq minute (nth 7 item))
2366 (setq content (nth 10 item))
2367 (setq count (nth 1 item)))
2368 (mixi-make-comment parent (mixi-make-friend owner-id
2372 (string-to-number minute)
2373 (string-to-number hour)
2374 (string-to-number day)
2375 (string-to-number month)
2376 (string-to-number year))
2380 (defmacro mixi-new-comment-list-page ()
2381 `(concat "/new_comment.pl?page=%d"))
2383 (defconst mixi-new-comment-list-regexp
2384 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)\">")
2387 (defun mixi-get-new-comments (&optional range)
2389 (let ((items (mixi-get-matched-items (mixi-new-comment-list-page)
2390 mixi-new-comment-list-regexp
2393 (mapcar (lambda (item)
2394 (let* ((diary (mixi-make-diary
2395 (mixi-make-friend (nth 1 item))
2397 (comment-count (mixi-diary-comment-count diary))
2398 (count (string-to-number (nth 2 item))))
2399 (when (or (null comment-count)
2400 (< comment-count count))
2401 (mixi-diary-set-comment-count diary count)
2405 (defmacro mixi-new-bbs-comment-list-page ()
2406 `(concat "/new_bbs_comment.pl?page=%d"))
2408 (defconst mixi-new-bbs-comment-list-regexp
2409 "<a href=\"?view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\"?>")
2412 (defun mixi-get-new-bbs-comments (&optional range)
2413 "Get new BBS comments."
2414 (let ((items (mixi-get-matched-items (mixi-new-bbs-comment-list-page)
2415 mixi-new-bbs-comment-list-regexp
2418 (mapcar (lambda (item)
2419 (let ((name (nth 0 item)))
2420 (when (string= name "bbs")
2421 (setq name "topic"))
2422 (let ((make-func (intern (concat "mixi-make-" name)))
2424 (intern (concat "mixi-" name "-comment-count")))
2425 (set-comment-count-func
2426 (intern (concat "mixi-" name
2427 "-set-comment-count"))))
2428 (let* ((bbs (funcall make-func
2429 (mixi-make-community (nth 3 item))
2431 (comment-count (funcall comment-count-func bbs))
2432 (count (string-to-number (nth 2 item))))
2433 (when (or (null comment-count)
2434 (< comment-count count))
2435 (funcall set-comment-count-func bbs count)
2439 (defun mixi-post-diary-comment-page (diary)
2440 (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
2442 (defun mixi-post-topic-comment-page (topic)
2443 (concat "/add_bbs_comment.pl?id=" (mixi-topic-id topic)
2444 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2446 (defun mixi-post-event-comment-page (event)
2447 (concat "/add_event_comment.pl?id=" (mixi-event-id event)
2448 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2450 ;; FIXME: Support photos.
2452 (defun mixi-post-comment (parent content)
2453 "Post a comment to PARENT."
2454 (unless (mixi-object-p parent)
2455 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
2456 (unless (stringp content)
2457 (signal 'wrong-type-argument (list 'stringp content)))
2458 (let* ((name (mixi-object-name parent))
2459 (page (intern (concat mixi-object-prefix "post-" name
2462 (if (mixi-diary-p parent)
2464 `(("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2465 ("comment_body" . ,content)))
2466 (setq fields `(("comment" . ,content))))
2467 (with-mixi-post-form (funcall page parent) fields
2468 (if (re-search-forward mixi-post-key-regexp nil t)
2469 (setq post-key (match-string 1))
2470 (mixi-post-error 'cannot-find-key parent)))
2471 (if (mixi-diary-p parent)
2473 `(("post_key" . ,post-key)
2474 ("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2475 ("comment_body" . ,content)
2476 ("submit" . "confirm")))
2477 (setq fields `(("post_key" . ,post-key)
2478 ("comment" . ,content)
2479 ("submit" . "confirm"))))
2480 (with-mixi-post-form (funcall page parent) fields
2481 (unless (re-search-forward mixi-post-succeed-regexp nil t)
2482 (mixi-post-error 'cannot-find-succeed parent)))))
2485 (defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
2487 (defmacro mixi-message-box-p (box)
2488 `(memq ,box mixi-message-box-list))
2490 (defun mixi-message-box-name (box)
2491 "Return the name of BOX."
2492 (unless (mixi-message-box-p box)
2493 (signal 'wrong-type-argument (list 'mixi-message-box-p box)))
2496 (defvar mixi-message-cache (make-hash-table :test 'equal))
2497 (defun mixi-make-message (id box &optional owner title time content)
2498 "Return a message object."
2499 (mixi-make-cache (list id box)
2500 (cons 'mixi-message (vector nil id box owner title time
2502 mixi-message-cache))
2504 (defconst mixi-message-url-regexp
2505 "/view_message\\.pl\\?id=\\([a-z0-9]+\\)&box=\\([a-z]+\\)")
2507 (defun mixi-make-message-from-url (url)
2508 "Return a message object from URL."
2509 (when (string-match mixi-message-url-regexp url)
2510 (let ((id (match-string 1 url))
2511 (box (match-string 2 url)))
2512 (mixi-make-message id box))))
2514 (defmacro mixi-message-p (message)
2515 `(eq (mixi-object-class ,message) 'mixi-message))
2517 (defmacro mixi-message-page (message)
2518 `(concat "/view_message.pl?id=" (mixi-message-id ,message)
2519 "&box=" (mixi-message-box ,message)))
2521 (defconst mixi-message-owner-regexp
2522 "<font COLOR=#996600>\\(º¹½Ð¿Í\\|°¸ Àè\\)</font> : <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)\\(</a>\\|</td>\\)")
2523 (defconst mixi-message-time-regexp
2524 "<font COLOR=#996600>Æü\\(¡¡\\| \\)ÉÕ</font> : \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ ")
2525 (defconst mixi-message-title-regexp
2526 "<font COLOR=#996600>·ï\\(¡¡\\| \\)̾</font> : \\(.*\\)\n?</td>")
2527 (defconst mixi-message-content-regexp
2528 "<tr><td CLASS=h120 width=\"500\">\\(.*\\)</td></tr>")
2530 (defun mixi-realize-message (message)
2531 "Realize a MESSAGE."
2532 (unless (mixi-object-realized-p message)
2533 (with-mixi-retrieve (mixi-message-page message)
2534 (if (re-search-forward mixi-message-owner-regexp nil t)
2535 (mixi-message-set-owner message
2536 (mixi-make-friend (match-string 2)
2538 (mixi-realization-error 'cannot-find-owner message))
2539 (if (re-search-forward mixi-message-time-regexp nil t)
2540 (mixi-message-set-time
2541 message (encode-time 0 (string-to-number (match-string 6))
2542 (string-to-number (match-string 5))
2543 (string-to-number (match-string 4))
2544 (string-to-number (match-string 3))
2545 (string-to-number (match-string 2))))
2546 (mixi-realization-error 'cannot-find-time message))
2547 (if (re-search-forward mixi-message-title-regexp nil t)
2548 (mixi-message-set-title message (match-string 2))
2549 (mixi-realization-error 'cannot-find-title message))
2550 (if (re-search-forward mixi-message-content-regexp nil t)
2551 (mixi-message-set-content message (match-string 1))
2552 (mixi-realization-error 'cannot-find-content message)))
2553 (mixi-object-touch message)))
2555 (defun mixi-message-id (message)
2556 "Return the id of MESSAGE."
2557 (unless (mixi-message-p message)
2558 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2559 (aref (cdr message) 1))
2561 (defun mixi-message-box (message)
2562 "Return the box of MESSAGE."
2563 (unless (mixi-message-p message)
2564 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2565 (aref (cdr message) 2))
2567 (defun mixi-message-owner (message)
2568 "Return the owner of MESSAGE."
2569 (unless (mixi-message-p message)
2570 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2571 (mixi-realize-message message)
2572 (aref (cdr message) 3))
2574 (defun mixi-message-title (message)
2575 "Return the title of MESSAGE."
2576 (unless (mixi-message-p message)
2577 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2578 (mixi-realize-message message)
2579 (aref (cdr message) 4))
2581 (defun mixi-message-time (message)
2582 "Return the date of MESSAGE."
2583 (unless (mixi-message-p message)
2584 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2585 (mixi-realize-message message)
2586 (aref (cdr message) 5))
2588 (defun mixi-message-content (message)
2589 "Return the content of MESSAGE."
2590 (unless (mixi-message-p message)
2591 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2592 (mixi-realize-message message)
2593 (aref (cdr message) 6))
2595 (defun mixi-message-set-owner (message owner)
2596 "Set the owner of MESSAGE."
2597 (unless (mixi-message-p message)
2598 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2599 (aset (cdr message) 3 owner))
2601 (defun mixi-message-set-title (message title)
2602 "Set the title of MESSAGE."
2603 (unless (mixi-message-p message)
2604 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2605 (aset (cdr message) 4 title))
2607 (defun mixi-message-set-time (message time)
2608 "Set the date of MESSAGE."
2609 (unless (mixi-message-p message)
2610 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2611 (aset (cdr message) 5 time))
2613 (defun mixi-message-set-content (message content)
2614 "Set the content of MESSAGE."
2615 (unless (mixi-message-p message)
2616 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2617 (aset (cdr message) 6 content))
2619 (defmacro mixi-message-list-page (&optional box)
2620 `(concat "/list_message.pl?page=%d"
2621 (when ,box (concat "&box=" ,box))))
2623 (defconst mixi-message-list-regexp
2624 "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
2627 (defun mixi-get-messages (&rest box-or-range)
2628 "Get messages of BOX."
2629 (when (> (length box-or-range) 2)
2630 (signal 'wrong-number-of-arguments
2631 (list 'mixi-get-messages (length box-or-range))))
2632 (let ((box (nth 0 box-or-range))
2633 (range (nth 1 box-or-range)))
2634 (when (or (not (mixi-message-box-p box))
2635 (mixi-message-box-p range))
2636 (setq box (nth 1 box-or-range))
2637 (setq range (nth 0 box-or-range)))
2638 (let ((items (mixi-get-matched-items
2639 (mixi-message-list-page
2640 (when box (mixi-message-box-name box)))
2641 mixi-message-list-regexp
2643 (mapcar (lambda (item)
2644 (mixi-make-message (nth 0 item) (nth 1 item)))
2647 (defmacro mixi-post-message-page (friend)
2648 `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
2650 (defconst mixi-post-message-key-regexp
2651 "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
2653 (defconst mixi-post-message-succeed-regexp
2654 "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
2657 (defun mixi-post-message (friend title content)
2658 "Post a message to FRIEND."
2659 (unless (mixi-friend-p friend)
2660 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2661 (unless (stringp title)
2662 (signal 'wrong-type-argument (list 'stringp title)))
2663 (unless (stringp content)
2664 (signal 'wrong-type-argument (list 'stringp content)))
2665 (let ((fields `(("subject" . ,title)
2667 ("submit" . "main")))
2669 (with-mixi-post-form (mixi-post-message-page friend) fields
2670 (if (re-search-forward mixi-post-message-key-regexp nil t)
2671 (setq post-key (match-string 1))
2672 (mixi-post-error 'cannot-find-key friend)))
2673 (setq fields `(("post_key" . ,post-key)
2674 ("subject" . ,title)
2676 ("yes" . "¡¡Á÷¡¡¿®¡¡")
2677 ("submit" . "confirm")))
2678 (with-mixi-post-form (mixi-post-message-page friend) fields
2679 (unless (re-search-forward mixi-post-message-succeed-regexp nil t)
2680 (mixi-post-error 'cannot-find-succeed friend)))))
2682 ;; Introduction object.
2683 (defun mixi-make-introduction (parent owner content)
2684 "Return a introduction object."
2685 (cons 'mixi-introduction (vector parent owner content)))
2687 (defmacro mixi-introduction-p (introduction)
2688 `(eq (mixi-object-class ,introduction) 'mixi-introduction))
2690 (defun mixi-introduction-parent (introduction)
2691 "Return the parent of INTRODUCTION."
2692 (unless (mixi-introduction-p introduction)
2693 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2694 (aref (cdr introduction) 0))
2696 (defun mixi-introduction-owner (introduction)
2697 "Return the owner of INTRODUCTION."
2698 (unless (mixi-introduction-p introduction)
2699 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2700 (aref (cdr introduction) 1))
2702 (defun mixi-introduction-content (introduction)
2703 "Return the content of INTRODUCTION."
2704 (unless (mixi-introduction-p introduction)
2705 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2706 (aref (cdr introduction) 3))
2708 (defmacro mixi-introduction-list-page (&optional friend)
2709 `(concat "/show_intro.pl?page=%d"
2710 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
2712 (defconst mixi-introduction-list-regexp
2713 "<tr bgcolor=#FFFFFF>
2714 <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>
2721 \\(\\(.\\|\n<br>\\)+\\)\\|
2722 \\(\\(.\\|\n<br>\\)+\\)\\)
2729 (defconst mixi-my-introduction-list-regexp
2730 "<tr bgcolor=#FFFFFF>
2731 <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>
2739 \\(\\(.\\|\n<br>\\)+\\)\\|
2740 \\(\\(.\\|\n<br>\\)+\\)\\)
2744 <a href=\"edit_intro\\.pl\\?id=\\1&type=edit\">¤³¤Îͧ¿Í¤ò¾Ò²ð¤¹¤ë</a>
2748 <a href=\"delete_intro\\.pl\\?id=\\1\">ºï½ü</a>
2754 (defun mixi-get-introductions (&rest friend-or-range)
2755 "Get introductions of FRIEND."
2756 (when (> (length friend-or-range) 2)
2757 (signal 'wrong-number-of-arguments
2758 (list 'mixi-get-introduction (length friend-or-range))))
2759 (let ((friend (nth 0 friend-or-range))
2760 (range (nth 1 friend-or-range)))
2761 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
2762 (setq friend (nth 1 friend-or-range))
2763 (setq range (nth 0 friend-or-range)))
2764 (unless (or (null friend) (mixi-friend-p friend))
2765 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2766 (let* ((regexp (if friend mixi-introduction-list-regexp
2767 mixi-my-introduction-list-regexp))
2768 (items (mixi-get-matched-items (mixi-introduction-list-page friend)
2771 (mapcar (lambda (item)
2772 (mixi-make-introduction (or friend (mixi-make-me))
2773 (mixi-make-friend (nth 0 item)
2779 (defvar mixi-news-cache (make-hash-table :test 'equal))
2780 (defun mixi-make-news (media-id id &optional media time title content)
2781 "Return a news object."
2782 (mixi-make-cache (list media-id id)
2783 (cons 'mixi-news (vector nil media-id id media time title
2787 (defconst mixi-news-url-regexp
2788 "/view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)")
2790 (defun mixi-make-news-from-url (url)
2791 "Return a news object from URL."
2792 (when (string-match mixi-news-url-regexp url)
2793 (let ((id (match-string 1 url))
2794 (media-id (match-string 2 url)))
2795 (mixi-make-news media-id id))))
2797 (defmacro mixi-news-p (news)
2798 `(eq (mixi-object-class ,news) 'mixi-news))
2800 (defmacro mixi-news-page (news)
2801 `(concat "http://news.mixi.jp/view_news.pl?id=" (mixi-news-id ,news)
2802 "&media_id=" (mixi-news-media-id ,news)))
2804 (defconst mixi-news-finished-regexp
2805 "¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤³¤Î¥Ë¥å¡¼¥¹¤Ï·ÇºÜ¤¬½ªÎ»¤·¤¿¤«¡¢URL¤¬´Ö°ã¤Ã¤Æ¤¤¤¤¤ë¤¿¤á¤´Í÷¤¤¤¿¤À¤±¤Þ¤»¤ó¡£</td>")
2806 (defconst mixi-news-title-regexp
2807 "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)\\(
2809 (defconst mixi-news-media-time-regexp
2810 "<td COLSPAN=\"2\" ALIGN=\"right\">(\\(.+\\) - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))</td></tr>")
2811 (defconst mixi-news-content-regexp
2812 "<td CLASS=\"h150\">
2819 \\(</td>\\|<br>\\)")
2821 (defun mixi-realize-news (news)
2823 ;; FIXME: Check a expiration of cache?
2824 (unless (mixi-object-realized-p news)
2825 (with-mixi-retrieve (mixi-news-page news)
2826 (if (re-search-forward mixi-news-finished-regexp nil t)
2827 (mixi-news-set-content news (match-string 0))
2828 (if (re-search-forward mixi-news-title-regexp nil t)
2829 (mixi-news-set-title news (match-string 1))
2830 (mixi-realization-error 'cannot-find-title news))
2831 (if (re-search-forward mixi-news-media-time-regexp nil t)
2833 (mixi-news-set-media news (match-string 1))
2834 (let ((year (nth 5 (decode-time (current-time))))
2835 (month (nth 4 (decode-time (current-time))))
2836 (month-of-item (string-to-number (match-string 2))))
2837 (when (> month-of-item month)
2840 news (encode-time 0 (string-to-number (match-string 5))
2841 (string-to-number (match-string 4))
2842 (string-to-number (match-string 3))
2844 (mixi-realization-error 'cannot-find-media-time news))
2845 (if (re-search-forward mixi-news-content-regexp nil t)
2846 (mixi-news-set-content news (match-string 1))
2847 (mixi-realization-error 'cannot-find-content news))))
2848 (mixi-object-touch news)))
2850 (defun mixi-news-media-id (news)
2851 "Return the media-id of NEWS."
2852 (unless (mixi-news-p news)
2853 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2854 (aref (cdr news) 1))
2856 (defun mixi-news-id (news)
2857 "Return the id of NEWS."
2858 (unless (mixi-news-p news)
2859 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2860 (aref (cdr news) 2))
2862 (defun mixi-news-media (news)
2863 "Return the media of NEWS."
2864 (unless (mixi-news-p news)
2865 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2866 (unless (aref (cdr news) 3)
2867 (mixi-realize-news news))
2868 (aref (cdr news) 3))
2870 (defun mixi-news-time (news)
2871 "Return the time of NEWS."
2872 (unless (mixi-news-p news)
2873 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2874 (unless (aref (cdr news) 4)
2875 (mixi-realize-news news))
2876 (aref (cdr news) 4))
2878 (defun mixi-news-title (news)
2879 "Return the title of NEWS."
2880 (unless (mixi-news-p news)
2881 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2882 (unless (aref (cdr news) 5)
2883 (mixi-realize-news news))
2884 (aref (cdr news) 5))
2886 (defun mixi-news-content (news)
2887 "Return the content of NEWS."
2888 (unless (mixi-news-p news)
2889 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2890 (mixi-realize-news news)
2891 (aref (cdr news) 6))
2893 (defun mixi-news-set-media (news media)
2894 "Set the media of NEWS."
2895 (unless (mixi-news-p news)
2896 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2897 (aset (cdr news) 3 media))
2899 (defun mixi-news-set-time (news time)
2900 "Set the time of NEWS."
2901 (unless (mixi-news-p news)
2902 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2903 (aset (cdr news) 4 time))
2905 (defun mixi-news-set-title (news title)
2906 "Set the title of NEWS."
2907 (unless (mixi-news-p news)
2908 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2909 (aset (cdr news) 5 title))
2911 (defun mixi-news-set-content (news content)
2912 "Set the content of NEWS."
2913 (unless (mixi-news-p news)
2914 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2915 (aset (cdr news) 6 content))
2917 (defconst mixi-news-category-list '(domestic politics economy area abroad
2918 sports entertainment IT))
2920 (defmacro mixi-news-category-p (category)
2921 `(memq ,category mixi-news-category-list))
2923 (defun mixi-news-category-id (category)
2924 "Return the id of CATEGORY."
2925 (unless (mixi-news-category-p category)
2926 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2928 (1+ (- (length mixi-news-category-list)
2929 (length (memq category mixi-news-category-list))))))
2931 (defconst mixi-news-sort-list '(newest pickup))
2933 (defmacro mixi-news-sort-p (sort)
2934 `(memq ,sort mixi-news-sort-list))
2936 (defun mixi-news-sort-id (sort)
2937 "Return the id of SORT."
2938 (unless (mixi-news-sort-p sort)
2939 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
2941 (- (length mixi-news-sort-list)
2942 (length (memq sort mixi-news-sort-list)))))
2944 (defmacro mixi-news-list-page (category sort)
2945 `(concat "http://news.mixi.jp/list_news_category.pl?page=%d"
2946 "&sort=" (mixi-news-sort-id ,sort)
2947 "&id=" (mixi-news-category-id ,category)
2950 (defconst mixi-news-list-regexp
2951 "<tr bgcolor=\"\\(#FCF5EB\\|#FFFFFF\\)\">
2952 <td WIDTH=\"1%\" valign=top CLASS=\"h120\">¡¦</td>
2953 <td WIDTH=\"97%\" CLASS=\"h120\"><A HREF=\"view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)\"class=\"new_link\">\\(.+\\)</A>
2954 \\(<IMG SRC=\"http://img\\.mixi\\.jp/img/news_camera3\\.gif\" WIDTH=\"11\" HEIGHT=\"12\">\\|\\)
2957 <td WIDTH=\"1%\" nowrap CLASS=\"f08\"><A HREF=\"list_news_media\\.pl\\?id=[0-9]+\">\\(.+\\)</A></td>
2958 <td WIDTH=\"1%\" nowrap CLASS=\"f08\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td></tr>")
2961 (defun mixi-get-news (category sort &optional range)
2962 "Get news of CATEGORY and SORT."
2963 (unless (mixi-news-category-p category)
2964 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2965 (unless (mixi-news-sort-p sort)
2966 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
2967 (let ((items (mixi-get-matched-items (mixi-news-list-page category sort)
2968 mixi-news-list-regexp
2970 (year (nth 5 (decode-time (current-time))))
2971 (month (nth 4 (decode-time (current-time)))))
2972 (mapcar (lambda (item)
2973 (let ((month-of-item (string-to-number (nth 6 item))))
2974 (when (> month-of-item month)
2976 (setq month month-of-item)
2977 (mixi-make-news (nth 2 item) (nth 1 item) (nth 5 item)
2979 0 (string-to-number (nth 9 item))
2980 (string-to-number (nth 8 item))
2981 (string-to-number (nth 7 item))
2988 ;;; mixi.el ends here