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
main v0.0.1
a. fox 2 years ago
parent b59004fce1
commit 029b02b6e8

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

@ -28,6 +28,12 @@
(create-directory (dir) (create-directory (dir)
(ensure-directories-exist (uiop:ensure-directory-pathname (make-pathname :name 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) (download-item-or-children (item)
;; 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)
@ -47,17 +53,15 @@
(gethash "Id" item)) (gethash "Id" item))
:auth auth))))) :auth auth)))))
(if (zerop (gethash "ChildCount" root 0))
(download root)
(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) (when (getf opts :verbose)
(format t "Downloading ~A~%" (generate-filename child))) (format t "Downloading ~A~%" (generate-filename child)))
(download-media (generate-filename child) (download child)
(format-url domain "Items/~A/Download"
(gethash "Id" child))
auth)
:else :else
:do :do
@ -67,7 +71,7 @@
;; ensure that a directory exists for Parent ;; ensure that a directory exists for Parent
;; then recurse with children ;; then recurse with children
(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)))))))
(when (or (getf opts :assume-yes) (when (or (getf opts :assume-yes)
(y-or-n-p "Download \"~A\"" (generate-root-name))) (y-or-n-p "Download \"~A\"" (generate-root-name)))
@ -89,7 +93,9 @@
(and (every #'null args) (and (every #'null args)
(every #'null opts))) (every #'null opts)))
(opts:describe :usage-of "seanut" (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)) (uiop:quit 0))
(when (getf opts :version) (when (getf opts :version)
@ -116,15 +122,8 @@
(getf opts :media-type) (getf opts :media-type)
(url-encode search-term)))) (url-encode search-term))))
(if (< 0 (length results)) (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 (loop :for item :across results
:do (prompt-and-download domain authorization :do (prompt-and-download domain authorization item opts))
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)

@ -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" 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,ChildCount&includeItemTypes=~A&recursive=true&searchTerm=~A"
type name) type name)
:auth auth))) :auth auth)))

Loading…
Cancel
Save