| 1 | ;;; emms-info-mp3info.el --- Info-method for EMMS using mp3info -*- lexical-binding: t; -*- |
| 2 | |
| 3 | ;; Copyright (C) 2003-2021 Free Software Foundation, Inc. |
| 4 | |
| 5 | ;; Authors: Ulrik Jensen <terryp@daimi.au.dk> |
| 6 | ;; Jorgen Schäfer <forcer@forcix.cx> |
| 7 | ;; Keywords: |
| 8 | |
| 9 | ;; This file is part of EMMS. |
| 10 | |
| 11 | ;; EMMS is free software; you can redistribute it and/or modify |
| 12 | ;; it under the terms of the GNU General Public License as published by |
| 13 | ;; the Free Software Foundation; either version 3, or (at your option) |
| 14 | ;; any later version. |
| 15 | |
| 16 | ;; EMMS is distributed in the hope that it will be useful, |
| 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | ;; GNU General Public License for more details. |
| 20 | |
| 21 | ;; You should have received a copy of the GNU General Public License |
| 22 | ;; along with EMMS; see the file COPYING. If not, write to the |
| 23 | ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 24 | ;; Boston, MA 02110-1301, USA. |
| 25 | |
| 26 | ;;; Commentary: |
| 27 | |
| 28 | ;; This code has been adapted from code found in mp3player.el, written |
| 29 | ;; by Jean-Philippe Theberge (jphiltheberge@videotron.ca), Mario |
| 30 | ;; Domgoergen (kanaldrache@gmx.de) and Jorgen Schäfer |
| 31 | ;; <forcer@forcix.cx> |
| 32 | |
| 33 | ;; To activate this method for getting info, use something like: |
| 34 | |
| 35 | ;; (require 'emms-info-mp3info) |
| 36 | ;; (add-to-list 'emms-info-functions 'emms-info-mp3info) |
| 37 | |
| 38 | ;;; Code: |
| 39 | |
| 40 | (require 'emms-info) |
| 41 | |
| 42 | (defvar emms-info-mp3info-version "0.2 $Revision: 1.10 $" |
| 43 | "EMMS info mp3info version string.") |
| 44 | ;; $Id: emms-info-mp3info.el,v 1.10 2005/08/12 18:01:16 xwl Exp $ |
| 45 | |
| 46 | (defgroup emms-info-mp3info nil |
| 47 | "An EMMS-info method for getting/setting ID3v1 tags, using the |
| 48 | external mp3info program" |
| 49 | :group 'emms-info) |
| 50 | |
| 51 | (defcustom emms-info-mp3info-coding-system 'utf-8 |
| 52 | "Coding system used in the output of mp3info." |
| 53 | :type 'coding-system) |
| 54 | |
| 55 | (defcustom emms-info-mp3info-program-name "mp3info" |
| 56 | "The name/path of the mp3info tag program." |
| 57 | :type 'string) |
| 58 | |
| 59 | (defcustom emms-info-mp3find-arguments |
| 60 | `("-p" ,(concat "info-artist=%a\\n" |
| 61 | "info-title=%t\\n" |
| 62 | "info-album=%l\\n" |
| 63 | "info-tracknumber=%n\\n" |
| 64 | "info-year=%y\\n" |
| 65 | "info-genre=%g\\n" |
| 66 | "info-note=%c\\n" |
| 67 | "info-playing-time=%S\\n")) |
| 68 | "The argument to pass to `emms-info-mp3info-program-name'. |
| 69 | This should be a list of info-flag=value lines." |
| 70 | :type '(repeat string)) |
| 71 | |
| 72 | (defun emms-info-mp3info (track) |
| 73 | "Add track information to TRACK. |
| 74 | This is a useful element for `emms-info-functions'." |
| 75 | (when (and (emms-track-file-p track) |
| 76 | (string-match "\\.[Mm][Pp]3\\'" (emms-track-name track))) |
| 77 | (with-temp-buffer |
| 78 | (when (zerop |
| 79 | (apply (if (fboundp 'emms-i18n-call-process-simple) |
| 80 | 'emms-i18n-call-process-simple |
| 81 | 'call-process) |
| 82 | emms-info-mp3info-program-name |
| 83 | nil t nil |
| 84 | (append emms-info-mp3find-arguments |
| 85 | (list (emms-track-name track))))) |
| 86 | (goto-char (point-min)) |
| 87 | (while (looking-at "^\\([^=\n]+\\)=\\(.*\\)$") |
| 88 | (let ((name (intern (match-string 1))) |
| 89 | (value (match-string 2))) |
| 90 | (when (> (length value) |
| 91 | 0) |
| 92 | (emms-track-set track |
| 93 | name |
| 94 | (if (eq name 'info-playing-time) |
| 95 | (string-to-number value) |
| 96 | value)))) |
| 97 | (forward-line 1)))))) |
| 98 | |
| 99 | (provide 'emms-info-mp3info) |
| 100 | ;;; emms-info-mp3info.el ends here |