aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Bonnet <lucas@rincevent.net>2010-08-11 00:04:45 +0200
committerLucas Bonnet <lucas@rincevent.net>2010-08-11 00:04:45 +0200
commit0f17db6914b8f4503f56347c953cc78f6dc76edb (patch)
tree709facc224be8c004267dc2c5798603793701ee6
parentc10ea241e3da219126a6d6d3b9f88c359270e70d (diff)
parent8272fecd7becc4bc9d557282842e722a4e950940 (diff)
Merge branch 'master' of ssh://git.sv.gnu.org/srv/git/emms
-rw-r--r--doc/emms.texinfo4
-rw-r--r--lisp/emms-lastfm-client.el58
2 files changed, 34 insertions, 28 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
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