marquesafonso commited on
Commit
6c68a13
·
1 Parent(s): 2b0ce36

fix zip archive api response.

Browse files
Files changed (3) hide show
  1. main.py +6 -6
  2. utils/process_video.py +6 -4
  3. utils/zip_response.py +0 -1
main.py CHANGED
@@ -71,15 +71,15 @@ async def process_video_api(video_file: UploadFile = File(...),
71
  finally:
72
  srt_file.file.close()
73
  logging.info("Processing the video...")
74
- output_path = process_video(temp_input_path, SRT_PATH, max_words_per_line, fontsize, font, bg_color, text_color)
75
  logging.info("Archiving response...")
76
- zip_path = zip_response(os.path.join(temp_vid_dir,"archive.zip"), [SRT_PATH, output_path])
77
- return FileResponse(zip_path, media_type='application/zip', filename=f'result_{video_file.filename}.zip')
78
  logging.info("Processing the video...")
79
- output_path = process_video(temp_input_path, None, max_words_per_line, fontsize, font, bg_color, text_color)
80
  logging.info("Archiving response...")
81
- zip_path = zip_response(os.path.join(temp_vid_dir,"archive.zip"), [SRT_PATH, output_path])
82
- return FileResponse(zip_path, media_type='application/zip', filename=f'result_{video_file.filename}.zip')
83
 
84
  except Exception as e:
85
  raise HTTPException(status_code=500, detail=str(e))
 
71
  finally:
72
  srt_file.file.close()
73
  logging.info("Processing the video...")
74
+ output_path, srt_path = process_video(temp_input_path, SRT_PATH, max_words_per_line, fontsize, font, bg_color, text_color)
75
  logging.info("Archiving response...")
76
+ zip_path = zip_response(os.path.join(temp_vid_dir,"archive.zip"), [output_path, srt_path])
77
+ return FileResponse(zip_path, media_type='application/zip', filename=f"result_{video_file.filename.split('.')[0]}.zip")
78
  logging.info("Processing the video...")
79
+ output_path, srt_path = process_video(temp_input_path, None, max_words_per_line, fontsize, font, bg_color, text_color)
80
  logging.info("Archiving response...")
81
+ zip_path = zip_response(os.path.join(temp_vid_dir,"archive.zip"), [output_path, srt_path])
82
+ return FileResponse(zip_path, media_type='application/zip', filename=f"result_{video_file.filename.split('.')[0]}.zip")
83
 
84
  except Exception as e:
85
  raise HTTPException(status_code=500, detail=str(e))
utils/process_video.py CHANGED
@@ -25,12 +25,14 @@ def process_video(invideo_filename:str,
25
  if srt_path:
26
  subtitler(invideo_filename, srt_path, OUTVIDEO_PATH, fontsize, font, bg_color, text_color)
27
  return OUTVIDEO_PATH
 
28
  INAUDIO_PATH = os.path.abspath(f"{invideo_filename.split('.')[0]}.mp3")
29
- convert_mp4_to_mp3(invideo_filename, INAUDIO_PATH)
 
30
  SRT_PATH = os.path.abspath(f"{invideo_filename.split('.')[0]}.srt")
 
31
  if not os.path.exists(SRT_PATH):
32
  transcriber(INAUDIO_PATH, SRT_PATH, max_words_per_line)
33
- logging.info("Transcription Complete")
34
  subtitler(invideo_filename, SRT_PATH, OUTVIDEO_PATH, fontsize, font, bg_color, text_color)
35
- logging.info("Subtitling Complete")
36
- return OUTVIDEO_PATH
 
25
  if srt_path:
26
  subtitler(invideo_filename, srt_path, OUTVIDEO_PATH, fontsize, font, bg_color, text_color)
27
  return OUTVIDEO_PATH
28
+ logging.info("Converting Video to Audio")
29
  INAUDIO_PATH = os.path.abspath(f"{invideo_filename.split('.')[0]}.mp3")
30
+ if not os.path.exists(INAUDIO_PATH):
31
+ convert_mp4_to_mp3(invideo_filename, INAUDIO_PATH)
32
  SRT_PATH = os.path.abspath(f"{invideo_filename.split('.')[0]}.srt")
33
+ logging.info("Transcribing...")
34
  if not os.path.exists(SRT_PATH):
35
  transcriber(INAUDIO_PATH, SRT_PATH, max_words_per_line)
36
+ logging.info("Subtitling...")
37
  subtitler(invideo_filename, SRT_PATH, OUTVIDEO_PATH, fontsize, font, bg_color, text_color)
38
+ return OUTVIDEO_PATH, SRT_PATH
 
utils/zip_response.py CHANGED
@@ -6,5 +6,4 @@ def zip_response(archive_name: str, files: list):
6
  # Add specific files to the zip file
7
  for file in files:
8
  zipf.write(file, arcname=os.path.basename(file))
9
- zipf.write(file, arcname=os.path.basename(file))
10
  return archive_name
 
6
  # Add specific files to the zip file
7
  for file in files:
8
  zipf.write(file, arcname=os.path.basename(file))
 
9
  return archive_name