aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--doc/emms.texinfo15
-rw-r--r--lisp/emms-librefm-scrobbler.el49
3 files changed, 54 insertions, 11 deletions
diff --git a/NEWS b/NEWS
index eb6e5be..6acba63 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ News since version 4.0:
- Change the default behavior of C-k in emms-playlist-mode.
- Covers can have several extensions. See
`emms-browser-covers-file-extensions'.
+ - Libre.fm login details can, and should, be stored in authinfo now.
News since version 3.0:
diff --git a/doc/emms.texinfo b/doc/emms.texinfo
index 1bfc91b..7c973a6 100644
--- a/doc/emms.texinfo
+++ b/doc/emms.texinfo
@@ -1273,15 +1273,24 @@ but can work with any GNU FM server by configuring the variable
@var{emms-librefm-scrobbler-handshake-url} to the URL of the GNU FM
server.
-Provide your credentials on the GNU FM server by setting the
-appropriate variables:
+The recommended way of providing your credentials to the GNU FM server
+is by using an authinfo file. Add authentication to your auth-info
+file, typically @file{~/.authinfo.gpg}, as:
+@smallexample
+machine libre.fm login USERNAME password PASSWORD
+@end smallexample
+If you are using some other server than libre.fm, change
+``@example{libre.fm}'' to match
+@var{emms-librefm-scrobbler-handshake-url}.
+
+Alternatively, you can save the password in plaintext in your init-file
+by setting these variables:
@lisp
(setq emms-librefm-scrobbler-username "USERNAME"
emms-librefm-scrobbler-password "PASSWORD")
@end lisp
-
@menu
* Uploading Track Information:: How to submit listened track information.
* GNU FM Streaming:: Streaming music from a GNU FM server.
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))))
;;; ------------------------------------------------------------------