X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mixi.el;h=f379efba1845cb1c35f9e2bf0d50386d8311befb;hb=62f72e32751615fcecbf7a5a7344373981c0f340;hp=67de34d23e2aa3382317a3045b8379aa4ccaed7c;hpb=63afadb98c0e995b15fd53440fed8f7b39f5f632;p=elisp%2Fmixi.git diff --git a/mixi.el b/mixi.el index 67de34d..f379efb 100644 --- a/mixi.el +++ b/mixi.el @@ -1,6 +1,6 @@ ;; mixi.el --- API libraries for accessing to mixi -*- coding: euc-jp -*- -;; Copyright (C) 2005, 2006, 2007 OHASHI Akira +;; Copyright (C) 2005, 2006, 2007, 2008 OHASHI Akira ;; Author: OHASHI Akira ;; Keywords: hypermedia @@ -18,9 +18,9 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program; if not, you can either send email to this -;; program's maintainer or write to: The Free Software Foundation, -;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. ;;; Commentary: @@ -29,19 +29,23 @@ ;; * mixi-get-friends ;; * mixi-get-favorites ;; * mixi-get-logs +;; * mixi-get-recommended-friends (indies) ;; * mixi-get-diaries ;; * mixi-get-new-diaries ;; * mixi-search-diaries ;; * mixi-get-communities ;; * mixi-search-communities +;; * mixi-get-recommended-communities (indies) ;; * mixi-get-bbses ;; * mixi-get-new-bbses ;; * mixi-search-bbses ;; * mixi-get-comments ;; * mixi-get-new-comments +;; * mixi-get-new-bbs-comments ;; * mixi-get-messages -;; * mixi-get-introductions +;; * mixi-get-introductions (broken) ;; * mixi-get-news +;; * mixi-get-releases ;; ;; APIs for posting: ;; @@ -135,6 +139,8 @@ (autoload 'w3m-retrieve "w3m") (autoload 'url-retrieve-synchronously "url")) +(defconst mixi-revision "$Revision: 1.189 $") + (defgroup mixi nil "API library for accessing to mixi." :group 'hypermedia) @@ -433,7 +439,7 @@ Increase this value when unexpected error frequently occurs." (defun mixi-logout () (mixi-retrieve "/logout.pl")) -(defconst mixi-login-form "
") +(defconst mixi-login-form "") (defmacro with-mixi-retrieve (url &rest body) `(with-current-buffer (get-buffer-create mixi-temp-buffer-name) @@ -470,7 +476,8 @@ Increase this value when unexpected error frequently occurs." (let ((page 1) ids) (catch 'end - (while (or (null range) (< (length ids) range)) + (while (and (or (null range) (< (length ids) range)) + (or (= page 1) (and (stringp url) (string-match "%d" url)))) (with-mixi-retrieve (when url (format url page)) (let ((func (if reverse (progn (goto-char (point-max)) @@ -1144,6 +1151,23 @@ Increase this value when unexpected error frequently occurs." (string-to-number (nth 0 item))))) items))) +;; Recommended friend. +(defmacro mixi-recommended-friend-list-page () + `(concat "http://indies.mixi.jp/recommend.pl")) + +(defconst mixi-recommended-friend-list-regexp + "\\(.+?\\)¤µ¤ó([0-9]+)") + +;;;###autoload +(defun mixi-get-recommended-friends (&optional range) + "Get recommended friends." + (let ((items (mixi-get-matched-items (mixi-recommended-friend-list-page) + mixi-recommended-friend-list-regexp + range))) + (mapcar (lambda (item) + (mixi-make-friend (nth 0 item) (nth 1 item))) + items))) + ;; Diary object. (defvar mixi-diary-cache (make-hash-table :test 'equal)) (defun mixi-make-diary (owner id &optional comment-count time title content) @@ -1322,6 +1346,8 @@ Increase this value when unexpected error frequently occurs." (defconst mixi-new-diary-list-regexp "
\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)
\\(.+\\) (\\(.*\\))
̾  Á° -\\(.*\\) - - - - -¥¿¥¤¥È¥ë -\\(.+\\) - - -ËÜ  Ê¸ -\\(.*\\) - - - -ºîÀ®Æü»þ -\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) -¾ÜºÙ¤ò¸«¤ë - -") + "
  • + +
    +
    \\(.+\\)\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)
    +

    \\(.*\\) +

    +
  • ") ;;;###autoload (defun mixi-search-diaries (keyword &optional range) @@ -1376,20 +1404,20 @@ Increase this value when unexpected error frequently occurs." (year (nth 5 (decode-time (current-time)))) (month (nth 4 (decode-time (current-time))))) (mapcar (lambda (item) - (let ((month-of-item (string-to-number (nth 3 item)))) + (let ((month-of-item (string-to-number (nth 4 item)))) (when (> month-of-item month) (decf year)) (setq month month-of-item) - (mixi-make-diary (mixi-make-friend (nth 8 item) (nth 0 item)) - (nth 7 item) + (mixi-make-diary (mixi-make-friend (nth 1 item) (nth 2 item)) + (nth 0 item) nil (encode-time - 0 (string-to-number (nth 6 item)) + 0 (string-to-number (nth 7 item)) + (string-to-number (nth 6 item)) (string-to-number (nth 5 item)) - (string-to-number (nth 4 item)) month year) - (nth 1 item) - (nth 2 item)))) + (nth 3 item) + (nth 8 item)))) items))) (defmacro mixi-post-diary-page () @@ -1398,7 +1426,7 @@ Increase this value when unexpected error frequently occurs." (defconst mixi-post-key-regexp "\\(ºîÀ®\\|½ñ¤­¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É½¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¾¯¡¹¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£

    ") + "\\(ºîÀ®\\|½ñ¤­¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£

    ") ;; FIXME: Support photos. ;;;###autoload @@ -1456,7 +1484,7 @@ Increase this value when unexpected error frequently occurs." (defconst mixi-community-nodata-regexp "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó") (defconst mixi-community-name-regexp - "
    + "

    \\(.*\\)

    ") (defconst mixi-community-birthday-regexp "
    ³«ÀßÆü
    @@ -1698,6 +1726,23 @@ Increase this value when unexpected error frequently occurs." (mixi-make-community (nth 0 item) (nth 1 item))) items))) +;; Recommended community. +(defalias 'mixi-recommended-community-list-page + 'mixi-recommended-friend-list-page) + +(defconst mixi-recommended-community-list-regexp + "\\(.+\\)([0-9]+)") + +;;;###autoload +(defun mixi-get-recommended-communities (&optional range) + "Get recommended communities." + (let ((items (mixi-get-matched-items (mixi-recommended-community-list-page) + mixi-recommended-community-list-regexp + range))) + (mapcar (lambda (item) + (mixi-make-community (nth 0 item) (nth 1 item))) + items))) + ;; Topic object. (defvar mixi-topic-cache (make-hash-table :test 'equal)) (defun mixi-make-topic (community id &optional comment-count time title owner @@ -1917,9 +1962,9 @@ Increase this value when unexpected error frequently occurs." "
    ³«ºÅ¾ì½ê
    \\(.+\\)
    ") (defconst mixi-event-owner-regexp - "
    \\(.*\\)
    ") + "
    \\((mixi Âà²ñºÑ)\\|\\(.*\\)\\)
    ") (defconst mixi-event-owner-seceded-regexp - "
    \\((mixi Âà²ñºÑ)\\)
    ") + "(mixi Âà²ñºÑ)") (defconst mixi-event-detail-regexp "
    \\(\\(.\\|\r?\n\\)*?\\)
    ") @@ -1958,12 +2003,14 @@ Increase this value when unexpected error frequently occurs." (mixi-event-set-place event (match-string 1)) (mixi-realization-error 'cannot-find-place event)) (if (re-search-forward mixi-event-owner-regexp nil t) - (mixi-event-set-owner event (mixi-make-friend (match-string 1) - (match-string 2))) - (if (re-search-forward mixi-event-owner-seceded-regexp nil t) - (mixi-event-set-owner event - (mixi-make-friend nil (match-string 1))) - (mixi-realization-error 'cannot-find-owner event))) + (let ((seceded-or-not (match-string 1)) + (id (match-string 2)) + (nick (match-string 3))) + (if (string= mixi-event-owner-seceded-regexp seceded-or-not) + (mixi-event-set-owner event + (mixi-make-friend nil seceded-or-not)) + (mixi-event-set-owner event (mixi-make-friend id nick)))) + (mixi-realization-error 'cannot-find-owner event)) (if (re-search-forward mixi-event-detail-regexp nil t) (mixi-event-set-detail event (match-string 1)) (mixi-realization-error 'cannot-find-detail event)) @@ -2150,7 +2197,7 @@ Increase this value when unexpected error frequently occurs." ;;;###autoload (defun mixi-get-bbses (community &optional range) - "Get bbese of COMMUNITY." + "Get bbses of COMMUNITY." (unless (mixi-community-p community) (signal 'wrong-type-argument (list 'mixi-community-p community))) (let ((items (mixi-get-matched-items (mixi-bbs-list-page community) @@ -2230,9 +2277,9 @@ Increase this value when unexpected error frequently occurs." (funcall func parent page))) ;; Comment object. -(defun mixi-make-comment (parent owner time content) +(defun mixi-make-comment (parent owner time content &optional count) "Return a comment object." - (cons 'mixi-comment (vector parent owner time content))) + (cons 'mixi-comment (vector parent owner time content count))) (defmacro mixi-comment-p (comment) `(eq (mixi-object-class ,comment) 'mixi-comment)) @@ -2261,6 +2308,12 @@ Increase this value when unexpected error frequently occurs." (signal 'wrong-type-argument (list 'mixi-comment-p comment))) (aref (cdr comment) 3)) +(defun mixi-comment-count (comment) + "Return the count of COMMENT." + (unless (mixi-comment-p comment) + (signal 'wrong-type-argument (list 'mixi-comment-p comment))) + (aref (cdr comment) 4)) + (defun mixi-diary-comment-list-page (diary) (concat "/view_diary.pl?full=1" "&id=" (mixi-diary-id diary) @@ -2275,23 +2328,8 @@ Increase this value when unexpected error frequently occurs." \\|\\) \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) - - -? - - - - - - - - - - - - -? ++
    \\(\\(.\\|\r?\n\\)*?\\)
    @@ -2305,7 +2343,8 @@ Increase this value when unexpected error frequently occurs." ;; FIXME: Split regexp to time, owner(id and nick) and contents. (defconst mixi-topic-comment-list-regexp - "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) + "
    \\(\\|\\) +\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)
    \\(.*\\)
    @@ -2320,7 +2359,8 @@ Increase this value when unexpected error frequently occurs." ;; FIXME: Split regexp to time, owner(id and nick) and contents. (defconst mixi-event-comment-list-regexp - "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) + "
    \\(\\|\\) +\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)
    \\(.*\\)
    @@ -2344,7 +2384,8 @@ Increase this value when unexpected error frequently occurs." (setq page nil)) (let ((items (mixi-get-matched-items page regexp range t))) (mapcar (lambda (item) - (let (owner-id owner-nick year month day hour minute content) + (let (owner-id owner-nick year month day hour minute content + count) (if (eq (mixi-object-class parent) 'mixi-diary) (progn (setq owner-id (nth 1 item)) @@ -2355,14 +2396,15 @@ Increase this value when unexpected error frequently occurs." (setq hour (nth 7 item)) (setq minute (nth 8 item)) (setq content (nth 9 item))) - (setq owner-id (nth 5 item)) - (setq owner-nick (nth 6 item)) - (setq year (nth 0 item)) - (setq month (nth 1 item)) - (setq day (nth 2 item)) - (setq hour (nth 3 item)) - (setq minute (nth 4 item)) - (setq content (nth 7 item))) + (setq owner-id (nth 8 item)) + (setq owner-nick (nth 9 item)) + (setq year (nth 3 item)) + (setq month (nth 4 item)) + (setq day (nth 5 item)) + (setq hour (nth 6 item)) + (setq minute (nth 7 item)) + (setq content (nth 10 item)) + (setq count (nth 1 item))) (mixi-make-comment parent (mixi-make-friend owner-id owner-nick) (encode-time @@ -2372,7 +2414,7 @@ Increase this value when unexpected error frequently occurs." (string-to-number day) (string-to-number month) (string-to-number year)) - content))) + content count))) items)))) (defmacro mixi-new-comment-list-page () @@ -2400,6 +2442,40 @@ Increase this value when unexpected error frequently occurs." diary))) items)))) +(defmacro mixi-new-bbs-comment-list-page () + `(concat "/new_bbs_comment.pl?page=%d")) + +(defconst mixi-new-bbs-comment-list-regexp + "") + +;;;###autoload +(defun mixi-get-new-bbs-comments (&optional range) + "Get new BBS comments." + (let ((items (mixi-get-matched-items (mixi-new-bbs-comment-list-page) + mixi-new-bbs-comment-list-regexp + range))) + (delq nil + (mapcar (lambda (item) + (let ((name (nth 0 item))) + (when (string= name "bbs") + (setq name "topic")) + (let ((make-func (intern (concat "mixi-make-" name))) + (comment-count-func + (intern (concat "mixi-" name "-comment-count"))) + (set-comment-count-func + (intern (concat "mixi-" name + "-set-comment-count")))) + (let* ((bbs (funcall make-func + (mixi-make-community (nth 3 item)) + (nth 1 item))) + (comment-count (funcall comment-count-func bbs)) + (count (string-to-number (nth 2 item)))) + (when (or (null comment-count) + (< comment-count count)) + (funcall set-comment-count-func bbs count) + bbs))))) + items)))) + (defun mixi-post-diary-comment-page (diary) (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary))) @@ -2766,21 +2842,18 @@ Increase this value when unexpected error frequently occurs." "&media_id=" (mixi-news-media-id ,news))) (defconst mixi-news-finished-regexp - "¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤³¤Î¥Ë¥å¡¼¥¹¤Ï·ÇºÜ¤¬½ªÎ»¤·¤¿¤«¡¢URL¤¬´Ö°ã¤Ã¤Æ¤¤¤¤¤ë¤¿¤á¤´Í÷¤¤¤¿¤À¤±¤Þ¤»¤ó¡£") + "

    ¢¨¿½¤·Ìõ¤¢¤ê¤Þ¤»¤ó¤¬¡¢¤³¤Î¥Ë¥å¡¼¥¹¤Ï·ÇºÜ´ü´Ö¤¬½ªÎ»¤·¤¿¤«¡¢URL¤¬´Ö°ã¤Ã¤Æ¤¤¤ë¤¿¤á¤´Í÷¤¤¤¿¤À¤±¤Þ¤»¤ó¡£¾Ü¤·¤¯¤Ï¤³¤Á¤é¤ò¤´Í÷¤¯¤À¤µ¤¤¡£

    ") (defconst mixi-news-title-regexp - "\\(.+\\)\\( -\\)?") + "
    +

    \\(.+\\)

    ") (defconst mixi-news-media-time-regexp - "(\\(.+\\) - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))") + "

    ¡Ê\\(.+\\) - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)¡Ë

    ") (defconst mixi-news-content-regexp - " - + "
    \\(.+\\) -
    -\\(.* -\\)? - -\\(\\|
    \\)") ++ +\\(
    +
    \\|
    \\)") (defun mixi-realize-news (news) "Realize a NEWS." @@ -2879,7 +2952,8 @@ Increase this value when unexpected error frequently occurs." (aset (cdr news) 6 content)) (defconst mixi-news-category-list '(domestic politics economy area abroad - sports entertainment IT)) + sports entertainment IT game-anime + column)) (defmacro mixi-news-category-p (category) `(memq ,category mixi-news-category-list)) @@ -2912,14 +2986,9 @@ Increase this value when unexpected error frequently occurs." "&type=bn")) (defconst mixi-news-list-regexp - " -¡¦ -\\(.+\\) -\\(\\|\\) - - -\\(.+\\) -\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)") + "

    ¡¦ \\(.+\\)\"\"

    +\\(.+\\) +\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)") ;;;###autoload (defun mixi-get-news (category sort &optional range) @@ -2934,17 +3003,80 @@ Increase this value when unexpected error frequently occurs." (year (nth 5 (decode-time (current-time)))) (month (nth 4 (decode-time (current-time))))) (mapcar (lambda (item) - (let ((month-of-item (string-to-number (nth 6 item)))) + (let ((month-of-item (string-to-number (nth 4 item)))) (when (> month-of-item month) (decf year)) (setq month month-of-item) - (mixi-make-news (nth 2 item) (nth 1 item) (nth 5 item) + (mixi-make-news (nth 1 item) (nth 0 item) (nth 3 item) (encode-time - 0 (string-to-number (nth 9 item)) - (string-to-number (nth 8 item)) - (string-to-number (nth 7 item)) + 0 (string-to-number (nth 7 item)) + (string-to-number (nth 6 item)) + (string-to-number (nth 5 item)) month year) - (nth 3 item)))) + (nth 2 item)))) + items))) + +;; Release object. +(defun mixi-make-release (title time content) + "Return a release object." + (cons 'mixi-release (vector title time content))) + +(defmacro mixi-release-p (release) + `(eq (mixi-object-class ,release) 'mixi-release)) + +(defun mixi-release-title (release) + "Return the title of RELEASE." + (unless (mixi-release-p release) + (signal 'wrong-type-argument (list 'mixi-release-p release))) + (aref (cdr release) 0)) + +(defun mixi-release-time (release) + "Return the time of RELEASE." + (unless (mixi-release-p release) + (signal 'wrong-type-argument (list 'mixi-release-p release))) + (aref (cdr release) 1)) + +(defun mixi-release-content (release) + "Return the content of RELEASE." + (unless (mixi-release-p release) + (signal 'wrong-type-argument (list 'mixi-release-p release))) + (aref (cdr release) 2)) + +(defmacro mixi-release-list-page () + `(concat "/release_info.pl?page=%d")) + +(defconst mixi-release-list-regexp + " ¢£ \\(.+\\) +\\([1-9][0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\) + + + + + + +
    + + + + + +
    +\\(.+\\) +
    ") + +;;;###autoload +(defun mixi-get-releases (&optional range) + "Get releases." + (let ((items (mixi-get-matched-items (mixi-release-list-page) + mixi-release-list-regexp + range))) + (mapcar (lambda (item) + (mixi-make-release (nth 0 item) + (encode-time 0 0 0 + (string-to-number (nth 3 item)) + (string-to-number (nth 2 item)) + (string-to-number (nth 1 item))) + (nth 4 item))) items))) (provide 'mixi)