ensured we check the root item for children before using the children

removed large outdated comment
print supported media types in --help text
added ChildCount field to initial search query
This commit is contained in:
a. fox 2023-11-17 16:47:54 -05:00
parent b59004fce1
commit cee3d84f94
3 changed files with 33 additions and 31 deletions

View File

@ -24,6 +24,9 @@
(defparameter *authorization-format*
"MediaBrowser Client=\"~A\", Device=\"~A\", DeviceId=\"~A\", Version=\"~A\", Token=\"~A\"")
(defparameter *command-line-brief*
"Supported media types: ~{~A~^, ~}")
(defparameter *valid-media-types*
'("Book" "BoxSet" "Movie" "MusicAlbum" "MusicArtist"
"MusicGenre" "Playlist" "Season" "Series"))

View File

@ -28,6 +28,12 @@
(create-directory (dir)
(ensure-directories-exist (uiop:ensure-directory-pathname (make-pathname :name dir))))
(download (item)
(download-media (generate-filename item)
(format-url domain "Items/~A/Download"
(gethash "Id" item))
auth))
(download-item-or-children (item)
;; PARENTS is a list of all parent names with FIRST being
;; the oldest grandparent (for building complete download path)
@ -47,27 +53,25 @@
(gethash "Id" item))
:auth auth)))))
(loop :for child :across children
:if (zerop (gethash "ChildCount" child 0))
:do
;; download single file
(when (getf opts :verbose)
(format t "Downloading ~A~%" (generate-filename child)))
(download-media (generate-filename child)
(format-url domain "Items/~A/Download"
(gethash "Id" child))
auth)
:else
:do
;; if the item has children we need to download them.
;; to accomplish this we get the list of children
;; and loop over them, recursing for each one
;; ensure that a directory exists for Parent
;; then recurse with children
(uiop:with-current-directory ((create-directory (gethash "Name" child)))
(download-item-or-children child))))))
(if (zerop (gethash "ChildCount" root 0))
(download root)
(loop :for child :across children
:if (zerop (gethash "ChildCount" child 0))
:do
;; download single file
(when (getf opts :verbose)
(format t "Downloading ~A~%" (generate-filename child)))
(download child)
:else
:do
;; if the item has children we need to download them.
;; to accomplish this we get the list of children
;; and loop over them, recursing for each one
;; ensure that a directory exists for Parent
;; then recurse with children
(uiop:with-current-directory ((create-directory (gethash "Name" child)))
(download-item-or-children child)))))))
(when (or (getf opts :assume-yes)
(y-or-n-p "Download \"~A\"" (generate-root-name)))
@ -89,7 +93,9 @@
(and (every #'null args)
(every #'null opts)))
(opts:describe :usage-of "seanut"
:args "DOMAIN MEDIA-NAME")
:args "DOMAIN MEDIA-NAME"
:suffix (format nil *command-line-brief*
*valid-media-types*))
(uiop:quit 0))
(when (getf opts :version)
@ -116,15 +122,8 @@
(getf opts :media-type)
(url-encode search-term))))
(if (< 0 (length results))
;; FIXME: for some reason this access token is not "valid" enough to get
;; 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
;; whole? look into this more tomorrow
;;
;; after reading more
(loop :for item :across results
:do (prompt-and-download domain authorization
item opts))
:do (prompt-and-download domain authorization item opts))
(quit-with-message 0 "No results found for ~A" search-term)))))
(error (e)

View File

@ -40,7 +40,7 @@ if CONTENT is non-nil, passes that along to the request"
can probably be removed and the request can be made in-line"
(gethash "Items"
(json-request (format-url domain "Items?fields=Path&includeItemTypes=~A&recursive=true&searchTerm=~A"
(json-request (format-url domain "Items?fields=Path,ChildCount&includeItemTypes=~A&recursive=true&searchTerm=~A"
type name)
:auth auth)))