1 ;; mixi.el --- API libraries for accessing to mixi -*- coding: euc-jp -*-
3 ;; Copyright (C) 2005, 2006, 2007, 2008 OHASHI Akira
5 ;; Author: OHASHI Akira <bg66@koka-in.org>
6 ;; Keywords: hypermedia
8 ;; This file is *NOT* a part of Emacs.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;; APIs for getting contents:
30 ;; * mixi-get-favorites
32 ;; * mixi-get-recommended-friends (indies)
34 ;; * mixi-get-new-diaries
35 ;; * mixi-search-diaries
36 ;; * mixi-get-communities
37 ;; * mixi-search-communities
38 ;; * mixi-get-recommended-communities (indies)
40 ;; * mixi-get-new-bbses
41 ;; * mixi-search-bbses
42 ;; * mixi-get-comments
43 ;; * mixi-get-new-comments
44 ;; * mixi-get-new-bbs-comments
45 ;; * mixi-get-messages
46 ;; * mixi-get-introductions (broken)
48 ;; * mixi-get-releases
54 ;; * mixi-post-comment
55 ;; * mixi-post-message
59 ;; * mixi-remove-markup (half broken)
63 ;; Display newest 3 diaries like a mail format.
66 ;; (buffer (get-buffer-create "*temp*"))
67 ;; (format "%Y/%m/%d %H:%M"))
68 ;; (pop-to-buffer buffer)
69 ;; (let ((diaries (mixi-get-new-diaries range)))
71 ;; (let* ((diary (car diaries))
72 ;; (subject (mixi-diary-title diary))
73 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
74 ;; (date (format-time-string format (mixi-diary-time diary)))
75 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
76 ;; (insert "From: " from "\n"
77 ;; "Subject: " subject "\n"
78 ;; "Date: " date "\n\n"
80 ;; (setq diaries (cdr diaries))))
81 ;; (set-buffer-modified-p nil)
82 ;; (setq buffer-read-only t)
83 ;; (goto-char (point-min)))
85 ;; Display newest 3 diaries including newest 3 comments like a mail format.
86 ;; Comments are displayed like a reply mail.
89 ;; (buffer (get-buffer-create "*temp*"))
90 ;; (format "%Y/%m/%d %H:%M"))
91 ;; (pop-to-buffer buffer)
92 ;; (let ((diaries (mixi-get-new-diaries range)))
94 ;; (let* ((diary (car diaries))
95 ;; (subject (mixi-diary-title diary))
96 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
97 ;; (date (format-time-string format (mixi-diary-time diary)))
98 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
99 ;; (insert "From: " from "\n"
100 ;; "Subject: " subject "\n"
101 ;; "Date: " date "\n\n"
103 ;; (let ((comments (mixi-get-comments diary range)))
105 ;; (let* ((comment (car comments))
106 ;; (from (mixi-friend-nick (mixi-comment-owner comment)))
107 ;; (subject (concat "Re: " subject))
108 ;; (date (format-time-string format
109 ;; (mixi-comment-time comment)))
110 ;; (body (mixi-remove-markup (mixi-comment-content comment))))
111 ;; (insert "From: " from "\n"
112 ;; "Subject: " subject "\n"
113 ;; "Date: " date "\n\n"
115 ;; (setq comments (cdr comments)))))
116 ;; (setq diaries (cdr diaries))))
117 ;; (set-buffer-modified-p nil)
118 ;; (setq buffer-read-only t)
119 ;; (goto-char (point-min)))
123 ;; If you have bug reports and/or suggestions for improvement, please
124 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
128 (eval-when-compile (require 'cl))
130 ;; Functions and variables which should be defined in the other module
133 (defvar w3m-use-cookies)
134 (defvar url-request-method)
135 (defvar url-request-data)
136 (defvar url-request-extra-headers)
137 (defvar url-show-status)
138 (autoload 'w3m-decode-buffer "w3m")
139 (autoload 'w3m-retrieve "w3m")
140 (autoload 'url-retrieve-synchronously "url"))
142 (defconst mixi-revision "$Revision: 1.189 $")
145 "API library for accessing to mixi."
148 (defcustom mixi-url "http://mixi.jp"
153 (defcustom mixi-directory (expand-file-name "~/.mixi")
154 "*Where to look for mixi files."
158 (defcustom mixi-coding-system 'euc-jp
159 "*Coding system for mixi."
163 (defcustom mixi-curl-program "curl"
164 "*The program name of `curl'."
168 (defcustom mixi-curl-cookie-file (expand-file-name "cookies.txt"
170 "*The location of cookie file created by `curl'."
174 (defcustom mixi-backend
175 (or (condition-case nil
183 (if (fboundp 'url-retrieve-synchronously)
186 (if (and (fboundp 'executable-find)
187 (executable-find mixi-curl-program))
189 (error "Cannot set `mixi-backend'."))
190 "*The backend for accessing to mixi."
191 :type '(radio (const :tag "Use emacs-w3m" w3m)
192 (const :tag "Use url.el" url)
193 (const :tag "Use curl" curl)
194 (symbol :tag "The other backend"))
197 (defcustom mixi-login-use-ssl nil
198 "*If non-ni, login using SSL."
202 (defcustom mixi-default-email nil
203 "*Default E-mail address that is used to login automatically."
204 :type '(radio (string :tag "E-mail address")
205 (const :tag "Asked when it is necessary" nil))
208 (defcustom mixi-default-password nil
209 "*Default password that is used to login automatically."
210 :type '(radio (string :tag "Password")
211 (const :tag "Asked when it is necessary" nil))
214 (defcustom mixi-accept-adult-contents t
215 "*If non-nil, accept to access to the adult contents."
219 (defcustom mixi-continuously-access-interval 4.0
220 "*Time interval between each mixi access.
221 Increase this value when unexpected error frequently occurs."
225 (defcustom mixi-cache-expires nil
226 "*Seconds for expiration of a cached object."
227 :type '(radio (integer :tag "Expired seconds")
228 (const :tag "Don't expire" nil)
229 (const :tag "Don't cache" t))
232 ;; FIXME: Not implemented.
233 (defcustom mixi-cache-use-file t
234 "*If non-nil, caches are saved to files."
238 (defvar mixi-temp-buffer-name " *mixi temp*")
242 (defmacro mixi-message (&rest strings)
243 `(concat "[mixi] " ,@strings))
245 (put 'mixi-realization-error
246 'error-message (mixi-message "Cannot realize object"))
247 (put 'mixi-realization-error
248 'error-conditions '(mixi-realization-error error))
250 (put 'mixi-post-error
251 'error-message (mixi-message "Cannot post"))
252 (put 'mixi-post-error
253 'error-conditions '(mixi-post-error error))
255 (defmacro mixi-realization-error (type object)
256 `(let ((data (if debug-on-error
257 (list ,type ,object (buffer-string))
258 (list ,type ,object))))
259 (signal 'mixi-realization-error data)))
261 (defmacro mixi-post-error (type &optional object)
262 `(let ((data (when debug-on-error (list (buffer-string)))))
264 (setq data (cons ,type (cons ,object data)))
265 (setq data (cons ,type data)))
266 (signal 'mixi-post-error data)))
268 (defconst mixi-message-adult-contents
269 "¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
270 ±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
271 (defconst mixi-message-continuously-accessing
272 "°ÂÄꤷ¤Æ¥µ¥¤¥È¤Î±¿±Ä¤ò¤ª¤³¤Ê¤¦°Ù¡¢´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹<br>
273 ¿·¤ÏÀ©¸Â¤µ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤ª¤ê¤Þ¤¹¡£¤´ÌÂÏǤò¤ª¤«¤±¤¤¤¿¤·¤Þ¤¹¤¬¡¢¤·¤Ð¤é¤¯¤ª<br>
274 ÂÔ¤Á¤¤¤¿¤À¤¤¤Æ¤«¤éÁàºî¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£")
275 (defconst mixi-warning-continuously-accessing
276 "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«<br>
277 ¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ<br>
278 ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
280 (defmacro mixi-retrieve (url &optional post-data)
281 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-retrieve"))
284 (defmacro mixi-post-form (url fields)
285 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-post-form"))
288 (defun mixi-parse-buffer (url buffer &optional post-data)
289 (when (string-match mixi-message-adult-contents buffer)
290 (if mixi-accept-adult-contents
291 (setq buffer (mixi-retrieve url "submit=agree"))
292 (setq buffer (mixi-retrieve (concat url "?")))))
293 (when (string-match mixi-warning-continuously-accessing buffer)
294 (error (mixi-message "Access denied. Please wait a while and increase "
295 "the value of `mixi-continuously-access-interval'.")))
296 (if (not (string-match mixi-message-continuously-accessing buffer))
298 (message (mixi-message "Waiting for continuously accessing..."))
299 (sleep-for mixi-continuously-access-interval)
300 (mixi-retrieve url post-data)))
302 (defmacro mixi-expand-url (url)
303 `(if (string-match "^http" ,url)
305 (concat mixi-url ,url)))
307 ;; FIXME: Support files.
308 (defun mixi-make-form-data (fields)
309 "Make form data and return (CONTENT-TYPE . FORM-DATA)."
310 (let* ((boundary (apply 'format "--_%d_%d_%d" (current-time)))
311 (content-type (concat "multipart/form-data; boundary=" boundary))
315 (concat "--" boundary "\r\n"
316 "Content-Disposition: form-data; name=\""
319 (encode-coding-string (cdr field) mixi-coding-system)))
321 (cons content-type (concat form-data "\r\n--" boundary "--"))))
323 (defun mixi-url-retrieve (url &optional post-data extra-headers)
324 "Retrieve the URL and return gotten strings."
325 (let* ((url-request-method (if post-data "POST" "GET"))
326 (url-request-data post-data)
327 (url-request-extra-headers extra-headers)
328 (url (mixi-expand-url url))
330 (buffer (url-retrieve-synchronously url))
332 (unless (bufferp buffer)
333 (error (mixi-message "Cannot retrieve: " url)))
334 (with-current-buffer buffer
335 (goto-char (point-min))
336 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
337 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
338 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
339 (error (mixi-message "Cannot retrieve: " url)))
340 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
341 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
343 (mixi-parse-buffer url ret post-data))))
345 (defun mixi-url-post-form (url fields)
346 (let* ((form-data (mixi-make-form-data fields))
347 (extra-headers `(("Content-Type" . ,(car form-data)))))
348 (mixi-url-retrieve url (cdr form-data) extra-headers)))
350 (defun mixi-w3m-retrieve (url &optional post-data)
351 "Retrieve the URL and return gotten strings."
352 (let ((url (mixi-expand-url url)))
354 (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
355 (error (mixi-message "Cannot retrieve: " url))
356 (w3m-decode-buffer url)
357 (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
358 (mixi-parse-buffer url ret post-data))))))
360 (defun mixi-w3m-post-form (url fields)
361 (let ((form-data (mixi-make-form-data fields)))
362 (mixi-w3m-retrieve url form-data)))
364 (defun mixi-curl-retrieve (url &optional post-data form-data)
365 "Retrieve the URL and return gotten strings."
367 (if (fboundp 'set-buffer-multibyte)
368 (set-buffer-multibyte nil))
369 (let ((orig-mode (default-file-modes))
370 (coding-system-for-read 'binary)
371 (coding-system-for-write 'binary)
375 (set-default-file-modes 448)
377 (apply #'start-process "curl" (current-buffer)
379 (append (if post-data '("-d" "@-"))
382 "-b" mixi-curl-cookie-file
383 "-c" mixi-curl-cookie-file
384 (mixi-expand-url url)))))
385 (set-process-sentinel process #'ignore))
386 (set-default-file-modes orig-mode))
388 (process-send-string process (concat post-data "\n"))
389 (process-send-eof process))
390 (while (eq (process-status process) 'run)
391 (accept-process-output process 1))
392 (goto-char (point-min))
393 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
394 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
395 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
396 (error (mixi-message "Cannot retrieve: " url)))
397 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
398 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
399 (mixi-parse-buffer url ret post-data))))
401 (defun mixi-curl-post-form (url fields)
403 (mapcar (lambda (field)
404 (push "-F" form-data)
405 (push (concat (car field) "="
406 (encode-coding-string (cdr field)
410 (mixi-curl-retrieve url nil (reverse form-data))))
412 (defconst mixi-my-id-regexp
413 "<a href=\"show_profile\\.pl\\?id=\\([0-9]+\\)")
415 (defun mixi-login (&optional email password)
417 (when (and (eq mixi-backend 'w3m) (not w3m-use-cookies))
418 (error (mixi-message "Require to accept cookies. Please set "
419 "`w3m-use-cookies' to t.")))
420 (let ((email (or email mixi-default-email
421 (read-from-minibuffer (mixi-message "Login Email: "))))
422 (password (or password mixi-default-password
423 (read-passwd (mixi-message "Login Password: ")))))
424 (let ((url (mixi-expand-url "/login.pl")))
425 (when (and mixi-login-use-ssl (string-match "^http:" url))
426 (setq url (replace-match "https:" nil nil url)))
427 (let ((buffer (mixi-retrieve url
428 (concat "email=" email
429 "&password=" password
432 (unless (string-match "url=/check\\.pl\\?n=" buffer)
433 (error (mixi-message "Cannot login")))
434 (setq buffer (mixi-retrieve "/check.pl?n=home.pl"))
435 (if (string-match mixi-my-id-regexp buffer)
436 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
437 (error (mixi-message "Cannot login")))))))
439 (defun mixi-logout ()
440 (mixi-retrieve "/logout.pl"))
442 (defconst mixi-login-form "<form action=\"/login.pl\" method=\"post\" name=\"login_form\">")
444 (defmacro with-mixi-retrieve (url &rest body)
445 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
448 (insert (mixi-retrieve ,url))
449 (goto-char (point-min))
450 (when (search-forward mixi-login-form nil t)
453 (insert (mixi-retrieve ,url))))
454 (goto-char (point-min))
456 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
457 (put 'with-mixi-retrieve 'edebug-form-spec '(body))
459 (defmacro with-mixi-post-form (url fields &rest body)
460 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
463 (insert (mixi-post-form ,url ,fields))
464 (goto-char (point-min))
465 (when (search-forward mixi-login-form nil t)
468 (insert (mixi-post-form ,url ,fields))))
469 (goto-char (point-min))
471 (put 'with-mixi-post-form 'lisp-indent-function 'defun)
472 (put 'with-mixi-post-form 'edebug-form-spec '(body))
474 (defun mixi-get-matched-items (url regexp &optional range reverse)
475 "Get matched items to REGEXP in URL."
479 (while (and (or (null range) (< (length ids) range))
480 (or (= page 1) (and (stringp url) (string-match "%d" url))))
481 (with-mixi-retrieve (when url (format url page))
482 (let ((func (if reverse (progn
483 (goto-char (point-max))
487 (while (and (funcall func regexp nil t)
488 (or (null range) (< (length ids) range)))
491 (while (match-string num)
492 (setq list (cons (match-string num) list))
494 (when (not (member (reverse list) ids))
496 (setq ids (cons (reverse list) ids)))))
502 ;; stolen (and modified) from shimbun.el
503 (defun mixi-remove-markup (string)
504 "Remove markups from STRING."
506 (insert (or string ""))
508 (goto-char (point-min))
509 (while (search-forward "<!--" nil t)
510 (delete-region (match-beginning 0)
511 (or (search-forward "-->" nil t)
513 (goto-char (point-min))
514 (while (re-search-forward "<[^>]+>" nil t)
515 (replace-match "" t t))
516 (goto-char (point-min))
517 (while (re-search-forward "
\r" nil t)
518 (replace-match "\n" t t)))
519 ;; FIXME: Decode entities.
522 ;; stolen (and modified) from w3m.el
523 (defconst mixi-entity-alist '(("gt" . ">")
526 "Alist of html character entities and values.")
528 ;; stolen (and modified) from w3m.el
529 (defun mixi-encode-specials-string (str)
530 "Encode special characters in the string STR."
533 (while (string-match "[<>&]" str pos)
536 (cons (car (rassoc (match-string 0 str) mixi-entity-alist))
538 (cons (substring str pos (match-beginning 0))
542 (apply 'concat (nreverse (cons (substring str pos) buf)))
545 ;; stolen (and modified) from w3m.el
546 (defun mixi-url-encode-string (string)
547 (apply (function concat)
551 ((eq char ?\n) ; newline
553 ((string-match "[-a-zA-Z0-9_:/.]" (char-to-string char)) ; xxx?
554 (char-to-string char)) ; printable
555 ((char-equal char ?\x20) ; space
558 (format "%%%02x" char)))) ; escape
559 ;; Coerce a string into a list of chars.
560 (append (encode-coding-string (or string "") mixi-coding-system)
563 (defun mixi-url-encode-and-quote-percent-string (string)
564 (let ((string (mixi-url-encode-string string))
566 (while (string-match "%" string pos)
567 (setq string (replace-match "%%" nil nil string))
568 (setq pos (+ (match-end 0) 1)))
572 (defconst mixi-object-prefix "mixi-")
574 (defmacro mixi-object-class (object)
577 (defmacro mixi-object-p (object)
578 `(let ((class (mixi-object-class ,object)))
579 (when (symbolp class)
580 (eq (string-match (concat "^" mixi-object-prefix)
581 (symbol-name class)) 0))))
583 (defun mixi-object-name (object)
584 "Return the name of OBJECT."
585 (unless (mixi-object-p object)
586 (signal 'wrong-type-argument (list 'mixi-object-p object)))
587 (let ((class (mixi-object-class object)))
588 (substring (symbol-name class) (length mixi-object-prefix))))
590 (defun mixi-read-object (exp)
591 "Read one Lisp expression as mixi object."
592 (if (mixi-object-p exp)
593 (let ((func (intern (concat mixi-object-prefix "make-"
594 (mixi-object-name exp))))
595 (args (mapcar (lambda (arg)
596 (mixi-read-object arg))
598 (let ((object (apply func (cdr args))))
600 (mixi-object-set-timestamp object (car args)))
604 (defun mixi-object-timestamp (object)
605 "Return the timestamp of OJBECT."
606 (unless (mixi-object-p object)
607 (signal 'wrong-type-argument (list 'mixi-object-p object)))
608 (aref (cdr object) 0))
609 (defalias 'mixi-object-realized-p 'mixi-object-timestamp)
611 (defun mixi-object-owner (object)
612 "Return the owner of OBJECT."
613 (unless (mixi-object-p object)
614 (signal 'wrong-type-argument (list 'mixi-object-p object)))
615 (let ((func (intern (concat mixi-object-prefix
616 (mixi-object-name object) "-owner"))))
617 (funcall func object)))
619 (defun mixi-object-id (object)
620 "Return the id of OBJECT."
621 (unless (mixi-object-p object)
622 (signal 'wrong-type-argument (list 'mixi-object-p object)))
623 (let ((func (intern (concat mixi-object-prefix
624 (mixi-object-name object) "-id"))))
625 (funcall func object)))
627 (defun mixi-object-time (object)
628 "Return the time of OBJECT."
629 (unless (mixi-object-p object)
630 (signal 'wrong-type-argument (list 'mixi-object-p object)))
631 (let ((func (intern (concat mixi-object-prefix
632 (mixi-object-name object) "-time"))))
633 (funcall func object)))
635 (defun mixi-object-title (object)
636 "Return the title of OBJECT."
637 (unless (mixi-object-p object)
638 (signal 'wrong-type-argument (list 'mixi-object-p object)))
639 (let ((func (intern (concat mixi-object-prefix
640 (mixi-object-name object) "-title"))))
641 (funcall func object)))
643 (defun mixi-object-content (object)
644 "Return the content of OBJECT."
645 (unless (mixi-object-p object)
646 (signal 'wrong-type-argument (list 'mixi-object-p object)))
647 (let ((func (intern (concat mixi-object-prefix
648 (mixi-object-name object) "-content"))))
649 (funcall func object)))
651 (defun mixi-object-set-timestamp (object timestamp)
652 "Set the timestamp of OBJECT."
653 (unless (mixi-object-p object)
654 (signal 'wrong-type-argument (list 'mixi-object-p object)))
655 (aset (cdr object) 0 timestamp))
657 (defmacro mixi-object-touch (object)
658 `(mixi-object-set-timestamp ,object (current-time)))
660 (defconst mixi-object-url-regexp
661 "/\\(show\\|view\\)_\\([a-z]+\\)\\.pl")
663 (defun mixi-make-object-from-url (url)
664 "Return a mixi object from URL."
665 (if (string-match mixi-object-url-regexp url)
666 (let ((name (match-string 2 url)))
667 (cond ((string= name "bbs")
669 ((string= name "profile")
670 (setq name "friend")))
671 (let ((func (intern (concat mixi-object-prefix "make-" name
674 (when (string-match "/home\\.pl" url)
675 (mixi-make-friend-from-url url))))
678 ;; stolen from time-date.el
679 (defun mixi-time-less-p (t1 t2)
680 "Say whether time value T1 is less than time value T2."
681 (unless (numberp (cdr t1))
682 (setq t1 (cons (car t1) (car (cdr t1)))))
683 (unless (numberp (cdr t2))
684 (setq t2 (cons (car t2) (car (cdr t2)))))
685 (or (< (car t1) (car t2))
686 (and (= (car t1) (car t2))
687 (< (cdr t1) (cdr t2)))))
689 (defun mixi-time-add (t1 t2)
690 "Add two time values. One should represent a time difference."
691 (unless (numberp (cdr t1))
692 (setq t1 (cons (car t1) (car (cdr t1)))))
693 (unless (numberp (cdr t2))
694 (setq t2 (cons (car t2) (car (cdr t2)))))
695 (let ((low (+ (cdr t1) (cdr t2))))
696 (cons (+ (car t1) (car t2) (lsh low -16)) low)))
698 ;; stolen from time-date.el
699 (defun mixi-seconds-to-time (seconds)
700 "Convert SECONDS (a floating point number) to a time value."
701 (cons (floor seconds 65536)
702 (floor (mod seconds 65536))))
704 (defun mixi-cache-expired-p (object)
705 "Whether a cache of OBJECT is expired."
706 (let ((timestamp (mixi-object-timestamp object)))
707 (unless (or (null mixi-cache-expires)
709 (if (numberp mixi-cache-expires)
711 (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
715 (defun mixi-make-cache (key value table)
716 "Make a cache object and return it."
717 (let ((cache (gethash key table)))
718 (if (and cache (not (mixi-cache-expired-p cache)))
720 (puthash key value table))))
722 (defconst mixi-cache-file-regexp "[a-z]+-cache$")
723 (defconst mixi-cache-regexp (concat mixi-object-prefix
724 mixi-cache-file-regexp))
726 (defun mixi-save-cache ()
727 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
728 (unless (file-directory-p cache-directory)
729 (make-directory cache-directory t))
730 (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
732 (with-temp-file (expand-file-name
733 (substring (symbol-name (car caches))
734 (length mixi-object-prefix))
736 (let ((coding-system-for-write mixi-coding-system)
737 (cache (symbol-value (car caches))))
738 (insert "#s(hash-table size "
739 (number-to-string (hash-table-count cache))
740 " test equal data (\n")
743 (let (print-level print-length)
744 (insert (prin1-to-string key) " "
745 (prin1-to-string value) "\n")))
748 (setq caches (cdr caches))))))
750 ;; stolen (and modified) from lsdb.el
751 (defun mixi-read-cache (&optional marker)
752 "Read one Lisp expression as text from MARKER, return as Lisp object."
755 (if (looking-at "^#s(")
758 (forward-char 2);skip "#s"
759 (forward-sexp);move to the left paren
762 (buffer-disable-undo)
763 (insert-buffer-substring (marker-buffer marker)
765 (goto-char (point-min))
767 (let ((object (read (current-buffer)))
769 (if (eq 'hash-table (car object))
771 (setq data (plist-get (cdr object) 'data))
773 (pop data);throw it away
774 (mixi-read-object (pop data))))
778 (defun mixi-load-cache ()
779 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
780 (when (file-directory-p cache-directory)
781 ;; FIXME: Load friend and community first.
782 (let ((files (directory-files cache-directory t
783 mixi-cache-file-regexp)))
785 (let ((buffer (find-file-noselect (car files))))
789 (goto-char (point-min))
790 (re-search-forward "^#s(")
791 (goto-char (match-beginning 0))
792 (mixi-read-cache (point-marker)))
793 (kill-buffer buffer)))
794 (setq files (cdr files)))))))
797 (defvar mixi-friend-cache (make-hash-table :test 'equal))
798 (defun mixi-make-friend (id &optional nick name sex address age birthday
799 blood-type birthplace hobby job organization
801 "Return a friend object."
802 (mixi-make-cache id (cons 'mixi-friend (vector nil id nick name sex address
803 age birthday blood-type
805 organization profile))
808 (defun mixi-make-me ()
809 "Return a my object."
811 (with-mixi-retrieve "/home.pl"
812 (if (re-search-forward mixi-my-id-regexp nil t)
813 (setq mixi-me (mixi-make-friend (match-string 1)))
814 (signal 'error (list 'who-am-i)))))
817 (defconst mixi-friend-url-regexp
818 "/show_\\(friend\\|profile\\)\\.pl\\?id=\\([0-9]+\\)")
820 (defun mixi-make-friend-from-url (url)
821 "Return a friend object from URL."
822 (if (string-match mixi-friend-url-regexp url)
823 (let ((id (match-string 2 url)))
824 (mixi-make-friend id))
825 (when (string-match "/home\\.pl" url)
828 (defmacro mixi-friend-p (friend)
829 `(eq (mixi-object-class ,friend) 'mixi-friend))
831 (defmacro mixi-friend-page (friend)
832 `(concat "/show_profile.pl?id=" (mixi-friend-id ,friend)))
834 (defconst mixi-friend-nick-regexp
835 "<h3>\\(.*\\)¤µ¤ó([0-9]+)</h3>")
836 (defconst mixi-friend-name-regexp
837 "<dt>̾Á°</dt>\n?<dd>\\(.+?\\)\\(<img\\|</dd>\\)")
838 (defconst mixi-friend-sex-regexp
839 "<dt>ÀÊÌ</dt>\n?<dd>\\([Ã˽÷]\\)À\\(<img\\|</dd>\\)")
840 (defconst mixi-friend-address-regexp
841 "<dt>¸½½»½ê</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
842 (defconst mixi-friend-age-regexp
843 "<dt>ǯÎð</dt>\n?<dd>\\([0-9]+\\)ºÐ\\( <img\\|</dd>\\)")
844 (defconst mixi-friend-birthday-regexp
845 "<dt>ÃÂÀ¸Æü</dt>\n?<dd>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(<img \\|</dd>\\)")
846 (defconst mixi-friend-blood-type-regexp
847 "<dt>·ì±Õ·¿</dt>\n?<dd>\\([ABO]B?\\)·¿\\(<img \\|</dd>\\)")
848 (defconst mixi-friend-birthplace-regexp
849 "<dt>½Ð¿ÈÃÏ</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
850 (defconst mixi-friend-hobby-regexp
851 "<dt>¼ñÌ£</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
852 (defconst mixi-friend-job-regexp
853 "<dt>¿¦¶È</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
854 (defconst mixi-friend-organization-regexp
855 "<dt>½ê°</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
856 (defconst mixi-friend-profile-regexp
857 "<dt>¼«¸Ê¾Ò²ð</dt>\n?<dd class=\"userInput\">\\(.+?\\)</dd>")
859 (defun mixi-realize-friend (friend)
861 ;; FIXME: Check a expiration of cache?
862 (unless (mixi-object-realized-p friend)
863 (with-mixi-retrieve (mixi-friend-page friend)
864 (let ((case-fold-search t))
865 (if (re-search-forward mixi-friend-nick-regexp nil t)
866 (mixi-friend-set-nick friend (match-string 1))
867 (mixi-realization-error 'cannot-find-nick friend))
868 (when (re-search-forward mixi-friend-name-regexp nil t)
869 (mixi-friend-set-name friend (match-string 1)))
870 (when (re-search-forward mixi-friend-sex-regexp nil t)
871 (mixi-friend-set-sex friend (if (string= (match-string 1) "ÃË")
873 (when (re-search-forward mixi-friend-address-regexp nil t)
874 (mixi-friend-set-address friend (match-string 1)))
875 (when (re-search-forward mixi-friend-age-regexp nil t)
876 (mixi-friend-set-age friend (string-to-number (match-string 1))))
877 (when (re-search-forward mixi-friend-birthday-regexp nil t)
878 (mixi-friend-set-birthday
879 friend (list (string-to-number (match-string 1))
880 (string-to-number (match-string 2)))))
881 (when (re-search-forward mixi-friend-blood-type-regexp nil t)
882 (mixi-friend-set-blood-type friend (intern (match-string 1))))
883 (when (re-search-forward mixi-friend-birthplace-regexp nil t)
884 (mixi-friend-set-birthplace friend (match-string 1)))
885 (when (re-search-forward mixi-friend-hobby-regexp nil t)
886 (mixi-friend-set-hobby friend (split-string (match-string 1) ", ")))
887 (when (re-search-forward mixi-friend-job-regexp nil t)
888 (mixi-friend-set-job friend (match-string 1)))
889 (when (re-search-forward mixi-friend-organization-regexp nil t)
890 (mixi-friend-set-organization friend (match-string 1)))
891 (when (re-search-forward mixi-friend-profile-regexp nil t)
892 (mixi-friend-set-profile friend (match-string 1)))))
893 (mixi-object-touch friend)))
895 (defun mixi-friend-id (friend)
896 "Return the id of FRIEND."
897 (unless (mixi-friend-p friend)
898 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
899 (aref (cdr friend) 1))
901 (defun mixi-friend-nick (friend)
902 "Return the nick of FRIEND."
903 (unless (mixi-friend-p friend)
904 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
905 (unless (aref (cdr friend) 2)
906 (mixi-realize-friend friend))
907 (aref (cdr friend) 2))
909 (defun mixi-friend-name (friend)
910 "Return the name of FRIEND."
911 (unless (mixi-friend-p friend)
912 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
913 (mixi-realize-friend friend)
914 (aref (cdr friend) 3))
916 (defun mixi-friend-sex (friend)
917 "Return the sex of FRIEND."
918 (unless (mixi-friend-p friend)
919 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
920 (mixi-realize-friend friend)
921 (aref (cdr friend) 4))
923 (defun mixi-friend-address (friend)
924 "Return the address of FRIEND."
925 (unless (mixi-friend-p friend)
926 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
927 (mixi-realize-friend friend)
928 (aref (cdr friend) 5))
930 (defun mixi-friend-age (friend)
931 "Return the age of FRIEND."
932 (unless (mixi-friend-p friend)
933 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
934 (mixi-realize-friend friend)
935 (aref (cdr friend) 6))
937 (defun mixi-friend-birthday (friend)
938 "Return the birthday of FRIEND."
939 (unless (mixi-friend-p friend)
940 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
941 (mixi-realize-friend friend)
942 (aref (cdr friend) 7))
944 (defun mixi-friend-blood-type (friend)
945 "Return the blood type of FRIEND."
946 (unless (mixi-friend-p friend)
947 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
948 (mixi-realize-friend friend)
949 (aref (cdr friend) 8))
951 (defun mixi-friend-birthplace (friend)
952 "Return the birthplace of FRIEND."
953 (unless (mixi-friend-p friend)
954 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
955 (mixi-realize-friend friend)
956 (aref (cdr friend) 9))
958 (defun mixi-friend-hobby (friend)
959 "Return the hobby of FRIEND."
960 (unless (mixi-friend-p friend)
961 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
962 (mixi-realize-friend friend)
963 (aref (cdr friend) 10))
965 (defun mixi-friend-job (friend)
966 "Return the job of FRIEND."
967 (unless (mixi-friend-p friend)
968 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
969 (mixi-realize-friend friend)
970 (aref (cdr friend) 11))
972 (defun mixi-friend-organization (friend)
973 "Return the organization of FRIEND."
974 (unless (mixi-friend-p friend)
975 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
976 (mixi-realize-friend friend)
977 (aref (cdr friend) 12))
979 (defun mixi-friend-profile (friend)
980 "Return the profile of FRIEND."
981 (unless (mixi-friend-p friend)
982 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
983 (mixi-realize-friend friend)
984 (aref (cdr friend) 13))
986 (defun mixi-friend-set-nick (friend nick)
987 "Set the nick of FRIEND."
988 (unless (mixi-friend-p friend)
989 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
990 (aset (cdr friend) 2 nick))
992 (defun mixi-friend-set-name (friend name)
993 "Set the name of FRIEND."
994 (unless (mixi-friend-p friend)
995 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
996 (aset (cdr friend) 3 name))
998 (defun mixi-friend-set-sex (friend sex)
999 "Set the sex of FRIEND."
1000 (unless (mixi-friend-p friend)
1001 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1002 (aset (cdr friend) 4 sex))
1004 (defun mixi-friend-set-address (friend address)
1005 "Set the address of FRIEND."
1006 (unless (mixi-friend-p friend)
1007 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1008 (aset (cdr friend) 5 address))
1010 (defun mixi-friend-set-age (friend age)
1011 "Set the age of FRIEND."
1012 (unless (mixi-friend-p friend)
1013 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1014 (aset (cdr friend) 6 age))
1016 (defun mixi-friend-set-birthday (friend birthday)
1017 "Set the birthday of FRIEND."
1018 (unless (mixi-friend-p friend)
1019 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1020 (aset (cdr friend) 7 birthday))
1022 (defun mixi-friend-set-blood-type (friend blood-type)
1023 "Set the blood type of FRIEND."
1024 (unless (mixi-friend-p friend)
1025 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1026 (aset (cdr friend) 8 blood-type))
1028 (defun mixi-friend-set-birthplace (friend birthplace)
1029 "Set the birthplace of FRIEND."
1030 (unless (mixi-friend-p friend)
1031 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1032 (aset (cdr friend) 9 birthplace))
1034 (defun mixi-friend-set-hobby (friend hobby)
1035 "Set the hobby of FRIEND."
1036 (unless (mixi-friend-p friend)
1037 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1038 (aset (cdr friend) 10 hobby))
1040 (defun mixi-friend-set-job (friend job)
1041 "Set the job of FRIEND."
1042 (unless (mixi-friend-p friend)
1043 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1044 (aset (cdr friend) 11 job))
1046 (defun mixi-friend-set-organization (friend organization)
1047 "Set the organization of FRIEND."
1048 (unless (mixi-friend-p friend)
1049 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1050 (aset (cdr friend) 12 organization))
1052 (defun mixi-friend-set-profile (friend profile)
1053 "Set the profile of FRIEND."
1054 (unless (mixi-friend-p friend)
1055 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1056 (aset (cdr friend) 13 profile))
1058 (defmacro mixi-friend-list-page (&optional friend)
1059 `(concat "/list_friend.pl?page=%d"
1060 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1062 (defconst mixi-friend-list-id-regexp
1063 "<a href=\"?show_friend\\.pl\\?id=\\([0-9]+\\)\"?")
1064 (defconst mixi-friend-list-nick-regexp
1065 "<span>\\(.+\\)¤µ¤ó([0-9]+)</span>")
1068 (defun mixi-get-friends (&rest friend-or-range)
1069 "Get friends of FRIEND."
1070 (when (> (length friend-or-range) 2)
1071 (signal 'wrong-number-of-arguments (list 'mixi-get-friends
1072 (length friend-or-range))))
1073 (let ((friend (nth 0 friend-or-range))
1074 (range (nth 1 friend-or-range)))
1075 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1076 (setq friend (nth 1 friend-or-range))
1077 (setq range (nth 0 friend-or-range)))
1078 (unless (or (null friend) (mixi-friend-p friend))
1079 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1080 (let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
1081 mixi-friend-list-id-regexp
1083 (nicks (mixi-get-matched-items (mixi-friend-list-page friend)
1084 mixi-friend-list-nick-regexp
1088 (while (< index (length ids))
1089 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1090 (nth 0 (nth index nicks))) ret))
1095 (defmacro mixi-favorite-list-page ()
1096 `(concat "/list_bookmark.pl?page=%d"))
1098 (defconst mixi-favorite-list-regexp
1099 "<td bgcolor=\"#FDF9F2\"><font color=\"#996600\">̾Á°</font></td>
1100 <td colspan=\"2\" bgcolor=\"#FFFFFF\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></td>")
1103 (defun mixi-get-favorites (&optional range)
1105 (let ((items (mixi-get-matched-items (mixi-favorite-list-page)
1106 mixi-favorite-list-regexp
1108 (mapcar (lambda (item)
1109 (mixi-make-friend (nth 0 item) (nth 1 item)))
1113 (defun mixi-make-log (friend time)
1114 "Return a log object."
1115 (cons 'mixi-log (vector friend time)))
1117 (defmacro mixi-log-p (log)
1118 `(eq (mixi-object-class ,log) 'mixi-log))
1120 (defun mixi-log-friend (log)
1121 "Return the friend of LOG."
1122 (unless (mixi-log-p log)
1123 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1126 (defun mixi-log-time (log)
1127 "Return the time of LOG."
1128 (unless (mixi-log-p log)
1129 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1132 (defmacro mixi-log-list-page ()
1133 `(concat "/show_log.pl"))
1135 (defconst mixi-log-list-regexp
1136 "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)</a>")
1139 (defun mixi-get-logs (&optional range)
1141 (let ((items (mixi-get-matched-items (mixi-log-list-page)
1142 mixi-log-list-regexp
1144 (mapcar (lambda (item)
1145 (mixi-make-log (mixi-make-friend (nth 5 item) (nth 6 item))
1147 (string-to-number (nth 4 item))
1148 (string-to-number (nth 3 item))
1149 (string-to-number (nth 2 item))
1150 (string-to-number (nth 1 item))
1151 (string-to-number (nth 0 item)))))
1154 ;; Recommended friend.
1155 (defmacro mixi-recommended-friend-list-page ()
1156 `(concat "http://indies.mixi.jp/recommend.pl"))
1158 (defconst mixi-recommended-friend-list-regexp
1159 "<div class=\"iconListImage\"><a href=\"http://mixi\\.jp/show_friend\\.pl\\?id=\\([0-9]+\\)\" [^>]+>.+</a></div><span>\\(.+?\\)¤µ¤ó([0-9]+)</span>")
1162 (defun mixi-get-recommended-friends (&optional range)
1163 "Get recommended friends."
1164 (let ((items (mixi-get-matched-items (mixi-recommended-friend-list-page)
1165 mixi-recommended-friend-list-regexp
1167 (mapcar (lambda (item)
1168 (mixi-make-friend (nth 0 item) (nth 1 item)))
1172 (defvar mixi-diary-cache (make-hash-table :test 'equal))
1173 (defun mixi-make-diary (owner id &optional comment-count time title content)
1174 "Return a diary object."
1175 (let ((owner (or owner (mixi-make-me))))
1176 (mixi-make-cache (list (mixi-friend-id owner) id)
1177 (cons 'mixi-diary (vector nil owner id comment-count time
1181 (defconst mixi-diary-url-regexp
1182 "/view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?")
1184 (defun mixi-make-diary-from-url (url)
1185 "Return a diary object from URL."
1186 (when (string-match mixi-diary-url-regexp url)
1187 (let ((id (match-string 1 url))
1188 (owner-id (match-string 2 url))
1189 (comment-count (match-string 4 url)))
1190 (mixi-make-diary (mixi-make-friend owner-id) id comment-count))))
1192 (defmacro mixi-diary-p (diary)
1193 `(eq (mixi-object-class ,diary) 'mixi-diary))
1195 (defmacro mixi-diary-page (diary)
1196 `(concat "/view_diary.pl?id=" (mixi-diary-id ,diary)
1197 "&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
1199 (defconst mixi-diary-closed-regexp
1200 "<td>ͧ¿Í\\(¤Îͧ¿Í\\)?¤Þ¤Ç¸ø³«¤Î¤¿¤áÆɤळ¤È¤¬½ÐÍè¤Þ¤»¤ó¡£</td>")
1201 (defconst mixi-diary-owner-nick-regexp
1202 "<div class=\"diaryTitle\\(Friend\\)? clearfix\">
1203 <h2>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ</h2>")
1204 (defconst mixi-diary-title-regexp
1205 "<div class=\"listDiaryTitle\">
1206 <dl class=\"clearfix\">
1207 <dt>\\([^<\n]+\\)\\(<span>\\)?")
1208 (defconst mixi-diary-time-regexp
1209 "<dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\\([0-9]+\\):\\([0-9]+\\)</dd>")
1210 (defconst mixi-diary-content-regexp
1211 "<div class=\"txtconfirmArea\">
1212 \\(\\(.\\|\r?\n\\)*?\\)
1213 <!--/viewDiaryBox--></div>")
1215 (defun mixi-realize-diary (diary &optional page)
1217 ;; FIXME: Check a expiration of cache?
1218 (unless (mixi-object-realized-p diary)
1219 (with-mixi-retrieve (or page (mixi-diary-page diary))
1220 (let ((case-fold-search t))
1221 (unless (re-search-forward mixi-diary-closed-regexp nil t)
1222 (if (re-search-forward mixi-diary-owner-nick-regexp nil t)
1223 (mixi-friend-set-nick (mixi-diary-owner diary)
1225 (mixi-realization-error 'cannot-find-owner-nick diary))
1226 (if (re-search-forward mixi-diary-title-regexp nil t)
1227 (mixi-diary-set-title diary (match-string 1))
1228 (mixi-realization-error 'cannot-find-title diary))
1229 (if (re-search-forward mixi-diary-time-regexp nil t)
1230 (mixi-diary-set-time
1231 diary (encode-time 0 (string-to-number (match-string 5))
1232 (string-to-number (match-string 4))
1233 (string-to-number (match-string 3))
1234 (string-to-number (match-string 2))
1235 (string-to-number (match-string 1))))
1236 (mixi-realization-error 'cannot-find-time diary))
1237 (if (re-search-forward mixi-diary-content-regexp nil t)
1238 (mixi-diary-set-content diary (match-string 1))
1239 (mixi-realization-error 'cannot-find-content diary)))))
1240 (mixi-object-touch diary)))
1242 (defun mixi-diary-owner (diary)
1243 "Return the owner of DIARY."
1244 (unless (mixi-diary-p diary)
1245 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1246 (aref (cdr diary) 1))
1248 (defun mixi-diary-id (diary)
1249 "Return the id of DIARY."
1250 (unless (mixi-diary-p diary)
1251 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1252 (aref (cdr diary) 2))
1254 (defun mixi-diary-comment-count (diary)
1255 "Return the comment-count of DIARY."
1256 (unless (mixi-diary-p diary)
1257 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1258 (aref (cdr diary) 3))
1260 (defun mixi-diary-time (diary)
1261 "Return the time of DIARY."
1262 (unless (mixi-diary-p diary)
1263 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1264 (unless (aref (cdr diary) 3)
1265 (mixi-realize-diary diary))
1266 (aref (cdr diary) 4))
1268 (defun mixi-diary-title (diary)
1269 "Return the title of DIARY."
1270 (unless (mixi-diary-p diary)
1271 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1272 (unless (aref (cdr diary) 4)
1273 (mixi-realize-diary diary))
1274 (aref (cdr diary) 5))
1276 (defun mixi-diary-content (diary)
1277 "Return the content of DIARY."
1278 (unless (mixi-diary-p diary)
1279 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1280 (mixi-realize-diary diary)
1281 (aref (cdr diary) 6))
1283 (defun mixi-diary-set-comment-count (diary comment-count)
1284 "Set the comment-count of DIARY."
1285 (unless (mixi-diary-p diary)
1286 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1287 (aset (cdr diary) 3 comment-count))
1289 (defun mixi-diary-set-time (diary time)
1290 "Set the time of DIARY."
1291 (unless (mixi-diary-p diary)
1292 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1293 (aset (cdr diary) 4 time))
1295 (defun mixi-diary-set-title (diary title)
1296 "Set the title of DIARY."
1297 (unless (mixi-diary-p diary)
1298 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1299 (aset (cdr diary) 5 title))
1301 (defun mixi-diary-set-content (diary content)
1302 "Set the content of DIARY."
1303 (unless (mixi-diary-p diary)
1304 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1305 (aset (cdr diary) 6 content))
1307 (defmacro mixi-diary-list-page (&optional friend)
1308 `(concat "/list_diary.pl?page=%d"
1309 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1311 (defconst mixi-diary-list-regexp
1312 "<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>
1313 <dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\n?\\([0-9]+\\):\\([0-9]+\\)</dd>
1317 (defun mixi-get-diaries (&rest friend-or-range)
1318 "Get diaries of FRIEND."
1319 (when (> (length friend-or-range) 2)
1320 (signal 'wrong-number-of-arguments
1321 (list 'mixi-get-diaries (length friend-or-range))))
1322 (let ((friend (nth 0 friend-or-range))
1323 (range (nth 1 friend-or-range)))
1324 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1325 (setq friend (nth 1 friend-or-range))
1326 (setq range (nth 0 friend-or-range)))
1327 (unless (or (null friend) (mixi-friend-p friend))
1328 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1329 (let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
1330 mixi-diary-list-regexp
1332 (mapcar (lambda (item)
1333 (mixi-make-diary friend (nth 1 item) nil
1335 0 (string-to-number (nth 8 item))
1336 (string-to-number (nth 7 item))
1337 (string-to-number (nth 6 item))
1338 (string-to-number (nth 5 item))
1339 (string-to-number (nth 4 item)))
1343 (defmacro mixi-new-diary-list-page ()
1344 `(concat "/new_friend_diary.pl?page=%d"))
1346 (defconst mixi-new-diary-list-regexp
1347 "<dt>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</dt>
1348 <dd><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\">\\(.+\\)</a> (\\(.*\\))<div ")
1349 (defconst mixi-new-diary-list-title-regexp
1350 "\\(.+\\) (\\([0-9]+\\))")
1353 (defun mixi-get-new-diaries (&optional range)
1355 (let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
1356 mixi-new-diary-list-regexp
1359 (mapcar (lambda (item)
1360 (let ((title (nth 7 item))
1362 (when (string-match mixi-new-diary-list-title-regexp
1364 (setq count (string-to-number (match-string 2 title)))
1365 (setq title (match-string 1 title)))
1366 (let* ((diary (mixi-make-diary
1367 (mixi-make-friend (nth 6 item)
1370 (comment-count (mixi-diary-comment-count diary)))
1371 (mixi-diary-set-time diary
1373 0 (string-to-number (nth 4 item))
1374 (string-to-number (nth 3 item))
1375 (string-to-number (nth 2 item))
1376 (string-to-number (nth 1 item))
1377 (string-to-number (nth 0 item))))
1378 (mixi-diary-set-title diary title)
1379 (when (or (null comment-count)
1380 (< comment-count count))
1381 (mixi-diary-set-comment-count diary count)
1385 (defmacro mixi-search-diary-list-page (keyword)
1386 `(concat "/search_diary.pl?page=%d&submit=search&keyword="
1387 (mixi-url-encode-and-quote-percent-string ,keyword)))
1389 (defconst mixi-search-diary-list-regexp
1391 <div class=\"listIcon\"><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\"><img src=\".*\" alt=\".*\" /></a>
1392 <span class=\"name\"><a href=\"view_diary\\.pl\\?id=[0-9]+&owner_id=[0-9]+\">\\(.*\\)</a></span></div>
1393 <div class=\"listContents\">
1394 <div class=\"heading\"><a href=\"view_diary\\.pl\\?id=[0-9]+&owner_id=[0-9]+\" class=\"name\">\\(.+\\)</a><span class=\"date\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></div>
1395 <p class=\"description\">\\(.*\\)
1400 (defun mixi-search-diaries (keyword &optional range)
1401 (let ((items (mixi-get-matched-items (mixi-search-diary-list-page keyword)
1402 mixi-search-diary-list-regexp
1404 (year (nth 5 (decode-time (current-time))))
1405 (month (nth 4 (decode-time (current-time)))))
1406 (mapcar (lambda (item)
1407 (let ((month-of-item (string-to-number (nth 4 item))))
1408 (when (> month-of-item month)
1410 (setq month month-of-item)
1411 (mixi-make-diary (mixi-make-friend (nth 1 item) (nth 2 item))
1415 0 (string-to-number (nth 7 item))
1416 (string-to-number (nth 6 item))
1417 (string-to-number (nth 5 item))
1423 (defmacro mixi-post-diary-page ()
1424 `(concat "/add_diary.pl"))
1426 (defconst mixi-post-key-regexp
1427 "<input type=\"?hidden\"? name=\"?post_key\"? +value=\"\\([a-z0-9]+\\)\"")
1428 (defconst mixi-post-succeed-regexp
1429 "<p\\(\\| class=\"messageAlert\"\\)>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£</p>")
1431 ;; FIXME: Support photos.
1433 (defun mixi-post-diary (title content)
1435 (unless (stringp title)
1436 (signal 'wrong-type-argument (list 'stringp title)))
1437 (unless (stringp content)
1438 (signal 'wrong-type-argument (list 'stringp content)))
1439 (let ((fields `(("id" . ,(mixi-friend-id (mixi-make-me)))
1440 ("diary_title" . ,title)
1441 ("diary_body" . ,content)
1442 ("submit" . "main")))
1444 (with-mixi-post-form (mixi-post-diary-page) fields
1445 (if (re-search-forward mixi-post-key-regexp nil t)
1446 (setq post-key (match-string 1))
1447 (mixi-post-error 'cannot-find-key)))
1448 (setq fields `(("post_key" . ,post-key)
1449 ("id" . ,(mixi-friend-id (mixi-make-me)))
1450 ("diary_title" . ,title)
1451 ("diary_body" . ,content)
1452 ("submit" . "confirm")))
1453 (with-mixi-post-form (mixi-post-diary-page) fields
1454 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1455 (mixi-post-error 'cannot-find-succeed)))))
1457 ;; Community object.
1458 (defvar mixi-community-cache (make-hash-table :test 'equal))
1459 (defun mixi-make-community (id &optional name birthday owner category members
1460 open-level authority description)
1461 "Return a community object."
1462 (mixi-make-cache id (cons 'mixi-community (vector nil id name birthday owner
1464 open-level authority
1466 mixi-community-cache))
1468 (defconst mixi-community-url-regexp
1469 "/view_community\\.pl\\?id=\\([0-9]+\\)")
1471 (defun mixi-make-community-from-url (url)
1472 "Return a community object from URL."
1473 (when (string-match mixi-community-url-regexp url)
1474 (let ((id (match-string 1 url)))
1475 (mixi-make-community id))))
1477 (defmacro mixi-community-p (community)
1478 `(eq (mixi-object-class ,community) 'mixi-community))
1480 (defmacro mixi-community-page (community)
1481 `(concat "/view_community.pl?id=" (mixi-community-id ,community)))
1483 ;; FIXME: Not community specific.
1484 (defconst mixi-community-nodata-regexp
1485 "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1486 (defconst mixi-community-name-regexp
1487 "<div class=\"pageTitle communityTitle002 communityTop\">
1489 (defconst mixi-community-birthday-regexp
1491 <dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br />")
1492 ;; FIXME: Care when the owner has seceded.
1493 (defconst mixi-community-owner-regexp
1496 <a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\\(.*\\)</a>")
1497 (defconst mixi-community-category-regexp
1500 (defconst mixi-community-members-regexp
1501 "<dt>¥á¥ó¥Ð¡¼¿ô</dt>
1502 <dd>\\([0-9]+\\)¿Í</dd>")
1503 (defconst mixi-community-open-level-regexp
1504 "<dt>»²²Ã¾ò·ï¤È<br />¸ø³«¥ì¥Ù¥ë</dt>
1506 (defconst mixi-community-authority-regexp
1507 "<dt>¥È¥Ô¥Ã¥¯¤Î<br />ºîÀ®¸¢¸Â</dt>
1513 (defconst mixi-community-description-regexp
1514 "<div id=\"communityIntro\">
1517 (defun mixi-realize-community (community)
1518 "Realize a COMMUNITY."
1519 ;; FIXME: Check a expiration of cache?
1520 (unless (mixi-object-realized-p community)
1521 (with-mixi-retrieve (mixi-community-page community)
1522 (let ((case-fold-search t))
1523 (if (re-search-forward mixi-community-nodata-regexp nil t)
1524 ;; FIXME: Set all members?
1525 (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1526 (if (re-search-forward mixi-community-name-regexp nil t)
1527 (mixi-community-set-name community (match-string 1))
1528 (mixi-realization-error 'cannot-find-name community))
1529 (if (re-search-forward mixi-community-birthday-regexp nil t)
1530 (mixi-community-set-birthday
1531 community (encode-time 0 0 0
1532 (string-to-number (match-string 3))
1533 (string-to-number (match-string 2))
1534 (string-to-number (match-string 1))))
1535 (mixi-realization-error 'cannot-find-birthday community))
1536 (if (re-search-forward mixi-community-owner-regexp nil t)
1537 (if (string= (match-string 1) "home.pl")
1538 (mixi-community-set-owner community (mixi-make-me))
1539 (mixi-community-set-owner community (mixi-make-friend
1542 (mixi-realization-error 'cannot-find-owner community))
1543 (if (re-search-forward mixi-community-category-regexp nil t)
1544 (mixi-community-set-category community (match-string 1))
1545 (mixi-realization-error 'cannot-find-category community))
1546 (if (re-search-forward mixi-community-members-regexp nil t)
1547 (mixi-community-set-members community
1548 (string-to-number (match-string 1)))
1549 (mixi-realization-error 'cannot-find-members community))
1550 (if (re-search-forward mixi-community-open-level-regexp nil t)
1551 (mixi-community-set-open-level community (match-string 1))
1552 (mixi-realization-error 'cannot-find-open-level community))
1553 (if (re-search-forward mixi-community-authority-regexp nil t)
1554 (mixi-community-set-authority community (match-string 1))
1555 (mixi-realization-error 'cannot-find-authority community))
1556 (if (re-search-forward mixi-community-description-regexp nil t)
1557 (mixi-community-set-description community (match-string 1))
1558 (mixi-realization-error 'cannot-find-description community)))))
1559 (mixi-object-touch community)))
1561 (defun mixi-community-id (community)
1562 "Return the id of COMMUNITY."
1563 (unless (mixi-community-p community)
1564 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1565 (aref (cdr community) 1))
1567 (defun mixi-community-name (community)
1568 "Return the name of COMMUNITY."
1569 (unless (mixi-community-p community)
1570 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1571 (unless (aref (cdr community) 2)
1572 (mixi-realize-community community))
1573 (aref (cdr community) 2))
1575 (defun mixi-community-birthday (community)
1576 "Return the birthday of COMMUNITY."
1577 (unless (mixi-community-p community)
1578 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1579 (mixi-realize-community community)
1580 (aref (cdr community) 3))
1582 (defun mixi-community-owner (community)
1583 "Return the owner of COMMUNITY."
1584 (unless (mixi-community-p community)
1585 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1586 (mixi-realize-community community)
1587 (aref (cdr community) 4))
1589 (defun mixi-community-category (community)
1590 "Return the category of COMMUNITY."
1591 (unless (mixi-community-p community)
1592 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1593 (mixi-realize-community community)
1594 (aref (cdr community) 5))
1596 (defun mixi-community-members (community)
1597 "Return the members of COMMUNITY."
1598 (unless (mixi-community-p community)
1599 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1600 (mixi-realize-community community)
1601 (aref (cdr community) 6))
1603 (defun mixi-community-open-level (community)
1604 "Return the open-level of COMMUNITY."
1605 (unless (mixi-community-p community)
1606 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1607 (mixi-realize-community community)
1608 (aref (cdr community) 7))
1610 (defun mixi-community-authority (community)
1611 "Return the authority of COMMUNITY."
1612 (unless (mixi-community-p community)
1613 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1614 (mixi-realize-community community)
1615 (aref (cdr community) 8))
1617 (defun mixi-community-description (community)
1618 "Return the description of COMMUNITY."
1619 (unless (mixi-community-p community)
1620 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1621 (mixi-realize-community community)
1622 (aref (cdr community) 9))
1624 (defun mixi-community-set-name (community name)
1625 "Set the name of COMMUNITY."
1626 (unless (mixi-community-p community)
1627 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1628 (aset (cdr community) 2 name))
1630 (defun mixi-community-set-birthday (community birthday)
1631 "Set the birthday of COMMUNITY."
1632 (unless (mixi-community-p community)
1633 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1634 (aset (cdr community) 3 birthday))
1636 (defun mixi-community-set-owner (community owner)
1637 "Set the owner of COMMUNITY."
1638 (unless (mixi-community-p community)
1639 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1640 (unless (mixi-friend-p owner)
1641 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1642 (aset (cdr community) 4 owner))
1644 (defun mixi-community-set-category (community category)
1645 "Set the category of COMMUNITY."
1646 (unless (mixi-community-p community)
1647 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1648 (aset (cdr community) 5 category))
1650 (defun mixi-community-set-members (community members)
1651 "Set the name of COMMUNITY."
1652 (unless (mixi-community-p community)
1653 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1654 (aset (cdr community) 6 members))
1656 (defun mixi-community-set-open-level (community open-level)
1657 "Set the name of COMMUNITY."
1658 (unless (mixi-community-p community)
1659 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1660 (aset (cdr community) 7 open-level))
1662 (defun mixi-community-set-authority (community authority)
1663 "Set the name of COMMUNITY."
1664 (unless (mixi-community-p community)
1665 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1666 (aset (cdr community) 8 authority))
1668 (defun mixi-community-set-description (community description)
1669 "Set the name of COMMUNITY."
1670 (unless (mixi-community-p community)
1671 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1672 (aset (cdr community) 9 description))
1674 (defmacro mixi-community-list-page (&optional friend)
1675 `(concat "/list_community.pl?page=%d"
1676 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1678 (defconst mixi-community-list-id-regexp
1679 "<a href=\"?view_community\\.pl\\?id=\\([0-9]+\\)\"?")
1680 (defconst mixi-community-list-name-regexp
1681 "<span>\\(.+\\)([0-9]+)</span>")
1684 (defun mixi-get-communities (&rest friend-or-range)
1685 "Get communities of FRIEND."
1686 (when (> (length friend-or-range) 2)
1687 (signal 'wrong-number-of-arguments
1688 (list 'mixi-get-communities (length friend-or-range))))
1689 (let ((friend (nth 0 friend-or-range))
1690 (range (nth 1 friend-or-range)))
1691 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1692 (setq friend (nth 1 friend-or-range))
1693 (setq range (nth 0 friend-or-range)))
1694 (unless (or (null friend) (mixi-friend-p friend))
1695 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1696 (let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
1697 mixi-community-list-id-regexp
1699 (names (mixi-get-matched-items (mixi-community-list-page friend)
1700 mixi-community-list-name-regexp
1704 (while (< index (length ids))
1705 (setq ret (cons (mixi-make-community (nth 0 (nth index ids))
1706 (nth 0 (nth index names))) ret))
1710 (defmacro mixi-search-community-list-page (keyword)
1711 `(concat "/search_community.pl?page=%d&&sort=date&type=com&submit=main"
1712 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
1715 (defconst mixi-search-community-list-regexp
1716 "<dt class=\"communityTitle\"><a href=\"view_community\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\) ([0-9]+)</a>")
1718 ;; FIXME: Support category.
1720 (defun mixi-search-communities (keyword &optional range)
1721 (let ((items (mixi-get-matched-items (mixi-search-community-list-page
1723 mixi-search-community-list-regexp
1725 (mapcar (lambda (item)
1726 (mixi-make-community (nth 0 item) (nth 1 item)))
1729 ;; Recommended community.
1730 (defalias 'mixi-recommended-community-list-page
1731 'mixi-recommended-friend-list-page)
1733 (defconst mixi-recommended-community-list-regexp
1734 "<div class=\"iconListImage\"><a href=\"http://mixi\\.jp/view_community\\.pl\\?id=\\([0-9]+\\)\" [^>]+>.+</a></div><span>\\(.+\\)([0-9]+)</span>")
1737 (defun mixi-get-recommended-communities (&optional range)
1738 "Get recommended communities."
1739 (let ((items (mixi-get-matched-items (mixi-recommended-community-list-page)
1740 mixi-recommended-community-list-regexp
1742 (mapcar (lambda (item)
1743 (mixi-make-community (nth 0 item) (nth 1 item)))
1747 (defvar mixi-topic-cache (make-hash-table :test 'equal))
1748 (defun mixi-make-topic (community id &optional comment-count time title owner
1750 "Return a topic object."
1751 (mixi-make-cache (list (mixi-community-id community) id)
1752 (cons 'mixi-topic (vector nil community id comment-count
1753 time title owner content))
1756 (defconst mixi-topic-url-regexp
1757 "/view_bbs\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1759 (defun mixi-make-topic-from-url (url)
1760 "Return a topic object from URL."
1761 (when (string-match mixi-topic-url-regexp url)
1762 (let ((id (match-string 1 url))
1763 (comment-count (match-string 3 url))
1764 (community-id (match-string 4 url)))
1765 (mixi-make-topic (mixi-make-community community-id) id comment-count))))
1767 (defmacro mixi-topic-p (topic)
1768 `(eq (mixi-object-class ,topic) 'mixi-topic))
1770 (defmacro mixi-topic-page (topic)
1771 `(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
1772 "&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
1774 (defconst mixi-topic-community-regexp
1775 "<div class=\"pageTitle communityTitle002\">
1776 <h2>\\(.+\\) ¥È¥Ô¥Ã¥¯</h2>")
1777 (defconst mixi-topic-title-regexp
1778 "<span class=\"title\">\\([^<]+\\)</span>")
1779 (defconst mixi-topic-time-regexp
1780 "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>")
1781 (defconst mixi-topic-owner-regexp
1782 "<dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)\\(¤µ¤ó\\)?</a>")
1783 (defconst mixi-topic-content-regexp
1784 "<dd>\\(\\(.\\|\r?\n\\)*?\\)</dd>")
1786 (defun mixi-realize-topic (topic &optional page)
1788 ;; FIXME: Check a expiration of cache?
1789 (unless (mixi-object-realized-p topic)
1790 (with-mixi-retrieve (or page (mixi-topic-page topic))
1791 (if (re-search-forward mixi-topic-community-regexp nil t)
1792 (mixi-community-set-name (mixi-topic-community topic)
1794 (mixi-realization-error 'cannot-find-community topic))
1795 (if (re-search-forward mixi-topic-title-regexp nil t)
1796 (mixi-topic-set-title topic (match-string 1))
1797 (mixi-realization-error 'cannot-find-title topic))
1798 (if (re-search-forward mixi-topic-time-regexp nil t)
1799 (mixi-topic-set-time
1800 topic (encode-time 0 (string-to-number (match-string 5))
1801 (string-to-number (match-string 4))
1802 (string-to-number (match-string 3))
1803 (string-to-number (match-string 2))
1804 (string-to-number (match-string 1))))
1805 (mixi-realization-error 'cannot-find-time topic))
1806 (if (re-search-forward mixi-topic-owner-regexp nil t)
1807 (mixi-topic-set-owner topic (mixi-make-friend (match-string 1)
1809 (mixi-realization-error 'cannot-find-owner topic))
1810 (if (re-search-forward mixi-topic-content-regexp nil t)
1811 (mixi-topic-set-content topic (match-string 1))
1812 (mixi-realization-error 'cannot-find-content topic)))
1813 (mixi-object-touch topic)))
1815 (defun mixi-topic-community (topic)
1816 "Return the community of TOPIC."
1817 (unless (mixi-topic-p topic)
1818 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1819 (aref (cdr topic) 1))
1821 (defun mixi-topic-id (topic)
1822 "Return the id of TOPIC."
1823 (unless (mixi-topic-p topic)
1824 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1825 (aref (cdr topic) 2))
1827 (defun mixi-topic-comment-count (topic)
1828 "Return the comment-count of TOPIC."
1829 (unless (mixi-topic-p topic)
1830 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1831 (aref (cdr topic) 3))
1833 (defun mixi-topic-time (topic)
1834 "Return the time of TOPIC."
1835 (unless (mixi-topic-p topic)
1836 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1837 (mixi-realize-topic topic)
1838 (aref (cdr topic) 4))
1840 (defun mixi-topic-title (topic)
1841 "Return the title of TOPIC."
1842 (unless (mixi-topic-p topic)
1843 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1844 (mixi-realize-topic topic)
1845 (aref (cdr topic) 5))
1847 (defun mixi-topic-owner (topic)
1848 "Return the owner of TOPIC."
1849 (unless (mixi-topic-p topic)
1850 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1851 (mixi-realize-topic topic)
1852 (aref (cdr topic) 6))
1854 (defun mixi-topic-content (topic)
1855 "Return the content of TOPIC."
1856 (unless (mixi-topic-p topic)
1857 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1858 (mixi-realize-topic topic)
1859 (aref (cdr topic) 7))
1861 (defun mixi-topic-set-comment-count (topic comment-count)
1862 "Set the comment-count of TOPIC."
1863 (unless (mixi-topic-p topic)
1864 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1865 (aset (cdr topic) 3 comment-count))
1867 (defun mixi-topic-set-time (topic time)
1868 "Set the time of TOPIC."
1869 (unless (mixi-topic-p topic)
1870 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1871 (aset (cdr topic) 4 time))
1873 (defun mixi-topic-set-title (topic title)
1874 "Set the title of TOPIC."
1875 (unless (mixi-topic-p topic)
1876 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1877 (aset (cdr topic) 5 title))
1879 (defun mixi-topic-set-owner (topic owner)
1880 "Set the owner of TOPIC."
1881 (unless (mixi-topic-p topic)
1882 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1883 (unless (mixi-friend-p owner)
1884 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1885 (aset (cdr topic) 6 owner))
1887 (defun mixi-topic-set-content (topic content)
1888 "Set the content of TOPIC."
1889 (unless (mixi-topic-p topic)
1890 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1891 (aset (cdr topic) 7 content))
1893 (defmacro mixi-post-topic-page (community)
1894 `(concat "/add_bbs.pl?id=" (mixi-community-id community)))
1896 ;; FIXME: Support photos.
1898 (defun mixi-post-topic (community title content)
1899 "Post a topic to COMMUNITY."
1900 (unless (mixi-community-p community)
1901 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1902 (unless (stringp title)
1903 (signal 'wrong-type-argument (list 'stringp title)))
1904 (unless (stringp content)
1905 (signal 'wrong-type-argument (list 'stringp content)))
1906 (let ((fields `(("bbs_title" . ,title)
1907 ("bbs_body" . ,content)
1908 ("submit" . "main")))
1910 (with-mixi-post-form (mixi-post-topic-page community) fields
1911 (if (re-search-forward mixi-post-key-regexp nil t)
1912 (setq post-key (match-string 1))
1913 (mixi-post-error 'cannot-find-key community)))
1914 (setq fields `(("post_key" . ,post-key)
1915 ("bbs_title" . ,title)
1916 ("bbs_body" . ,content)
1917 ("submit" . "confirm")))
1918 (with-mixi-post-form (mixi-post-topic-page community) fields
1919 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1920 (mixi-post-error 'cannot-find-succeed community)))))
1923 (defvar mixi-event-cache (make-hash-table :test 'equal))
1924 (defun mixi-make-event (community id &optional comment-count time title owner
1925 date place detail limit members)
1926 "Return a event object."
1927 (mixi-make-cache (list (mixi-community-id community) id)
1928 (cons 'mixi-event (vector nil community id comment-count
1929 time title owner date place
1930 detail limit members))
1933 (defconst mixi-event-url-regexp
1934 "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1936 (defun mixi-make-event-from-url (url)
1937 "Return a event object from URL."
1938 (when (string-match mixi-event-url-regexp url)
1939 (let ((id (match-string 1 url))
1940 (comment-count (match-string 3 url))
1941 (community-id (match-string 4 url)))
1942 (mixi-make-event (mixi-make-community community-id) id comment-count))))
1944 (defmacro mixi-event-p (event)
1945 `(eq (mixi-object-class ,event) 'mixi-event))
1947 (defmacro mixi-event-page (event)
1948 `(concat "/view_event.pl?id=" (mixi-event-id ,event)
1949 "&comm_id=" (mixi-community-id (mixi-event-community ,event))))
1951 (defconst mixi-event-community-regexp
1952 "<div class=\"pageTitle communityTitle002\">
1953 <h2>\\(.+\\) ¥¤¥Ù¥ó¥È</h2>")
1954 (defconst mixi-event-title-regexp
1955 "<span class=\"title\">\\([^<]+\\)</span>")
1956 (defconst mixi-event-time-regexp
1957 "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>")
1958 (defconst mixi-event-date-regexp
1961 (defconst mixi-event-place-regexp
1964 (defconst mixi-event-owner-regexp
1965 "<dt>\\((mixi Âà²ñºÑ)\\|<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>\\)</dt>")
1966 (defconst mixi-event-owner-seceded-regexp
1968 (defconst mixi-event-detail-regexp
1969 "<dd>\\(\\(.\\|\r?\n\\)*?\\)</dd>
1971 (defconst mixi-event-limit-regexp
1974 (defconst mixi-event-members-regexp
1978 (defun mixi-realize-event (event &optional page)
1980 ;; FIXME: Check a expiration of cache?
1981 (unless (mixi-object-realized-p event)
1982 (with-mixi-retrieve (or page (mixi-event-page event))
1983 (let ((case-fold-search t))
1984 (if (re-search-forward mixi-event-community-regexp nil t)
1985 (mixi-community-set-name (mixi-event-community event)
1987 (mixi-realization-error 'cannot-find-community event))
1988 (if (re-search-forward mixi-event-title-regexp nil t)
1989 (mixi-event-set-title event (match-string 1))
1990 (mixi-realization-error 'cannot-find-title event))
1991 (if (re-search-forward mixi-event-time-regexp nil t)
1992 (mixi-event-set-time
1993 event (encode-time 0 (string-to-number (match-string 5))
1994 (string-to-number (match-string 4))
1995 (string-to-number (match-string 3))
1996 (string-to-number (match-string 2))
1997 (string-to-number (match-string 1))))
1998 (mixi-realization-error 'cannot-find-time event))
1999 (if (re-search-forward mixi-event-date-regexp nil t)
2000 (mixi-event-set-date event (match-string 1))
2001 (mixi-realization-error 'cannot-find-date event))
2002 (if (re-search-forward mixi-event-place-regexp nil t)
2003 (mixi-event-set-place event (match-string 1))
2004 (mixi-realization-error 'cannot-find-place event))
2005 (if (re-search-forward mixi-event-owner-regexp nil t)
2006 (let ((seceded-or-not (match-string 1))
2007 (id (match-string 2))
2008 (nick (match-string 3)))
2009 (if (string= mixi-event-owner-seceded-regexp seceded-or-not)
2010 (mixi-event-set-owner event
2011 (mixi-make-friend nil seceded-or-not))
2012 (mixi-event-set-owner event (mixi-make-friend id nick))))
2013 (mixi-realization-error 'cannot-find-owner event))
2014 (if (re-search-forward mixi-event-detail-regexp nil t)
2015 (mixi-event-set-detail event (match-string 1))
2016 (mixi-realization-error 'cannot-find-detail event))
2017 (if (re-search-forward mixi-event-limit-regexp nil t)
2018 (mixi-event-set-limit event (match-string 1))
2019 (mixi-realization-error 'cannot-find-limit event))
2020 (if (re-search-forward mixi-event-members-regexp nil t)
2021 (mixi-event-set-members event (match-string 1))
2022 (mixi-realization-error 'cannot-find-members event))))
2023 (mixi-object-touch event)))
2025 (defun mixi-event-community (event)
2026 "Return the community of EVENT."
2027 (unless (mixi-event-p event)
2028 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2029 (aref (cdr event) 1))
2031 (defun mixi-event-id (event)
2032 "Return the id of EVENT."
2033 (unless (mixi-event-p event)
2034 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2035 (aref (cdr event) 2))
2037 (defun mixi-event-comment-count (event)
2038 "Return the comment-count of EVENT."
2039 (unless (mixi-event-p event)
2040 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2041 (aref (cdr event) 3))
2043 (defun mixi-event-time (event)
2044 "Return the time 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) 4))
2050 (defun mixi-event-title (event)
2051 "Return the title 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) 5))
2057 (defun mixi-event-owner (event)
2058 "Return the owner of EVENT."
2059 (unless (mixi-event-p event)
2060 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2061 (mixi-realize-event event)
2062 (aref (cdr event) 6))
2064 (defun mixi-event-date (event)
2065 "Return the date of EVENT."
2066 (unless (mixi-event-p event)
2067 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2068 (mixi-realize-event event)
2069 (aref (cdr event) 7))
2071 (defun mixi-event-place (event)
2072 "Return the place of EVENT."
2073 (unless (mixi-event-p event)
2074 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2075 (mixi-realize-event event)
2076 (aref (cdr event) 8))
2078 (defun mixi-event-detail (event)
2079 "Return the detail of EVENT."
2080 (unless (mixi-event-p event)
2081 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2082 (mixi-realize-event event)
2083 (aref (cdr event) 9))
2085 (defun mixi-event-limit (event)
2086 "Return the limit of EVENT."
2087 (unless (mixi-event-p event)
2088 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2089 (mixi-realize-event event)
2090 (aref (cdr event) 10))
2092 (defun mixi-event-members (event)
2093 "Return the members of EVENT."
2094 (unless (mixi-event-p event)
2095 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2096 (mixi-realize-event event)
2097 (aref (cdr event) 11))
2099 (defun mixi-event-set-comment-count (event comment-count)
2100 "Set the comment-count of EVENT."
2101 (unless (mixi-event-p event)
2102 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2103 (aset (cdr event) 3 comment-count))
2105 (defun mixi-event-set-time (event time)
2106 "Set the time of EVENT."
2107 (unless (mixi-event-p event)
2108 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2109 (aset (cdr event) 4 time))
2111 (defun mixi-event-set-title (event title)
2112 "Set the title of EVENT."
2113 (unless (mixi-event-p event)
2114 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2115 (aset (cdr event) 5 title))
2117 (defun mixi-event-set-owner (event owner)
2118 "Set the owner of EVENT."
2119 (unless (mixi-event-p event)
2120 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2121 (unless (mixi-friend-p owner)
2122 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
2123 (aset (cdr event) 6 owner))
2125 (defun mixi-event-set-date (event date)
2126 "Set the date of EVENT."
2127 (unless (mixi-event-p event)
2128 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2129 (aset (cdr event) 7 date))
2131 (defun mixi-event-set-place (event place)
2132 "Set the place of EVENT."
2133 (unless (mixi-event-p event)
2134 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2135 (aset (cdr event) 8 place))
2137 (defun mixi-event-set-detail (event detail)
2138 "Set the detail of EVENT."
2139 (unless (mixi-event-p event)
2140 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2141 (aset (cdr event) 9 detail))
2143 (defun mixi-event-set-limit (event limit)
2144 "Set the limit of EVENT."
2145 (unless (mixi-event-p event)
2146 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2147 (aset (cdr event) 10 limit))
2149 (defun mixi-event-set-members (event members)
2150 "Set the members of EVENT."
2151 (unless (mixi-event-p event)
2152 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2153 (aset (cdr event) 11 members))
2156 (defconst mixi-bbs-list '(mixi-topic mixi-event))
2158 (defmacro mixi-bbs-p (bbs)
2159 `(memq (mixi-object-class ,bbs) mixi-bbs-list))
2161 (defun mixi-bbs-community (bbs)
2162 "Return the community of BBS."
2163 (unless (mixi-bbs-p bbs)
2164 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2165 (let ((func (intern (concat mixi-object-prefix
2166 (mixi-object-name bbs) "-community"))))
2167 (funcall func bbs)))
2169 (defun mixi-bbs-comment-count (bbs)
2170 "Return the comment-count of BBS."
2171 (unless (mixi-bbs-p bbs)
2172 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2173 (let ((func (intern (concat mixi-object-prefix
2174 (mixi-object-name bbs) "-comment-count"))))
2175 (funcall func bbs)))
2177 (defun mixi-bbs-set-comment-count (bbs count)
2178 "Set the comment-count of BBS."
2179 (unless (mixi-bbs-p bbs)
2180 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2181 (let ((func (intern (concat mixi-object-prefix
2182 (mixi-object-name bbs) "-set-comment-count"))))
2183 (funcall func bbs count)))
2185 (defalias 'mixi-bbs-id 'mixi-object-id)
2186 (defalias 'mixi-bbs-time 'mixi-object-time)
2187 (defalias 'mixi-bbs-title 'mixi-object-title)
2188 (defalias 'mixi-bbs-owner 'mixi-object-owner)
2189 (defalias 'mixi-bbs-content 'mixi-object-content)
2191 (defmacro mixi-bbs-list-page (community)
2192 `(concat "/list_bbs.pl?page=%d"
2193 "&id=" (mixi-community-id ,community)))
2195 (defconst mixi-bbs-list-regexp
2196 "<a href=\"?view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)")
2199 (defun mixi-get-bbses (community &optional range)
2200 "Get bbses of COMMUNITY."
2201 (unless (mixi-community-p community)
2202 (signal 'wrong-type-argument (list 'mixi-community-p community)))
2203 (let ((items (mixi-get-matched-items (mixi-bbs-list-page community)
2204 mixi-bbs-list-regexp
2206 (mapcar (lambda (item)
2207 (let ((name (nth 0 item)))
2208 (when (string= name "bbs")
2209 (setq name "topic"))
2210 (let ((func (intern (concat "mixi-make-" name))))
2211 (funcall func community (nth 1 item)))))
2214 (defmacro mixi-new-bbs-list-page ()
2215 `(concat "/new_bbs.pl?page=%d"))
2217 (defconst mixi-new-bbs-list-regexp
2218 "<dd><a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\">")
2221 (defun mixi-get-new-bbses (&optional range)
2223 (let ((items (mixi-get-matched-items (mixi-new-bbs-list-page)
2224 mixi-new-bbs-list-regexp
2227 (mapcar (lambda (item)
2228 (let ((name (nth 0 item)))
2229 (when (string= name "bbs")
2230 (setq name "topic"))
2231 (let* ((func (intern (concat "mixi-make-" name)))
2233 (mixi-make-community (nth 3 item))
2235 (comment-count (mixi-bbs-comment-count bbs))
2236 (count (string-to-number (nth 2 item))))
2237 (when (or (null comment-count)
2238 (< comment-count count))
2239 (mixi-bbs-set-comment-count bbs count)
2243 (defmacro mixi-search-bbs-list-page (keyword)
2244 `(concat "/search_topic.pl?page=%d&type=top&submit=search"
2245 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
2246 "&community_id=0&category_id=0"))
2248 (defconst mixi-search-bbs-list-regexp
2249 "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\" class=\"title\">")
2251 ;; FIXME: Support community and category.
2253 (defun mixi-search-bbses (keyword &optional range)
2254 (let ((items (mixi-get-matched-items (mixi-search-bbs-list-page keyword)
2255 mixi-search-bbs-list-regexp
2257 (mapcar (lambda (item)
2258 (let ((name (nth 0 item)))
2259 (when (string= name "bbs")
2260 (setq name "topic"))
2261 (let ((func (intern (concat "mixi-make-" name))))
2262 (funcall func (mixi-make-community (nth 2 item))
2267 (defmacro mixi-parent-p (object)
2268 `(or (eq (mixi-object-class ,object) 'mixi-diary)
2269 (mixi-bbs-p ,object)))
2271 (defun mixi-realize-parent (parent &optional page)
2273 (unless (mixi-parent-p parent)
2274 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2275 (let ((func (intern (concat mixi-object-prefix "realize-"
2276 (mixi-object-name parent)))))
2277 (funcall func parent page)))
2280 (defun mixi-make-comment (parent owner time content &optional count)
2281 "Return a comment object."
2282 (cons 'mixi-comment (vector parent owner time content count)))
2284 (defmacro mixi-comment-p (comment)
2285 `(eq (mixi-object-class ,comment) 'mixi-comment))
2287 (defun mixi-comment-parent (comment)
2288 "Return the parent of COMMENT."
2289 (unless (mixi-comment-p comment)
2290 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2291 (aref (cdr comment) 0))
2293 (defun mixi-comment-owner (comment)
2294 "Return the owner of COMMENT."
2295 (unless (mixi-comment-p comment)
2296 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2297 (aref (cdr comment) 1))
2299 (defun mixi-comment-time (comment)
2300 "Return the time of COMMENT."
2301 (unless (mixi-comment-p comment)
2302 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2303 (aref (cdr comment) 2))
2305 (defun mixi-comment-content (comment)
2306 "Return the content of COMMENT."
2307 (unless (mixi-comment-p comment)
2308 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2309 (aref (cdr comment) 3))
2311 (defun mixi-comment-count (comment)
2312 "Return the count of COMMENT."
2313 (unless (mixi-comment-p comment)
2314 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2315 (aref (cdr comment) 4))
2317 (defun mixi-diary-comment-list-page (diary)
2318 (concat "/view_diary.pl?full=1"
2319 "&id=" (mixi-diary-id diary)
2320 "&owner_id=" (mixi-friend-id (mixi-diary-owner diary))))
2322 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2323 (defconst mixi-diary-comment-list-regexp
2324 "<span class=\"commentTitleName\">\\(<input type=\"checkbox\" name=\"comment_id\" value=\".+\" />
2325 \\|\\)<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2327 | <a href=\"delete_comment\\.pl\\?diary_id=[0-9]+&owner_id=[0-9]+&comment_id=.+&type=comment\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a>
2330 <span class=\"commentTitleDate\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>
2334 \\(\\(.\\|\r?\n\\)*?\\)
2339 (defun mixi-topic-comment-list-page (topic)
2340 (concat "/view_bbs.pl?page=all"
2341 "&id=" (mixi-topic-id topic)
2342 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2344 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2345 (defconst mixi-topic-comment-list-regexp
2346 "<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>
2347 <span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
2349 <dl class=\"commentContent01\">
2350 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
2352 \\(\\(.\\|\r?\n\\)*?\\)
2355 (defun mixi-event-comment-list-page (event)
2356 (concat "/view_event.pl?page=all"
2357 "&id=" (mixi-event-id event)
2358 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2360 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2361 (defconst mixi-event-comment-list-regexp
2362 "<dt class=\"commentDate clearfix\"><span class=\"senderId\">\\(<input id=\"commentCheck01\" name=\"comment_id\" type=\"checkbox\" value=\"[0-9]+\" /><label for=\"commentCheck01\">\\|\\)\\([0-9]+\\)\\(<span class=\"deleteTextArea\"><a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+&type=event\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a></span>\\|</label>\\|\\)</span>
2363 <span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
2365 <dl class=\"commentContent01\">
2366 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
2368 \\(\\(.\\|\r?\n\\)*?\\)
2372 (defun mixi-get-comments (parent &optional range)
2373 "Get comments of PARENT."
2374 (unless (mixi-parent-p parent)
2375 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2376 (let* ((name (mixi-object-name parent))
2377 (list-page (intern (concat mixi-object-prefix name
2378 "-comment-list-page")))
2379 (regexp (eval (intern (concat mixi-object-prefix name
2380 "-comment-list-regexp"))))
2381 (page (funcall list-page parent)))
2382 (unless (mixi-object-realized-p parent)
2383 (mixi-realize-parent parent page)
2385 (let ((items (mixi-get-matched-items page regexp range t)))
2386 (mapcar (lambda (item)
2387 (let (owner-id owner-nick year month day hour minute content
2389 (if (eq (mixi-object-class parent) 'mixi-diary)
2391 (setq owner-id (nth 1 item))
2392 (setq owner-nick (nth 2 item))
2393 (setq year (nth 4 item))
2394 (setq month (nth 5 item))
2395 (setq day (nth 6 item))
2396 (setq hour (nth 7 item))
2397 (setq minute (nth 8 item))
2398 (setq content (nth 9 item)))
2399 (setq owner-id (nth 8 item))
2400 (setq owner-nick (nth 9 item))
2401 (setq year (nth 3 item))
2402 (setq month (nth 4 item))
2403 (setq day (nth 5 item))
2404 (setq hour (nth 6 item))
2405 (setq minute (nth 7 item))
2406 (setq content (nth 10 item))
2407 (setq count (nth 1 item)))
2408 (mixi-make-comment parent (mixi-make-friend owner-id
2412 (string-to-number minute)
2413 (string-to-number hour)
2414 (string-to-number day)
2415 (string-to-number month)
2416 (string-to-number year))
2420 (defmacro mixi-new-comment-list-page ()
2421 `(concat "/new_comment.pl?page=%d"))
2423 (defconst mixi-new-comment-list-regexp
2424 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)\">")
2427 (defun mixi-get-new-comments (&optional range)
2429 (let ((items (mixi-get-matched-items (mixi-new-comment-list-page)
2430 mixi-new-comment-list-regexp
2433 (mapcar (lambda (item)
2434 (let* ((diary (mixi-make-diary
2435 (mixi-make-friend (nth 1 item))
2437 (comment-count (mixi-diary-comment-count diary))
2438 (count (string-to-number (nth 2 item))))
2439 (when (or (null comment-count)
2440 (< comment-count count))
2441 (mixi-diary-set-comment-count diary count)
2445 (defmacro mixi-new-bbs-comment-list-page ()
2446 `(concat "/new_bbs_comment.pl?page=%d"))
2448 (defconst mixi-new-bbs-comment-list-regexp
2449 "<a href=\"?view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\"?>")
2452 (defun mixi-get-new-bbs-comments (&optional range)
2453 "Get new BBS comments."
2454 (let ((items (mixi-get-matched-items (mixi-new-bbs-comment-list-page)
2455 mixi-new-bbs-comment-list-regexp
2458 (mapcar (lambda (item)
2459 (let ((name (nth 0 item)))
2460 (when (string= name "bbs")
2461 (setq name "topic"))
2462 (let ((make-func (intern (concat "mixi-make-" name)))
2464 (intern (concat "mixi-" name "-comment-count")))
2465 (set-comment-count-func
2466 (intern (concat "mixi-" name
2467 "-set-comment-count"))))
2468 (let* ((bbs (funcall make-func
2469 (mixi-make-community (nth 3 item))
2471 (comment-count (funcall comment-count-func bbs))
2472 (count (string-to-number (nth 2 item))))
2473 (when (or (null comment-count)
2474 (< comment-count count))
2475 (funcall set-comment-count-func bbs count)
2479 (defun mixi-post-diary-comment-page (diary)
2480 (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
2482 (defun mixi-post-topic-comment-page (topic)
2483 (concat "/add_bbs_comment.pl?id=" (mixi-topic-id topic)
2484 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2486 (defun mixi-post-event-comment-page (event)
2487 (concat "/add_event_comment.pl?id=" (mixi-event-id event)
2488 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2490 ;; FIXME: Support photos.
2492 (defun mixi-post-comment (parent content)
2493 "Post a comment to PARENT."
2494 (unless (mixi-object-p parent)
2495 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
2496 (unless (stringp content)
2497 (signal 'wrong-type-argument (list 'stringp content)))
2498 (let* ((name (mixi-object-name parent))
2499 (page (intern (concat mixi-object-prefix "post-" name
2502 (if (mixi-diary-p parent)
2504 `(("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2505 ("comment_body" . ,content)))
2506 (setq fields `(("comment" . ,content))))
2507 (with-mixi-post-form (funcall page parent) fields
2508 (if (re-search-forward mixi-post-key-regexp nil t)
2509 (setq post-key (match-string 1))
2510 (mixi-post-error 'cannot-find-key parent)))
2511 (if (mixi-diary-p parent)
2513 `(("post_key" . ,post-key)
2514 ("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2515 ("comment_body" . ,content)
2516 ("submit" . "confirm")))
2517 (setq fields `(("post_key" . ,post-key)
2518 ("comment" . ,content)
2519 ("submit" . "confirm"))))
2520 (with-mixi-post-form (funcall page parent) fields
2521 (unless (re-search-forward mixi-post-succeed-regexp nil t)
2522 (mixi-post-error 'cannot-find-succeed parent)))))
2525 (defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
2527 (defmacro mixi-message-box-p (box)
2528 `(memq ,box mixi-message-box-list))
2530 (defun mixi-message-box-name (box)
2531 "Return the name of BOX."
2532 (unless (mixi-message-box-p box)
2533 (signal 'wrong-type-argument (list 'mixi-message-box-p box)))
2536 (defvar mixi-message-cache (make-hash-table :test 'equal))
2537 (defun mixi-make-message (id box &optional owner title time content)
2538 "Return a message object."
2539 (mixi-make-cache (list id box)
2540 (cons 'mixi-message (vector nil id box owner title time
2542 mixi-message-cache))
2544 (defconst mixi-message-url-regexp
2545 "/view_message\\.pl\\?id=\\([a-z0-9]+\\)&box=\\([a-z]+\\)")
2547 (defun mixi-make-message-from-url (url)
2548 "Return a message object from URL."
2549 (when (string-match mixi-message-url-regexp url)
2550 (let ((id (match-string 1 url))
2551 (box (match-string 2 url)))
2552 (mixi-make-message id box))))
2554 (defmacro mixi-message-p (message)
2555 `(eq (mixi-object-class ,message) 'mixi-message))
2557 (defmacro mixi-message-page (message)
2558 `(concat "/view_message.pl?id=" (mixi-message-id ,message)
2559 "&box=" (mixi-message-box ,message)))
2561 (defconst mixi-message-owner-regexp
2562 "<font COLOR=#996600>\\(º¹½Ð¿Í\\|°¸ Àè\\)</font> : <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)\\(</a>\\|</td>\\)")
2563 (defconst mixi-message-time-regexp
2564 "<font COLOR=#996600>Æü\\(¡¡\\| \\)ÉÕ</font> : \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ ")
2565 (defconst mixi-message-title-regexp
2566 "<font COLOR=#996600>·ï\\(¡¡\\| \\)̾</font> : \\(.*\\)\n?</td>")
2567 (defconst mixi-message-content-regexp
2568 "<tr><td CLASS=h120 width=\"500\">\\(.*\\)</td></tr>")
2570 (defun mixi-realize-message (message)
2571 "Realize a MESSAGE."
2572 (unless (mixi-object-realized-p message)
2573 (with-mixi-retrieve (mixi-message-page message)
2574 (if (re-search-forward mixi-message-owner-regexp nil t)
2575 (mixi-message-set-owner message
2576 (mixi-make-friend (match-string 2)
2578 (mixi-realization-error 'cannot-find-owner message))
2579 (if (re-search-forward mixi-message-time-regexp nil t)
2580 (mixi-message-set-time
2581 message (encode-time 0 (string-to-number (match-string 6))
2582 (string-to-number (match-string 5))
2583 (string-to-number (match-string 4))
2584 (string-to-number (match-string 3))
2585 (string-to-number (match-string 2))))
2586 (mixi-realization-error 'cannot-find-time message))
2587 (if (re-search-forward mixi-message-title-regexp nil t)
2588 (mixi-message-set-title message (match-string 2))
2589 (mixi-realization-error 'cannot-find-title message))
2590 (if (re-search-forward mixi-message-content-regexp nil t)
2591 (mixi-message-set-content message (match-string 1))
2592 (mixi-realization-error 'cannot-find-content message)))
2593 (mixi-object-touch message)))
2595 (defun mixi-message-id (message)
2596 "Return the id of MESSAGE."
2597 (unless (mixi-message-p message)
2598 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2599 (aref (cdr message) 1))
2601 (defun mixi-message-box (message)
2602 "Return the box of MESSAGE."
2603 (unless (mixi-message-p message)
2604 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2605 (aref (cdr message) 2))
2607 (defun mixi-message-owner (message)
2608 "Return the owner of MESSAGE."
2609 (unless (mixi-message-p message)
2610 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2611 (mixi-realize-message message)
2612 (aref (cdr message) 3))
2614 (defun mixi-message-title (message)
2615 "Return the title of MESSAGE."
2616 (unless (mixi-message-p message)
2617 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2618 (mixi-realize-message message)
2619 (aref (cdr message) 4))
2621 (defun mixi-message-time (message)
2622 "Return the date of MESSAGE."
2623 (unless (mixi-message-p message)
2624 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2625 (mixi-realize-message message)
2626 (aref (cdr message) 5))
2628 (defun mixi-message-content (message)
2629 "Return the content of MESSAGE."
2630 (unless (mixi-message-p message)
2631 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2632 (mixi-realize-message message)
2633 (aref (cdr message) 6))
2635 (defun mixi-message-set-owner (message owner)
2636 "Set the owner of MESSAGE."
2637 (unless (mixi-message-p message)
2638 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2639 (aset (cdr message) 3 owner))
2641 (defun mixi-message-set-title (message title)
2642 "Set the title of MESSAGE."
2643 (unless (mixi-message-p message)
2644 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2645 (aset (cdr message) 4 title))
2647 (defun mixi-message-set-time (message time)
2648 "Set the date of MESSAGE."
2649 (unless (mixi-message-p message)
2650 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2651 (aset (cdr message) 5 time))
2653 (defun mixi-message-set-content (message content)
2654 "Set the content of MESSAGE."
2655 (unless (mixi-message-p message)
2656 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2657 (aset (cdr message) 6 content))
2659 (defmacro mixi-message-list-page (&optional box)
2660 `(concat "/list_message.pl?page=%d"
2661 (when ,box (concat "&box=" ,box))))
2663 (defconst mixi-message-list-regexp
2664 "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
2667 (defun mixi-get-messages (&rest box-or-range)
2668 "Get messages of BOX."
2669 (when (> (length box-or-range) 2)
2670 (signal 'wrong-number-of-arguments
2671 (list 'mixi-get-messages (length box-or-range))))
2672 (let ((box (nth 0 box-or-range))
2673 (range (nth 1 box-or-range)))
2674 (when (or (not (mixi-message-box-p box))
2675 (mixi-message-box-p range))
2676 (setq box (nth 1 box-or-range))
2677 (setq range (nth 0 box-or-range)))
2678 (let ((items (mixi-get-matched-items
2679 (mixi-message-list-page
2680 (when box (mixi-message-box-name box)))
2681 mixi-message-list-regexp
2683 (mapcar (lambda (item)
2684 (mixi-make-message (nth 0 item) (nth 1 item)))
2687 (defmacro mixi-post-message-page (friend)
2688 `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
2690 (defconst mixi-post-message-key-regexp
2691 "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
2693 (defconst mixi-post-message-succeed-regexp
2694 "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
2697 (defun mixi-post-message (friend title content)
2698 "Post a message to FRIEND."
2699 (unless (mixi-friend-p friend)
2700 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2701 (unless (stringp title)
2702 (signal 'wrong-type-argument (list 'stringp title)))
2703 (unless (stringp content)
2704 (signal 'wrong-type-argument (list 'stringp content)))
2705 (let ((fields `(("subject" . ,title)
2707 ("submit" . "main")))
2709 (with-mixi-post-form (mixi-post-message-page friend) fields
2710 (if (re-search-forward mixi-post-message-key-regexp nil t)
2711 (setq post-key (match-string 1))
2712 (mixi-post-error 'cannot-find-key friend)))
2713 (setq fields `(("post_key" . ,post-key)
2714 ("subject" . ,title)
2716 ("yes" . "¡¡Á÷¡¡¿®¡¡")
2717 ("submit" . "confirm")))
2718 (with-mixi-post-form (mixi-post-message-page friend) fields
2719 (unless (re-search-forward mixi-post-message-succeed-regexp nil t)
2720 (mixi-post-error 'cannot-find-succeed friend)))))
2722 ;; Introduction object.
2723 (defun mixi-make-introduction (parent owner content)
2724 "Return a introduction object."
2725 (cons 'mixi-introduction (vector parent owner content)))
2727 (defmacro mixi-introduction-p (introduction)
2728 `(eq (mixi-object-class ,introduction) 'mixi-introduction))
2730 (defun mixi-introduction-parent (introduction)
2731 "Return the parent of INTRODUCTION."
2732 (unless (mixi-introduction-p introduction)
2733 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2734 (aref (cdr introduction) 0))
2736 (defun mixi-introduction-owner (introduction)
2737 "Return the owner of INTRODUCTION."
2738 (unless (mixi-introduction-p introduction)
2739 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2740 (aref (cdr introduction) 1))
2742 (defun mixi-introduction-content (introduction)
2743 "Return the content of INTRODUCTION."
2744 (unless (mixi-introduction-p introduction)
2745 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2746 (aref (cdr introduction) 3))
2748 (defmacro mixi-introduction-list-page (&optional friend)
2749 `(concat "/show_intro.pl?page=%d"
2750 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
2752 (defconst mixi-introduction-list-regexp
2753 "<tr bgcolor=#FFFFFF>
2754 <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>
2761 \\(\\(.\\|\n<br>\\)+\\)\\|
2762 \\(\\(.\\|\n<br>\\)+\\)\\)
2769 (defconst mixi-my-introduction-list-regexp
2770 "<tr bgcolor=#FFFFFF>
2771 <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>
2779 \\(\\(.\\|\n<br>\\)+\\)\\|
2780 \\(\\(.\\|\n<br>\\)+\\)\\)
2784 <a href=\"edit_intro\\.pl\\?id=\\1&type=edit\">¤³¤Îͧ¿Í¤ò¾Ò²ð¤¹¤ë</a>
2788 <a href=\"delete_intro\\.pl\\?id=\\1\">ºï½ü</a>
2794 (defun mixi-get-introductions (&rest friend-or-range)
2795 "Get introductions of FRIEND."
2796 (when (> (length friend-or-range) 2)
2797 (signal 'wrong-number-of-arguments
2798 (list 'mixi-get-introduction (length friend-or-range))))
2799 (let ((friend (nth 0 friend-or-range))
2800 (range (nth 1 friend-or-range)))
2801 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
2802 (setq friend (nth 1 friend-or-range))
2803 (setq range (nth 0 friend-or-range)))
2804 (unless (or (null friend) (mixi-friend-p friend))
2805 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2806 (let* ((regexp (if friend mixi-introduction-list-regexp
2807 mixi-my-introduction-list-regexp))
2808 (items (mixi-get-matched-items (mixi-introduction-list-page friend)
2811 (mapcar (lambda (item)
2812 (mixi-make-introduction (or friend (mixi-make-me))
2813 (mixi-make-friend (nth 0 item)
2819 (defvar mixi-news-cache (make-hash-table :test 'equal))
2820 (defun mixi-make-news (media-id id &optional media time title content)
2821 "Return a news object."
2822 (mixi-make-cache (list media-id id)
2823 (cons 'mixi-news (vector nil media-id id media time title
2827 (defconst mixi-news-url-regexp
2828 "/view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)")
2830 (defun mixi-make-news-from-url (url)
2831 "Return a news object from URL."
2832 (when (string-match mixi-news-url-regexp url)
2833 (let ((id (match-string 1 url))
2834 (media-id (match-string 2 url)))
2835 (mixi-make-news media-id id))))
2837 (defmacro mixi-news-p (news)
2838 `(eq (mixi-object-class ,news) 'mixi-news))
2840 (defmacro mixi-news-page (news)
2841 `(concat "http://news.mixi.jp/view_news.pl?id=" (mixi-news-id ,news)
2842 "&media_id=" (mixi-news-media-id ,news)))
2844 (defconst mixi-news-finished-regexp
2845 "<p class=\"supplement01\">¢¨¿½¤·Ìõ¤¢¤ê¤Þ¤»¤ó¤¬¡¢¤³¤Î¥Ë¥å¡¼¥¹¤Ï·ÇºÜ´ü´Ö¤¬½ªÎ»¤·¤¿¤«¡¢URL¤¬´Ö°ã¤Ã¤Æ¤¤¤ë¤¿¤á¤´Í÷¤¤¤¿¤À¤±¤Þ¤»¤ó¡£¾Ü¤·¤¯¤Ï<a href=\"http://mixi.jp/help.pl#16h\">¤³¤Á¤é</a>¤ò¤´Í÷¤¯¤À¤µ¤¤¡£</p>")
2846 (defconst mixi-news-title-regexp
2847 "<div class=\"articleH[ae][ae]ding\">
2849 (defconst mixi-news-media-time-regexp
2850 "<p class=\"date\">¡Ê\\(.+\\) - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)¡Ë</p>")
2851 (defconst mixi-news-content-regexp
2852 "<div class=\"article\">
2856 </div>\\|<div class=\"additional\">\\)")
2858 (defun mixi-realize-news (news)
2860 ;; FIXME: Check a expiration of cache?
2861 (unless (mixi-object-realized-p news)
2862 (with-mixi-retrieve (mixi-news-page news)
2863 (if (re-search-forward mixi-news-finished-regexp nil t)
2864 (mixi-news-set-content news (match-string 0))
2865 (if (re-search-forward mixi-news-title-regexp nil t)
2866 (mixi-news-set-title news (match-string 1))
2867 (mixi-realization-error 'cannot-find-title news))
2868 (if (re-search-forward mixi-news-media-time-regexp nil t)
2870 (mixi-news-set-media news (match-string 1))
2871 (let ((year (nth 5 (decode-time (current-time))))
2872 (month (nth 4 (decode-time (current-time))))
2873 (month-of-item (string-to-number (match-string 2))))
2874 (when (> month-of-item month)
2877 news (encode-time 0 (string-to-number (match-string 5))
2878 (string-to-number (match-string 4))
2879 (string-to-number (match-string 3))
2881 (mixi-realization-error 'cannot-find-media-time news))
2882 (if (re-search-forward mixi-news-content-regexp nil t)
2883 (mixi-news-set-content news (match-string 1))
2884 (mixi-realization-error 'cannot-find-content news))))
2885 (mixi-object-touch news)))
2887 (defun mixi-news-media-id (news)
2888 "Return the media-id of NEWS."
2889 (unless (mixi-news-p news)
2890 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2891 (aref (cdr news) 1))
2893 (defun mixi-news-id (news)
2894 "Return the id of NEWS."
2895 (unless (mixi-news-p news)
2896 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2897 (aref (cdr news) 2))
2899 (defun mixi-news-media (news)
2900 "Return the media of NEWS."
2901 (unless (mixi-news-p news)
2902 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2903 (unless (aref (cdr news) 3)
2904 (mixi-realize-news news))
2905 (aref (cdr news) 3))
2907 (defun mixi-news-time (news)
2908 "Return the time of NEWS."
2909 (unless (mixi-news-p news)
2910 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2911 (unless (aref (cdr news) 4)
2912 (mixi-realize-news news))
2913 (aref (cdr news) 4))
2915 (defun mixi-news-title (news)
2916 "Return the title of NEWS."
2917 (unless (mixi-news-p news)
2918 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2919 (unless (aref (cdr news) 5)
2920 (mixi-realize-news news))
2921 (aref (cdr news) 5))
2923 (defun mixi-news-content (news)
2924 "Return the content of NEWS."
2925 (unless (mixi-news-p news)
2926 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2927 (mixi-realize-news news)
2928 (aref (cdr news) 6))
2930 (defun mixi-news-set-media (news media)
2931 "Set the media of NEWS."
2932 (unless (mixi-news-p news)
2933 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2934 (aset (cdr news) 3 media))
2936 (defun mixi-news-set-time (news time)
2937 "Set the time of NEWS."
2938 (unless (mixi-news-p news)
2939 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2940 (aset (cdr news) 4 time))
2942 (defun mixi-news-set-title (news title)
2943 "Set the title of NEWS."
2944 (unless (mixi-news-p news)
2945 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2946 (aset (cdr news) 5 title))
2948 (defun mixi-news-set-content (news content)
2949 "Set the content of NEWS."
2950 (unless (mixi-news-p news)
2951 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2952 (aset (cdr news) 6 content))
2954 (defconst mixi-news-category-list '(domestic politics economy area abroad
2955 sports entertainment IT game-anime
2958 (defmacro mixi-news-category-p (category)
2959 `(memq ,category mixi-news-category-list))
2961 (defun mixi-news-category-id (category)
2962 "Return the id of CATEGORY."
2963 (unless (mixi-news-category-p category)
2964 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2966 (1+ (- (length mixi-news-category-list)
2967 (length (memq category mixi-news-category-list))))))
2969 (defconst mixi-news-sort-list '(newest pickup))
2971 (defmacro mixi-news-sort-p (sort)
2972 `(memq ,sort mixi-news-sort-list))
2974 (defun mixi-news-sort-id (sort)
2975 "Return the id of SORT."
2976 (unless (mixi-news-sort-p sort)
2977 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
2979 (- (length mixi-news-sort-list)
2980 (length (memq sort mixi-news-sort-list)))))
2982 (defmacro mixi-news-list-page (category sort)
2983 `(concat "http://news.mixi.jp/list_news_category.pl?page=%d"
2984 "&sort=" (mixi-news-sort-id ,sort)
2985 "&id=" (mixi-news-category-id ,category)
2988 (defconst mixi-news-list-regexp
2989 "<td class=\"newsTitle\"><p>¡¦ <a href=\"view_news\\.pl\\?id=\\([0-9]+\\)&media_id=\\([0-9]+\\)\">\\(.+\\)</a><img src=\"http://img\\.mixi\\.jp/img/news_camera3\\.gif\" width=\"11\" height=\"12\" alt=\"\" /></p></td>
2990 <td class=\"media\"><a href=\"list_news_media\\.pl\\?id=[0-9]+\">\\(.+\\)</a></td>
2991 <td class=\"date\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>")
2994 (defun mixi-get-news (category sort &optional range)
2995 "Get news of CATEGORY and SORT."
2996 (unless (mixi-news-category-p category)
2997 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2998 (unless (mixi-news-sort-p sort)
2999 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
3000 (let ((items (mixi-get-matched-items (mixi-news-list-page category sort)
3001 mixi-news-list-regexp
3003 (year (nth 5 (decode-time (current-time))))
3004 (month (nth 4 (decode-time (current-time)))))
3005 (mapcar (lambda (item)
3006 (let ((month-of-item (string-to-number (nth 4 item))))
3007 (when (> month-of-item month)
3009 (setq month month-of-item)
3010 (mixi-make-news (nth 1 item) (nth 0 item) (nth 3 item)
3012 0 (string-to-number (nth 7 item))
3013 (string-to-number (nth 6 item))
3014 (string-to-number (nth 5 item))
3020 (defun mixi-make-release (title time content)
3021 "Return a release object."
3022 (cons 'mixi-release (vector title time content)))
3024 (defmacro mixi-release-p (release)
3025 `(eq (mixi-object-class ,release) 'mixi-release))
3027 (defun mixi-release-title (release)
3028 "Return the title of RELEASE."
3029 (unless (mixi-release-p release)
3030 (signal 'wrong-type-argument (list 'mixi-release-p release)))
3031 (aref (cdr release) 0))
3033 (defun mixi-release-time (release)
3034 "Return the time of RELEASE."
3035 (unless (mixi-release-p release)
3036 (signal 'wrong-type-argument (list 'mixi-release-p release)))
3037 (aref (cdr release) 1))
3039 (defun mixi-release-content (release)
3040 "Return the content of RELEASE."
3041 (unless (mixi-release-p release)
3042 (signal 'wrong-type-argument (list 'mixi-release-p release)))
3043 (aref (cdr release) 2))
3045 (defmacro mixi-release-list-page ()
3046 `(concat "/release_info.pl?page=%d"))
3048 (defconst mixi-release-list-regexp
3049 "<td> <span STYLE=\"font-size:8pt;color:#DFB479\">¢£</span> <b><font COLOR=#605048>\\(.+\\)</font></b></td>
3050 <td ALIGN=right><font COLOR=#605048>\\([1-9][0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)</font></td>
3059 <table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=450>
3068 (defun mixi-get-releases (&optional range)
3070 (let ((items (mixi-get-matched-items (mixi-release-list-page)
3071 mixi-release-list-regexp
3073 (mapcar (lambda (item)
3074 (mixi-make-release (nth 0 item)
3076 (string-to-number (nth 3 item))
3077 (string-to-number (nth 2 item))
3078 (string-to-number (nth 1 item)))
3084 ;;; mixi.el ends here