aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emms-lastfm.el72
1 files changed, 31 insertions, 41 deletions
diff --git a/emms-lastfm.el b/emms-lastfm.el
index 7735615..63e7497 100644
--- a/emms-lastfm.el
+++ b/emms-lastfm.el
@@ -204,25 +204,23 @@ These will be displayed on the user's last.fm page."
(musicbrainz-id "")
(track-length (number-to-string
(emms-track-get emms-lastfm-current-track
- 'info-playing-time)))
- (url-http-attempt-keepalives nil)
- (url-show-status emms-lastfm-submission-verbose-p)
- (url-request-method "POST")
- (url-request-extra-headers
- '(("Content-type" .
- "application/x-www-form-urlencoded; charset=utf-8")))
- (url-request-data
- (encode-coding-string
- (concat "&s=" emms-lastfm-session-id
- "&a[0]=" (emms-escape-url artist)
- "&t[0]=" (emms-escape-url title)
- "&b[0]=" (emms-escape-url album)
- "&l[0]=" track-length
- "&n[0]=" track-number
- "&m[0]=" musicbrainz-id)
- 'utf-8)))
- (url-retrieve emms-lastfm-now-playing-url
- 'emms-lastfm-submit-now-playing-sentinel)))
+ 'info-playing-time))))
+ ;; wait up to 5 seconds to submit np infos in order to finish handshaking.
+ (dotimes (i 5)
+ (when (not (and emms-lastfm-session-id
+ emms-lastfm-now-playing-url))
+ (sit-for 1)))
+ (when (and emms-lastfm-session-id
+ emms-lastfm-now-playing-url)
+ (emms-lastfm-http-POST emms-lastfm-now-playing-url
+ (concat "&s=" emms-lastfm-session-id
+ "&a[0]=" (emms-url-quote artist)
+ "&t[0]=" (emms-url-quote title)
+ "&b[0]=" (emms-url-quote album)
+ "&l[0]=" track-length
+ "&n[0]=" track-number
+ "&m[0]=" musicbrainz-id)
+ 'emms-lastfm-submit-now-playing-sentinel))))
(defun emms-lastfm-submit-now-playing-sentinel (&rest args)
"Parses the server reponse and inform the user if all worked
@@ -379,28 +377,20 @@ last.fm."
(musicbrainz-id "")
(track-length (number-to-string
(emms-track-get emms-lastfm-current-track
- 'info-playing-time)))
- (url-http-attempt-keepalives nil)
- (url-show-status emms-lastfm-submission-verbose-p)
- (url-request-method "POST")
- (url-request-extra-headers
- '(("Content-type" .
- "application/x-www-form-urlencoded; charset=utf-8")))
- (url-request-data
- (encode-coding-string
- (concat "&s=" emms-lastfm-session-id
- "&a[0]=" (emms-escape-url artist)
- "&t[0]=" (emms-escape-url title)
- "&i[0]=" emms-lastfm-current-track-starting-time-string
- "&o[0]=P" ;; TODO: Maybe support others. See the API.
- "&r[0]=" ;; The rating. Empty if not applicable (for P it's not)
- "&l[0]=" track-length
- "&b[0]=" (emms-escape-url album)
- "&n[0]=" track-number
- "&m[0]=" musicbrainz-id)
- 'utf-8)))
- (url-retrieve emms-lastfm-submit-url
- 'emms-lastfm-submission-sentinel)))
+ 'info-playing-time))))
+ (emms-lastfm-http-POST
+ emms-lastfm-submit-url
+ (concat "&s=" emms-lastfm-session-id
+ "&a[0]=" (emms-url-quote artist)
+ "&t[0]=" (emms-url-quote title)
+ "&i[0]=" emms-lastfm-current-track-starting-time-string
+ "&o[0]=P" ;; TODO: Maybe support others. See the API.
+ "&r[0]=" ;; The rating. Empty if not applicable (for P it's not)
+ "&l[0]=" track-length
+ "&b[0]=" (emms-url-quote album)
+ "&n[0]=" track-number
+ "&m[0]=" musicbrainz-id)
+ 'emms-lastfm-submission-sentinel)))
(defun emms-lastfm-submission-sentinel (&rest args)
"Parses the server reponse and inform the user if all worked