VeuReu commited on
Commit
962104d
·
verified ·
1 Parent(s): ae2abb0

Update main_process/main_router.py

Browse files
Files changed (1) hide show
  1. main_process/main_router.py +80 -2
main_process/main_router.py CHANGED
@@ -238,7 +238,7 @@ def pipeline_preprocessing_audio(video_path: str, voice_col):
238
 
239
  return full_transcription, diarization_info
240
 
241
- @router.post("/generate_srt_salamandra", tags=["Transcription Process"])
242
  async def pipeline_video_analysis(
243
  sha1: str,
244
  token: str = Query(..., description="Token required for authorization")
@@ -333,4 +333,82 @@ async def pipeline_video_analysis(
333
  }, f, ensure_ascii=False, indent=4)
334
 
335
  # The endpoint returns OK message info
336
- return {"status": "ok", "message": "Initial SRT and info JSON generated"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
 
239
  return full_transcription, diarization_info
240
 
241
+ @router.post("/generate_srt", tags=["Transcription Process"])
242
  async def pipeline_video_analysis(
243
  sha1: str,
244
  token: str = Query(..., description="Token required for authorization")
 
333
  }, f, ensure_ascii=False, indent=4)
334
 
335
  # The endpoint returns OK message info
336
+ return {"status": "ok", "message": "Initial SRT and info JSON generated"}
337
+
338
+ def get_initial_info_path(sha1:str):
339
+ video_root = MEDIA_ROOT / sha1
340
+ srt_dir = video_root / "initial_srt"
341
+ final_path = srt_dir / "initial_info.json"
342
+
343
+ if not video_root.exists() or not video_root.is_dir():
344
+ raise HTTPException(status_code=404, detail="SHA1 folder not found")
345
+ if not srt_dir.exists() or not srt_dir.is_dir():
346
+ raise HTTPException(status_code=404, detail="initial_srt folder not found")
347
+ if not final_path.exists() or not final_path.is_file():
348
+ raise HTTPException(status_code=404, detail="initial_info JSON not found")
349
+
350
+ return final_path
351
+
352
+ def get_initial_srt_path(sha1:str):
353
+ video_root = MEDIA_ROOT / sha1
354
+ srt_dir = video_root / "initial_srt"
355
+ final_path = srt_dir / "initial.srt"
356
+
357
+ if not video_root.exists() or not video_root.is_dir():
358
+ raise HTTPException(status_code=404, detail="SHA1 folder not found")
359
+ if not srt_dir.exists() or not srt_dir.is_dir():
360
+ raise HTTPException(status_code=404, detail="initial_srt folder not found")
361
+ if not final_path.exists() or not final_path.is_file():
362
+ raise HTTPException(status_code=404, detail="initial.srt SRT not found")
363
+
364
+ return final_path
365
+
366
+ @router.get("/download_initial_srt", tags=["Transcription Process"])
367
+ def download_initial_srt(
368
+ sha1: str,
369
+ token: str = Query(..., description="Token required for authorization")
370
+ ):
371
+ """
372
+ Download the cast CSV for a specific video identified by its SHA-1.
373
+ The CSV is expected under:
374
+ /data/media/<sha1>/cast/cast.csv
375
+ Steps:
376
+ - Validate the token.
377
+ - Ensure /data/media/<sha1> and /cast exist.
378
+ - Return the CSV as a FileResponse.
379
+ - Raise 404 if any folder or file is missing.
380
+ """
381
+ validate_token(token)
382
+
383
+ file_path = get_initial_srt_path(sha1)
384
+
385
+ return FileResponse(
386
+ path=file_path,
387
+ media_type="text/srt",
388
+ filename="initial.srt"
389
+ )
390
+
391
+ @router.get("/download_initial_info", tags=["Transcription Process"])
392
+ def download_initial_info(
393
+ sha1: str,
394
+ token: str = Query(..., description="Token required for authorization")
395
+ ):
396
+ """
397
+ Download the cast CSV for a specific video identified by its SHA-1.
398
+ The CSV is expected under:
399
+ /data/media/<sha1>/cast/cast.csv
400
+ Steps:
401
+ - Validate the token.
402
+ - Ensure /data/media/<sha1> and /cast exist.
403
+ - Return the CSV as a FileResponse.
404
+ - Raise 404 if any folder or file is missing.
405
+ """
406
+ validate_token(token)
407
+
408
+ file_path = get_initial_info_path(sha1)
409
+
410
+ return FileResponse(
411
+ path=file_path,
412
+ media_type="text/json",
413
+ filename="initial_info.json"
414
+ )