From 64a3c174e3d477d840adfab5014a8a1d88547a25 Mon Sep 17 00:00:00 2001 From: Victor Mylle Date: Wed, 22 Mar 2023 22:04:38 +0000 Subject: [PATCH] Added download with train, test, val --- backend/src/routers/category.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/src/routers/category.py b/backend/src/routers/category.py index 3a9c427..4ca250f 100755 --- a/backend/src/routers/category.py +++ b/backend/src/routers/category.py @@ -128,17 +128,22 @@ async def download_all(category_id: int, background_tasks: BackgroundTasks, Auth category_signs = c.signs # get all the paths of the sign videos - paths = [] + all_videos = [] for sign in category_signs: for video in sign.sign_videos: - paths.append(video.path) + all_videos.append(video) zip_path = f"/tmp/{datetime.datetime.now().timestamp()}.zip" # create the zip file with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED, False) as zip_file: - for path in paths: - zip_file.write(f"{settings.DATA_PATH}/{path}", os.path.basename(path)) + for video in all_videos: + splitted = os.path.basename(video.path).split("!") + # insert the dataset name at index 1 + splitted.insert(1, video.dataset) + # join the splitted list to a string + new_name = "!".join(splitted) + zip_file.write(f"{settings.DATA_PATH}/{video.path}", new_name) background_tasks.add_task(delete_zip_file, zip_path) # serve the zip file as the response