| 1 | ;;; emms-info-opusinfo.el --- Emms information from Ogg Opus files. -*- lexical-binding: t; -*- |
| 2 | |
| 3 | ;; Copyright (C) 2018-2021 Free Software Foundation, Inc. |
| 4 | |
| 5 | ;; Author: Pierre Neidhardt <mail@ambrevar.xyz> |
| 6 | |
| 7 | ;; This file is part of EMMS. |
| 8 | |
| 9 | ;; EMMS is free software; you can redistribute it and/or modify it |
| 10 | ;; under the terms of the GNU General Public License as published by |
| 11 | ;; the Free Software Foundation; either version 3 of the License, or |
| 12 | ;; (at your option) any later version. |
| 13 | |
| 14 | ;; EMMS is distributed in the hope that it will be useful, |
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | ;; GNU General Public License for more details. |
| 18 | |
| 19 | ;; You should have received a copy of the GNU General Public License |
| 20 | ;; along with EMMS; if not, write to the Free Software Foundation, |
| 21 | ;; Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | |
| 23 | ;;; Commentary: |
| 24 | ;; |
| 25 | |
| 26 | ;;; Code: |
| 27 | |
| 28 | (require 'emms-info) |
| 29 | |
| 30 | (defgroup emms-info-opusinfo nil |
| 31 | "An EMMS-info method for getting, using the external opusinfo |
| 32 | program" |
| 33 | :group 'emms-info) |
| 34 | |
| 35 | (defcustom emms-info-opusinfo-coding-system 'utf-8 |
| 36 | "Coding system used in the output of opusinfo." |
| 37 | :type 'coding-system) |
| 38 | |
| 39 | (defcustom emms-info-opusinfo-program-name "opusinfo" |
| 40 | "The name/path of the opusinfo tag program." |
| 41 | :type 'string) |
| 42 | |
| 43 | (defun emms-info-opusinfo (track) |
| 44 | "Add track information to TRACK. |
| 45 | This is a useful element for `emms-info-functions'." |
| 46 | (when (and (emms-track-file-p track) |
| 47 | (or (string-match "\\.[Oo][Gg][Gg]\\'" (emms-track-name track)) |
| 48 | (string-match "\\.[Oo][Pp][Uu][Ss]\\'" (emms-track-name track)))) |
| 49 | |
| 50 | (with-temp-buffer |
| 51 | (call-process emms-info-opusinfo-program-name |
| 52 | nil t nil (emms-track-name track)) |
| 53 | |
| 54 | ;; play time |
| 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))) |
| 77 | (emms-track-set track |
| 78 | (intern (downcase (concat "info-" (match-string 1)))) |
| 79 | (match-string 2)))))))))) |
| 80 | |
| 81 | (provide 'emms-info-opusinfo) |
| 82 | |
| 83 | ;;; emms-info-opusinfo.el ends here |