aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Xu <william.xwl@gmail.com>2007-03-02 14:11:00 +0000
committerWilliam Xu <william.xwl@gmail.com>2007-03-02 14:11:00 +0000
commit7a900b9da3998446b7b61fe8d17d0ea5f276ee6e (patch)
tree43e47aa2fcc2e717412a814873456f9dd39340ab
parentcddc8bac0335301b8c9837a6b997d09b26c943fc (diff)
emms-lyrics.el: Add chinese lyrics lookup support to
`emms-lyrics-visit-lyric'. darcs-hash:20070302141102-cfa61-314352c7bbddecdcac1c21df80e410d36b12df10.gz
-rw-r--r--emms-lyrics.el48
1 files changed, 39 insertions, 9 deletions
diff --git a/emms-lyrics.el b/emms-lyrics.el
index 32025d9..454a1fd 100644
--- a/emms-lyrics.el
+++ b/emms-lyrics.el
@@ -44,7 +44,7 @@
;; 1. Maybe the lyric setup should run before `emms-start'.
;; 2. Give a user a chance to choose when finding out multiple lyrics.
-;; 3. Search lyrics from internet ?
+;; 3. Search .lrc format lyrics from internet ?
;;; Code:
@@ -199,14 +199,15 @@ If we can't find it from local disk, then search it from internet."
(unless title
(setq title (file-name-sans-extension
(file-name-nondirectory name))))
- ;; (if (string-match "\\cc" title)
- ;; baidu couldn't handle chinese correctly?
- ;; "http://mp3.baidu.com/m?f=ms&rn=10&tn=baidump3lyric&ct=150994944&word=hello
- ;; &submit=%B0%D9%B6%C8%CB%D1%CB%F7&lm=-1"
- ;; "http://mp3.baidu.com/"
- (setq url (concat "http://search.lyrics.astraweb.com/?word="
- ;;"http://www.lyrics007.com/cgi-bin/s.cgi?q="
- (replace-regexp-in-string " " "+" title)))
+ (cond ((string-match "\\cc" title) ; chinese lyrics
+ (setq url (format
+ "http://mp3.baidu.com/m?f=ms&rn=10&tn=baidump3lyric&ct=150994944&word=%s&lm=-1"
+ (emms-lyrics-url-quote-plus
+ (encode-coding-string title 'gb2312)))))
+ (else ; english lyrics
+ (setq url (format "http://search.lyrics.astraweb.com/?word=%s"
+ ;;"http://www.lyrics007.com/cgi-bin/s.cgi?q="
+ (replace-regexp-in-string " " "+" title)))))
(browse-url url)
(message "lyric file does not exist, search it from internet...done")))))
@@ -468,6 +469,35 @@ NEXT-LYRIC."
(setq pos (1+ pos))))))
+;;; Utilities
+
+(defun emms-lyrics-url-quote (s &optional safe)
+ "Replace special characters in S using the `%xx' escape.
+Characters in [a-zA-Z_.-/] and SAFE(default is \"\")) will never be
+quoted.
+e.g.,
+ (url-quote \"abc def\") => \"abc%20def\"."
+ (or safe (setq safe ""))
+ (mapconcat (lambda (c)
+ (if (if (string-match "]" safe)
+ ;; ] should be place at the beginning inside []
+ (string-match
+ (format "[]a-zA-Z_.-/%s]"
+ (replace-regexp-in-string "]" "" safe))
+ (char-to-string c))
+ (string-match (format "[a-zA-Z_.-/%s]" safe)
+ (char-to-string c)))
+ (char-to-string c)
+ (format "%%%02x" c)))
+ (string-to-list (encode-coding-string s 'utf-8))
+ ""))
+
+(defun emms-lyrics-url-quote-plus (s &optional safe)
+ "Run (emms-url-quote s \" \"), then replace ` ' with `+'."
+ (replace-regexp-in-string
+ " " "+" (emms-url-quote s (concat safe " "))))
+
+
;;; emms-lyrics-mode
(defvar emms-lyrics-mode-map