diff --git a/package.lisp b/package.lisp index 5a65c55..4798aab 100644 --- a/package.lisp +++ b/package.lisp @@ -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")) diff --git a/seanut.lisp b/seanut.lisp index b3eb54e..0ff2033 100644 --- a/seanut.lisp +++ b/seanut.lisp @@ -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) diff --git a/web.lisp b/web.lisp index 864a2ba..823868b 100644 --- a/web.lisp +++ b/web.lisp @@ -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)))