From 7c05231415f877a3902f4f247b512c5373a08407 Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Sun, 8 Apr 2007 20:50:00 +0000 Subject: emms-player-mpd: Integrate with emms-lastfm to show track * emms-lastfm (emms-lastfm-np): Expand to take optional callback argument. Rename `arg' to `insertp' for clarity. * emms-player-mpd (emms-player-mpd-show-1): Detect if emms-lastfm is activated, and if the current track is a LastFM URL. If so, call emms-lastfm-np rather than continuing on. (emms-player-mpd-show): Docfix. darcs-hash:20070408205000-1bfb2-6207ca703571a4602c7b1510f62be33df9722a8d.gz --- NEWS | 2 ++ emms-lastfm.el | 25 +++++++++++++++-------- emms-player-mpd.el | 59 +++++++++++++++++++++++++++++++----------------------- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/NEWS b/NEWS index bb96cd6..bfb723f 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,8 @@ News since version 2.1: - Display the correct error message if an error occurs while trying to play a stream. - Handle any encoding errors that occur during playback. + - Integrate with emms-lastfm.el in `emms-player-mpd-show', if + emms-lastfm is loaded and active. - emms-playing-time supports different display styles now. - emms-lyrics: Now support lyrics auto-scrolling. diff --git a/emms-lastfm.el b/emms-lastfm.el index ced9a0b..ffb1e20 100644 --- a/emms-lastfm.el +++ b/emms-lastfm.el @@ -435,11 +435,18 @@ high. (But then streaming a 128KHz mp3 won't be fun anyway.)" (message "EMMS: Playing Last.fm stream")) (message "EMMS: Bad response from Last.fm")))) -(defun emms-lastfm-np (&optional arg) - "Show the currently-playing lastfm radio tune." +(defun emms-lastfm-np (&optional insertp callback) + "Show the currently-playing lastfm radio tune. + +If INSERTP is non-nil, insert the description into the current +buffer instead. + +If CALLBACK is a function, call it with the current buffer and +description as arguments instead of displaying the description or +inserting it." (interactive "P") (emms-lastfm-radio-request-metadata - (lambda (status arg buffer) + (lambda (status insertp buffer callback) (let (artist title) (save-excursion (set-buffer emms-lastfm-buffer) @@ -449,11 +456,13 @@ high. (But then streaming a 128KHz mp3 won't be fun anyway.)" (let ((msg (if title (format emms-show-format (format "%s - %s" artist title)) "Nothing playing right now"))) - (if (and arg title) - (with-current-buffer buffer - (insert msg)) - (message msg))))) - (list arg (current-buffer)))) + (cond ((functionp callback) + (funcall callback buffer msg)) + ((and insertp title) + (with-current-buffer buffer + (insert msg))) + (t (message msg)))))) + (list insertp (current-buffer) callback))) (defun emms-lastfm-radio-similar-artists (artist) "Plays the similar artist radio of ARTIST." diff --git a/emms-player-mpd.el b/emms-player-mpd.el index f329f0c..b5fb198 100644 --- a/emms-player-mpd.el +++ b/emms-player-mpd.el @@ -1002,30 +1002,38 @@ positive or negative." (when info (when name (setq desc name)) - (when file - (let ((track (emms-dictionary '*track*)) - track-desc) - (if (string-match "\\`http://" file) - (emms-track-set track 'type 'url) - (emms-track-set track 'type 'file)) - (emms-track-set track 'name file) - (emms-info-mpd track info) - (setq track-desc (emms-track-description track)) - (when (and (stringp track-desc) (not (string= track-desc ""))) - (setq desc (if desc - (concat desc ": " track-desc) - track-desc)))))) - (if (not desc) - (message "Nothing playing right now") - (setq desc (format emms-show-format desc)) - (cond ((functionp callback) - (funcall callback buffer desc)) - (insertp - (when (buffer-live-p buffer) - (with-current-buffer buffer - (insert desc)))) - (t - (message "%s" desc)))))) + ;; if we are playing lastfm radio, use its show function instead + (if (and (boundp 'emms-lastfm-radio-stream-url) + (stringp emms-lastfm-radio-stream-url) + (string= emms-lastfm-radio-stream-url file)) + (with-current-buffer buffer + (and (fboundp 'emms-lastfm-np) + (emms-lastfm-np insertp callback))) + ;; otherwise build and show the description + (when file + (let ((track (emms-dictionary '*track*)) + track-desc) + (if (string-match "\\`http://" file) + (emms-track-set track 'type 'url) + (emms-track-set track 'type 'file)) + (emms-track-set track 'name file) + (emms-info-mpd track info) + (setq track-desc (emms-track-description track)) + (when (and (stringp track-desc) (not (string= track-desc ""))) + (setq desc (if desc + (concat desc ": " track-desc) + track-desc)))))) + (if (not desc) + (message "Nothing playing right now") + (setq desc (format emms-show-format desc)) + (cond ((functionp callback) + (funcall callback buffer desc)) + (insertp + (when (buffer-live-p buffer) + (with-current-buffer buffer + (insert desc)))) + (t + (message "%s" desc))))))) ;;;###autoload (defun emms-player-mpd-show (&optional insertp callback) @@ -1035,7 +1043,8 @@ If INSERTP is non-nil, insert the description into the current buffer instead. If CALLBACK is a function, call it with the current buffer and -description. +description as arguments instead of displaying the description or +inserting it. This function uses `emms-show-format' to format the current track. It differs from `emms-show' in that it asks MusicPD for the current track, -- cgit v1.2.3