fordon_greeman / voidfiles

Branch: 2079ec5
Switch branches/tags
main
theidioticdev add emacs 2079ec5 23h ago
83 lines · 3 KB Raw Blame History
1 ;;; emms-info-ogginfo.el --- Emms information from Ogg Vorbis files. -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2005-2021 Free Software Foundation, Inc.
4
5 ;; Author: Jorgen Schaefer <forcer@forcix.cx>
6 ;; Yoni Rabkin <yrk@gnu.org>
7
8 ;; This file is part of EMMS.
9
10 ;; EMMS is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; EMMS is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with EMMS; if not, write to the Free Software Foundation,
22 ;; Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
23
24 ;;; Commentary:
25 ;;
26
27 ;;; Code:
28
29 (require 'emms-info)
30
31 (defgroup emms-info-ogginfo nil
32 "An EMMS-info method for getting, using the external ogginfo
33 program"
34 :group 'emms-info)
35
36 (defcustom emms-info-ogginfo-coding-system 'utf-8
37 "Coding system used in the output of ogginfo."
38 :type 'coding-system)
39
40 (defcustom emms-info-ogginfo-program-name "ogginfo"
41 "The name/path of the ogginfo tag program."
42 :type 'string)
43
44 (defun emms-info-ogginfo (track)
45 "Add track information to TRACK.
46 This is a useful element for `emms-info-functions'."
47 (when (and (emms-track-file-p track)
48 (string-match "\\.[Oo][Gg][Gg]\\'" (emms-track-name track)))
49
50 (with-temp-buffer
51 (call-process emms-info-ogginfo-program-name
52 nil t nil (emms-track-name track))
53
54 ;; play time, emms-info-ogg.el [U. Jensen]
55 (goto-char (point-min))
56 (when (re-search-forward
57 "Playback length: \\([0-9]*\\)m:\\([0-9]*\\)" nil t)
58 (let* ((minutes (string-to-number (match-string 1)))
59 (seconds (string-to-number (match-string 2)))
60 (ptime-total (+ (* minutes 60) seconds))
61 (ptime-min minutes)
62 (ptime-sec seconds))
63 (emms-track-set track 'info-playing-time ptime-total)
64 (emms-track-set track 'info-playing-time-min ptime-min)
65 (emms-track-set track 'info-playing-time-sec ptime-sec)
66 (emms-track-set track 'info-file (emms-track-name track))))
67
68 ;; all the rest of the info available
69 (goto-char (point-min))
70 (when (re-search-forward "^.*\\.\\.\\.$" (point-max) t)
71 (while (zerop (forward-line 1))
72 (when (looking-at "^\t\\(.*?\\)=\\(.*\\)$") ; recognize the first '='
73 (let ((a (match-string 1))
74 (b (match-string 2)))
75 (when (and (< 0 (length a))
76 (< 0 (length b) 1024))
77 (emms-track-set track
78 (intern (downcase (concat "info-" (match-string 1))))
79 (match-string 2))))))))))
80
81 (provide 'emms-info-ogginfo)
82
83 ;;; emms-info-ogginfo.el ends here