aboutsummaryrefslogtreecommitdiff
path: root/emms-lastfm.el
diff options
context:
space:
mode:
authorTassilo Horn <tassilo@member.fsf.org>2007-01-02 22:24:00 +0000
committerTassilo Horn <tassilo@member.fsf.org>2007-01-02 22:24:00 +0000
commit8be497eb448358bcbf457bba3a28d60ea997799f (patch)
tree70f762cd255274a06488a0cdee0e1cd8874bb028 /emms-lastfm.el
parent55934a3e90ef9183a1065f2d4bba2d89dd4524de (diff)
metadata-for-lastfm-streams.dpatch
Now the Artist and Title of the current song are displayed in the mode-line when listening to a last.fm stream. Additionally I made all user options customizable. darcs-hash:20070102222433-c06f4-8817244e846fa35dad3089f6f7e2796cece14d37.gz
Diffstat (limited to 'emms-lastfm.el')
-rw-r--r--emms-lastfm.el61
1 files changed, 56 insertions, 5 deletions
diff --git a/emms-lastfm.el b/emms-lastfm.el
index 68454ef..31ce054 100644
--- a/emms-lastfm.el
+++ b/emms-lastfm.el
@@ -70,10 +70,20 @@
(require 'url)
(require 'emms)
-(defvar emms-lastfm-username ""
- "Your last.fm username")
-(defvar emms-lastfm-password ""
- "Your last.fm password")
+(defgroup emms-lastfm nil
+ "Interaction with the services offered by http://www.last.fm."
+ :prefix "emms-lastfm-"
+ :group 'emms)
+
+(defcustom emms-lastfm-username ""
+ "Your last.fm username"
+ :type 'string
+ :group 'emms-lastfm)
+
+(defcustom emms-lastfm-password ""
+ "Your last.fm password"
+ :type 'string
+ :group 'emms-lastfm)
(defconst emms-lastfm-server "http://post.audioscrobbler.com/"
"The last.fm server responsible for the handshaking
@@ -277,7 +287,8 @@ well or if an error occured."
;;; Playback of lastfm:// streams
(defvar emms-lastfm-radio-base-url "http://ws.audioscrobbler.com"
- "The base URL for playing lastfm:// stream.")
+ "The base URL for playing lastfm:// stream.
+-- only used internally --")
(defvar emms-lastfm-radio-session nil "-- only used internally --")
(defvar emms-lastfm-radio-stream-url nil "-- only used internally --")
@@ -352,6 +363,12 @@ or
(if (string= (key-value "response") "OK")
(progn
(emms-play-url emms-lastfm-radio-stream-url)
+ (when emms-lastfm-radio-metadata-period
+ (setq emms-lastfm-timer
+ (run-with-timer 0 emms-lastfm-radio-metadata-period
+ 'emms-lastfm-radio-request-metadata))
+ (add-hook 'emms-player-stopped-hook
+ 'emms-lastfm-cancel-timer))
(message "EMMS: Playing Last.fm stream."))
(message "EMMS: Bad response from Last.fm."))))
@@ -403,6 +420,40 @@ song."
(message "EMMS: Rated current track.")
(message "EMMS: Rating failed."))))
+(defun emms-lastfm-radio-request-metadata ()
+ "Request the metadata of the current song and display it."
+ (interactive)
+ (let ((url-request-method "GET"))
+ (setq emms-lastfm-buffer
+ (url-retrieve
+ (url-escape
+ (concat emms-lastfm-radio-base-url
+ "/radio/np.php?"
+ "session=" emms-lastfm-radio-session
+ "&debug=" (number-to-string 0)))
+ 'emms-lastfm-radio-request-metadata-sentinel))))
+
+(defcustom emms-lastfm-radio-metadata-period 15
+ "When listening to Last.fm Radio every how many seconds should
+emms-lastfm poll for metadata? If set to nil, there won't be any
+polling at all.
+
+The default is 15: That means that the mode line will display the
+wrong (last) track's data for a maximum of 15 seconds. If your
+network connection has a big latency this value may be too
+high. (But then streaming a 128KHz mp3 won't be fun anyway.)"
+ :type 'integer
+ :group 'emms-lastfm)
+
+(defun emms-lastfm-radio-request-metadata-sentinel (&rest args)
+ (save-excursion
+ (set-buffer emms-lastfm-buffer)
+ (let ((artist (key-value "artist"))
+ (title (key-value "track")))
+ (setq emms-mode-line-string (format emms-mode-line-format
+ (concat artist " - " title)))
+ (force-mode-line-update))))
+
;;; Utility functions