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
49 ;; * mixi-get-echoes (limited)
50 ;; * mixi-get-new-echoes (limited)
56 ;; * mixi-post-comment
57 ;; * mixi-post-message
58 ;; * mixi-post-echo (limited)
62 ;; * mixi-remove-markup (half broken)
66 ;; Display newest 3 diaries like a mail format.
69 ;; (buffer (get-buffer-create "*temp*"))
70 ;; (format "%Y/%m/%d %H:%M"))
71 ;; (pop-to-buffer buffer)
72 ;; (let ((diaries (mixi-get-new-diaries range)))
74 ;; (let* ((diary (car diaries))
75 ;; (subject (mixi-diary-title diary))
76 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
77 ;; (date (format-time-string format (mixi-diary-time diary)))
78 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
79 ;; (insert "From: " from "\n"
80 ;; "Subject: " subject "\n"
81 ;; "Date: " date "\n\n"
83 ;; (setq diaries (cdr diaries))))
84 ;; (set-buffer-modified-p nil)
85 ;; (setq buffer-read-only t)
86 ;; (goto-char (point-min)))
88 ;; Display newest 3 diaries including newest 3 comments like a mail format.
89 ;; Comments are displayed like a reply mail.
92 ;; (buffer (get-buffer-create "*temp*"))
93 ;; (format "%Y/%m/%d %H:%M"))
94 ;; (pop-to-buffer buffer)
95 ;; (let ((diaries (mixi-get-new-diaries range)))
97 ;; (let* ((diary (car diaries))
98 ;; (subject (mixi-diary-title diary))
99 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
100 ;; (date (format-time-string format (mixi-diary-time diary)))
101 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
102 ;; (insert "From: " from "\n"
103 ;; "Subject: " subject "\n"
104 ;; "Date: " date "\n\n"
106 ;; (let ((comments (mixi-get-comments diary range)))
108 ;; (let* ((comment (car comments))
109 ;; (from (mixi-friend-nick (mixi-comment-owner comment)))
110 ;; (subject (concat "Re: " subject))
111 ;; (date (format-time-string format
112 ;; (mixi-comment-time comment)))
113 ;; (body (mixi-remove-markup (mixi-comment-content comment))))
114 ;; (insert "From: " from "\n"
115 ;; "Subject: " subject "\n"
116 ;; "Date: " date "\n\n"
118 ;; (setq comments (cdr comments)))))
119 ;; (setq diaries (cdr diaries))))
120 ;; (set-buffer-modified-p nil)
121 ;; (setq buffer-read-only t)
122 ;; (goto-char (point-min)))
126 ;; If you have bug reports and/or suggestions for improvement, please
127 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
131 (eval-when-compile (require 'cl))
133 ;; Functions and variables which should be defined in the other module
136 (defvar w3m-use-cookies)
137 (autoload 'w3m-decode-buffer "w3m")
138 (autoload 'w3m-retrieve "w3m")
139 (autoload 'url-retrieve-synchronously "url"))
141 (defconst mixi-revision "$Revision: 1.200 $")
144 "API library for accessing to mixi."
147 (defcustom mixi-url "http://mixi.jp"
152 (defcustom mixi-directory (expand-file-name "~/.mixi")
153 "*Where to look for mixi files."
157 (defcustom mixi-coding-system 'euc-jp
158 "*Coding system for mixi."
162 (defcustom mixi-curl-program "curl"
163 "*The program name of `curl'."
167 (defcustom mixi-curl-cookie-file (expand-file-name "cookies.txt"
169 "*The location of cookie file created by `curl'."
173 (defcustom mixi-backend
174 (or (condition-case nil
182 (if (fboundp 'url-retrieve-synchronously)
185 (if (and (fboundp 'executable-find)
186 (executable-find mixi-curl-program))
188 (error "Cannot set `mixi-backend'."))
189 "*The backend for accessing to mixi."
190 :type '(radio (const :tag "Use emacs-w3m" w3m)
191 (const :tag "Use url.el" url)
192 (const :tag "Use curl" curl)
193 (symbol :tag "The other backend"))
196 (defcustom mixi-login-use-ssl nil
197 "*If non-ni, login using SSL."
201 (defcustom mixi-default-email nil
202 "*Default E-mail address that is used to login automatically."
203 :type '(radio (string :tag "E-mail address")
204 (const :tag "Asked when it is necessary" nil))
207 (defcustom mixi-default-password nil
208 "*Default password that is used to login automatically."
209 :type '(radio (string :tag "Password")
210 (const :tag "Asked when it is necessary" nil))
213 (defcustom mixi-accept-adult-contents t
214 "*If non-nil, accept to access to the adult contents."
218 (defcustom mixi-continuously-access-interval 4.0
219 "*Time interval between each mixi access.
220 Increase this value when unexpected error frequently occurs."
224 (defcustom mixi-cache-expires nil
225 "*Seconds for expiration of a cached object."
226 :type '(radio (integer :tag "Expired seconds")
227 (const :tag "Don't expire" nil)
228 (const :tag "Don't cache" t))
231 ;; FIXME: Not implemented.
232 (defcustom mixi-cache-use-file t
233 "*If non-nil, caches are saved to files."
237 (defvar mixi-temp-buffer-name " *mixi temp*")
241 (defmacro mixi-message (&rest strings)
242 `(concat "[mixi] " ,@strings))
244 (put 'mixi-realization-error
245 'error-message (mixi-message "Cannot realize object"))
246 (put 'mixi-realization-error
247 'error-conditions '(mixi-realization-error error))
249 (put 'mixi-post-error
250 'error-message (mixi-message "Cannot post"))
251 (put 'mixi-post-error
252 'error-conditions '(mixi-post-error error))
254 (defmacro mixi-realization-error (type object)
255 `(let ((data (if debug-on-error
256 (list ,type ,object (buffer-string))
257 (list ,type ,object))))
258 (signal 'mixi-realization-error data)))
260 (defmacro mixi-post-error (type &optional object)
261 `(let ((data (when debug-on-error (list (buffer-string)))))
263 (setq data (cons ,type (cons ,object data)))
264 (setq data (cons ,type data)))
265 (signal 'mixi-post-error data)))
267 (defconst mixi-message-adult-contents
268 "¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
269 ±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
270 (defconst mixi-message-continuously-accessing
271 "°ÂÄꤷ¤Æ¥µ¥¤¥È¤Î±¿±Ä¤ò¤ª¤³¤Ê¤¦°Ù¡¢´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹<br>
272 ¿·¤ÏÀ©¸Â¤µ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤ª¤ê¤Þ¤¹¡£¤´ÌÂÏǤò¤ª¤«¤±¤¤¤¿¤·¤Þ¤¹¤¬¡¢¤·¤Ð¤é¤¯¤ª<br>
273 ÂÔ¤Á¤¤¤¿¤À¤¤¤Æ¤«¤éÁàºî¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£")
274 (defconst mixi-warning-continuously-accessing
275 "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
277 (defmacro mixi-retrieve (url &optional post-data)
278 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-retrieve"))
281 (defmacro mixi-post-form (url fields)
282 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-post-form"))
285 (defun mixi-parse-buffer (url buffer &optional post-data)
286 (when (string-match mixi-message-adult-contents buffer)
287 (if mixi-accept-adult-contents
288 (setq buffer (mixi-retrieve url "submit=agree"))
289 (setq buffer (mixi-retrieve (concat url "?")))))
290 (when (string-match mixi-warning-continuously-accessing buffer)
291 (error (mixi-message "Access denied. Please wait a while and increase "
292 "the value of `mixi-continuously-access-interval'.")))
293 (if (not (string-match mixi-message-continuously-accessing buffer))
295 (message (mixi-message "Waiting for continuously accessing..."))
296 (sleep-for mixi-continuously-access-interval)
297 (mixi-retrieve url post-data)))
299 (defmacro mixi-expand-url (url)
300 `(if (string-match "^http" ,url)
302 (concat mixi-url ,url)))
304 ;; FIXME: Support files.
305 (defun mixi-make-form-data (fields)
306 "Make form data and return (CONTENT-TYPE . FORM-DATA)."
307 (let* ((boundary (apply 'format "--_%d_%d_%d" (current-time)))
308 (content-type (concat "multipart/form-data; boundary=" boundary))
312 (concat "--" boundary "\r\n"
313 "Content-Disposition: form-data; name=\""
316 (encode-coding-string (cdr field) mixi-coding-system)))
318 (cons content-type (concat form-data "\r\n--" boundary "--"))))
320 (defun mixi-url-retrieve (url &optional post-data extra-headers)
321 "Retrieve the URL and return gotten strings."
322 (let* ((url-request-method (if post-data "POST" "GET"))
323 (url-request-data post-data)
324 (url-request-extra-headers extra-headers)
325 (url (mixi-expand-url url))
327 (buffer (url-retrieve-synchronously url))
329 (unless (bufferp buffer)
330 (error (mixi-message "Cannot retrieve: " url)))
331 (with-current-buffer buffer
332 (goto-char (point-min))
333 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
334 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
335 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
336 (error (mixi-message "Cannot retrieve: " url)))
337 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
338 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
340 (mixi-parse-buffer url ret post-data))))
342 (defun mixi-url-post-form (url fields)
343 (let* ((form-data (mixi-make-form-data fields))
344 (extra-headers `(("Content-Type" . ,(car form-data)))))
345 (mixi-url-retrieve url (cdr form-data) extra-headers)))
347 (defun mixi-w3m-retrieve (url &optional post-data)
348 "Retrieve the URL and return gotten strings."
349 (let ((url (mixi-expand-url url)))
351 (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
352 (error (mixi-message "Cannot retrieve: " url))
353 (w3m-decode-buffer url)
354 (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
355 (mixi-parse-buffer url ret post-data))))))
357 (defun mixi-w3m-post-form (url fields)
358 (let ((form-data (mixi-make-form-data fields)))
359 (mixi-w3m-retrieve url form-data)))
361 (defun mixi-curl-retrieve (url &optional post-data form-data)
362 "Retrieve the URL and return gotten strings."
364 (if (fboundp 'set-buffer-multibyte)
365 (set-buffer-multibyte nil))
366 (let ((orig-mode (default-file-modes))
367 (coding-system-for-read 'binary)
368 (coding-system-for-write 'binary)
372 (set-default-file-modes 448)
374 (apply #'start-process "curl" (current-buffer)
376 (append (if post-data '("-d" "@-"))
379 "-b" mixi-curl-cookie-file
380 "-c" mixi-curl-cookie-file
381 (mixi-expand-url url)))))
382 (set-process-sentinel process #'ignore))
383 (set-default-file-modes orig-mode))
385 (process-send-string process (concat post-data "\n"))
386 (process-send-eof process))
387 (while (eq (process-status process) 'run)
388 (accept-process-output process 1))
389 (goto-char (point-min))
390 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
391 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
392 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
393 (error (mixi-message "Cannot retrieve: " url)))
394 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
395 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
396 (mixi-parse-buffer url ret post-data))))
398 (defun mixi-curl-post-form (url fields)
400 (mapcar (lambda (field)
401 (push "-F" form-data)
402 (push (concat (car field) "="
403 (encode-coding-string (cdr field)
407 (mixi-curl-retrieve url nil (reverse form-data))))
409 (defconst mixi-my-id-regexp
410 "<a href=\"show_profile\\.pl\\?id=\\([0-9]+\\)")
412 (defun mixi-login (&optional email password)
414 (when (and (eq mixi-backend 'w3m) (not w3m-use-cookies))
415 (error (mixi-message "Require to accept cookies. Please set "
416 "`w3m-use-cookies' to t.")))
417 (let ((email (or email mixi-default-email
418 (read-from-minibuffer (mixi-message "Login Email: "))))
419 (password (or password mixi-default-password
420 (read-passwd (mixi-message "Login Password: ")))))
421 (let ((url (mixi-expand-url "/login.pl")))
422 (when (and mixi-login-use-ssl (string-match "^http:" url))
423 (setq url (replace-match "https:" nil nil url)))
424 (let ((buffer (mixi-retrieve url
425 (concat "email=" email
426 "&password=" password
429 (unless (string-match "url=/check\\.pl\\?n=" buffer)
430 (error (mixi-message "Cannot login")))
431 (setq buffer (mixi-retrieve "/check.pl?n=home.pl"))
432 (if (string-match mixi-my-id-regexp buffer)
433 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
434 (error (mixi-message "Cannot login")))))))
436 (defun mixi-logout ()
437 (mixi-retrieve "/logout.pl"))
439 (defconst mixi-login-form "<form action=\"/login.pl\" method=\"post\" name=\"login_form\">")
441 (defmacro with-mixi-retrieve (url &rest body)
442 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
445 (insert (mixi-retrieve ,url))
446 (goto-char (point-min))
447 (when (search-forward mixi-login-form nil t)
450 (insert (mixi-retrieve ,url))))
451 (goto-char (point-min))
453 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
454 (put 'with-mixi-retrieve 'edebug-form-spec '(body))
456 (defmacro with-mixi-post-form (url fields &rest body)
457 `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
460 (insert (mixi-post-form ,url ,fields))
461 (goto-char (point-min))
462 (when (search-forward mixi-login-form nil t)
465 (insert (mixi-post-form ,url ,fields))))
466 (goto-char (point-min))
468 (put 'with-mixi-post-form 'lisp-indent-function 'defun)
469 (put 'with-mixi-post-form 'edebug-form-spec '(body))
471 (defun mixi-get-matched-items (url regexp &optional range reverse)
472 "Get matched items to REGEXP in URL."
476 (while (and (or (null range) (< (length ids) range))
477 (or (= page 1) (and (stringp url) (string-match "%d" url))))
478 (with-mixi-retrieve (when url (format url page))
479 (let ((func (if reverse (progn
480 (goto-char (point-max))
484 (while (and (funcall func regexp nil t)
485 (or (null range) (< (length ids) range)))
488 (while (match-string num)
489 (setq list (cons (match-string num) list))
491 (when (not (member (reverse list) ids))
493 (setq ids (cons (reverse list) ids)))))
499 ;; stolen (and modified) from shimbun.el
500 (defun mixi-remove-markup (string)
501 "Remove markups from STRING."
503 (insert (or string ""))
505 (goto-char (point-min))
506 (while (search-forward "<!--" nil t)
507 (delete-region (match-beginning 0)
508 (or (search-forward "-->" nil t)
510 (goto-char (point-min))
511 (while (re-search-forward "<[^>]+>" nil t)
512 (replace-match "" t t))
513 (goto-char (point-min))
514 (while (re-search-forward "
\r" nil t)
515 (replace-match "\n" t t)))
516 ;; FIXME: Decode entities.
519 ;; stolen (and modified) from w3m.el
520 (defconst mixi-entity-alist '(("gt" . ">")
523 "Alist of html character entities and values.")
525 ;; stolen (and modified) from w3m.el
526 (defun mixi-encode-specials-string (str)
527 "Encode special characters in the string STR."
530 (while (string-match "[<>&]" str pos)
533 (cons (car (rassoc (match-string 0 str) mixi-entity-alist))
535 (cons (substring str pos (match-beginning 0))
539 (apply 'concat (nreverse (cons (substring str pos) buf)))
542 ;; stolen (and modified) from w3m.el
543 (defun mixi-url-encode-string (string)
544 (apply (function concat)
548 ((eq char ?\n) ; newline
550 ((string-match "[-a-zA-Z0-9_:/.]" (char-to-string char)) ; xxx?
551 (char-to-string char)) ; printable
552 ((char-equal char ?\x20) ; space
555 (format "%%%02x" char)))) ; escape
556 ;; Coerce a string into a list of chars.
557 (append (encode-coding-string (or string "") mixi-coding-system)
560 (defun mixi-url-encode-and-quote-percent-string (string)
561 (let ((string (mixi-url-encode-string string))
563 (while (string-match "%" string pos)
564 (setq string (replace-match "%%" nil nil string))
565 (setq pos (+ (match-end 0) 1)))
569 (defconst mixi-object-prefix "mixi-")
571 (defmacro mixi-object-class (object)
574 (defmacro mixi-object-p (object)
575 `(let ((class (mixi-object-class ,object)))
576 (when (symbolp class)
577 (eq (string-match (concat "^" mixi-object-prefix)
578 (symbol-name class)) 0))))
580 (defun mixi-object-name (object)
581 "Return the name of OBJECT."
582 (unless (mixi-object-p object)
583 (signal 'wrong-type-argument (list 'mixi-object-p object)))
584 (let ((class (mixi-object-class object)))
585 (substring (symbol-name class) (length mixi-object-prefix))))
587 (defun mixi-read-object (exp)
588 "Read one Lisp expression as mixi object."
589 (if (mixi-object-p exp)
590 (let ((func (intern (concat mixi-object-prefix "make-"
591 (mixi-object-name exp))))
592 (args (mapcar (lambda (arg)
593 (mixi-read-object arg))
595 (let ((object (apply func (cdr args))))
597 (mixi-object-set-timestamp object (car args)))
601 (defun mixi-object-timestamp (object)
602 "Return the timestamp of OJBECT."
603 (unless (mixi-object-p object)
604 (signal 'wrong-type-argument (list 'mixi-object-p object)))
605 (aref (cdr object) 0))
606 (defalias 'mixi-object-realized-p 'mixi-object-timestamp)
608 (defun mixi-object-owner (object)
609 "Return the owner of OBJECT."
610 (unless (mixi-object-p object)
611 (signal 'wrong-type-argument (list 'mixi-object-p object)))
612 (let ((func (intern (concat mixi-object-prefix
613 (mixi-object-name object) "-owner"))))
614 (funcall func object)))
616 (defun mixi-object-id (object)
617 "Return the id of OBJECT."
618 (unless (mixi-object-p object)
619 (signal 'wrong-type-argument (list 'mixi-object-p object)))
620 (let ((func (intern (concat mixi-object-prefix
621 (mixi-object-name object) "-id"))))
622 (funcall func object)))
624 (defun mixi-object-time (object)
625 "Return the time of OBJECT."
626 (unless (mixi-object-p object)
627 (signal 'wrong-type-argument (list 'mixi-object-p object)))
628 (let ((func (intern (concat mixi-object-prefix
629 (mixi-object-name object) "-time"))))
630 (funcall func object)))
632 (defun mixi-object-title (object)
633 "Return the title of OBJECT."
634 (unless (mixi-object-p object)
635 (signal 'wrong-type-argument (list 'mixi-object-p object)))
636 (let ((func (intern (concat mixi-object-prefix
637 (mixi-object-name object) "-title"))))
638 (funcall func object)))
640 (defun mixi-object-content (object)
641 "Return the content of OBJECT."
642 (unless (mixi-object-p object)
643 (signal 'wrong-type-argument (list 'mixi-object-p object)))
644 (let ((func (intern (concat mixi-object-prefix
645 (mixi-object-name object) "-content"))))
646 (funcall func object)))
648 (defun mixi-object-set-timestamp (object timestamp)
649 "Set the timestamp of OBJECT."
650 (unless (mixi-object-p object)
651 (signal 'wrong-type-argument (list 'mixi-object-p object)))
652 (aset (cdr object) 0 timestamp))
654 (defmacro mixi-object-touch (object)
655 `(mixi-object-set-timestamp ,object (current-time)))
657 (defconst mixi-object-url-regexp
658 "/\\(show\\|view\\)_\\([a-z]+\\)\\.pl")
660 (defun mixi-make-object-from-url (url)
661 "Return a mixi object from URL."
662 (if (string-match mixi-object-url-regexp url)
663 (let ((name (match-string 2 url)))
664 (cond ((string= name "bbs")
666 ((string= name "profile")
667 (setq name "friend")))
668 (let ((func (intern (concat mixi-object-prefix "make-" name
671 (when (string-match "/home\\.pl" url)
672 (mixi-make-friend-from-url url))))
675 ;; stolen from time-date.el
676 (defun mixi-time-less-p (t1 t2)
677 "Say whether time value T1 is less than time value T2."
678 (unless (numberp (cdr t1))
679 (setq t1 (cons (car t1) (car (cdr t1)))))
680 (unless (numberp (cdr t2))
681 (setq t2 (cons (car t2) (car (cdr t2)))))
682 (or (< (car t1) (car t2))
683 (and (= (car t1) (car t2))
684 (< (cdr t1) (cdr t2)))))
686 (defun mixi-time-add (t1 t2)
687 "Add two time values. One should represent a time difference."
688 (unless (numberp (cdr t1))
689 (setq t1 (cons (car t1) (car (cdr t1)))))
690 (unless (numberp (cdr t2))
691 (setq t2 (cons (car t2) (car (cdr t2)))))
692 (let ((low (+ (cdr t1) (cdr t2))))
693 (cons (+ (car t1) (car t2) (lsh low -16)) low)))
695 ;; stolen from time-date.el
696 (defun mixi-seconds-to-time (seconds)
697 "Convert SECONDS (a floating point number) to a time value."
698 (cons (floor seconds 65536)
699 (floor (mod seconds 65536))))
701 (defun mixi-cache-expired-p (object)
702 "Whether a cache of OBJECT is expired."
703 (let ((timestamp (mixi-object-timestamp object)))
704 (unless (or (null mixi-cache-expires)
706 (if (numberp mixi-cache-expires)
708 (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
712 (defun mixi-make-cache (key value table)
713 "Make a cache object and return it."
714 (let ((cache (gethash key table)))
715 (if (and cache (not (mixi-cache-expired-p cache)))
717 (puthash key value table))))
719 (defconst mixi-cache-file-regexp "[a-z]+-cache$")
720 (defconst mixi-cache-regexp (concat mixi-object-prefix
721 mixi-cache-file-regexp))
723 (defun mixi-save-cache ()
724 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
725 (unless (file-directory-p cache-directory)
726 (make-directory cache-directory t))
727 (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
729 (with-temp-file (expand-file-name
730 (substring (symbol-name (car caches))
731 (length mixi-object-prefix))
733 (let ((coding-system-for-write mixi-coding-system)
734 (cache (symbol-value (car caches))))
735 (insert "#s(hash-table size "
736 (number-to-string (hash-table-count cache))
737 " test equal data (\n")
740 (let (print-level print-length)
741 (insert (prin1-to-string key) " "
742 (prin1-to-string value) "\n")))
745 (setq caches (cdr caches))))))
747 ;; stolen (and modified) from lsdb.el
748 (defun mixi-read-cache (&optional marker)
749 "Read one Lisp expression as text from MARKER, return as Lisp object."
752 (if (looking-at "^#s(")
755 (forward-char 2);skip "#s"
756 (forward-sexp);move to the left paren
759 (buffer-disable-undo)
760 (insert-buffer-substring (marker-buffer marker)
762 (goto-char (point-min))
764 (let ((object (read (current-buffer)))
766 (if (eq 'hash-table (car object))
768 (setq data (plist-get (cdr object) 'data))
770 (pop data);throw it away
771 (mixi-read-object (pop data))))
775 (defun mixi-load-cache ()
776 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
777 (when (file-directory-p cache-directory)
778 ;; FIXME: Load friend and community first.
779 (let ((files (directory-files cache-directory t
780 mixi-cache-file-regexp)))
782 (let ((buffer (find-file-noselect (car files))))
786 (goto-char (point-min))
787 (re-search-forward "^#s(")
788 (goto-char (match-beginning 0))
789 (mixi-read-cache (point-marker)))
790 (kill-buffer buffer)))
791 (setq files (cdr files)))))))
794 (defvar mixi-friend-cache (make-hash-table :test 'equal))
795 (defun mixi-make-friend (id &optional nick name sex address age birthday
796 blood-type birthplace hobby job organization
798 "Return a friend object."
799 (mixi-make-cache id (cons 'mixi-friend (vector nil id nick name sex address
800 age birthday blood-type
802 organization profile))
805 (defun mixi-make-me ()
806 "Return a my object."
808 (with-mixi-retrieve "/home.pl"
809 (if (re-search-forward mixi-my-id-regexp nil t)
810 (setq mixi-me (mixi-make-friend (match-string 1)))
811 (signal 'error (list 'who-am-i)))))
814 (defconst mixi-friend-url-regexp
815 "/show_\\(friend\\|profile\\)\\.pl\\?id=\\([0-9]+\\)")
817 (defun mixi-make-friend-from-url (url)
818 "Return a friend object from URL."
819 (if (string-match mixi-friend-url-regexp url)
820 (let ((id (match-string 2 url)))
821 (mixi-make-friend id))
822 (when (string-match "/home\\.pl" url)
825 (defmacro mixi-friend-p (friend)
826 `(eq (mixi-object-class ,friend) 'mixi-friend))
828 (defmacro mixi-friend-page (friend)
829 `(concat "/show_profile.pl?id=" (mixi-friend-id ,friend)))
831 (defconst mixi-friend-nick-regexp
832 "<h3>\\(.*\\)¤µ¤ó([0-9]+)</h3>")
833 (defconst mixi-friend-name-regexp
834 "<dt>̾Á°</dt>\n?<dd>\\(.+?\\)\\(<img\\|</dd>\\)")
835 (defconst mixi-friend-sex-regexp
836 "<dt>ÀÊÌ</dt>\n?<dd>\\([Ã˽÷]\\)À\\(<img\\|</dd>\\)")
837 (defconst mixi-friend-address-regexp
838 "<dt>¸½½»½ê</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
839 (defconst mixi-friend-age-regexp
840 "<dt>ǯÎð</dt>\n?<dd>\\([0-9]+\\)ºÐ\\( <img\\|</dd>\\)")
841 (defconst mixi-friend-birthday-regexp
842 "<dt>ÃÂÀ¸Æü</dt>\n?<dd>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(<img \\|</dd>\\)")
843 (defconst mixi-friend-blood-type-regexp
844 "<dt>·ì±Õ·¿</dt>\n?<dd>\\([ABO]B?\\)·¿\\(<img \\|</dd>\\)")
845 (defconst mixi-friend-birthplace-regexp
846 "<dt>½Ð¿ÈÃÏ</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
847 (defconst mixi-friend-hobby-regexp
848 "<dt>¼ñÌ£</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
849 (defconst mixi-friend-job-regexp
850 "<dt>¿¦¶È</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
851 (defconst mixi-friend-organization-regexp
852 "<dt>½ê°</dt>\n?<dd>\\(.+?\\)\\(<img \\|</dd>\\)")
853 (defconst mixi-friend-profile-regexp
854 "<dt>¼«¸Ê¾Ò²ð</dt>\n?<dd class=\"userInput\">\\(.+?\\)</dd>")
856 (defun mixi-realize-friend (friend)
858 ;; FIXME: Check an expiration of cache?
859 (unless (mixi-object-realized-p friend)
860 (with-mixi-retrieve (mixi-friend-page friend)
861 (let ((case-fold-search t))
862 (if (re-search-forward mixi-friend-nick-regexp nil t)
863 (mixi-friend-set-nick friend (match-string 1))
864 (mixi-realization-error 'cannot-find-nick friend))
865 (when (re-search-forward mixi-friend-name-regexp nil t)
866 (mixi-friend-set-name friend (match-string 1)))
867 (when (re-search-forward mixi-friend-sex-regexp nil t)
868 (mixi-friend-set-sex friend (if (string= (match-string 1) "ÃË")
870 (when (re-search-forward mixi-friend-address-regexp nil t)
871 (mixi-friend-set-address friend (match-string 1)))
872 (when (re-search-forward mixi-friend-age-regexp nil t)
873 (mixi-friend-set-age friend (string-to-number (match-string 1))))
874 (when (re-search-forward mixi-friend-birthday-regexp nil t)
875 (mixi-friend-set-birthday
876 friend (list (string-to-number (match-string 1))
877 (string-to-number (match-string 2)))))
878 (when (re-search-forward mixi-friend-blood-type-regexp nil t)
879 (mixi-friend-set-blood-type friend (intern (match-string 1))))
880 (when (re-search-forward mixi-friend-birthplace-regexp nil t)
881 (mixi-friend-set-birthplace friend (match-string 1)))
882 (when (re-search-forward mixi-friend-hobby-regexp nil t)
883 (mixi-friend-set-hobby friend (split-string (match-string 1) ", ")))
884 (when (re-search-forward mixi-friend-job-regexp nil t)
885 (mixi-friend-set-job friend (match-string 1)))
886 (when (re-search-forward mixi-friend-organization-regexp nil t)
887 (mixi-friend-set-organization friend (match-string 1)))
888 (when (re-search-forward mixi-friend-profile-regexp nil t)
889 (mixi-friend-set-profile friend (match-string 1)))))
890 (mixi-object-touch friend)))
892 (defun mixi-friend-id (friend)
893 "Return the id of FRIEND."
894 (unless (mixi-friend-p friend)
895 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
896 (aref (cdr friend) 1))
898 (defun mixi-friend-nick (friend)
899 "Return the nick of FRIEND."
900 (unless (mixi-friend-p friend)
901 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
902 (unless (aref (cdr friend) 2)
903 (mixi-realize-friend friend))
904 (aref (cdr friend) 2))
906 (defun mixi-friend-name (friend)
907 "Return the name of FRIEND."
908 (unless (mixi-friend-p friend)
909 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
910 (mixi-realize-friend friend)
911 (aref (cdr friend) 3))
913 (defun mixi-friend-sex (friend)
914 "Return the sex of FRIEND."
915 (unless (mixi-friend-p friend)
916 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
917 (mixi-realize-friend friend)
918 (aref (cdr friend) 4))
920 (defun mixi-friend-address (friend)
921 "Return the address of FRIEND."
922 (unless (mixi-friend-p friend)
923 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
924 (mixi-realize-friend friend)
925 (aref (cdr friend) 5))
927 (defun mixi-friend-age (friend)
928 "Return the age of FRIEND."
929 (unless (mixi-friend-p friend)
930 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
931 (mixi-realize-friend friend)
932 (aref (cdr friend) 6))
934 (defun mixi-friend-birthday (friend)
935 "Return the birthday of FRIEND."
936 (unless (mixi-friend-p friend)
937 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
938 (mixi-realize-friend friend)
939 (aref (cdr friend) 7))
941 (defun mixi-friend-blood-type (friend)
942 "Return the blood type of FRIEND."
943 (unless (mixi-friend-p friend)
944 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
945 (mixi-realize-friend friend)
946 (aref (cdr friend) 8))
948 (defun mixi-friend-birthplace (friend)
949 "Return the birthplace of FRIEND."
950 (unless (mixi-friend-p friend)
951 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
952 (mixi-realize-friend friend)
953 (aref (cdr friend) 9))
955 (defun mixi-friend-hobby (friend)
956 "Return the hobby of FRIEND."
957 (unless (mixi-friend-p friend)
958 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
959 (mixi-realize-friend friend)
960 (aref (cdr friend) 10))
962 (defun mixi-friend-job (friend)
963 "Return the job of FRIEND."
964 (unless (mixi-friend-p friend)
965 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
966 (mixi-realize-friend friend)
967 (aref (cdr friend) 11))
969 (defun mixi-friend-organization (friend)
970 "Return the organization of FRIEND."
971 (unless (mixi-friend-p friend)
972 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
973 (mixi-realize-friend friend)
974 (aref (cdr friend) 12))
976 (defun mixi-friend-profile (friend)
977 "Return the profile of FRIEND."
978 (unless (mixi-friend-p friend)
979 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
980 (mixi-realize-friend friend)
981 (aref (cdr friend) 13))
983 (defun mixi-friend-set-nick (friend nick)
984 "Set the nick of FRIEND."
985 (unless (mixi-friend-p friend)
986 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
987 (aset (cdr friend) 2 nick))
989 (defun mixi-friend-set-name (friend name)
990 "Set the name of FRIEND."
991 (unless (mixi-friend-p friend)
992 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
993 (aset (cdr friend) 3 name))
995 (defun mixi-friend-set-sex (friend sex)
996 "Set the sex of FRIEND."
997 (unless (mixi-friend-p friend)
998 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
999 (aset (cdr friend) 4 sex))
1001 (defun mixi-friend-set-address (friend address)
1002 "Set the address of FRIEND."
1003 (unless (mixi-friend-p friend)
1004 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1005 (aset (cdr friend) 5 address))
1007 (defun mixi-friend-set-age (friend age)
1008 "Set the age of FRIEND."
1009 (unless (mixi-friend-p friend)
1010 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1011 (aset (cdr friend) 6 age))
1013 (defun mixi-friend-set-birthday (friend birthday)
1014 "Set the birthday of FRIEND."
1015 (unless (mixi-friend-p friend)
1016 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1017 (aset (cdr friend) 7 birthday))
1019 (defun mixi-friend-set-blood-type (friend blood-type)
1020 "Set the blood type of FRIEND."
1021 (unless (mixi-friend-p friend)
1022 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1023 (aset (cdr friend) 8 blood-type))
1025 (defun mixi-friend-set-birthplace (friend birthplace)
1026 "Set the birthplace of FRIEND."
1027 (unless (mixi-friend-p friend)
1028 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1029 (aset (cdr friend) 9 birthplace))
1031 (defun mixi-friend-set-hobby (friend hobby)
1032 "Set the hobby of FRIEND."
1033 (unless (mixi-friend-p friend)
1034 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1035 (aset (cdr friend) 10 hobby))
1037 (defun mixi-friend-set-job (friend job)
1038 "Set the job of FRIEND."
1039 (unless (mixi-friend-p friend)
1040 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1041 (aset (cdr friend) 11 job))
1043 (defun mixi-friend-set-organization (friend organization)
1044 "Set the organization of FRIEND."
1045 (unless (mixi-friend-p friend)
1046 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1047 (aset (cdr friend) 12 organization))
1049 (defun mixi-friend-set-profile (friend profile)
1050 "Set the profile of FRIEND."
1051 (unless (mixi-friend-p friend)
1052 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1053 (aset (cdr friend) 13 profile))
1055 (defun mixi-my-friend-list-page (&optional dummy)
1056 (concat "/list_friend_simple.pl?page=%d"))
1058 (defun mixi-friend-list-page (friend)
1059 (concat "/list_friend.pl?page=%d&id=" (mixi-friend-id friend)))
1061 (defconst mixi-friend-list-id-regexp
1062 "<a href=\"?show_friend\\.pl\\?id=\\([0-9]+\\)\"?")
1063 (defconst mixi-my-friend-list-nick-regexp
1064 "<p>\\(.+\\)([0-9]+)</p>")
1065 (defconst mixi-friend-list-nick-regexp
1066 "<span>\\(.+\\)¤µ¤ó([0-9]+)</span>")
1069 (defun mixi-get-friends (&rest friend-or-range)
1070 "Get friends of FRIEND."
1071 (when (> (length friend-or-range) 2)
1072 (signal 'wrong-number-of-arguments (list 'mixi-get-friends
1073 (length friend-or-range))))
1074 (let ((friend (nth 0 friend-or-range))
1075 (range (nth 1 friend-or-range)))
1076 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1077 (setq friend (nth 1 friend-or-range))
1078 (setq range (nth 0 friend-or-range)))
1079 (unless (or (null friend) (mixi-friend-p friend))
1080 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1081 (let (list-page list-nick-regexp)
1082 (if (or (null friend) (equal friend mixi-me))
1083 (setq list-page 'mixi-my-friend-list-page
1084 list-nick-regexp mixi-my-friend-list-nick-regexp)
1085 (setq list-page 'mixi-friend-list-page
1086 list-nick-regexp mixi-friend-list-nick-regexp))
1087 (let ((ids (mixi-get-matched-items (funcall list-page friend)
1088 mixi-friend-list-id-regexp
1090 (nicks (mixi-get-matched-items (funcall list-page friend)
1095 (while (< index (length ids))
1096 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1097 (nth 0 (nth index nicks))) ret))
1102 (defmacro mixi-favorite-list-page ()
1103 `(concat "/list_bookmark.pl?page=%d"))
1105 (defconst mixi-favorite-list-regexp
1106 "<td bgcolor=\"#FDF9F2\"><font color=\"#996600\">̾Á°</font></td>
1107 <td colspan=\"2\" bgcolor=\"#FFFFFF\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></td>")
1110 (defun mixi-get-favorites (&optional range)
1112 (let ((items (mixi-get-matched-items (mixi-favorite-list-page)
1113 mixi-favorite-list-regexp
1115 (mapcar (lambda (item)
1116 (mixi-make-friend (nth 0 item) (nth 1 item)))
1120 (defun mixi-make-log (friend time)
1121 "Return a log object."
1122 (cons 'mixi-log (vector friend time)))
1124 (defmacro mixi-log-p (log)
1125 `(eq (mixi-object-class ,log) 'mixi-log))
1127 (defun mixi-log-friend (log)
1128 "Return the friend of LOG."
1129 (unless (mixi-log-p log)
1130 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1133 (defun mixi-log-time (log)
1134 "Return the time of LOG."
1135 (unless (mixi-log-p log)
1136 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1139 (defmacro mixi-log-list-page ()
1140 `(concat "/show_log.pl"))
1142 (defconst mixi-log-list-regexp
1143 "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)</a>")
1146 (defun mixi-get-logs (&optional range)
1148 (let ((items (mixi-get-matched-items (mixi-log-list-page)
1149 mixi-log-list-regexp
1151 (mapcar (lambda (item)
1152 (mixi-make-log (mixi-make-friend (nth 5 item) (nth 6 item))
1154 (string-to-number (nth 4 item))
1155 (string-to-number (nth 3 item))
1156 (string-to-number (nth 2 item))
1157 (string-to-number (nth 1 item))
1158 (string-to-number (nth 0 item)))))
1161 ;; Recommended friend.
1162 (defmacro mixi-recommended-friend-list-page ()
1163 `(concat "http://indies.mixi.jp/recommend.pl"))
1165 (defconst mixi-recommended-friend-list-regexp
1166 "<div class=\"iconListImage\"><a href=\"http://mixi\\.jp/show_friend\\.pl\\?id=\\([0-9]+\\)\" [^>]+>.+</a></div><span>\\(.+?\\)¤µ¤ó([0-9]+)</span>")
1169 (defun mixi-get-recommended-friends (&optional range)
1170 "Get recommended friends."
1171 (let ((items (mixi-get-matched-items (mixi-recommended-friend-list-page)
1172 mixi-recommended-friend-list-regexp
1174 (mapcar (lambda (item)
1175 (mixi-make-friend (nth 0 item) (nth 1 item)))
1179 (defvar mixi-diary-cache (make-hash-table :test 'equal))
1180 (defun mixi-make-diary (owner id &optional comment-count time title content)
1181 "Return a diary object."
1182 (let ((owner (or owner (mixi-make-me))))
1183 (mixi-make-cache (list (mixi-friend-id owner) id)
1184 (cons 'mixi-diary (vector nil owner id comment-count time
1188 (defconst mixi-diary-url-regexp
1189 "/view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?")
1191 (defun mixi-make-diary-from-url (url)
1192 "Return a diary object from URL."
1193 (when (string-match mixi-diary-url-regexp url)
1194 (let ((id (match-string 1 url))
1195 (owner-id (match-string 2 url))
1196 (comment-count (match-string 4 url)))
1197 (mixi-make-diary (mixi-make-friend owner-id) id comment-count))))
1199 (defmacro mixi-diary-p (diary)
1200 `(eq (mixi-object-class ,diary) 'mixi-diary))
1202 (defmacro mixi-diary-page (diary)
1203 `(concat "/view_diary.pl?id=" (mixi-diary-id ,diary)
1204 "&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
1206 (defconst mixi-diary-closed-regexp
1207 "¤³¤ÎÆüµ¤Ë¥¢¥¯¥»¥¹¤Ç¤¤Þ¤»¤ó¡£°Ê²¼¤Î²ÄǽÀ¤¬¹Í¤¨¤é¤ì¤Þ¤¹¡£<br />")
1208 (defconst mixi-diary-owner-nick-regexp
1209 "<div class=\"diaryTitle\\(Friend\\)? clearfix\">
1210 <h2>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ</h2>")
1211 (defconst mixi-diary-title-regexp
1212 "<div class=\"listDiaryTitle\">
1213 <dl class=\"clearfix\">
1214 <dt>\\([^<\n]+\\)\\(<span>\\)?")
1215 (defconst mixi-diary-time-regexp
1216 "<dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\\([0-9]+\\):\\([0-9]+\\)</dd>")
1217 (defconst mixi-diary-content-regexp
1218 "<div class=\"txtconfirmArea\">
1219 \\(\\(.\\|\r?\n\\)*?\\)
1220 <!--/viewDiaryBox--></div>")
1222 (defun mixi-realize-diary (diary &optional page)
1224 ;; FIXME: Check an expiration of cache?
1225 (unless (mixi-object-realized-p diary)
1226 (with-mixi-retrieve (or page (mixi-diary-page diary))
1227 (let ((case-fold-search t))
1228 (unless (re-search-forward mixi-diary-closed-regexp nil t)
1229 (if (re-search-forward mixi-diary-owner-nick-regexp nil t)
1230 (mixi-friend-set-nick (mixi-diary-owner diary)
1232 (mixi-realization-error 'cannot-find-owner-nick diary))
1233 (if (re-search-forward mixi-diary-title-regexp nil t)
1234 (mixi-diary-set-title diary (match-string 1))
1235 (mixi-realization-error 'cannot-find-title diary))
1236 (if (re-search-forward mixi-diary-time-regexp nil t)
1237 (mixi-diary-set-time
1238 diary (encode-time 0 (string-to-number (match-string 5))
1239 (string-to-number (match-string 4))
1240 (string-to-number (match-string 3))
1241 (string-to-number (match-string 2))
1242 (string-to-number (match-string 1))))
1243 (mixi-realization-error 'cannot-find-time diary))
1244 (if (re-search-forward mixi-diary-content-regexp nil t)
1245 (mixi-diary-set-content diary (match-string 1))
1246 (mixi-realization-error 'cannot-find-content diary)))))
1247 (mixi-object-touch diary)))
1249 (defun mixi-diary-owner (diary)
1250 "Return the owner of DIARY."
1251 (unless (mixi-diary-p diary)
1252 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1253 (aref (cdr diary) 1))
1255 (defun mixi-diary-id (diary)
1256 "Return the id of DIARY."
1257 (unless (mixi-diary-p diary)
1258 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1259 (aref (cdr diary) 2))
1261 (defun mixi-diary-comment-count (diary)
1262 "Return the comment-count of DIARY."
1263 (unless (mixi-diary-p diary)
1264 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1265 (aref (cdr diary) 3))
1267 (defun mixi-diary-time (diary)
1268 "Return the time of DIARY."
1269 (unless (mixi-diary-p diary)
1270 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1271 (unless (aref (cdr diary) 3)
1272 (mixi-realize-diary diary))
1273 (aref (cdr diary) 4))
1275 (defun mixi-diary-title (diary)
1276 "Return the title of DIARY."
1277 (unless (mixi-diary-p diary)
1278 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1279 (unless (aref (cdr diary) 4)
1280 (mixi-realize-diary diary))
1281 (aref (cdr diary) 5))
1283 (defun mixi-diary-content (diary)
1284 "Return the content of DIARY."
1285 (unless (mixi-diary-p diary)
1286 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1287 (mixi-realize-diary diary)
1288 (aref (cdr diary) 6))
1290 (defun mixi-diary-set-comment-count (diary comment-count)
1291 "Set the comment-count of DIARY."
1292 (unless (mixi-diary-p diary)
1293 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1294 (aset (cdr diary) 3 comment-count))
1296 (defun mixi-diary-set-time (diary time)
1297 "Set the time of DIARY."
1298 (unless (mixi-diary-p diary)
1299 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1300 (aset (cdr diary) 4 time))
1302 (defun mixi-diary-set-title (diary title)
1303 "Set the title of DIARY."
1304 (unless (mixi-diary-p diary)
1305 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1306 (aset (cdr diary) 5 title))
1308 (defun mixi-diary-set-content (diary content)
1309 "Set the content of DIARY."
1310 (unless (mixi-diary-p diary)
1311 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1312 (aset (cdr diary) 6 content))
1314 (defmacro mixi-diary-list-page (&optional friend)
1315 `(concat "/list_diary.pl?page=%d"
1316 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1318 (defconst mixi-diary-list-regexp
1319 "<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>
1320 <dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\n?\\([0-9]+\\):\\([0-9]+\\)</dd>
1324 (defun mixi-get-diaries (&rest friend-or-range)
1325 "Get diaries of FRIEND."
1326 (when (> (length friend-or-range) 2)
1327 (signal 'wrong-number-of-arguments
1328 (list 'mixi-get-diaries (length friend-or-range))))
1329 (let ((friend (nth 0 friend-or-range))
1330 (range (nth 1 friend-or-range)))
1331 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1332 (setq friend (nth 1 friend-or-range))
1333 (setq range (nth 0 friend-or-range)))
1334 (unless (or (null friend) (mixi-friend-p friend))
1335 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1336 (let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
1337 mixi-diary-list-regexp
1339 (mapcar (lambda (item)
1340 (mixi-make-diary friend (nth 1 item) nil
1342 0 (string-to-number (nth 8 item))
1343 (string-to-number (nth 7 item))
1344 (string-to-number (nth 6 item))
1345 (string-to-number (nth 5 item))
1346 (string-to-number (nth 4 item)))
1350 (defmacro mixi-new-diary-list-page ()
1351 `(concat "/new_friend_diary.pl?page=%d"))
1353 (defconst mixi-new-diary-list-regexp
1354 "<dt>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</dt>
1355 <dd><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\">\\(.+\\)</a> (\\(.*\\))<div ")
1356 (defconst mixi-new-diary-list-title-regexp
1357 "\\(.+\\) (\\([0-9]+\\))")
1360 (defun mixi-get-new-diaries (&optional range)
1362 (let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
1363 mixi-new-diary-list-regexp
1366 (mapcar (lambda (item)
1367 (let ((title (nth 7 item))
1369 (when (string-match mixi-new-diary-list-title-regexp
1371 (setq count (string-to-number (match-string 2 title)))
1372 (setq title (match-string 1 title)))
1373 (let* ((diary (mixi-make-diary
1374 (mixi-make-friend (nth 6 item)
1377 (comment-count (mixi-diary-comment-count diary)))
1378 (mixi-diary-set-time diary
1380 0 (string-to-number (nth 4 item))
1381 (string-to-number (nth 3 item))
1382 (string-to-number (nth 2 item))
1383 (string-to-number (nth 1 item))
1384 (string-to-number (nth 0 item))))
1385 (mixi-diary-set-title diary title)
1386 (when (or (null comment-count)
1387 (< comment-count count))
1388 (mixi-diary-set-comment-count diary count)
1392 (defmacro mixi-search-diary-list-page (keyword)
1393 `(concat "/search_diary.pl?page=%d&submit=search&keyword="
1394 (mixi-url-encode-and-quote-percent-string ,keyword)))
1396 (defconst mixi-search-diary-list-regexp
1398 <div class=\"listIcon\"><a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\"><img src=\".*\" alt=\".*\" /></a>
1399 <span class=\"name\"><a href=\"view_diary\\.pl\\?id=[0-9]+&owner_id=[0-9]+\">\\(.*\\)</a></span></div>
1400 <div class=\"listContents\">
1401 <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>
1402 <p class=\"description\">\\(.*\\)
1407 (defun mixi-search-diaries (keyword &optional range)
1408 (let ((items (mixi-get-matched-items (mixi-search-diary-list-page keyword)
1409 mixi-search-diary-list-regexp
1411 (year (nth 5 (decode-time (current-time))))
1412 (month (nth 4 (decode-time (current-time)))))
1413 (mapcar (lambda (item)
1414 (let ((month-of-item (string-to-number (nth 4 item))))
1415 (when (> month-of-item month)
1417 (setq month month-of-item)
1418 (mixi-make-diary (mixi-make-friend (nth 1 item) (nth 2 item))
1422 0 (string-to-number (nth 7 item))
1423 (string-to-number (nth 6 item))
1424 (string-to-number (nth 5 item))
1430 (defmacro mixi-post-diary-page ()
1431 `(concat "/add_diary.pl"))
1433 (defconst mixi-post-key-regexp
1434 "<input type=\"?hidden\"? name=\"?post_key\"? +value=\"\\([a-z0-9]+\\)\"")
1435 (defconst mixi-post-succeed-regexp
1436 "<p\\(\\| class=\"messageAlert\"\\)>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£</p>")
1438 ;; FIXME: Support photos.
1440 (defun mixi-post-diary (title content)
1442 (unless (stringp title)
1443 (signal 'wrong-type-argument (list 'stringp title)))
1444 (unless (stringp content)
1445 (signal 'wrong-type-argument (list 'stringp content)))
1446 (let ((fields `(("id" . ,(mixi-friend-id (mixi-make-me)))
1447 ("diary_title" . ,title)
1448 ("diary_body" . ,content)
1449 ("submit" . "main")))
1451 (with-mixi-post-form (mixi-post-diary-page) fields
1452 (if (re-search-forward mixi-post-key-regexp nil t)
1453 (setq post-key (match-string 1))
1454 (mixi-post-error 'cannot-find-key)))
1455 (setq fields `(("post_key" . ,post-key)
1456 ("id" . ,(mixi-friend-id (mixi-make-me)))
1457 ("diary_title" . ,title)
1458 ("diary_body" . ,content)
1459 ("submit" . "confirm")))
1460 (with-mixi-post-form (mixi-post-diary-page) fields
1461 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1462 (mixi-post-error 'cannot-find-succeed)))))
1464 ;; Community object.
1465 (defvar mixi-community-cache (make-hash-table :test 'equal))
1466 (defun mixi-make-community (id &optional name birthday owner category members
1467 open-level authority description)
1468 "Return a community object."
1469 (mixi-make-cache id (cons 'mixi-community (vector nil id name birthday owner
1471 open-level authority
1473 mixi-community-cache))
1475 (defconst mixi-community-url-regexp
1476 "/view_community\\.pl\\?id=\\([0-9]+\\)")
1478 (defun mixi-make-community-from-url (url)
1479 "Return a community object from URL."
1480 (when (string-match mixi-community-url-regexp url)
1481 (let ((id (match-string 1 url)))
1482 (mixi-make-community id))))
1484 (defmacro mixi-community-p (community)
1485 `(eq (mixi-object-class ,community) 'mixi-community))
1487 (defmacro mixi-community-page (community)
1488 `(concat "/view_community.pl?id=" (mixi-community-id ,community)))
1490 ;; FIXME: Not community specific.
1491 (defconst mixi-community-nodata-regexp
1492 "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1493 (defconst mixi-community-name-regexp
1494 "<div class=\"pageTitle communityTitle002 communityTop\">
1496 (defconst mixi-community-birthday-regexp
1498 <dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br />")
1499 ;; FIXME: Care when the owner has seceded.
1500 (defconst mixi-community-owner-regexp
1503 <a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\\(.*\\)</a>")
1504 (defconst mixi-community-category-regexp
1507 (defconst mixi-community-members-regexp
1508 "<dt>¥á¥ó¥Ð¡¼¿ô</dt>
1509 <dd>\\([0-9]+\\)¿Í</dd>")
1510 (defconst mixi-community-open-level-regexp
1511 "<dt>»²²Ã¾ò·ï¤È<br />¸ø³«¥ì¥Ù¥ë</dt>
1513 (defconst mixi-community-authority-regexp
1514 "<dt>¥È¥Ô¥Ã¥¯¤Î<br />ºîÀ®¸¢¸Â</dt>
1520 (defconst mixi-community-description-regexp
1521 "<div id=\"communityIntro\">
1524 (defun mixi-realize-community (community)
1525 "Realize a COMMUNITY."
1526 ;; FIXME: Check an expiration of cache?
1527 (unless (mixi-object-realized-p community)
1528 (with-mixi-retrieve (mixi-community-page community)
1529 (let ((case-fold-search t))
1530 (if (re-search-forward mixi-community-nodata-regexp nil t)
1531 ;; FIXME: Set all members?
1532 (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1533 (if (re-search-forward mixi-community-name-regexp nil t)
1534 (mixi-community-set-name community (match-string 1))
1535 (mixi-realization-error 'cannot-find-name community))
1536 (if (re-search-forward mixi-community-birthday-regexp nil t)
1537 (mixi-community-set-birthday
1538 community (encode-time 0 0 0
1539 (string-to-number (match-string 3))
1540 (string-to-number (match-string 2))
1541 (string-to-number (match-string 1))))
1542 (mixi-realization-error 'cannot-find-birthday community))
1543 (if (re-search-forward mixi-community-owner-regexp nil t)
1544 (if (string= (match-string 1) "home.pl")
1545 (mixi-community-set-owner community (mixi-make-me))
1546 (mixi-community-set-owner community (mixi-make-friend
1549 (mixi-realization-error 'cannot-find-owner community))
1550 (if (re-search-forward mixi-community-category-regexp nil t)
1551 (mixi-community-set-category community (match-string 1))
1552 (mixi-realization-error 'cannot-find-category community))
1553 (if (re-search-forward mixi-community-members-regexp nil t)
1554 (mixi-community-set-members community
1555 (string-to-number (match-string 1)))
1556 (mixi-realization-error 'cannot-find-members community))
1557 (if (re-search-forward mixi-community-open-level-regexp nil t)
1558 (mixi-community-set-open-level community (match-string 1))
1559 (mixi-realization-error 'cannot-find-open-level community))
1560 (if (re-search-forward mixi-community-authority-regexp nil t)
1561 (mixi-community-set-authority community (match-string 1))
1562 (mixi-realization-error 'cannot-find-authority community))
1563 (if (re-search-forward mixi-community-description-regexp nil t)
1564 (mixi-community-set-description community (match-string 1))
1565 (mixi-realization-error 'cannot-find-description community)))))
1566 (mixi-object-touch community)))
1568 (defun mixi-community-id (community)
1569 "Return the id of COMMUNITY."
1570 (unless (mixi-community-p community)
1571 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1572 (aref (cdr community) 1))
1574 (defun mixi-community-name (community)
1575 "Return the name of COMMUNITY."
1576 (unless (mixi-community-p community)
1577 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1578 (unless (aref (cdr community) 2)
1579 (mixi-realize-community community))
1580 (aref (cdr community) 2))
1582 (defun mixi-community-birthday (community)
1583 "Return the birthday 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) 3))
1589 (defun mixi-community-owner (community)
1590 "Return the owner 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) 4))
1596 (defun mixi-community-category (community)
1597 "Return the category 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) 5))
1603 (defun mixi-community-members (community)
1604 "Return the members 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) 6))
1610 (defun mixi-community-open-level (community)
1611 "Return the open-level 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) 7))
1617 (defun mixi-community-authority (community)
1618 "Return the authority 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) 8))
1624 (defun mixi-community-description (community)
1625 "Return the description of COMMUNITY."
1626 (unless (mixi-community-p community)
1627 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1628 (mixi-realize-community community)
1629 (aref (cdr community) 9))
1631 (defun mixi-community-set-name (community name)
1632 "Set the name of COMMUNITY."
1633 (unless (mixi-community-p community)
1634 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1635 (aset (cdr community) 2 name))
1637 (defun mixi-community-set-birthday (community birthday)
1638 "Set the birthday of COMMUNITY."
1639 (unless (mixi-community-p community)
1640 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1641 (aset (cdr community) 3 birthday))
1643 (defun mixi-community-set-owner (community owner)
1644 "Set the owner of COMMUNITY."
1645 (unless (mixi-community-p community)
1646 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1647 (unless (mixi-friend-p owner)
1648 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1649 (aset (cdr community) 4 owner))
1651 (defun mixi-community-set-category (community category)
1652 "Set the category of COMMUNITY."
1653 (unless (mixi-community-p community)
1654 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1655 (aset (cdr community) 5 category))
1657 (defun mixi-community-set-members (community members)
1658 "Set the name of COMMUNITY."
1659 (unless (mixi-community-p community)
1660 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1661 (aset (cdr community) 6 members))
1663 (defun mixi-community-set-open-level (community open-level)
1664 "Set the name of COMMUNITY."
1665 (unless (mixi-community-p community)
1666 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1667 (aset (cdr community) 7 open-level))
1669 (defun mixi-community-set-authority (community authority)
1670 "Set the name of COMMUNITY."
1671 (unless (mixi-community-p community)
1672 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1673 (aset (cdr community) 8 authority))
1675 (defun mixi-community-set-description (community description)
1676 "Set the name of COMMUNITY."
1677 (unless (mixi-community-p community)
1678 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1679 (aset (cdr community) 9 description))
1681 (defmacro mixi-community-list-page (&optional friend)
1682 `(concat "/list_community.pl?page=%d"
1683 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1685 (defconst mixi-community-list-id-regexp
1686 "<a href=\"?view_community\\.pl\\?id=\\([0-9]+\\)\"?")
1687 (defconst mixi-community-list-name-regexp
1688 "<span>\\(.+\\)([0-9]+)</span>")
1691 (defun mixi-get-communities (&rest friend-or-range)
1692 "Get communities of FRIEND."
1693 (when (> (length friend-or-range) 2)
1694 (signal 'wrong-number-of-arguments
1695 (list 'mixi-get-communities (length friend-or-range))))
1696 (let ((friend (nth 0 friend-or-range))
1697 (range (nth 1 friend-or-range)))
1698 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1699 (setq friend (nth 1 friend-or-range))
1700 (setq range (nth 0 friend-or-range)))
1701 (unless (or (null friend) (mixi-friend-p friend))
1702 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1703 (let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
1704 mixi-community-list-id-regexp
1706 (names (mixi-get-matched-items (mixi-community-list-page friend)
1707 mixi-community-list-name-regexp
1711 (while (< index (length ids))
1712 (setq ret (cons (mixi-make-community (nth 0 (nth index ids))
1713 (nth 0 (nth index names))) ret))
1717 (defmacro mixi-search-community-list-page (keyword)
1718 `(concat "/search_community.pl?page=%d&&sort=date&type=com&submit=main"
1719 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
1722 (defconst mixi-search-community-list-regexp
1723 "<dt class=\"communityTitle\"><a href=\"view_community\\.pl\\?id=\\([0-9]+\\)\">\\(.+\\) ([0-9]+)</a>")
1725 ;; FIXME: Support category.
1727 (defun mixi-search-communities (keyword &optional range)
1728 (let ((items (mixi-get-matched-items (mixi-search-community-list-page
1730 mixi-search-community-list-regexp
1732 (mapcar (lambda (item)
1733 (mixi-make-community (nth 0 item) (nth 1 item)))
1736 ;; Recommended community.
1737 (defalias 'mixi-recommended-community-list-page
1738 'mixi-recommended-friend-list-page)
1740 (defconst mixi-recommended-community-list-regexp
1741 "<div class=\"iconListImage\"><a href=\"http://mixi\\.jp/view_community\\.pl\\?id=\\([0-9]+\\)\" [^>]+>.+</a></div><span>\\(.+\\)([0-9]+)</span>")
1744 (defun mixi-get-recommended-communities (&optional range)
1745 "Get recommended communities."
1746 (let ((items (mixi-get-matched-items (mixi-recommended-community-list-page)
1747 mixi-recommended-community-list-regexp
1749 (mapcar (lambda (item)
1750 (mixi-make-community (nth 0 item) (nth 1 item)))
1754 (defvar mixi-topic-cache (make-hash-table :test 'equal))
1755 (defun mixi-make-topic (community id &optional comment-count time title owner
1757 "Return a topic object."
1758 (mixi-make-cache (list (mixi-community-id community) id)
1759 (cons 'mixi-topic (vector nil community id comment-count
1760 time title owner content))
1763 (defconst mixi-topic-url-regexp
1764 "/view_bbs\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1766 (defun mixi-make-topic-from-url (url)
1767 "Return a topic object from URL."
1768 (when (string-match mixi-topic-url-regexp url)
1769 (let ((id (match-string 1 url))
1770 (comment-count (match-string 3 url))
1771 (community-id (match-string 4 url)))
1772 (mixi-make-topic (mixi-make-community community-id) id comment-count))))
1774 (defmacro mixi-topic-p (topic)
1775 `(eq (mixi-object-class ,topic) 'mixi-topic))
1777 (defmacro mixi-topic-page (topic)
1778 `(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
1779 "&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
1781 (defconst mixi-topic-community-regexp
1782 "<div class=\"pageTitle communityTitle002\">
1783 <h2>\\(.+\\) ¥È¥Ô¥Ã¥¯</h2>")
1784 (defconst mixi-topic-title-regexp
1785 "<span class=\"title\">\\([^<]+\\)</span>")
1786 (defconst mixi-topic-time-regexp
1787 "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>")
1788 (defconst mixi-topic-owner-regexp
1789 "<dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)\\(¤µ¤ó\\)?</a>")
1790 (defconst mixi-topic-content-regexp
1791 "<dd>\\(\\(.\\|\r?\n\\)*?\\)</dd>")
1793 (defun mixi-realize-topic (topic &optional page)
1795 ;; FIXME: Check an expiration of cache?
1796 (unless (mixi-object-realized-p topic)
1797 (with-mixi-retrieve (or page (mixi-topic-page topic))
1798 (if (re-search-forward mixi-topic-community-regexp nil t)
1799 (mixi-community-set-name (mixi-topic-community topic)
1801 (mixi-realization-error 'cannot-find-community topic))
1802 (if (re-search-forward mixi-topic-title-regexp nil t)
1803 (mixi-topic-set-title topic (match-string 1))
1804 (mixi-realization-error 'cannot-find-title topic))
1805 (if (re-search-forward mixi-topic-time-regexp nil t)
1806 (mixi-topic-set-time
1807 topic (encode-time 0 (string-to-number (match-string 5))
1808 (string-to-number (match-string 4))
1809 (string-to-number (match-string 3))
1810 (string-to-number (match-string 2))
1811 (string-to-number (match-string 1))))
1812 (mixi-realization-error 'cannot-find-time topic))
1813 (if (re-search-forward mixi-topic-owner-regexp nil t)
1814 (mixi-topic-set-owner topic (mixi-make-friend (match-string 1)
1816 (mixi-realization-error 'cannot-find-owner topic))
1817 (if (re-search-forward mixi-topic-content-regexp nil t)
1818 (mixi-topic-set-content topic (match-string 1))
1819 (mixi-realization-error 'cannot-find-content topic)))
1820 (mixi-object-touch topic)))
1822 (defun mixi-topic-community (topic)
1823 "Return the community of TOPIC."
1824 (unless (mixi-topic-p topic)
1825 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1826 (aref (cdr topic) 1))
1828 (defun mixi-topic-id (topic)
1829 "Return the id of TOPIC."
1830 (unless (mixi-topic-p topic)
1831 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1832 (aref (cdr topic) 2))
1834 (defun mixi-topic-comment-count (topic)
1835 "Return the comment-count of TOPIC."
1836 (unless (mixi-topic-p topic)
1837 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1838 (aref (cdr topic) 3))
1840 (defun mixi-topic-time (topic)
1841 "Return the time 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) 4))
1847 (defun mixi-topic-title (topic)
1848 "Return the title 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) 5))
1854 (defun mixi-topic-owner (topic)
1855 "Return the owner 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) 6))
1861 (defun mixi-topic-content (topic)
1862 "Return the content of TOPIC."
1863 (unless (mixi-topic-p topic)
1864 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1865 (mixi-realize-topic topic)
1866 (aref (cdr topic) 7))
1868 (defun mixi-topic-set-comment-count (topic comment-count)
1869 "Set the comment-count of TOPIC."
1870 (unless (mixi-topic-p topic)
1871 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1872 (aset (cdr topic) 3 comment-count))
1874 (defun mixi-topic-set-time (topic time)
1875 "Set the time of TOPIC."
1876 (unless (mixi-topic-p topic)
1877 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1878 (aset (cdr topic) 4 time))
1880 (defun mixi-topic-set-title (topic title)
1881 "Set the title of TOPIC."
1882 (unless (mixi-topic-p topic)
1883 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1884 (aset (cdr topic) 5 title))
1886 (defun mixi-topic-set-owner (topic owner)
1887 "Set the owner of TOPIC."
1888 (unless (mixi-topic-p topic)
1889 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1890 (unless (mixi-friend-p owner)
1891 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1892 (aset (cdr topic) 6 owner))
1894 (defun mixi-topic-set-content (topic content)
1895 "Set the content of TOPIC."
1896 (unless (mixi-topic-p topic)
1897 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1898 (aset (cdr topic) 7 content))
1900 (defmacro mixi-post-topic-page (community)
1901 `(concat "/add_bbs.pl?id=" (mixi-community-id community)))
1903 ;; FIXME: Support photos.
1905 (defun mixi-post-topic (community title content)
1906 "Post a topic to COMMUNITY."
1907 (unless (mixi-community-p community)
1908 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1909 (unless (stringp title)
1910 (signal 'wrong-type-argument (list 'stringp title)))
1911 (unless (stringp content)
1912 (signal 'wrong-type-argument (list 'stringp content)))
1913 (let ((fields `(("bbs_title" . ,title)
1914 ("bbs_body" . ,content)
1915 ("submit" . "main")))
1917 (with-mixi-post-form (mixi-post-topic-page community) fields
1918 (if (re-search-forward mixi-post-key-regexp nil t)
1919 (setq post-key (match-string 1))
1920 (mixi-post-error 'cannot-find-key community)))
1921 (setq fields `(("post_key" . ,post-key)
1922 ("bbs_title" . ,title)
1923 ("bbs_body" . ,content)
1924 ("submit" . "confirm")))
1925 (with-mixi-post-form (mixi-post-topic-page community) fields
1926 (unless (re-search-forward mixi-post-succeed-regexp nil t)
1927 (mixi-post-error 'cannot-find-succeed community)))))
1930 (defvar mixi-event-cache (make-hash-table :test 'equal))
1931 (defun mixi-make-event (community id &optional comment-count time title owner
1932 date place detail limit members)
1933 "Return a event object."
1934 (mixi-make-cache (list (mixi-community-id community) id)
1935 (cons 'mixi-event (vector nil community id comment-count
1936 time title owner date place
1937 detail limit members))
1940 (defconst mixi-event-url-regexp
1941 "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=\\([0-9]+\\)\\)?&comm_id=\\([0-9]+\\)")
1943 (defun mixi-make-event-from-url (url)
1944 "Return a event object from URL."
1945 (when (string-match mixi-event-url-regexp url)
1946 (let ((id (match-string 1 url))
1947 (comment-count (match-string 3 url))
1948 (community-id (match-string 4 url)))
1949 (mixi-make-event (mixi-make-community community-id) id comment-count))))
1951 (defmacro mixi-event-p (event)
1952 `(eq (mixi-object-class ,event) 'mixi-event))
1954 (defmacro mixi-event-page (event)
1955 `(concat "/view_event.pl?id=" (mixi-event-id ,event)
1956 "&comm_id=" (mixi-community-id (mixi-event-community ,event))))
1958 (defconst mixi-event-community-regexp
1959 "<div class=\"pageTitle communityTitle002\">
1960 <h2>\\(.+\\) ¥¤¥Ù¥ó¥È</h2>")
1961 (defconst mixi-event-title-regexp
1962 "<span class=\"title\">\\([^<]+\\)</span>")
1963 (defconst mixi-event-time-regexp
1964 "<span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>")
1965 (defconst mixi-event-date-regexp
1968 (defconst mixi-event-place-regexp
1971 (defconst mixi-event-owner-regexp
1972 "<dt>\\((mixi Âà²ñºÑ)\\|<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>\\)</dt>")
1973 (defconst mixi-event-owner-seceded-regexp
1975 (defconst mixi-event-detail-regexp
1976 "<dd>\\(\\(.\\|\r?\n\\)*?\\)</dd>
1978 (defconst mixi-event-limit-regexp
1981 (defconst mixi-event-members-regexp
1985 (defun mixi-realize-event (event &optional page)
1987 ;; FIXME: Check an expiration of cache?
1988 (unless (mixi-object-realized-p event)
1989 (with-mixi-retrieve (or page (mixi-event-page event))
1990 (let ((case-fold-search t))
1991 (if (re-search-forward mixi-event-community-regexp nil t)
1992 (mixi-community-set-name (mixi-event-community event)
1994 (mixi-realization-error 'cannot-find-community event))
1995 (if (re-search-forward mixi-event-title-regexp nil t)
1996 (mixi-event-set-title event (match-string 1))
1997 (mixi-realization-error 'cannot-find-title event))
1998 (if (re-search-forward mixi-event-time-regexp nil t)
1999 (mixi-event-set-time
2000 event (encode-time 0 (string-to-number (match-string 5))
2001 (string-to-number (match-string 4))
2002 (string-to-number (match-string 3))
2003 (string-to-number (match-string 2))
2004 (string-to-number (match-string 1))))
2005 (mixi-realization-error 'cannot-find-time event))
2006 (if (re-search-forward mixi-event-date-regexp nil t)
2007 (mixi-event-set-date event (match-string 1))
2008 (mixi-realization-error 'cannot-find-date event))
2009 (if (re-search-forward mixi-event-place-regexp nil t)
2010 (mixi-event-set-place event (match-string 1))
2011 (mixi-realization-error 'cannot-find-place event))
2012 (if (re-search-forward mixi-event-owner-regexp nil t)
2013 (let ((seceded-or-not (match-string 1))
2014 (id (match-string 2))
2015 (nick (match-string 3)))
2016 (if (string= mixi-event-owner-seceded-regexp seceded-or-not)
2017 (mixi-event-set-owner event
2018 (mixi-make-friend nil seceded-or-not))
2019 (mixi-event-set-owner event (mixi-make-friend id nick))))
2020 (mixi-realization-error 'cannot-find-owner event))
2021 (if (re-search-forward mixi-event-detail-regexp nil t)
2022 (mixi-event-set-detail event (match-string 1))
2023 (mixi-realization-error 'cannot-find-detail event))
2024 (if (re-search-forward mixi-event-limit-regexp nil t)
2025 (mixi-event-set-limit event (match-string 1))
2026 (mixi-realization-error 'cannot-find-limit event))
2027 (if (re-search-forward mixi-event-members-regexp nil t)
2028 (mixi-event-set-members event (match-string 1))
2029 (mixi-realization-error 'cannot-find-members event))))
2030 (mixi-object-touch event)))
2032 (defun mixi-event-community (event)
2033 "Return the community of EVENT."
2034 (unless (mixi-event-p event)
2035 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2036 (aref (cdr event) 1))
2038 (defun mixi-event-id (event)
2039 "Return the id of EVENT."
2040 (unless (mixi-event-p event)
2041 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2042 (aref (cdr event) 2))
2044 (defun mixi-event-comment-count (event)
2045 "Return the comment-count of EVENT."
2046 (unless (mixi-event-p event)
2047 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2048 (aref (cdr event) 3))
2050 (defun mixi-event-time (event)
2051 "Return the time 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) 4))
2057 (defun mixi-event-title (event)
2058 "Return the title 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) 5))
2064 (defun mixi-event-owner (event)
2065 "Return the owner 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) 6))
2071 (defun mixi-event-date (event)
2072 "Return the date 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) 7))
2078 (defun mixi-event-place (event)
2079 "Return the place 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) 8))
2085 (defun mixi-event-detail (event)
2086 "Return the detail 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) 9))
2092 (defun mixi-event-limit (event)
2093 "Return the limit 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) 10))
2099 (defun mixi-event-members (event)
2100 "Return the members of EVENT."
2101 (unless (mixi-event-p event)
2102 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2103 (mixi-realize-event event)
2104 (aref (cdr event) 11))
2106 (defun mixi-event-set-comment-count (event comment-count)
2107 "Set the comment-count of EVENT."
2108 (unless (mixi-event-p event)
2109 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2110 (aset (cdr event) 3 comment-count))
2112 (defun mixi-event-set-time (event time)
2113 "Set the time of EVENT."
2114 (unless (mixi-event-p event)
2115 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2116 (aset (cdr event) 4 time))
2118 (defun mixi-event-set-title (event title)
2119 "Set the title of EVENT."
2120 (unless (mixi-event-p event)
2121 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2122 (aset (cdr event) 5 title))
2124 (defun mixi-event-set-owner (event owner)
2125 "Set the owner of EVENT."
2126 (unless (mixi-event-p event)
2127 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2128 (unless (mixi-friend-p owner)
2129 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
2130 (aset (cdr event) 6 owner))
2132 (defun mixi-event-set-date (event date)
2133 "Set the date of EVENT."
2134 (unless (mixi-event-p event)
2135 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2136 (aset (cdr event) 7 date))
2138 (defun mixi-event-set-place (event place)
2139 "Set the place of EVENT."
2140 (unless (mixi-event-p event)
2141 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2142 (aset (cdr event) 8 place))
2144 (defun mixi-event-set-detail (event detail)
2145 "Set the detail of EVENT."
2146 (unless (mixi-event-p event)
2147 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2148 (aset (cdr event) 9 detail))
2150 (defun mixi-event-set-limit (event limit)
2151 "Set the limit of EVENT."
2152 (unless (mixi-event-p event)
2153 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2154 (aset (cdr event) 10 limit))
2156 (defun mixi-event-set-members (event members)
2157 "Set the members of EVENT."
2158 (unless (mixi-event-p event)
2159 (signal 'wrong-type-argument (list 'mixi-event-p event)))
2160 (aset (cdr event) 11 members))
2163 (defconst mixi-bbs-list '(mixi-topic mixi-event))
2165 (defmacro mixi-bbs-p (bbs)
2166 `(memq (mixi-object-class ,bbs) mixi-bbs-list))
2168 (defun mixi-bbs-community (bbs)
2169 "Return the community of BBS."
2170 (unless (mixi-bbs-p bbs)
2171 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2172 (let ((func (intern (concat mixi-object-prefix
2173 (mixi-object-name bbs) "-community"))))
2174 (funcall func bbs)))
2176 (defun mixi-bbs-comment-count (bbs)
2177 "Return the comment-count of BBS."
2178 (unless (mixi-bbs-p bbs)
2179 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2180 (let ((func (intern (concat mixi-object-prefix
2181 (mixi-object-name bbs) "-comment-count"))))
2182 (funcall func bbs)))
2184 (defun mixi-bbs-set-comment-count (bbs count)
2185 "Set the comment-count of BBS."
2186 (unless (mixi-bbs-p bbs)
2187 (signal 'wrong-type-argument (list 'mixi-bbs-p bbs)))
2188 (let ((func (intern (concat mixi-object-prefix
2189 (mixi-object-name bbs) "-set-comment-count"))))
2190 (funcall func bbs count)))
2192 (defalias 'mixi-bbs-id 'mixi-object-id)
2193 (defalias 'mixi-bbs-time 'mixi-object-time)
2194 (defalias 'mixi-bbs-title 'mixi-object-title)
2195 (defalias 'mixi-bbs-owner 'mixi-object-owner)
2196 (defalias 'mixi-bbs-content 'mixi-object-content)
2198 (defmacro mixi-bbs-list-page (community)
2199 `(concat "/list_bbs.pl?page=%d"
2200 "&id=" (mixi-community-id ,community)))
2202 (defconst mixi-bbs-list-regexp
2203 "<a href=\"?view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)")
2206 (defun mixi-get-bbses (community &optional range)
2207 "Get bbses of COMMUNITY."
2208 (unless (mixi-community-p community)
2209 (signal 'wrong-type-argument (list 'mixi-community-p community)))
2210 (let ((items (mixi-get-matched-items (mixi-bbs-list-page community)
2211 mixi-bbs-list-regexp
2213 (mapcar (lambda (item)
2214 (let ((name (nth 0 item)))
2215 (when (string= name "bbs")
2216 (setq name "topic"))
2217 (let ((func (intern (concat "mixi-make-" name))))
2218 (funcall func community (nth 1 item)))))
2221 (defmacro mixi-new-bbs-list-page ()
2222 `(concat "/new_bbs.pl?page=%d"))
2224 (defconst mixi-new-bbs-list-regexp
2225 "<dd><a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\">")
2228 (defun mixi-get-new-bbses (&optional range)
2230 (let ((items (mixi-get-matched-items (mixi-new-bbs-list-page)
2231 mixi-new-bbs-list-regexp
2234 (mapcar (lambda (item)
2235 (let ((name (nth 0 item)))
2236 (when (string= name "bbs")
2237 (setq name "topic"))
2238 (let* ((func (intern (concat "mixi-make-" name)))
2240 (mixi-make-community (nth 3 item))
2242 (comment-count (mixi-bbs-comment-count bbs))
2243 (count (string-to-number (nth 2 item))))
2244 (when (or (null comment-count)
2245 (< comment-count count))
2246 (mixi-bbs-set-comment-count bbs count)
2250 (defmacro mixi-search-bbs-list-page (keyword)
2251 `(concat "/search_topic.pl?page=%d&type=top&submit=search"
2252 "&keyword=" (mixi-url-encode-and-quote-percent-string ,keyword)
2253 "&community_id=0&category_id=0"))
2255 (defconst mixi-search-bbs-list-regexp
2256 "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\" class=\"title\">")
2258 ;; FIXME: Support community and category.
2260 (defun mixi-search-bbses (keyword &optional range)
2261 (let ((items (mixi-get-matched-items (mixi-search-bbs-list-page keyword)
2262 mixi-search-bbs-list-regexp
2264 (mapcar (lambda (item)
2265 (let ((name (nth 0 item)))
2266 (when (string= name "bbs")
2267 (setq name "topic"))
2268 (let ((func (intern (concat "mixi-make-" name))))
2269 (funcall func (mixi-make-community (nth 2 item))
2274 (defmacro mixi-parent-p (object)
2275 `(or (eq (mixi-object-class ,object) 'mixi-diary)
2276 (mixi-bbs-p ,object)))
2278 (defun mixi-realize-parent (parent &optional page)
2280 (unless (mixi-parent-p parent)
2281 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2282 (let ((func (intern (concat mixi-object-prefix "realize-"
2283 (mixi-object-name parent)))))
2284 (funcall func parent page)))
2287 (defun mixi-make-comment (parent owner time content &optional count)
2288 "Return a comment object."
2289 (cons 'mixi-comment (vector parent owner time content count)))
2291 (defmacro mixi-comment-p (comment)
2292 `(eq (mixi-object-class ,comment) 'mixi-comment))
2294 (defun mixi-comment-parent (comment)
2295 "Return the parent of COMMENT."
2296 (unless (mixi-comment-p comment)
2297 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2298 (aref (cdr comment) 0))
2300 (defun mixi-comment-owner (comment)
2301 "Return the owner of COMMENT."
2302 (unless (mixi-comment-p comment)
2303 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2304 (aref (cdr comment) 1))
2306 (defun mixi-comment-time (comment)
2307 "Return the time of COMMENT."
2308 (unless (mixi-comment-p comment)
2309 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2310 (aref (cdr comment) 2))
2312 (defun mixi-comment-content (comment)
2313 "Return the content of COMMENT."
2314 (unless (mixi-comment-p comment)
2315 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2316 (aref (cdr comment) 3))
2318 (defun mixi-comment-count (comment)
2319 "Return the count of COMMENT."
2320 (unless (mixi-comment-p comment)
2321 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2322 (aref (cdr comment) 4))
2324 (defun mixi-diary-comment-list-page (diary)
2325 (concat "/view_diary.pl?full=1"
2326 "&id=" (mixi-diary-id diary)
2327 "&owner_id=" (mixi-friend-id (mixi-diary-owner diary))))
2329 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2330 (defconst mixi-diary-comment-list-regexp
2331 "<span class=\"commentTitleName\">\\(<input type=\"checkbox\" name=\"comment_id\" value=\".+\" />
2332 \\|\\)<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2334 | <a href=\"delete_comment\\.pl\\?diary_id=[0-9]+&owner_id=[0-9]+&comment_id=.+&type=comment\">¼«Ê¬¤Î¥³¥á¥ó¥È¤òºï½ü¤¹¤ë</a>
2337 <span class=\"commentTitleDate\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span>
2341 \\(\\(.\\|\r?\n\\)*?\\)
2346 (defun mixi-topic-comment-list-page (topic)
2347 (concat "/view_bbs.pl?page=all"
2348 "&id=" (mixi-topic-id topic)
2349 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2351 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2352 (defconst mixi-topic-comment-list-regexp
2353 "<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>
2354 <span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
2356 <dl class=\"commentContent01\">
2357 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
2359 \\(\\(.\\|\r?\n\\)*?\\)
2362 (defun mixi-event-comment-list-page (event)
2363 (concat "/view_event.pl?page=all"
2364 "&id=" (mixi-event-id event)
2365 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2367 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2368 (defconst mixi-event-comment-list-regexp
2369 "<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>
2370 <span class=\"date\">\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</span></dt>
2372 <dl class=\"commentContent01\">
2373 <dt><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></dt>
2375 \\(\\(.\\|\r?\n\\)*?\\)
2379 (defun mixi-get-comments (parent &optional range)
2380 "Get comments of PARENT."
2381 (unless (mixi-parent-p parent)
2382 (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
2383 (let* ((name (mixi-object-name parent))
2384 (list-page (intern (concat mixi-object-prefix name
2385 "-comment-list-page")))
2386 (regexp (eval (intern (concat mixi-object-prefix name
2387 "-comment-list-regexp"))))
2388 (page (funcall list-page parent)))
2389 (unless (mixi-object-realized-p parent)
2390 (mixi-realize-parent parent page)
2392 (let ((items (mixi-get-matched-items page regexp range t)))
2393 (mapcar (lambda (item)
2394 (let (owner-id owner-nick year month day hour minute content
2396 (if (eq (mixi-object-class parent) 'mixi-diary)
2398 (setq owner-id (nth 1 item))
2399 (setq owner-nick (nth 2 item))
2400 (setq year (nth 4 item))
2401 (setq month (nth 5 item))
2402 (setq day (nth 6 item))
2403 (setq hour (nth 7 item))
2404 (setq minute (nth 8 item))
2405 (setq content (nth 9 item)))
2406 (setq owner-id (nth 8 item))
2407 (setq owner-nick (nth 9 item))
2408 (setq year (nth 3 item))
2409 (setq month (nth 4 item))
2410 (setq day (nth 5 item))
2411 (setq hour (nth 6 item))
2412 (setq minute (nth 7 item))
2413 (setq content (nth 10 item))
2414 (setq count (nth 1 item)))
2415 (mixi-make-comment parent (mixi-make-friend owner-id
2419 (string-to-number minute)
2420 (string-to-number hour)
2421 (string-to-number day)
2422 (string-to-number month)
2423 (string-to-number year))
2427 (defmacro mixi-new-comment-list-page ()
2428 `(concat "/new_comment.pl?page=%d"))
2430 (defconst mixi-new-comment-list-regexp
2431 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)\">")
2434 (defun mixi-get-new-comments (&optional range)
2436 (let ((items (mixi-get-matched-items (mixi-new-comment-list-page)
2437 mixi-new-comment-list-regexp
2440 (mapcar (lambda (item)
2441 (let* ((diary (mixi-make-diary
2442 (mixi-make-friend (nth 1 item))
2444 (comment-count (mixi-diary-comment-count diary))
2445 (count (string-to-number (nth 2 item))))
2446 (when (or (null comment-count)
2447 (< comment-count count))
2448 (mixi-diary-set-comment-count diary count)
2452 (defmacro mixi-new-bbs-comment-list-page ()
2453 `(concat "/new_bbs_comment.pl?page=%d"))
2455 (defconst mixi-new-bbs-comment-list-regexp
2456 "<a href=\"?view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\"?>")
2459 (defun mixi-get-new-bbs-comments (&optional range)
2460 "Get new BBS comments."
2461 (let ((items (mixi-get-matched-items (mixi-new-bbs-comment-list-page)
2462 mixi-new-bbs-comment-list-regexp
2465 (mapcar (lambda (item)
2466 (let ((name (nth 0 item)))
2467 (when (string= name "bbs")
2468 (setq name "topic"))
2469 (let ((make-func (intern (concat "mixi-make-" name)))
2471 (intern (concat "mixi-" name "-comment-count")))
2472 (set-comment-count-func
2473 (intern (concat "mixi-" name
2474 "-set-comment-count"))))
2475 (let* ((bbs (funcall make-func
2476 (mixi-make-community (nth 3 item))
2478 (comment-count (funcall comment-count-func bbs))
2479 (count (string-to-number (nth 2 item))))
2480 (when (or (null comment-count)
2481 (< comment-count count))
2482 (funcall set-comment-count-func bbs count)
2486 (defun mixi-post-diary-comment-page (diary)
2487 (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
2489 (defun mixi-post-topic-comment-page (topic)
2490 (concat "/add_bbs_comment.pl?id=" (mixi-topic-id topic)
2491 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2493 (defun mixi-post-event-comment-page (event)
2494 (concat "/add_event_comment.pl?id=" (mixi-event-id event)
2495 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2497 ;; FIXME: Support photos.
2499 (defun mixi-post-comment (parent content)
2500 "Post a comment to PARENT."
2501 (unless (mixi-object-p parent)
2502 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
2503 (unless (stringp content)
2504 (signal 'wrong-type-argument (list 'stringp content)))
2505 (let* ((name (mixi-object-name parent))
2506 (page (intern (concat mixi-object-prefix "post-" name
2509 (if (mixi-diary-p parent)
2511 `(("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2512 ("comment_body" . ,content)))
2513 (setq fields `(("comment" . ,content))))
2514 (with-mixi-post-form (funcall page parent) fields
2515 (if (re-search-forward mixi-post-key-regexp nil t)
2516 (setq post-key (match-string 1))
2517 (mixi-post-error 'cannot-find-key parent)))
2518 (if (mixi-diary-p parent)
2520 `(("post_key" . ,post-key)
2521 ("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2522 ("comment_body" . ,content)
2523 ("submit" . "confirm")))
2524 (setq fields `(("post_key" . ,post-key)
2525 ("comment" . ,content)
2526 ("submit" . "confirm"))))
2527 (with-mixi-post-form (funcall page parent) fields
2528 (unless (re-search-forward mixi-post-succeed-regexp nil t)
2529 (mixi-post-error 'cannot-find-succeed parent)))))
2532 (defconst mixi-message-box-list
2533 '(inbox outbox savebox thrash noticebox)) ; thrash?
2535 (defmacro mixi-message-box-p (box)
2536 `(memq ,box mixi-message-box-list))
2538 (defun mixi-message-box-name (box)
2539 "Return the name of BOX."
2540 (unless (mixi-message-box-p box)
2541 (signal 'wrong-type-argument (list 'mixi-message-box-p box)))
2544 (defvar mixi-message-cache (make-hash-table :test 'equal))
2545 (defun mixi-make-message (id box &optional owner title time content)
2546 "Return a message object."
2547 (mixi-make-cache (list id box)
2548 (cons 'mixi-message (vector nil id box owner title time
2550 mixi-message-cache))
2552 (defconst mixi-message-url-regexp
2553 "/view_message\\.pl\\?id=\\([a-z0-9]+\\)&box=\\([a-z]+\\)")
2555 (defun mixi-make-message-from-url (url)
2556 "Return a message object from URL."
2557 (when (string-match mixi-message-url-regexp url)
2558 (let ((id (match-string 1 url))
2559 (box (match-string 2 url)))
2560 (mixi-make-message id box))))
2562 (defmacro mixi-message-p (message)
2563 `(eq (mixi-object-class ,message) 'mixi-message))
2565 (defmacro mixi-message-page (message)
2566 `(concat "/view_message.pl?id=" (mixi-message-id ,message)
2567 "&box=" (mixi-message-box ,message)))
2569 (defconst mixi-message-title-regexp
2570 "<div class=\"messageDetailHead\">
2572 (defconst mixi-message-time-regexp
2574 <dd>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ</dd>")
2575 (defconst mixi-message-owner-regexp
2578 <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>\\|mixi</dd>\\)")
2579 (defconst mixi-message-content-regexp
2580 "<div id=\"message_body\" class=\"messageDetailBody\">\\(\\(.\\|\r?\n\\)*?\\)</div>")
2582 (defun mixi-realize-message (message)
2583 "Realize a MESSAGE."
2584 (unless (mixi-object-realized-p message)
2585 (with-mixi-retrieve (mixi-message-page message)
2586 (if (re-search-forward mixi-message-title-regexp nil t)
2587 (mixi-message-set-title message (match-string 1))
2588 (mixi-realization-error 'cannot-find-title message))
2589 (if (re-search-forward mixi-message-time-regexp nil t)
2590 (mixi-message-set-time
2591 message (encode-time 0 (string-to-number (match-string 5))
2592 (string-to-number (match-string 4))
2593 (string-to-number (match-string 3))
2594 (string-to-number (match-string 2))
2595 (string-to-number (match-string 1))))
2596 (mixi-realization-error 'cannot-find-time message))
2597 (if (re-search-forward mixi-message-owner-regexp nil t)
2598 (unless (string= (match-string 1) "mixi</dd>")
2599 (mixi-message-set-owner message
2600 (mixi-make-friend (match-string 2)
2602 (mixi-realization-error 'cannot-find-owner message))
2603 (if (re-search-forward mixi-message-content-regexp nil t)
2604 (mixi-message-set-content message (match-string 1))
2605 (mixi-realization-error 'cannot-find-content message)))
2606 (mixi-object-touch message)))
2608 (defun mixi-message-id (message)
2609 "Return the id of MESSAGE."
2610 (unless (mixi-message-p message)
2611 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2612 (aref (cdr message) 1))
2614 (defun mixi-message-box (message)
2615 "Return the box of MESSAGE."
2616 (unless (mixi-message-p message)
2617 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2618 (aref (cdr message) 2))
2620 (defun mixi-message-owner (message)
2621 "Return the owner of MESSAGE."
2622 (unless (mixi-message-p message)
2623 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2624 (mixi-realize-message message)
2625 (aref (cdr message) 3))
2627 (defun mixi-message-title (message)
2628 "Return the title of MESSAGE."
2629 (unless (mixi-message-p message)
2630 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2631 (mixi-realize-message message)
2632 (aref (cdr message) 4))
2634 (defun mixi-message-time (message)
2635 "Return the date of MESSAGE."
2636 (unless (mixi-message-p message)
2637 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2638 (mixi-realize-message message)
2639 (aref (cdr message) 5))
2641 (defun mixi-message-content (message)
2642 "Return the content of MESSAGE."
2643 (unless (mixi-message-p message)
2644 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2645 (mixi-realize-message message)
2646 (aref (cdr message) 6))
2648 (defun mixi-message-set-owner (message owner)
2649 "Set the owner of MESSAGE."
2650 (unless (mixi-message-p message)
2651 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2652 (aset (cdr message) 3 owner))
2654 (defun mixi-message-set-title (message title)
2655 "Set the title of MESSAGE."
2656 (unless (mixi-message-p message)
2657 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2658 (aset (cdr message) 4 title))
2660 (defun mixi-message-set-time (message time)
2661 "Set the date of MESSAGE."
2662 (unless (mixi-message-p message)
2663 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2664 (aset (cdr message) 5 time))
2666 (defun mixi-message-set-content (message content)
2667 "Set the content of MESSAGE."
2668 (unless (mixi-message-p message)
2669 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2670 (aset (cdr message) 6 content))
2672 (defmacro mixi-message-list-page (&optional box)
2673 `(concat "/list_message.pl?page=%d"
2674 (when ,box (concat "&box=" ,box))))
2676 (defconst mixi-message-list-regexp
2677 "<a href=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
2680 (defun mixi-get-messages (&rest box-or-range)
2681 "Get messages of BOX."
2682 (when (> (length box-or-range) 2)
2683 (signal 'wrong-number-of-arguments
2684 (list 'mixi-get-messages (length box-or-range))))
2685 (let ((box (nth 0 box-or-range))
2686 (range (nth 1 box-or-range)))
2687 (when (or (not (mixi-message-box-p box))
2688 (mixi-message-box-p range))
2689 (setq box (nth 1 box-or-range))
2690 (setq range (nth 0 box-or-range)))
2691 (let ((items (mixi-get-matched-items
2692 (mixi-message-list-page
2693 (when box (mixi-message-box-name box)))
2694 mixi-message-list-regexp
2696 (mapcar (lambda (item)
2697 (mixi-make-message (nth 0 item) (nth 1 item)))
2700 (defmacro mixi-post-message-page (friend)
2701 `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
2703 (defconst mixi-post-message-key-regexp
2704 "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
2706 (defconst mixi-post-message-succeed-regexp
2707 "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
2710 (defun mixi-post-message (friend title content)
2711 "Post a message to FRIEND."
2712 (unless (mixi-friend-p friend)
2713 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2714 (unless (stringp title)
2715 (signal 'wrong-type-argument (list 'stringp title)))
2716 (unless (stringp content)
2717 (signal 'wrong-type-argument (list 'stringp content)))
2718 (let ((fields `(("subject" . ,title)
2720 ("submit" . "main")))
2722 (with-mixi-post-form (mixi-post-message-page friend) fields
2723 (if (re-search-forward mixi-post-message-key-regexp nil t)
2724 (setq post-key (match-string 1))
2725 (mixi-post-error 'cannot-find-key friend)))
2726 (setq fields `(("post_key" . ,post-key)
2727 ("subject" . ,title)
2729 ("yes" . "¡¡Á÷¡¡¿®¡¡")
2730 ("submit" . "confirm")))
2731 (with-mixi-post-form (mixi-post-message-page friend) fields
2732 (unless (re-search-forward mixi-post-message-succeed-regexp nil t)
2733 (mixi-post-error 'cannot-find-succeed friend)))))
2735 ;; Introduction object.
2736 (defun mixi-make-introduction (parent owner content)
2737 "Return a introduction object."
2738 (cons 'mixi-introduction (vector parent owner content)))
2740 (defmacro mixi-introduction-p (introduction)
2741 `(eq (mixi-object-class ,introduction) 'mixi-introduction))
2743 (defun mixi-introduction-parent (introduction)
2744 "Return the parent of INTRODUCTION."
2745 (unless (mixi-introduction-p introduction)
2746 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2747 (aref (cdr introduction) 0))
2749 (defun mixi-introduction-owner (introduction)
2750 "Return the owner of INTRODUCTION."
2751 (unless (mixi-introduction-p introduction)
2752 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2753 (aref (cdr introduction) 1))
2755 (defun mixi-introduction-content (introduction)
2756 "Return the content of INTRODUCTION."
2757 (unless (mixi-introduction-p introduction)
2758 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2759 (aref (cdr introduction) 3))
2761 (defmacro mixi-introduction-list-page (&optional friend)
2762 `(concat "/show_intro.pl?page=%d"
2763 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
2765 (defconst mixi-introduction-list-regexp
2766 "<tr bgcolor=#FFFFFF>
2767 <td WIDTH=150 background=http://img\\.mixi\\.jp/img/bg_line\\.gif align=\"center\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\"><img src=\".+\" border=0><br>
2774 \\(\\(.\\|\n<br>\\)+\\)\\|
2775 \\(\\(.\\|\n<br>\\)+\\)\\)
2782 (defconst mixi-my-introduction-list-regexp
2783 "<tr bgcolor=#FFFFFF>
2784 <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>
2792 \\(\\(.\\|\n<br>\\)+\\)\\|
2793 \\(\\(.\\|\n<br>\\)+\\)\\)
2797 <a href=\"edit_intro\\.pl\\?id=\\1&type=edit\">¤³¤Îͧ¿Í¤ò¾Ò²ð¤¹¤ë</a>
2801 <a href=\"delete_intro\\.pl\\?id=\\1\">ºï½ü</a>
2807 (defun mixi-get-introductions (&rest friend-or-range)
2808 "Get introductions of FRIEND."
2809 (when (> (length friend-or-range) 2)
2810 (signal 'wrong-number-of-arguments
2811 (list 'mixi-get-introduction (length friend-or-range))))
2812 (let ((friend (nth 0 friend-or-range))
2813 (range (nth 1 friend-or-range)))
2814 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
2815 (setq friend (nth 1 friend-or-range))
2816 (setq range (nth 0 friend-or-range)))
2817 (unless (or (null friend) (mixi-friend-p friend))
2818 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2819 (let* ((regexp (if friend mixi-introduction-list-regexp
2820 mixi-my-introduction-list-regexp))
2821 (items (mixi-get-matched-items (mixi-introduction-list-page friend)
2824 (mapcar (lambda (item)
2825 (mixi-make-introduction (or friend (mixi-make-me))
2826 (mixi-make-friend (nth 0 item)
2832 (defvar mixi-news-cache (make-hash-table :test 'equal))
2833 (defun mixi-make-news (media-id id &optional media time title content)
2834 "Return a news object."
2835 (mixi-make-cache (list media-id id)
2836 (cons 'mixi-news (vector nil media-id id media time title
2840 (defconst mixi-news-url-regexp
2841 "/view_news\\.pl\\?\\(id=\\([0-9]+\\)&media_id=\\([0-9]+\\)\\|media_id=\\([0-9]+\\)&id=\\([0-9]+\\)\\)")
2843 (defun mixi-make-news-from-url (url)
2844 "Return a news object from URL."
2845 (when (string-match mixi-news-url-regexp url)
2846 (let ((id (or (match-string 2 url) (match-string 5 url)))
2847 (media-id (or (match-string 3 url) (match-string 4 url))))
2848 (mixi-make-news media-id id))))
2850 (defmacro mixi-news-p (news)
2851 `(eq (mixi-object-class ,news) 'mixi-news))
2853 (defmacro mixi-news-page (news)
2854 `(concat "http://news.mixi.jp/view_news.pl?id=" (mixi-news-id ,news)
2855 "&media_id=" (mixi-news-media-id ,news)))
2857 (defconst mixi-news-finished-regexp
2858 "<p class=\"supplement01\">¢¨¿½¤·Ìõ¤¢¤ê¤Þ¤»¤ó¤¬¡¢¤³¤Î¥Ë¥å¡¼¥¹¤Ï·ÇºÜ´ü´Ö¤¬½ªÎ»¤·¤¿¤«¡¢URL¤¬´Ö°ã¤Ã¤Æ¤¤¤ë¤¿¤á¤´Í÷¤¤¤¿¤À¤±¤Þ¤»¤ó¡£¾Ü¤·¤¯¤Ï<a href=\"http://mixi.jp/help.pl#16h\">¤³¤Á¤é</a>¤ò¤´Í÷¤¯¤À¤µ¤¤¡£</p>")
2859 (defconst mixi-news-title-regexp
2860 "<div class=\"articleH[ae][ae]ding\">
2862 (defconst mixi-news-media-time-regexp
2863 "<p class=\"date\">¡Ê\\(.+\\) - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)¡Ë</p>")
2864 (defconst mixi-news-content-regexp
2865 "<div class=\"article\">
2866 \\(\\(.\\|\r?\n\\)*?\\)
2868 </div>\\|<div class=\"additional\">\\)")
2870 (defun mixi-realize-news (news)
2872 ;; FIXME: Check an expiration of cache?
2873 (unless (mixi-object-realized-p news)
2874 (with-mixi-retrieve (mixi-news-page news)
2875 (if (re-search-forward mixi-news-finished-regexp nil t)
2876 (mixi-news-set-content news (match-string 0))
2877 (if (re-search-forward mixi-news-title-regexp nil t)
2878 (mixi-news-set-title news (match-string 1))
2879 (mixi-realization-error 'cannot-find-title news))
2880 (if (re-search-forward mixi-news-media-time-regexp nil t)
2882 (mixi-news-set-media news (match-string 1))
2883 (let ((year (nth 5 (decode-time (current-time))))
2884 (month (nth 4 (decode-time (current-time))))
2885 (month-of-item (string-to-number (match-string 2))))
2886 (when (> month-of-item month)
2889 news (encode-time 0 (string-to-number (match-string 5))
2890 (string-to-number (match-string 4))
2891 (string-to-number (match-string 3))
2893 (mixi-realization-error 'cannot-find-media-time news))
2894 (if (re-search-forward mixi-news-content-regexp nil t)
2895 (mixi-news-set-content news (match-string 1))
2896 (mixi-realization-error 'cannot-find-content news))))
2897 (mixi-object-touch news)))
2899 (defun mixi-news-media-id (news)
2900 "Return the media-id of NEWS."
2901 (unless (mixi-news-p news)
2902 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2903 (aref (cdr news) 1))
2905 (defun mixi-news-id (news)
2906 "Return the id of NEWS."
2907 (unless (mixi-news-p news)
2908 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2909 (aref (cdr news) 2))
2911 (defun mixi-news-media (news)
2912 "Return the media of NEWS."
2913 (unless (mixi-news-p news)
2914 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2915 (unless (aref (cdr news) 3)
2916 (mixi-realize-news news))
2917 (aref (cdr news) 3))
2919 (defun mixi-news-time (news)
2920 "Return the time of NEWS."
2921 (unless (mixi-news-p news)
2922 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2923 (unless (aref (cdr news) 4)
2924 (mixi-realize-news news))
2925 (aref (cdr news) 4))
2927 (defun mixi-news-title (news)
2928 "Return the title of NEWS."
2929 (unless (mixi-news-p news)
2930 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2931 (unless (aref (cdr news) 5)
2932 (mixi-realize-news news))
2933 (aref (cdr news) 5))
2935 (defun mixi-news-content (news)
2936 "Return the content of NEWS."
2937 (unless (mixi-news-p news)
2938 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2939 (mixi-realize-news news)
2940 (aref (cdr news) 6))
2942 (defun mixi-news-set-media (news media)
2943 "Set the media of NEWS."
2944 (unless (mixi-news-p news)
2945 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2946 (aset (cdr news) 3 media))
2948 (defun mixi-news-set-time (news time)
2949 "Set the time of NEWS."
2950 (unless (mixi-news-p news)
2951 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2952 (aset (cdr news) 4 time))
2954 (defun mixi-news-set-title (news title)
2955 "Set the title of NEWS."
2956 (unless (mixi-news-p news)
2957 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2958 (aset (cdr news) 5 title))
2960 (defun mixi-news-set-content (news content)
2961 "Set the content of NEWS."
2962 (unless (mixi-news-p news)
2963 (signal 'wrong-type-argument (list 'mixi-news-p news)))
2964 (aset (cdr news) 6 content))
2966 (defconst mixi-news-category-list '(domestic politics economy area abroad
2967 sports entertainment IT game-anime
2970 (defmacro mixi-news-category-p (category)
2971 `(memq ,category mixi-news-category-list))
2973 (defun mixi-news-category-id (category)
2974 "Return the id of CATEGORY."
2975 (unless (mixi-news-category-p category)
2976 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
2978 (1+ (- (length mixi-news-category-list)
2979 (length (memq category mixi-news-category-list))))))
2981 (defconst mixi-news-sort-list '(newest pickup))
2983 (defmacro mixi-news-sort-p (sort)
2984 `(memq ,sort mixi-news-sort-list))
2986 (defun mixi-news-sort-id (sort)
2987 "Return the id of SORT."
2988 (unless (mixi-news-sort-p sort)
2989 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
2991 (- (length mixi-news-sort-list)
2992 (length (memq sort mixi-news-sort-list)))))
2994 (defmacro mixi-news-list-page (category sort)
2995 `(concat "http://news.mixi.jp/list_news_category.pl?page=%d"
2996 "&sort=" (mixi-news-sort-id ,sort)
2997 "&id=" (mixi-news-category-id ,category)
3000 (defconst mixi-news-list-regexp
3001 "<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>
3002 <td class=\"media\"><a href=\"list_news_media\\.pl\\?id=[0-9]+\">\\(.+\\)</a></td>
3003 <td class=\"date\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td>")
3006 (defun mixi-get-news (category sort &optional range)
3007 "Get news of CATEGORY and SORT."
3008 (unless (mixi-news-category-p category)
3009 (signal 'wrong-type-argument (list 'mixi-news-category-p category)))
3010 (unless (mixi-news-sort-p sort)
3011 (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
3012 (let ((items (mixi-get-matched-items (mixi-news-list-page category sort)
3013 mixi-news-list-regexp
3015 (year (nth 5 (decode-time (current-time))))
3016 (month (nth 4 (decode-time (current-time)))))
3017 (mapcar (lambda (item)
3018 (let ((month-of-item (string-to-number (nth 4 item))))
3019 (when (> month-of-item month)
3021 (setq month month-of-item)
3022 (mixi-make-news (nth 1 item) (nth 0 item) (nth 3 item)
3024 0 (string-to-number (nth 7 item))
3025 (string-to-number (nth 6 item))
3026 (string-to-number (nth 5 item))
3032 (defun mixi-make-release (title time content)
3033 "Return a release object."
3034 (cons 'mixi-release (vector title time content)))
3036 (defmacro mixi-release-p (release)
3037 `(eq (mixi-object-class ,release) 'mixi-release))
3039 (defun mixi-release-title (release)
3040 "Return the title of RELEASE."
3041 (unless (mixi-release-p release)
3042 (signal 'wrong-type-argument (list 'mixi-release-p release)))
3043 (aref (cdr release) 0))
3045 (defun mixi-release-time (release)
3046 "Return the time of RELEASE."
3047 (unless (mixi-release-p release)
3048 (signal 'wrong-type-argument (list 'mixi-release-p release)))
3049 (aref (cdr release) 1))
3051 (defun mixi-release-content (release)
3052 "Return the content of RELEASE."
3053 (unless (mixi-release-p release)
3054 (signal 'wrong-type-argument (list 'mixi-release-p release)))
3055 (aref (cdr release) 2))
3057 (defmacro mixi-release-list-page ()
3058 `(concat "/release_info.pl?page=%d"))
3060 (defconst mixi-release-list-regexp
3061 "<td> <span STYLE=\"font-size:8pt;color:#DFB479\">¢£</span> <b><font COLOR=#605048>\\(.+\\)</font></b></td>
3062 <td ALIGN=right><font COLOR=#605048>\\([1-9][0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)</font></td>
3071 <table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=450>
3080 (defun mixi-get-releases (&optional range)
3082 (let ((items (mixi-get-matched-items (mixi-release-list-page)
3083 mixi-release-list-regexp
3085 (mapcar (lambda (item)
3086 (mixi-make-release (nth 0 item)
3088 (string-to-number (nth 3 item))
3089 (string-to-number (nth 2 item))
3090 (string-to-number (nth 1 item)))
3095 (defvar mixi-echo-cache (make-hash-table :test 'equal))
3096 ;; FIXME: Support parent.
3097 (defun mixi-make-echo (owner post-time &optional content)
3098 "Return an echo object."
3099 (let ((owner (or owner (mixi-make-me))))
3100 (mixi-make-cache (list (mixi-friend-id owner) post-time)
3101 (cons 'mixi-echo (vector nil owner post-time content))
3104 (defconst mixi-echo-url-regexp
3105 "view_echo\\.pl\\?id=\\([0-9]+\\)&post_time=\\([0-9]+\\)")
3107 (defun mixi-make-echo-from-url (url)
3108 "Return an echo object from URL."
3109 (when (string-match mixi-echo-url-regexp url)
3110 (let ((owner-id (match-string 1 url))
3111 (post-time (match-string 2 url)))
3112 (mixi-make-echo (mixi-make-friend owner-id) post-time))))
3114 (defmacro mixi-echo-p (echo)
3115 `(eq (mixi-object-class ,echo) 'mixi-echo))
3117 (defmacro mixi-echo-page (echo)
3118 `(concat "/view_echo.pl?id=" (mixi-friend-id (mixi-echo-owner ,echo))
3119 "&post_time=" (mixi-echo-post-time ,echo)))
3121 (defconst mixi-echo-owner-nick-regexp
3122 "<div id=\"echo_nickname_[0-9]+\" style=\"display: none;\">\\(.*\\)</div>")
3123 (defconst mixi-echo-content-regexp
3124 "<div id=\"echo_body_[0-9]+\" style=\"display: none;\">\\(.+\\)</div>")
3126 (defun mixi-realize-echo (echo)
3128 ;; FIXME: Check an expiration of cache?
3129 (unless (mixi-object-realized-p echo)
3130 (with-mixi-retrieve (mixi-echo-page echo)
3131 (let ((case-fold-search t))
3132 (if (re-search-forward mixi-echo-owner-nick-regexp nil t)
3133 (mixi-friend-set-nick (mixi-echo-owner echo)
3135 (mixi-realization-error 'cannot-find-owner-nick echo))
3136 (if (re-search-forward mixi-echo-content-regexp nil t)
3137 (mixi-echo-set-content echo (match-string 1))
3138 (mixi-realization-error 'cannot-find-owner-nick echo))))
3139 (mixi-object-touch echo)))
3141 (defun mixi-echo-owner (echo)
3142 "Return the owner of ECHO."
3143 (unless (mixi-echo-p echo)
3144 (signal 'wrong-type-argument (list 'mixi-echo-p echo)))
3145 (aref (cdr echo) 1))
3147 (defun mixi-echo-post-time (echo)
3148 "Return the post-time of ECHO."
3149 (unless (mixi-echo-p echo)
3150 (signal 'wrong-type-argument (list 'mixi-echo-p echo)))
3151 (aref (cdr echo) 2))
3153 (defun mixi-echo-content (echo)
3154 "Return the content of ECHO."
3155 (unless (mixi-echo-p echo)
3156 (signal 'wrong-type-argument (list 'mixi-echo-p echo)))
3157 (mixi-realize-echo echo)
3158 (aref (cdr echo) 3))
3160 (defun mixi-echo-set-content (echo content)
3161 "Set the content of ECHO."
3162 (unless (mixi-echo-p echo)
3163 (signal 'wrong-type-argument (list 'mixi-echo-p echo)))
3164 (aset (cdr echo) 3 content))
3166 (defmacro mixi-echo-list-page (&optional friend)
3167 `(concat "/list_echo.pl?page=%d"
3168 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
3170 (defconst mixi-echo-list-regexp
3171 "<a href=\"view_echo\\.pl\\?id=\\([0-9]+\\)&post_time=\\([0-9]+\\)\">")
3174 (defun mixi-get-echoes (&rest friend-or-range)
3175 "Get echoes of FRIEND."
3176 (when (> (length friend-or-range) 2)
3177 (signal 'wrong-number-of-arguments
3178 (list 'mixi-get-echoes (length friend-or-range))))
3179 (let ((friend (nth 0 friend-or-range))
3180 (range (nth 1 friend-or-range)))
3181 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
3182 (setq friend (nth 1 friend-or-range))
3183 (setq range (nth 0 friend-or-range)))
3184 (unless (or (null friend) (mixi-friend-p friend))
3185 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
3186 (let ((items (mixi-get-matched-items (mixi-echo-list-page friend)
3187 mixi-echo-list-regexp
3189 (mapcar (lambda (item)
3190 (mixi-make-echo friend (nth 1 item)))
3193 (defmacro mixi-new-echo-list-page ()
3194 `(concat "/recent_echo.pl?page=%d"))
3196 (defconst mixi-new-echo-list-regexp
3197 "<a href=\"view_echo\\.pl\\?id=\\([0-9]+\\)&post_time=\\([0-9]+\\)\">")
3200 (defun mixi-get-new-echoes (&optional range)
3202 (let ((items (mixi-get-matched-items (mixi-new-echo-list-page)
3203 mixi-new-echo-list-regexp
3205 (mapcar (lambda (item)
3206 (mixi-make-echo (mixi-make-friend (nth 0 item)) (nth 1 item)))
3209 (defmacro mixi-post-echo-page ()
3210 `(concat "/add_echo.pl"))
3212 (defconst mixi-echo-post-succeed-regexp mixi-my-id-regexp)
3215 (defun mixi-post-echo (content &optional parent)
3217 (unless (stringp content)
3218 (signal 'wrong-type-argument (list 'stringp content)))
3219 (unless (or (null parent) (mixi-echo-p parent))
3220 (signal 'wrong-type-argument (list 'mixi-echo-p parent)))
3221 (let (fields post-key)
3222 (with-mixi-retrieve (mixi-post-echo-page)
3223 (if (re-search-forward mixi-post-key-regexp nil t)
3224 (setq post-key (match-string 1))
3225 (mixi-post-error 'cannot-find-key)))
3226 (setq fields `(("post_key" . ,post-key)
3227 ("redirect" . "home")
3228 ("body" . ,content)))
3229 (when (mixi-echo-p parent)
3230 (setq fields (cons `("parent_member_id" . ,(mixi-friend-id
3231 (mixi-echo-owner parent)))
3233 (setq fields (cons `("parent_post_time" . ,(mixi-echo-post-time parent))
3235 (with-mixi-post-form (mixi-post-echo-page) fields
3236 (unless (re-search-forward mixi-echo-post-succeed-regexp nil t)
3237 (mixi-post-error 'cannot-find-succeed)))))
3241 ;;; mixi.el ends here