From 359e391fcccbae069dcacc5b3528723b13a7388e Mon Sep 17 00:00:00 2001 From: Carey Metcalfe Date: Thu, 7 Oct 2021 10:22:37 -0400 Subject: [PATCH] Implement recursive downloading of folders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example use case: ``` Some Album/ ├── CD1 │ └── ├── CD2 │ └── └── cover.jpg ``` Previously, downloading the `Some Album` folder would result in no data being sent (not even `cover.jpg`) This commit changes folder-based downloads so that the entire folder tree (including any non-music) is added to the returned zip file. This allows any included album art, scans, notes, etc. to be distributed with the files. Album-based downloads are unaffected. --- supysonic/api/media.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/supysonic/api/media.py b/supysonic/api/media.py index 7c2a2ba..66e0dfd 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -249,14 +249,19 @@ def download_media(): except ObjectNotFound: raise NotFound("Folder") - # Stream a zip of the tracks + cover art to the client + # Stream a zip of multiple files to the client z = ZipStream(sized=True) - for track in rv.tracks: - z.add_path(track.path) + if isinstance(rv, Folder): + # Add the entire folder tree to the zip + z.add_path(rv.path, recurse=True) + else: + # Add tracks + cover art to the zip + for track in rv.tracks: + z.add_path(track.path) - cover_path = _cover_from_collection(rv, extract=False) - if cover_path: - z.add_path(cover_path) + cover_path = _cover_from_collection(rv, extract=False) + if cover_path: + z.add_path(cover_path) if not z: raise GenericError("Nothing to download")