Update main.py
Browse files
main.py
CHANGED
|
@@ -1066,7 +1066,7 @@ from fastapi.responses import RedirectResponse
|
|
| 1066 |
|
| 1067 |
@app.get("/batch/download-all/{batch_id}")
|
| 1068 |
async def download_batch_files(batch_id: str):
|
| 1069 |
-
"""
|
| 1070 |
if batch_id not in batch_status_store:
|
| 1071 |
raise HTTPException(status_code=404, detail="Batch not found")
|
| 1072 |
|
|
@@ -1078,35 +1078,40 @@ async def download_batch_files(batch_id: str):
|
|
| 1078 |
detail=f"Batch not completed. Status: {batch_status['status']}"
|
| 1079 |
)
|
| 1080 |
|
| 1081 |
-
|
| 1082 |
for result in batch_status["results"]:
|
| 1083 |
if result.get("success") and result.get("download_path"):
|
| 1084 |
file_path = result["download_path"]
|
| 1085 |
if os.path.exists(file_path):
|
| 1086 |
-
|
| 1087 |
-
|
| 1088 |
-
path
|
| 1089 |
-
|
| 1090 |
-
|
| 1091 |
-
|
| 1092 |
-
|
| 1093 |
-
|
|
|
|
|
|
|
| 1094 |
|
| 1095 |
@app.get("/batch/download-all")
|
| 1096 |
async def download_all_files():
|
| 1097 |
-
"""
|
| 1098 |
download_dir = Path(downloader.download_dir)
|
| 1099 |
|
| 1100 |
-
|
| 1101 |
for file_path in download_dir.glob("*"):
|
| 1102 |
if file_path.is_file():
|
| 1103 |
-
|
| 1104 |
-
|
| 1105 |
-
|
| 1106 |
-
|
| 1107 |
-
)
|
| 1108 |
|
| 1109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1110 |
|
| 1111 |
@app.get("/video/file/{filename}")
|
| 1112 |
async def download_file(filename: str):
|
|
|
|
| 1066 |
|
| 1067 |
@app.get("/batch/download-all/{batch_id}")
|
| 1068 |
async def download_batch_files(batch_id: str):
|
| 1069 |
+
"""Get JSON list of all downloadable files for a specific batch"""
|
| 1070 |
if batch_id not in batch_status_store:
|
| 1071 |
raise HTTPException(status_code=404, detail="Batch not found")
|
| 1072 |
|
|
|
|
| 1078 |
detail=f"Batch not completed. Status: {batch_status['status']}"
|
| 1079 |
)
|
| 1080 |
|
| 1081 |
+
files = []
|
| 1082 |
for result in batch_status["results"]:
|
| 1083 |
if result.get("success") and result.get("download_path"):
|
| 1084 |
file_path = result["download_path"]
|
| 1085 |
if os.path.exists(file_path):
|
| 1086 |
+
files.append({
|
| 1087 |
+
"filename": os.path.basename(file_path),
|
| 1088 |
+
"url": f"/video/file/{os.path.basename(file_path)}"
|
| 1089 |
+
})
|
| 1090 |
+
|
| 1091 |
+
if not files:
|
| 1092 |
+
raise HTTPException(status_code=404, detail="No downloadable files found in this batch")
|
| 1093 |
+
|
| 1094 |
+
return {"batch_id": batch_id, "total_files": len(files), "downloads": files}
|
| 1095 |
+
|
| 1096 |
|
| 1097 |
@app.get("/batch/download-all")
|
| 1098 |
async def download_all_files():
|
| 1099 |
+
"""Get JSON list of all available files in the download directory"""
|
| 1100 |
download_dir = Path(downloader.download_dir)
|
| 1101 |
|
| 1102 |
+
files = []
|
| 1103 |
for file_path in download_dir.glob("*"):
|
| 1104 |
if file_path.is_file():
|
| 1105 |
+
files.append({
|
| 1106 |
+
"filename": file_path.name,
|
| 1107 |
+
"url": f"/video/file/{file_path.name}"
|
| 1108 |
+
})
|
|
|
|
| 1109 |
|
| 1110 |
+
if not files:
|
| 1111 |
+
raise HTTPException(status_code=404, detail="No files available for download")
|
| 1112 |
+
|
| 1113 |
+
return {"total_files": len(files), "downloads": files}
|
| 1114 |
+
|
| 1115 |
|
| 1116 |
@app.get("/video/file/{filename}")
|
| 1117 |
async def download_file(filename: str):
|