diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/emms-librefm-scrobbler.el | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/lisp/emms-librefm-scrobbler.el b/lisp/emms-librefm-scrobbler.el index 4f83cdd..6244ed4 100644 --- a/lisp/emms-librefm-scrobbler.el +++ b/lisp/emms-librefm-scrobbler.el @@ -35,13 +35,18 @@ "http" "Transfer method.") -(defvar emms-librefm-scrobbler-username - "" - "Libre.fm username.") +(defvar emms-librefm-scrobbler-username nil + "Libre.fm username. -(defvar emms-librefm-scrobbler-password - "" - "Libre.fm user password.") +Note that the preferred way of authenticating is using authinfo +and only setting `emms-librefm-scrobbler-handshake-url'. See the +manual for details.") + +(defvar emms-librefm-scrobbler-password nil + "Libre.fm user password. + +Note that the preferred way of authenticating is using authinfo. +See also `emms-librefm-scrobbler-username'.") (defvar emms-librefm-scrobbler-debug "" @@ -69,6 +74,34 @@ ;;; ------------------------------------------------------------------ +;;; authenticate +;;; ------------------------------------------------------------------ +(defun emms-librefm-scrobbler--get-auth-detail (token) + "Return TOKEN from auth-source. +TOKEN is :user of :secret." + ;; TODO: Maybe we should enable :create t here. But it could be + ;; kind of annoying as it makes a pop-up when no name is present. + (require 'auth-source) + (plist-get + (car (auth-source-search :host (list emms-librefm-scrobbler-handshake-url "libre.fm") + :user (unless (equal emms-librefm-scrobbler-username "") + emms-librefm-scrobbler-username) + :max 1 :require '(:user :secret))) + token)) + +(defun emms-librefm-scrobbler--username () + "Return username for libre.fm." + (or (emms-librefm-scrobbler--get-auth-detail :user) + emms-librefm-scrobbler-username)) + +(defun emms-librefm-scrobbler--password () + "Return password for libre.fm." + (let ((token (emms-librefm-scrobbler--get-auth-detail :secret))) + (cond ((functionp token) (funcall token)) + ((characterp token) token) + (t emms-librefm-scrobbler-password)))) + +;;; ------------------------------------------------------------------ ;;; handshake ;;; ------------------------------------------------------------------ @@ -146,8 +179,8 @@ (emms-librefm-scrobbler-handle-handshake-response (emms-librefm-scrobbler-handshake-call emms-librefm-scrobbler-handshake-url - emms-librefm-scrobbler-username - emms-librefm-scrobbler-password))) + (emms-librefm-scrobbler--username) + (emms-librefm-scrobbler--password)))) ;;; ------------------------------------------------------------------ |