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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
;;; emms-info.el --- Retrieving track information
;; Copyright (C) 2005, 2006 Free Software Foundation Inc.
;; Author: Jorgen Schaefer <forcer@forcix.cx>
;; 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 2
;; 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:
;; This EMMS module provides a way to add information for a track.
;; This can use an ID3 or OGG comment like syntax.
;; The code will add info symbols to the track. The following symbols
;; are defined:
;; info-artist - string naming the artist
;; info-title - string naming the title of the song
;; info-album - string naming the album
;; info-tracknumber - string(?) naming the track number
;; info-year - string naming the year
;; info-note - string of free-form entry
;; info-genre - string naming the genre
;; info-playing-time - number giving the seconds of playtime
;;; Code:
(require 'emms)
(require 'later-do)
(defgroup emms-info nil
"*Track information. ID3, OGG, etc."
:group 'emms)
(defcustom emms-info-auto-update t
"*Non-nil when EMMS should update track information if the file changes.
This will cause hard drive activity on track loading. If this is
too annoying for you, set this variable to nil."
:type 'boolean
:group 'emms-info)
(defcustom emms-info-asynchronously t
"*Non-nil when track information should be loaded asynchronously.
This requires `later-do', which should come with EMMS."
:type 'boolean
:group 'emms-info)
(defcustom emms-info-report-each-num-tracks 200
"*Non-zero will report progress information every number of tracks.
The default is to display a message every 200 tracks.
This variable is only used when adding tracks asynchronously."
:type 'integer
:group 'emms-info)
(defcustom emms-info-functions nil
"*Functions which add information to tracks.
Each is called with a track as argument."
:type 'hook
:group 'emms-info)
(defvar emms-info-asynchronous-tracks 0
"Number of tracks we're waiting for to be done.")
(defun emms-info-initialize-track (track)
"Initialize TRACK with emms-info information.
This is a suitable value for `emms-track-initialize-functions'."
(if (not emms-info-asynchronously)
(emms-info-really-initialize-track track)
(setq emms-info-asynchronous-tracks (1+ emms-info-asynchronous-tracks))
(later-do 'emms-info-really-initialize-track track)))
(defun emms-info-really-initialize-track (track)
"Really initialize TRACK.
Return t when the track got changed."
(let ((file-mtime (when emms-info-auto-update
(emms-info-track-file-mtime track)))
(info-mtime (emms-track-get track 'info-mtime))
(name (emms-track-get track 'name)))
;; if the file's been modified or is new
(when (or (not file-mtime)
(not info-mtime)
(emms-time-less-p info-mtime file-mtime))
(run-hook-with-args 'emms-info-functions track)
;; not set by info functions
(when file-mtime
(emms-track-set track 'info-mtime file-mtime))
(emms-track-updated track))
(when emms-info-asynchronously
(setq emms-info-asynchronous-tracks (1- emms-info-asynchronous-tracks))
(if (zerop emms-info-asynchronous-tracks)
(message "EMMS: All track information loaded.")
(unless (zerop emms-info-report-each-num-tracks)
(if (zerop
(mod emms-info-asynchronous-tracks
emms-info-report-each-num-tracks))
(message "EMMS: %d tracks to go.."
emms-info-asynchronous-tracks)))))))
(defun emms-info-track-file-mtime (track)
"Return the mtime of the file of TRACK, if any.
Return nil otherwise."
(if (eq (emms-track-type track)
'file)
(nth 5 (file-attributes (emms-track-name track)))
nil))
(defun emms-info-track-description (track)
"Return a description of the current track."
(let ((artist (emms-track-get track 'info-artist))
(title (emms-track-get track 'info-title)))
(if (and artist title)
(format "%s - %s" artist title)
(emms-track-simple-description track))))
(provide 'emms-info)
;;; emms-info.el ends here
|