From 3f3dc1058db5f7accbc06e80e9ad329aec2ef434 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Tue, 29 Jul 2014 12:59:38 +0200 Subject: 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. --- lisp/emms-librefm-scrobbler.el | 49 +++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'lisp') 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 "" @@ -68,6 +73,34 @@ "Whether to display a user message on every submission.") +;;; ------------------------------------------------------------------ +;;; 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)))) ;;; ------------------------------------------------------------------ -- cgit v1.2.3