summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2024-02-02 09:57:48 -0500
committerKjetil Orbekk <kj@orbekk.com>2024-02-02 09:57:48 -0500
commit196d403a6e1ec5616a2e27114152e144752eac4c (patch)
tree0aeb851e712252f015d38ad1d6ffea7de20a74f7
parent9888d4e8beffa2ef4d7418d0f32bb761f238f81b (diff)
add spotify play via smudge
-rw-r--r--emacs/.config/emacs/lisp/kj-init.el49
1 files changed, 49 insertions, 0 deletions
diff --git a/emacs/.config/emacs/lisp/kj-init.el b/emacs/.config/emacs/lisp/kj-init.el
index 4766674..a21b51d 100644
--- a/emacs/.config/emacs/lisp/kj-init.el
+++ b/emacs/.config/emacs/lisp/kj-init.el
@@ -942,6 +942,55 @@
([remap describe-command] . 'helpful-command)
([remap describe-function] . 'helpful-callable)))
+;; Spotify
+(use-package smudge
+ :bind ("C-c a s" . 'smudge-command-map)
+ :init
+ (defvar kj/smudge-settings-file (expand-file-name ".smudge-credentials" kj/cache-dir))
+ (defvar kj/librespot-cache (expand-file-name "~/.cache/librespot"))
+ (defun kj/smudge-configure (client-id client-secret)
+ (interactive "sClient id: \nsClient secret: ")
+ (with-temp-buffer
+ (insert (pp `(client-id ,client-id
+ client-secret ,client-secret)))
+ (write-file kj/smudge-settings-file))
+ (unless (file-exists-p kj/librespot-cache)
+ (async-shell-command
+ (format "librespot -u orbekk -b 320 -C %s" kj/librespot-cache)
+ "*librespot*")))
+
+ (defun kj/smudge-init ()
+ (interactive)
+ (unless (and (file-exists-p kj/smudge-settings-file)
+ (file-exists-p kj/librespot-cache))
+ (user-error "%s"
+ (substitute-command-keys
+ "Press \\[kj/smudge-configure] to set up spotify")))
+ (with-temp-buffer
+ (insert-file kj/smudge-settings-file)
+ (goto-char (point-min))
+ (let ((credentials (read (current-buffer))))
+ (setq smudge-oauth2-client-secret (plist-get credentials 'client-secret))
+ (setq smudge-oauth2-client-id (plist-get credentials 'client-id))))
+ (start-process
+ "librespot"
+ "*librespot*"
+ "librespot" "-C" kj/librespot-cache)
+ ;; Give librespot some time to start, then select it.
+ (run-at-time 2 nil
+ (lambda ()
+ (smudge-api-device-list
+ (lambda (json)
+ (when-let* ((devices (gethash 'devices json))
+ (device (seq-find
+ (lambda (d) (equal (smudge-device-get-device-name d)
+ "Librespot"))
+ devices)))
+ (smudge-api-transfer-player (smudge-device-get-device-id device)
+ (lambda (json)
+ (setq smudge-selected-device-id (smudge-device-get-device-id device))
+ (message "Device selected"))))))))))
+
;; Enabled commands
(put 'narrow-to-region 'disabled nil)
(put 'downcase-region 'disabled nil)