From 196d403a6e1ec5616a2e27114152e144752eac4c Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 2 Feb 2024 09:57:48 -0500 Subject: add spotify play via smudge --- emacs/.config/emacs/lisp/kj-init.el | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) 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) -- cgit v1.2.3