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