add emms
[emacs.git] / .emacs.d / elisp / emms / lisp / emms-info-metaflac.el
1 ;;; emms-info-metaflac.el --- Info-method for EMMS using metaflac
2
3 ;; Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4
5 ;; Author: Matthew Kennedy <mkennedy@gentoo.org>
6 ;; Keywords:
7
8 ;; This file is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12
13 ;; This file is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 ;; Boston, MA 02110-1301 USA
22
23 ;;; Commentary:
24
25 ;; This code has been adapted from code found in emms-info-mp3info.el
26 ;; written by Ulrik Jensen <terryp@daimi.au.dk> which contains the
27 ;; following attribution:
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-metaflac)
37 ;; (add-to-list 'emms-info-methods-list 'emms-info-metaflac)
38
39 ;;; Code:
40
41 (eval-when-compile (require 'cl))
42 (require 'emms-info)
43
44 (defvar emms-info-metaflac-version "0.1 $Revision: 1.10 $"
45 "EMMS info metaflac version string.")
46
47 ;; $Id: emms-info-mp3info.el,v 1.10 2005/08/12 18:01:16 xwl Exp $
48
49 (defgroup emms-info-metaflac nil
50 "An EMMS-info method for getting/setting FLAC tags, using the
51 external metaflac program"
52 :group 'emms-info)
53
54 (defcustom emms-info-metaflac-program-name "metaflac"
55 "*The name/path of the metaflac program."
56 :type 'string
57 :group 'emms-info-metaflac)
58
59 (defcustom emms-info-metaflac-options
60 '("--no-utf8-convert"
61 "--show-tag=TITLE"
62 "--show-tag=ARTIST"
63 "--show-tag=ALBUM"
64 "--show-tag=NOTE"
65 "--show-tag=YEAR"
66 "--show-tag=TRACKNUMBER"
67 "--show-tag=DISCNUMBER"
68 "--show-tag=GENRE")
69 "The argument to pass to `emms-info-metaflac-program-name'."
70 :type '(repeat string)
71 :group 'emms-info-metaflac)
72
73 (defun emms-info-metaflac (track)
74 "Get the FLAC tag of file TRACK, using `emms-info-metaflac-program'
75 and return an emms-info structure representing it."
76 (when (and (eq 'file (emms-track-type track))
77 (string-match "\\.\\(flac\\|FLAC\\)\\'" (emms-track-name track)))
78 (with-temp-buffer
79 (when (zerop
80 (apply 'call-process
81 emms-info-metaflac-program-name
82 nil t nil
83 "--show-total-samples"
84 "--show-sample-rate"
85 (append emms-info-metaflac-options
86 (list (emms-track-name track)))))
87 (goto-char (point-min))
88 (emms-track-set track 'info-playing-time
89 (/ (string-to-number (buffer-substring (point) (line-end-position)))
90 (progn
91 (forward-line 1)
92 (string-to-number (buffer-substring (point) (line-end-position))))))
93 (forward-line 1)
94 (while (looking-at "^\\([^=\n]+\\)=\\(.*\\)$")
95 (let ((name (intern (concat "info-" (downcase (match-string 1)))))
96 (value (match-string 2)))
97 (when (> (length value)
98 0)
99 (emms-track-set track
100 name
101 (if (eq name 'info-playing-time)
102 (string-to-number value)
103 value))))
104 (forward-line 1))))))
105
106 (provide 'emms-info-metaflac)
107
108 ;;; emms-info-metaflac.el ends here