From 3981630c588a4ab4226f99ab325dcc97ee9c97ba Mon Sep 17 00:00:00 2001 From: Yoni Rabkin Date: Wed, 4 Aug 2010 22:02:29 +0300 Subject: * doc/emms.texinfo: Remove because it ain't true no more. --- doc/emms.texinfo | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/emms.texinfo b/doc/emms.texinfo index 702d95a..e09e139 100644 --- a/doc/emms.texinfo +++ b/doc/emms.texinfo @@ -2341,10 +2341,6 @@ Library. @kbd{M-x emms-lastfm-client-play-user-neighborhood}: A Last.fm user's ``neighborhood''. -The submission process isn't instantaneous. A high latency Internet -connection may produce annoying ``freezes'' while Emacs synchronously -communicates with the Last.fm servers. - @node Streaming Audio @chapter Streaming Audio -- cgit v1.2.3 From 8272fecd7becc4bc9d557282842e722a4e950940 Mon Sep 17 00:00:00 2001 From: Yoni Rabkin Date: Wed, 4 Aug 2010 22:03:56 +0300 Subject: * lisp/emms-lastfm-client.el: Make scobbles asynchronous. --- lisp/emms-lastfm-client.el | 58 +++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/lisp/emms-lastfm-client.el b/lisp/emms-lastfm-client.el index d0d519f..7456bc9 100644 --- a/lisp/emms-lastfm-client.el +++ b/lisp/emms-lastfm-client.el @@ -493,7 +493,7 @@ This function includes the cryptographic signature." "Submit the currently playing track with a `love' rating." (interactive) (if emms-lastfm-client-track - (let ((result (emms-lastfm-client-make-submission-call + (let ((result (emms-lastfm-client-make-async-submission-call emms-lastfm-client-track 'love))) ;; the following submission API call looks redundant but ;; isn't; indeed, it might be done away with in a future @@ -507,7 +507,7 @@ This function includes the cryptographic signature." "Submit currently playing track with a `ban' rating and skip." (interactive) (if emms-lastfm-client-track - (let ((result (emms-lastfm-client-make-submission-call + (let ((result (emms-lastfm-client-make-async-submission-call emms-lastfm-client-track 'ban))) (emms-lastfm-client-make-call-track-ban) (when (equal result 'track-successfully-submitted) @@ -524,7 +524,7 @@ This function includes the cryptographic signature." emms-lastfm-client-playlist-buffer) (when (and emms-lastfm-client-submission-api (not first)) - (let ((result (emms-lastfm-client-make-submission-call + (let ((result (emms-lastfm-client-make-async-submission-call emms-lastfm-client-track nil))) (when (equal result 'track-successfully-submitted) (message "track sucessfully submitted")))) @@ -1094,39 +1094,49 @@ This function includes the cryptographic signature." ;; does not mean that the submission was valid, but ;; only that the authentication and the form of the ;; submission was validated. - 'track-successfully-submitted) + (message "successfully submitted %s" + (emms-lastfm-client-xspf-get 'title track))) ((string= status "BADSESSION") (emms-lastfm-client-handshake) - (emms-lastfm-client-make-submission-call track rating)) + (emms-lastfm-client-make-async-submission-call track rating)) (t (error "unhandled submission failure"))))))) -(defun emms-lastfm-client-make-submission-call (track rating) - "Make submission call." +(defun emms-lastfm-client-submit () + "Submit the current track as having been played." + (if emms-lastfm-client-track + (emms-lastfm-client-make-async-submission-call + emms-lastfm-client-track nil) + (error "no current track"))) + +;;; ------------------------------------------------------------------ +;;; Asynchronous Submission +;;; ------------------------------------------------------------------ + +(defun emms-lastfm-client-async-submission-callback (status &optional cbargs) + "Pass response of asynchronous submission call to handler." + (let ((response (copy-sequence + (buffer-substring-no-properties + (point-min) (point-max))))) + (emms-lastfm-client-handle-submission-response + response + (car cbargs) ; track + (cdr cbargs) ; rating + ))) + +(defun emms-lastfm-client-make-async-submission-call (track rating) + "Make asynchronous submission call." (if emms-lastfm-client-playlist-valid (let* ((url-request-method "POST") (url-request-data (emms-lastfm-client-submission-data track rating)) (url-request-extra-headers - `(("Content-type" - . "application/x-www-form-urlencoded")))) - (let ((response - (url-retrieve-synchronously - emms-lastfm-client-submission-url))) - (emms-lastfm-client-handle-submission-response - (with-current-buffer response - (buffer-substring-no-properties - (point-min) (point-max))) - track rating))) + `(("Content-type" . "application/x-www-form-urlencoded")))) + (url-retrieve emms-lastfm-client-submission-url + #'emms-lastfm-client-async-submission-callback + (list (cons track rating)))) (error "cannot make submission call without initializing the client"))) -(defun emms-lastfm-client-submit () - "Submit the current track as having been played." - (if emms-lastfm-client-track - (emms-lastfm-client-make-submission-call - emms-lastfm-client-track nil) - (error "no current track"))) - (provide 'emms-lastfm-client) ;;; emms-lastfm-client.el ends here -- cgit v1.2.3