made authorization a keyword parameter in json-request

main
a. fox 2 years ago
parent 90532da65a
commit 51b659725f

@ -12,7 +12,7 @@
;; authenticates the user via username and password ;; authenticates the user via username and password
(gethash "AccessToken" (gethash "AccessToken"
(json-request (format-url domain "Users/AuthenticateByName") (json-request (format-url domain "Users/AuthenticateByName")
(generate-authorization) :auth (generate-authorization)
:method :post :method :post
:content `(("Username" . ,(getf options :username)) :content `(("Username" . ,(getf options :username))
("Pw" . ,(getf options :password)))))))) ("Pw" . ,(getf options :password))))))))
@ -23,7 +23,7 @@
(defun quick-connect-dance (domain) (defun quick-connect-dance (domain)
(let* ((auth (generate-authorization)) (let* ((auth (generate-authorization))
(qc-session (handler-case (qc-session (handler-case
(json-request (format-url domain "QuickConnect/Initiate") auth) (json-request (format-url domain "QuickConnect/Initiate") :auth auth)
(dex:http-request-unauthorized () (dex:http-request-unauthorized ()
(error "QuickConnect not enabled on this server."))))) (error "QuickConnect not enabled on this server.")))))
;; initiate quick connect session ;; initiate quick connect session
@ -44,7 +44,7 @@
(sleep 5) (sleep 5)
(let ((state (json-request (format-url domain "QuickConnect/Connect?secret=~A" (let ((state (json-request (format-url domain "QuickConnect/Connect?secret=~A"
(gethash "Secret" qc-session)) (gethash "Secret" qc-session))
auth))) :auth auth)))
(setf authed (gethash "Authenticated" state) (setf authed (gethash "Authenticated" state)
counter (1+ counter))) counter (1+ counter)))
@ -52,7 +52,8 @@
(when (> counter 20) (when (> counter 20)
(error "QuickConnect session timed out."))) (error "QuickConnect session timed out.")))
(gethash "AccessToken" (gethash "AccessToken"
(json-request (format-url domain "Users/AuthenticateWithQuickConnect") auth (json-request (format-url domain "Users/AuthenticateWithQuickConnect")
:auth auth
:method :post :method :post
:content (jzon:stringify (alist-hash-table `(("Secret" . ,(gethash "Secret" qc-session))))) :content (jzon:stringify (alist-hash-table `(("Secret" . ,(gethash "Secret" qc-session)))))
:extra-headers '(("Content-Type" . "application/json")))))) :extra-headers '(("Content-Type" . "application/json"))))))

@ -29,10 +29,10 @@
(json-request (format-url domain "Shows/~A/Episodes?fields=Path~@[&season=~A~]" (json-request (format-url domain "Shows/~A/Episodes?fields=Path~@[&season=~A~]"
(gethash "Id" item) (gethash "Id" item)
(getf opts :season-number)) (getf opts :season-number))
auth) :auth auth)
(json-request (format-url domain "Items?fields=Path&parentId=~A" (json-request (format-url domain "Items?fields=Path&parentId=~A"
(gethash "Id" item)) (gethash "Id" item))
auth)))) :auth auth))))
(if (zerop (length children)) (if (zerop (length children))
;; download single file ;; download single file
;; to get the extension type i think we may need to include ;; to get the extension type i think we may need to include
@ -104,6 +104,8 @@
;; certain info? when we run the parentID search it craps out on us? ;; certain info? when we run the parentID search it craps out on us?
;; maybe its not something wrong with the token, but the auth string as a ;; maybe its not something wrong with the token, but the auth string as a
;; whole? look into this more tomorrow ;; whole? look into this more tomorrow
;;
;; after reading more
(loop :for item :across results (loop :for item :across results
:do (prompt-and-download domain authorization :do (prompt-and-download domain authorization
item (getf opts :assume-yes))) item (getf opts :assume-yes)))

@ -20,21 +20,25 @@ ARGS are the arguments for the SLUG format string"
(uiop:string-prefix-p "https://" domain) (uiop:string-prefix-p "https://" domain)
domain (apply #'format `(nil ,slug ,@args)))) domain (apply #'format `(nil ,slug ,@args))))
(defun json-request (url auth &key (method :get) extra-headers content) (defun json-request (url &key auth (method :get) extra-headers content)
"makes a request to URL, using AUTH as the X-Emby-Authorization header and METHOD as the http method (defaults to get) and parses the returned value with jzon:parse "makes a request to URL, using AUTH as the X-Emby-Authorization header and METHOD as the http method (defaults to get) and parses the returned value with jzon:parse
if EXTRA-HEADERS is non-nil, includes them in the headers alongside the X-Emby-Authorization one if EXTRA-HEADERS is non-nil, includes them in the headers alongside the X-Emby-Authorization one
if CONTENT is non-nil, passes that along to the request" if CONTENT is non-nil, passes that along to the request"
(parse (dex:request url :method method (parse (dex:request url :method method
:content content :content content
:headers `(("Authorization" . ,auth) :headers `(,(when auth
`("Authorization" . ,auth))
,@extra-headers)))) ,@extra-headers))))
(defun run-search-query (domain auth type name) (defun run-search-query (domain auth type name)
"runs the search query to get the initial list of items
can probably be removed and the request can be made in-line"
(gethash "Items" (gethash "Items"
(json-request (format-url domain "Items?fields=Path&includeItemTypes=~A&recursive=true&searchTerm=~A" (json-request (format-url domain "Items?fields=Path&includeItemTypes=~A&recursive=true&searchTerm=~A"
type name) type name)
auth))) :auth auth)))
(defun download-media (path url auth) (defun download-media (path url auth)
"downloads the media at URL, using HEADER as the authorization header. "downloads the media at URL, using HEADER as the authorization header.

Loading…
Cancel
Save