diff options
author | forcer <forcer> | 2005-09-20 16:59:00 +0000 |
---|---|---|
committer | forcer <mwolson@gnu.org> | 2005-09-20 16:59:00 +0000 |
commit | d7e4c9c9465fefe3aae7da19f6eac079b06c6670 (patch) | |
tree | 3741b078debcd147de20694049f996f05eb8d243 | |
parent | 7a0a6df204101c34330cdef60f9b2cb4112729ee (diff) |
emms-info-mp3info.el updated for newest emms-info.el
darcs-hash:20050920165928-2189f-592a72839b3d1567866d6b7dd40a7c41a20d435e.gz
-rw-r--r-- | emms-info-mp3info.el | 142 |
1 files changed, 34 insertions, 108 deletions
diff --git a/emms-info-mp3info.el b/emms-info-mp3info.el index f1a0ed9..e20056c 100644 --- a/emms-info-mp3info.el +++ b/emms-info-mp3info.el @@ -2,7 +2,8 @@ ;; Copyright (C) 2003 Free Software Foundation, Inc. -;; Author: Ulrik Jensen <terryp@daimi.au.dk> +;; Authors: Ulrik Jensen <terryp@daimi.au.dk> +;; Jorgen Schäfer <forcer@forcix.cx> ;; Keywords: ;; This file is free software; you can redistribute it and/or modify @@ -24,135 +25,60 @@ ;; This code has been adapted from code found in mp3player.el, written ;; by Jean-Philippe Theberge (jphiltheberge@videotron.ca), Mario -;; Domgoergen (kanaldrache@gmx.de) and Jorgen Schäfer +;; Domgoergen (kanaldrache@gmx.de) and Jorgen Schäfer ;; <forcer@forcix.cx> ;; To activate this method for getting info, use something like: ;; (require 'emms-info-mp3info) -;; (add-to-list 'emms-info-methods-list 'emms-info-mp3info) +;; (add-to-list 'emms-info-functions 'emms-info-mp3info) ;;; Code: -(eval-when-compile (require 'cl)) -(require 'emms-info) (defvar emms-info-mp3info-version "0.2 $Revision: 1.10 $" "EMMS info mp3info version string.") ;; $Id: emms-info-mp3info.el,v 1.10 2005/08/12 18:01:16 xwl Exp $ (defgroup emms-info-mp3info nil - "An EMMS-info method for getting/setting ID3v1 tags, using a + "An EMMS-info method for getting/setting ID3v1 tags, using the external mp3info program" - :group 'emms-info-methods) + :group 'emms-info) (defcustom emms-info-mp3info-program-name "mp3info" "*The name/path of the mp3info tag program." :type 'string :group 'emms-info-mp3info) -(defcustom emms-info-mp3info-field-names - '(title "title" - artist "artist" - album "album" - note "description" - year "date" - genre "genre" - file (emms-track-name track) - playing-time "playing-time" - playing-time-min "playing-time-min" - playing-time-sec "playing-time-sec") - "Plist of field names." - :type 'plist +(defcustom emms-info-mp3findo-arguments + `("-p" ,(concat "info-artist=%a\\n" + "info-title=%t\\n" + "info-album=%l\\n" + "info-tracknum=%n\\n" + "info-year=%y\\n" + "info-genre=%g\\n" + "info-note=%c\\n" + "info-playing-time=%S\\n")) + "The argument to pass to `emms-info-mp3info-program-name'. +This should be a list of info-flag=value lines." + :type '(repeat string) :group 'emms-info-mp3info) -(defcustom emms-info-mp3info-set-parameter - '(title "-t" - artist "-a" - album "-l" - note "-c" - year "-y" - genre "-g") - "Parameter list" - :type 'plist - :group 'emms-info-mp3info) - -(defcustom emms-info-field-delemiter "=" - "Delemiter between field and content." - :type 'string - :group 'emms-info-mp3info) - -(defcustom emms-info-field-seperator "\n" - "Seperator between different fields." - :type 'string - :group 'emms-info-mp3info) - - -(define-emms-info-method emms-info-mp3info - :providep 'emms-info-mp3info-providep - :get 'emms-info-mp3info-get - :set 'emms-info-mp3info-set) - -(defun emms-info-mp3info-providep (track) - "Return non-nil if this info-method provides info for the track." - (if (and track (emms-track-name track) - (string-match "\\.mp3$" (emms-track-name track))) - t - nil)) - -(defun emms-info-mp3info-set (track info) - "Set the id3v1 tag of file TRACK to id3info INFO, using the -mp3info-program" - ;; 0 = discard & don't wait for termination. - (call-process emms-info-mp3info-program-name nil 0 nil - "-a" (emms-info-artist info) - "-t" (emms-info-title info) - "-l" (emms-info-album info) - "-c" (emms-info-note info) - "-y" (emms-info-year info) - (emms-track-name track))) - -(defun emms-info-retrieve (field) - "Search for field and get content. -If there is no field return an empty string" - (goto-char (point-min)) - (save-match-data - (or (progn - (re-search-forward - (concat field emms-info-field-delemiter "\\(.*\\)" - emms-info-field-seperator) - nil t) - (match-string 1)) - ""))) - - -(defun emms-info-mp3info-get (track) - "Get the id3v1 tag of file TRACK, using the mp3info-program and -return an emms-info structure representing it." - (with-temp-buffer - (call-process emms-info-mp3info-program-name nil t nil - "-p" - (concat "title=%t\n" "artist=%a\n" "album=%l\n" - "date=%y\n" "genre=%G\n" "description=%c\n" - "playing-time=%S\n" "playing-time-min=%m\n" - "playing-time-sec=%s\n") - (emms-track-name track)) - (flet ((retrieve-info (field) - (goto-char (point-min)) - (save-match-data - (when (re-search-forward (concat field "=\\(.*\\)") - nil t) - (or (match-string 1) ""))))) - (make-emms-info - :title (retrieve-info "title") - :artist (retrieve-info "artist") - :album (retrieve-info "album") - :note (retrieve-info "description") - :year (retrieve-info "date") - :genre (retrieve-info "genre") - :file (emms-track-name track) - :playing-time (retrieve-info "playing-time") - :playing-time-min (retrieve-info "playing-time-min") - :playing-time-sec (retrieve-info "playing-time-sec"))))) +(defun emms-info-mp3info (track) + "Add track information to TRACK. +This is a useful element for `emms-info-functions'." + (when (eq 'file (emms-track-type track)) + (with-temp-buffer + (when (zerop (apply 'call-process + emms-info-mp3info-program-name + nil t nil + (emms-track-name track) + emms-info-mp3findo-arguments)) + (goto-char (point-min)) + (while (looking-at "^\\([^=]+\\)=\\(.*\\)$") + (emms-track-set track + (intern (match-string 1)) + (match-string 2)) + (forward-line 1)))))) (provide 'emms-info-mp3info) ;;; emms-info-mp3info.el ends here |