bluenevus commited on
Commit
eb57b1b
·
verified ·
1 Parent(s): bafe69e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -96,13 +96,28 @@ def transcribe_audio_chunks(chunks):
96
  return ' '.join(transcriptions)
97
 
98
  def download_file(url):
99
- local_filename = url.split('/')[-1]
100
- with requests.get(url, stream=True) as r:
101
- r.raise_for_status()
102
- with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(local_filename)[1]) as temp_file:
103
- for chunk in r.iter_content(chunk_size=8192):
104
- temp_file.write(chunk)
105
- return temp_file.name
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
  def get_file_info(file_path):
108
  try:
 
96
  return ' '.join(transcriptions)
97
 
98
  def download_file(url):
99
+ with requests.Session() as session:
100
+ response = session.get(url, stream=True, allow_redirects=True)
101
+ response.raise_for_status()
102
+
103
+ # Check if we can get the filename from Content-Disposition header
104
+ content_disposition = response.headers.get('Content-Disposition')
105
+ if content_disposition:
106
+ filename = re.findall("filename=(.+)", content_disposition)[0].strip('"')
107
+ else:
108
+ # If not, use a default name with .mp4 extension
109
+ filename = 'downloaded_video.mp4'
110
+
111
+ # Save the content to a temporary file with .mp4 extension
112
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as temp_file:
113
+ for chunk in response.iter_content(chunk_size=8192):
114
+ if chunk:
115
+ temp_file.write(chunk)
116
+ temp_file_path = temp_file.name
117
+
118
+ logger.info(f"File downloaded and saved as: {temp_file_path}")
119
+ return temp_file_path
120
+
121
 
122
  def get_file_info(file_path):
123
  try: