fordon_greeman / voidfiles

Branch: main
Switch branches/tags
main
theidioticdev add emacs 2079ec5 1d ago
106 lines · 3.8 KB Raw Blame History
1 ;;; emms-info-metaflac.el --- Info-method for EMMS using metaflac -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2006-2021 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-hook 'emms-info-methods-list 'emms-info-metaflac)
38
39 ;;; Code:
40
41 (require 'emms-info)
42
43 (defvar emms-info-metaflac-version "0.1 $Revision: 1.10 $"
44 "EMMS info metaflac version string.")
45
46 ;; $Id: emms-info-mp3info.el,v 1.10 2005/08/12 18:01:16 xwl Exp $
47
48 (defgroup emms-info-metaflac nil
49 "An EMMS-info method for getting/setting FLAC tags, using the
50 external metaflac program"
51 :group 'emms-info)
52
53 (defcustom emms-info-metaflac-program-name "metaflac"
54 "The name/path of the metaflac program."
55 :type 'string)
56
57 (defcustom emms-info-metaflac-options
58 '("--no-utf8-convert"
59 "--show-tag=TITLE"
60 "--show-tag=ARTIST"
61 "--show-tag=ALBUMARTIST"
62 "--show-tag=ALBUM"
63 "--show-tag=NOTE"
64 "--show-tag=YEAR"
65 "--show-tag=TRACKNUMBER"
66 "--show-tag=DISCNUMBER"
67 "--show-tag=GENRE")
68 "The argument to pass to `emms-info-metaflac-program-name'."
69 :type '(repeat string))
70
71 (defun emms-info-metaflac (track)
72 "Get the FLAC tag of file TRACK, using `emms-info-metaflac-program'
73 and return an emms-info structure representing it."
74 (when (and (emms-track-file-p track)
75 (string-match "\\.\\(flac\\|FLAC\\)\\'" (emms-track-name track)))
76 (with-temp-buffer
77 (when (zerop
78 (apply 'call-process
79 emms-info-metaflac-program-name
80 nil t nil
81 "--show-total-samples"
82 "--show-sample-rate"
83 (append emms-info-metaflac-options
84 (list (emms-track-name track)))))
85 (goto-char (point-min))
86 (emms-track-set track 'info-playing-time
87 (/ (string-to-number (buffer-substring (point) (line-end-position)))
88 (progn
89 (forward-line 1)
90 (string-to-number (buffer-substring (point) (line-end-position))))))
91 (forward-line 1)
92 (while (looking-at "^\\([^=\n]+\\)=\\(.*\\)$")
93 (let ((name (intern (concat "info-" (downcase (match-string 1)))))
94 (value (match-string 2)))
95 (when (> (length value)
96 0)
97 (emms-track-set track
98 name
99 (if (eq name 'info-playing-time)
100 (string-to-number value)
101 value))))
102 (forward-line 1))))))
103
104 (provide 'emms-info-metaflac)
105
106 ;;; emms-info-metaflac.el ends here