fixed being unable to download specific season of show

removed debug format statements
fixed bug where opts weren't being passed to download func
changed internal identifier for "season" command line argument
main
a. fox 2 years ago
parent 96f6b24227
commit 5d9b4a4e22

@ -8,9 +8,12 @@
:long "help" :long "help"
:description "prints this help") :description "prints this help")
(:name :version (:name :version
:short #\v
:long "version" :long "version"
:description "prints the version") :description "prints the version")
(:name :verbose
:short #\v
:long "verbose"
:description "prints file names as they get downloaded")
(:name :assume-yes (:name :assume-yes
:long "no-prompt" :long "no-prompt"
:description "assumes yes for all download prompts") :description "assumes yes for all download prompts")
@ -48,7 +51,7 @@
:meta-var "PASSOWRD" :meta-var "PASSOWRD"
:arg-parser #'identity :arg-parser #'identity
:description "passowrd for the jellyfin server") :description "passowrd for the jellyfin server")
(:name :season-number (:name :season
:short #\s :short #\s
:long "season" :long "season"
:meta-var "SEASON" :meta-var "SEASON"

@ -2,7 +2,7 @@
(in-package #:seanut) (in-package #:seanut)
(defun prompt-and-download (domain auth root opts &optional assume-yes) (defun prompt-and-download (domain auth root opts)
"prompt the user with y-or-n-p and download ITEM" "prompt the user with y-or-n-p and download ITEM"
(labels ((fetch-user-id () (labels ((fetch-user-id ()
(gethash "Id" (json-request (format-url domain "Users/Me") (gethash "Id" (json-request (format-url domain "Users/Me")
@ -22,7 +22,7 @@
(format nil "~A (~A)~@[ Season ~A~]~@[/~]" (format nil "~A (~A)~@[ Season ~A~]~@[/~]"
(gethash "Name" root) (gethash "Name" root)
(gethash "ProductionYear" root) (gethash "ProductionYear" root)
(getf opts :season-number) (getf opts :season)
add-trailing)) add-trailing))
(create-directory (dir) (create-directory (dir)
@ -32,27 +32,28 @@
;; PARENTS is a list of all parent names with FIRST being ;; PARENTS is a list of all parent names with FIRST being
;; the oldest grandparent (for building complete download path) ;; the oldest grandparent (for building complete download path)
(let ((children (gethash "Items" (let ((children (gethash "Items"
(if (string= (gethash "Type" item) "Season") (if (or (string= (gethash "Type" item) "Season")
(json-request (format-url domain "Shows/~A/Episodes?fields=Path&seasonId=~A~@[&season=~A~]" (and (string= (gethash "Type" item) "Series")
(gethash "SeriesId" item) (getf opts :season)))
(gethash "Id" item) (json-request (format-url domain "Shows/~A/Episodes?fields=Path~@[&seasonId=~A~]~@[&season=~A~]"
(getf opts :season-number)) (or (gethash "SeriesId" item)
(gethash "Id" item))
(unless (getf opts :season)
(gethash "Id" item))
(getf opts :season))
:auth auth) :auth auth)
(json-request (format-url domain "Items?userId=~A&fields=Path,ChildCount&parentId=~A" (json-request (format-url domain "Items?userId=~A&fields=Path,ChildCount&parentId=~A"
(fetch-user-id) (fetch-user-id)
(gethash "Id" item)) (gethash "Id" item))
:auth auth))))) :auth auth)))))
;; DELETE: debug prints lmao
(loop :for child :across children
:do (format t "Name: ~A, Id: ~A~%"
(gethash "Name" child)
(gethash "Id" child)))
(loop :for child :across children (loop :for child :across children
:if (zerop (gethash "ChildCount" child 0)) :if (zerop (gethash "ChildCount" child 0))
:do :do
;; download single file ;; download single file
(when (getf opts :verbose)
(format t "Downloading ~A~%" (generate-filename child)))
(download-media (generate-filename child) (download-media (generate-filename child)
(format-url domain "Items/~A/Download" (format-url domain "Items/~A/Download"
(gethash "Id" child)) (gethash "Id" child))
@ -65,30 +66,19 @@
;; and loop over them, recursing for each one ;; and loop over them, recursing for each one
;; ensure that a directory exists for Parent ;; ensure that a directory exists for Parent
;; then recurse with children ;; then recurse with children
(format t "Creating child directory in ~A and recursing: ~A~%"
(uiop:getcwd) (gethash "Name" child))
(uiop:with-current-directory ((create-directory (gethash "Name" child))) (uiop:with-current-directory ((create-directory (gethash "Name" child)))
(download-item-or-children child)))))) (download-item-or-children child))))))
(format t "Name: ~A, Id: ~A~%" (when (or (getf opts :assume-yes)
(gethash "Name" root) (y-or-n-p "Download \"~A\"" (generate-root-name)))
(gethash "Id" root))
(when (or assume-yes
(y-or-n-p "Download ~A" (generate-root-name)))
;; CD into our output directory ;; CD into our output directory
(uiop:with-current-directory ((getf opts :output #P"./")) (uiop:with-current-directory ((getf opts :output #P"./"))
(let ((grandest-parent (format nil "~A (~A)~@[ Season ~A~]/"
(gethash "Name" root) ;; create our folder for our current download
(gethash "ProductionYear" root) ;; then CD into it, and start downloading
(getf opts :season-number)))) (uiop:with-current-directory ((create-directory (generate-root-name 'trailing-slash)))
(download-item-or-children root))))))
;; create our folder for our current download
(ensure-directories-exist grandest-parent)
;; CD into it, then download the files
(uiop:with-current-directory (grandest-parent)
(download-item-or-children root)))))))
(defun main () (defun main ()
@ -118,7 +108,7 @@
(when (some #'null args) (when (some #'null args)
(quit-with-message 1 "domain and/or media name not provided")) (quit-with-message 1 "domain and/or media name not provided"))
(destructuring-bind (domain search-term) args (destructuring-bind (domain search-term) args
(let* ((authorization (or (and (getf opts :token) (generate-authorization (getf opts :token))) (let* ((authorization (or (and (getf opts :token) (generate-authorization (getf opts :token)))
(generate-authorization (get-access-token domain opts)))) (generate-authorization (get-access-token domain opts))))
@ -134,7 +124,7 @@
;; after reading more ;; 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 opts))
(quit-with-message 0 "No results found for ~A" search-term))))) (quit-with-message 0 "No results found for ~A" search-term)))))
(error (e) (error (e)

Loading…
Cancel
Save