feat(tazjin/emacs): Add function for quick Songwhip lookups
Adds a function `songwhip-lookup-url` which looks up the supplied URL on Songwhip and copies the Songwhip link if a result was found. This is bound to `s-s w` for convenience. Change-Id: I3b529a058ee56f992942760910822490e6324259 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2002 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
		
							parent
							
								
									6bdc6c85cd
								
							
						
					
					
						commit
						48235517f6
					
				
					 2 changed files with 30 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -41,6 +41,9 @@
 | 
			
		|||
;; Insert TODO comments
 | 
			
		||||
(global-set-key (kbd "C-c t") 'insert-todo-comment)
 | 
			
		||||
 | 
			
		||||
;; Make sharing music easier
 | 
			
		||||
(global-set-key (kbd "s-s w") #'songwhip-lookup-url)
 | 
			
		||||
 | 
			
		||||
;; Add subthread collapsing to notmuch-show.
 | 
			
		||||
;;
 | 
			
		||||
;; C-, closes a thread, C-. opens a thread. This mirrors stepping
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -296,4 +296,31 @@
 | 
			
		|||
                             (magit-read-file-from-rev "HEAD" "Find file")
 | 
			
		||||
                             #'pop-to-buffer-same-window))
 | 
			
		||||
 | 
			
		||||
(defun songwhip--handle-result (status &optional cbargs)
 | 
			
		||||
  ;; TODO(tazjin): Inspect status, which looks different in practice
 | 
			
		||||
  ;; than the manual claims.
 | 
			
		||||
  (if-let* ((response (json-parse-string
 | 
			
		||||
                       (buffer-substring url-http-end-of-headers (point-max))))
 | 
			
		||||
            (sw-path (ht-get* response "data" "path"))
 | 
			
		||||
            (link (format "https://songwhip.com/%s" sw-path))
 | 
			
		||||
            (select-enable-clipboard t))
 | 
			
		||||
      (progn
 | 
			
		||||
        (kill-new link)
 | 
			
		||||
        (message "Copied Songwhip link (%s)" link))
 | 
			
		||||
    (warn "Something went wrong while retrieving Songwhip link!")
 | 
			
		||||
    ;; For debug purposes, the buffer is persisted in this case.
 | 
			
		||||
    (setq songwhip--debug-buffer (current-buffer))))
 | 
			
		||||
 | 
			
		||||
(defun songwhip-lookup-url (url)
 | 
			
		||||
  "Look up URL on Songwhip and copy the resulting link to the clipboard."
 | 
			
		||||
  (interactive "sEnter source URL: ")
 | 
			
		||||
  (let ((songwhip-url "https://songwhip.com/api/")
 | 
			
		||||
        (url-request-method "POST")
 | 
			
		||||
        (url-request-extra-headers '(("Content-Type" . "application/json")))
 | 
			
		||||
        (url-request-data
 | 
			
		||||
         (json-serialize `((country . "GB")
 | 
			
		||||
                           (url . ,url)))))
 | 
			
		||||
    (url-retrieve "https://songwhip.com/api/" #'songwhip--handle-result nil t t)
 | 
			
		||||
    (message "Requesting Songwhip URL ... please hold the line.")))
 | 
			
		||||
 | 
			
		||||
(provide 'functions)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue