aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorRasmus <rasmus@gmx.us>2014-07-29 12:59:38 +0200
committerrasmus <rasmus@gmx.us>2015-03-08 20:43:15 +0100
commit3f3dc1058db5f7accbc06e80e9ad329aec2ef434 (patch)
tree54b72e53cc030ae56eddc51b6b5d3f8bd7d2fea5 /lisp
parentdbcdc8513919dde524dcf2fa434a4b8e4770e57f (diff)
emms-librefm-scrobbler.el: use authinfo
The recommended way to store libre.fm login details are now via authinfo. See emms-librefm-scrobbler--username, emms-librefm-scrobbler--password and the manual.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/emms-librefm-scrobbler.el49
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))))
;;; ------------------------------------------------------------------