[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[emms-help] multiple coding system tag recognize
From: |
Ye Wenbin |
Subject: |
[emms-help] multiple coding system tag recognize |
Date: |
Thu, 07 Dec 2006 14:39:23 +0800 |
User-agent: |
Opera Mail/9.02 (Linux) |
I wrote the lib emms-i18n, it provide several funcition to handle
coding system convertion or detection.
emms-iconv is used for convert a string from one coding system to
other coding system, much like the iconv does. The difference between
emms-iconv and encode-coding-string is that,
emms-iconv is used when using a wrong coding system to decode text.
For example, the tags in file is encode by gb2312, but the
locale-coding-system is utf-8, so the process usually use utf-8 to
encode output. So to get a correct output, use
(emms-iconv 'gb2312 'utf-8 string)
This is a simple case to simulate the process:
(let* ((tags (char-to-string (decode-char 'ucs #xc0)))
(encode-tags (encode-coding-string tags 'latin-1))
(wrong-tags (decode-coding-string encode-tags 'utf-8))
(right-tags (emms-iconv 'latin-1 'utf-8 wrong-tags)))
(message "Tags in file is %s, which encoded to %s." tags encode-tags)
(message "I use wrong coding to decode the tag and get %s." wrong-tags)
(message "So need iconv the string, now get right tag: %s." right-tags))
emms-call-process-simple is mean to help detect coding system of
process output. This function run program and return the program
result. If the CAR part of `emms-default-coding-system' is non-nil,
the program result will be decode use the CAR part of
emms-default-coding-system. Otherwise, use
`emms-coding-dectect-functions' to detect the coding system of the
result. If the emms-coding-dectect-functions failed, use
`emms-detect-coding-function' to detect coding system. If all the
coding system is nil or in `emms-nerver-used-coding-system', decode
the result using `emms-coding-system-for-read'.
The emms-detect-coding-function which use intern function
detect-coding-region is very like the coding dectection like
find-file. So if your emacs can detect the file coding system
correctly, this function should return the correct result.
I think emms-info-mp3info can use emms-call-process-simple. Simply
replace 'call-process to 'emms-call-process-simple and remove the
coding convertion part will work. I test two mp3 file, one use gbk tag
and the other use utf-8 tag, the coding is recognize successfully.
By the way, ogginfo seems only support utf-8 tag.
The new emms-info-mp3info definition:
(require 'emms-i18n)
(defun emms-info-mp3info (track)
"Add track information to TRACK.
This is a useful element for `emms-info-functions'."
(when (and (eq 'file (emms-track-type track))
(string-match "\\.[Mm][Pp]3\\'" (emms-track-name track)))
(with-temp-buffer
(when (zerop
(apply 'emms-call-process-simple
emms-info-mp3info-program-name
nil t nil
(emms-track-name track)
emms-info-mp3find-arguments))
(goto-char (point-min))
(while (looking-at "^\\([^=\n]+\\)=\\(.*\\)$")
(let ((name (intern (match-string 1)))
(value (match-string 2)))
(when (> (length value)
0)
(emms-track-set track
name
(if (eq name 'info-playing-time)
(string-to-number value)
value))))
(forward-line 1))))))
--
Regard,
-- Ye Wenbin
- [emms-help] multiple coding system tag recognize,
Ye Wenbin <=