add emms
[emacs.git] / .emacs.d / elisp / emms / lisp / emms-info-mp3info.el
1 ;;; emms-info-mp3info.el --- Info-method for EMMS using mp3info
2
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008,
4 ;; 2009 Free Software Foundation, Inc.
5
6 ;; Authors: Ulrik Jensen <terryp@daimi.au.dk>
7 ;; Jorgen Schäfer <forcer@forcix.cx>
8 ;; Keywords:
9
10 ;; This file is part of EMMS.
11
12 ;; EMMS is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; EMMS is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with EMMS; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;; This code has been adapted from code found in mp3player.el, written
30 ;; by Jean-Philippe Theberge (jphiltheberge@videotron.ca), Mario
31 ;; Domgoergen (kanaldrache@gmx.de) and Jorgen Schäfer
32 ;; <forcer@forcix.cx>
33
34 ;; To activate this method for getting info, use something like:
35
36 ;; (require 'emms-info-mp3info)
37 ;; (add-to-list 'emms-info-functions 'emms-info-mp3info)
38
39 ;;; Code:
40
41 (require 'emms-info)
42
43 (defvar emms-info-mp3info-version "0.2 $Revision: 1.10 $"
44 "EMMS info mp3info version string.")
45 ;; $Id: emms-info-mp3info.el,v 1.10 2005/08/12 18:01:16 xwl Exp $
46
47 (defgroup emms-info-mp3info nil
48 "An EMMS-info method for getting/setting ID3v1 tags, using the
49 external mp3info program"
50 :group 'emms-info)
51
52 (defcustom emms-info-mp3info-coding-system 'utf-8
53 "*Coding system used in the output of mp3info."
54 :type 'coding-system
55 :group 'emms-info-mp3info)
56
57 (defcustom emms-info-mp3info-program-name "mp3info"
58 "*The name/path of the mp3info tag program."
59 :type 'string
60 :group 'emms-info-mp3info)
61
62 (defcustom emms-info-mp3find-arguments
63 `("-p" ,(concat "info-artist=%a\\n"
64 "info-title=%t\\n"
65 "info-album=%l\\n"
66 "info-tracknumber=%n\\n"
67 "info-year=%y\\n"
68 "info-genre=%g\\n"
69 "info-note=%c\\n"
70 "info-playing-time=%S\\n"))
71 "The argument to pass to `emms-info-mp3info-program-name'.
72 This should be a list of info-flag=value lines."
73 :type '(repeat string)
74 :group 'emms-info-mp3info)
75
76 (defun emms-info-mp3info (track)
77 "Add track information to TRACK.
78 This is a useful element for `emms-info-functions'."
79 (when (and (eq 'file (emms-track-type track))
80 (string-match "\\.[Mm][Pp]3\\'" (emms-track-name track)))
81 (with-temp-buffer
82 (when (zerop
83 (apply (if (fboundp 'emms-i18n-call-process-simple)
84 'emms-i18n-call-process-simple
85 'call-process)
86 emms-info-mp3info-program-name
87 nil t nil
88 (append emms-info-mp3find-arguments
89 (list (emms-track-name track)))))
90 (goto-char (point-min))
91 (while (looking-at "^\\([^=\n]+\\)=\\(.*\\)$")
92 (let ((name (intern (match-string 1)))
93 (value (match-string 2)))
94 (when (> (length value)
95 0)
96 (emms-track-set track
97 name
98 (if (eq name 'info-playing-time)
99 (string-to-number value)
100 value))))
101 (forward-line 1))))))
102
103 (provide 'emms-info-mp3info)
104 ;;; emms-info-mp3info.el ends here