aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlucas <lucas>2006-06-07 17:28:00 +0000
committerlucas <mwolson@gnu.org>2006-06-07 17:28:00 +0000
commit96a3ac588fbbd593558a305d95039abe8474a63c (patch)
tree6a573c3f0a34244f5b3be45a1f04afe0a20c1e17
parent84acadce0e7916d1dd95a80aa69e57752ec80615 (diff)
Very basic support for recording the time you last played a track.
* emms-last-played.el: New file. Nothing fancy right now, more to come soon. * emms-setup.el: emms-devel now requires and setups emms-last-played. darcs-hash:20060607172830-4f952-fd247551c7da305be27b8f783e785bdd9c2c8689.gz
-rw-r--r--emms-last-played.el107
-rw-r--r--emms-setup.el6
2 files changed, 112 insertions, 1 deletions
diff --git a/emms-last-played.el b/emms-last-played.el
new file mode 100644
index 0000000..428385c
--- /dev/null
+++ b/emms-last-played.el
@@ -0,0 +1,107 @@
+;;; emms-last-played.el --- Support for last-played-time of a track
+
+;; Copyright (C) 2006 Lucas Bonnet <lucas@rincevent.net>
+
+;; Author: Lucas Bonnet <lucas@rincevent.net>
+;; Keywords: emms, mp3, mpeg, multimedia
+
+;; This file 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, or (at your option)
+;; any later version.
+
+;; This file 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 GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; Records when the track was last played.
+;; Big portions of the time handling fuctions are copied from
+;; gnus-util.el, and slightly adapted.
+
+;;; Code:
+
+(require 'emms)
+
+(defvar emms-last-played-format-alist
+ '(((emms-last-played-seconds-today) . "%k:%M")
+ (604800 . "%a %k:%M") ;;that's one week
+ ((emms-last-played-seconds-month) . "%a %d")
+ ((emms-last-played-seconds-year) . "%b %d")
+ (t . "%b %d '%y")) ;;this one is used when no
+ ;;other does match
+ "Specifies date format depending on when a track was last played.
+This is an alist of items (AGE . FORMAT). AGE can be a number (of
+seconds) or a Lisp expression evaluating to a number. When the age of
+the track is less than this number, then use `format-time-string'
+with the corresponding FORMAT for displaying the date of the track.
+If AGE is not a number or a Lisp expression evaluating to a
+non-number, then the corresponding FORMAT is used as a default value.
+
+Note that the list is processed from the beginning, so it should be
+sorted by ascending AGE. Also note that items following the first
+non-number AGE will be ignored.
+
+You can use the functions `emms-last-played-seconds-today',
+`emms-last-played-seconds-month' and
+`emms-last-played-seconds-year' in the AGE spec. They return the
+number of seconds passed since the start of today, of this month,
+of this year, respectively.")
+
+
+(defun emms-last-played-update-track (track)
+ "Updates the last-played time of TRACK."
+ (emms-track-set track 'last-played (current-time)))
+
+(defun emms-last-played-update-current ()
+ "Updates the current track."
+ (emms-last-played-update-track (emms-playlist-current-selected-track)))
+
+(defun emms-last-played-seconds-today ()
+ "Return the number of seconds passed today."
+ (let ((now (decode-time (current-time))))
+ (+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600))))
+
+(defun emms-last-played-seconds-month ()
+ "Return the number of seconds passed this month."
+ (let ((now (decode-time (current-time))))
+ (+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600)
+ (* (- (car (nthcdr 3 now)) 1) 3600 24))))
+
+(defun emms-last-played-seconds-year ()
+ "Return the number of seconds passed this year."
+ (let ((now (decode-time (current-time)))
+ (days (format-time-string "%j" (current-time))))
+ (+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600)
+ (* (- (string-to-number days) 1) 3600 24))))
+
+(defun emms-last-played-format-date (messy-date)
+ "Format the messy-date according to emms-last-played-format-alist.
+Returns \" ? \" if there's bad input or if an other error occurs.
+Input should look like this: \"Sun, 14 Oct 2001 13:34:39 +0200\"."
+ (condition-case ()
+ (let* ((messy-date (time-to-seconds messy-date))
+ (now (time-to-seconds (current-time)))
+ ;;If we don't find something suitable we'll use this one
+ (my-format "%b %d '%y"))
+ (let* ((difference (- now messy-date))
+ (templist emms-last-played-format-alist)
+ (top (eval (caar templist))))
+ (while (if (numberp top) (< top difference) (not top))
+ (progn
+ (setq templist (cdr templist))
+ (setq top (eval (caar templist)))))
+ (if (stringp (cdr (car templist)))
+ (setq my-format (cdr (car templist)))))
+ (format-time-string (eval my-format) (seconds-to-time messy-date)))
+ (error "Never.")))
+
+(provide 'emms-last-played)
+;;; emms-last-played.el ends here
diff --git a/emms-setup.el b/emms-setup.el
index b99e237..9ed8645 100644
--- a/emms-setup.el
+++ b/emms-setup.el
@@ -121,7 +121,11 @@ on the edge."
;; define
(require 'emms-metaplaylist-mode)
(require 'emms-stream-info)
- (require 'emms-score))
+ (require 'emms-score)
+ (require 'emms-last-played)
+ ;; setup
+ (add-hook 'emms-player-started-hook 'emms-last-played-update-current))
+
;;;###autoload
(defun emms-default-players ()