From 1e3daf1289c4d23c2b046b212dbf7ea0a567daf3 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sat, 13 Jan 2007 10:49:00 +0000 Subject: fix-ampersands-and-question-marks-in-lastfm.dpatch Roman Lagunov reported a bug: the last.fm plugin failed scrobbling tracks with & in artist/title/album. The same applies to streams containing an ampersand. So I added ?& and ?? to `emms-url-specials'. But because both are needed to submit values via HTTP GET now you have to `emms-escape-url' only the arguments that may contain special chars instead the complete url, e.g.: (url-retrieve (concat emms-lastfm-server "?hs=true&p=1.1" "&c=" emms-lastfm-client-id "&v=" (number-to-string emms-lastfm-client-version) "&u=" (emms-escape-url emms-lastfm-username)) instead of (url-retrieve (emms-escape-url (concat emms-lastfm-server "?hs=true&p=1.1" "&c=" emms-lastfm-client-id "&v=" (number-to-string emms-lastfm-client-version) "&u=" emms-lastfm-username)) darcs-hash:20070113104902-c06f4-9bf8c040fff6d350a3a7dafcaf2cbf26700d2f04.gz --- emms-lastfm.el | 72 +++++++++++++++++++++++++++------------------------------- emms-url.el | 4 +++- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/emms-lastfm.el b/emms-lastfm.el index bda0388..1bb0b9a 100644 --- a/emms-lastfm.el +++ b/emms-lastfm.el @@ -220,11 +220,11 @@ the current track, too." (let ((url-request-method "GET")) (setq emms-lastfm-buffer (url-retrieve - (emms-escape-url (concat emms-lastfm-server "?hs=true&p=1.1" - "&c=" emms-lastfm-client-id - "&v=" (number-to-string - emms-lastfm-client-version) - "&u=" emms-lastfm-username)) + (concat emms-lastfm-server + "?hs=true&p=1.1" + "&c=" emms-lastfm-client-id + "&v=" (number-to-string emms-lastfm-client-version) + "&u=" (emms-escape-url emms-lastfm-username)) 'emms-lastfm-handshake-sentinel)))) (defun emms-lastfm-handshake-sentinel (&rest args) @@ -268,20 +268,20 @@ last.fm." (url-request-extra-headers '(("Content-type" . "application/x-www-form-urlencoded; charset=utf-8"))) - (url-request-data (encode-coding-string - (concat "u=" emms-lastfm-username - "&s=" (md5 (concat - (md5 emms-lastfm-password) - emms-lastfm-md5-challenge)) - "&a[0]=" artist - "&t[0]=" title - "&b[0]=" album - "&m[0]=" musicbrainz-id - "&l[0]=" track-length - "&i[0]=" date) - 'utf-8))) + (url-request-data + (encode-coding-string + (concat "u=" (emms-escape-url emms-lastfm-username) + "&s=" (md5 (concat (md5 emms-lastfm-password) + emms-lastfm-md5-challenge)) + "&a[0]=" (emms-escape-url artist) + "&t[0]=" (emms-escape-url title) + "&b[0]=" (emms-escape-url album) + "&m[0]=" musicbrainz-id + "&l[0]=" track-length + "&i[0]=" date) + 'utf-8))) (setq emms-lastfm-buffer - (url-retrieve (emms-escape-url emms-lastfm-submit-url) + (url-retrieve emms-lastfm-submit-url 'emms-lastfm-submission-sentinel)))) (defun emms-lastfm-submission-sentinel (&rest args) @@ -325,7 +325,7 @@ well or if an error occured." "handshake.php?version=" (number-to-string emms-lastfm-client-version) "&platform=" emms-lastfm-client-id - "&username=" emms-lastfm-username + "&username=" (emms-escape-url emms-lastfm-username) "&passwordmd5=" (md5 emms-lastfm-password) "&debug=" (number-to-string 9))) @@ -335,8 +335,7 @@ Calls FN when done with RADIO-URL as its only argument." (when emms-lastfm-buffer (kill-buffer emms-lastfm-buffer)) (let ((url-request-method "GET")) (setq emms-lastfm-buffer - (url-retrieve (emms-escape-url - (emms-lastfm-radio-get-handshake-url)) + (url-retrieve (emms-lastfm-radio-get-handshake-url) 'emms-lastfm-radio-handshake-sentinel (list fn radio-url))))) @@ -359,12 +358,11 @@ Calls FN when done with RADIO-URL as its only argument." (let ((url-request-method "GET")) (setq emms-lastfm-buffer (url-retrieve - (emms-escape-url - (concat emms-lastfm-radio-base-url - "adjust.php?" - "session=" emms-lastfm-radio-session - "&url=" lastfm-url - "&debug=" (number-to-string 0))) + (concat emms-lastfm-radio-base-url + "adjust.php?" + "session=" emms-lastfm-radio-session + "&url=" (emms-escape-url lastfm-url) + "&debug=" (number-to-string 0)) 'emms-lastfm-radio-sentinel))) (message "EMMS: Cannot play Last.fm stream"))) @@ -486,12 +484,11 @@ song." (let ((url-request-method "GET")) (setq emms-lastfm-buffer (url-retrieve - (emms-escape-url - (concat emms-lastfm-radio-base-url - "control.php?" - "session=" emms-lastfm-radio-session - "&command=" command - "&debug=" (number-to-string 0))) + (concat emms-lastfm-radio-base-url + "control.php?" + "session=" emms-lastfm-radio-session + "&command=" command + "&debug=" (number-to-string 0)) 'emms-lastfm-radio-rating-sentinel)))) (defun emms-lastfm-radio-rating-sentinel (&rest args) @@ -516,11 +513,10 @@ If DATA is given, it should be a list." (let ((url-request-method "GET")) (setq emms-lastfm-buffer (url-retrieve - (emms-escape-url - (concat emms-lastfm-radio-base-url - "np.php?" - "session=" emms-lastfm-radio-session - "&debug=" (number-to-string 0))) + (concat emms-lastfm-radio-base-url + "np.php?" + "session=" emms-lastfm-radio-session + "&debug=" (number-to-string 0)) (or fn 'emms-lastfm-radio-request-metadata-sentinel) data)))) diff --git a/emms-url.el b/emms-url.el index 1889347..3b5ccee 100644 --- a/emms-url.el +++ b/emms-url.el @@ -29,7 +29,9 @@ (defvar emms-url-specials '((?\ . "%20") - (?\n . "%0D%0A")) + (?\n . "%0D%0A") + (?& . "%26") + (?? . "%3F")) "*An alist of characters which must be represented specially in URLs. The transformation is the key of the pair.") -- cgit v1.2.3