Update app.py
Browse files
app.py
CHANGED
@@ -144,11 +144,19 @@ def process_media(file_path, is_url=False):
|
|
144 |
logger.info(f"Processing URL: {file_path}")
|
145 |
try:
|
146 |
temp_file = download_file(file_path)
|
147 |
-
|
|
|
|
|
|
|
148 |
except Exception as e:
|
149 |
logger.error(f"Error downloading URL content: {str(e)}")
|
150 |
return f"Error downloading URL content: {str(e)}", False
|
|
|
|
|
|
|
|
|
151 |
else:
|
|
|
152 |
logger.info("Processing uploaded file")
|
153 |
content_type, content_string = file_path.split(',')
|
154 |
decoded = base64.b64decode(content_string)
|
@@ -158,16 +166,16 @@ def process_media(file_path, is_url=False):
|
|
158 |
temp_file = temp_file.name
|
159 |
logger.info(f"Uploaded file saved: {temp_file}")
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
|
166 |
-
|
167 |
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
|
172 |
# Convert to WAV using ffmpeg
|
173 |
wav_path = tempfile.NamedTemporaryFile(delete=False, suffix='.wav').name
|
|
|
144 |
logger.info(f"Processing URL: {file_path}")
|
145 |
try:
|
146 |
temp_file = download_file(file_path)
|
147 |
+
file_size = os.path.getsize(temp_file)
|
148 |
+
logger.info(f"URL content downloaded: {temp_file} (Size: {file_size} bytes)")
|
149 |
+
if file_size < 1000000: # Less than 1MB
|
150 |
+
raise Exception(f"Downloaded file is too small ({file_size} bytes). Possible incomplete download.")
|
151 |
except Exception as e:
|
152 |
logger.error(f"Error downloading URL content: {str(e)}")
|
153 |
return f"Error downloading URL content: {str(e)}", False
|
154 |
+
|
155 |
+
# For downloaded files, we know it's an MP4, so we can skip file type determination
|
156 |
+
is_video = True
|
157 |
+
is_audio = False
|
158 |
else:
|
159 |
+
# For uploaded files, we still need to determine the file type
|
160 |
logger.info("Processing uploaded file")
|
161 |
content_type, content_string = file_path.split(',')
|
162 |
decoded = base64.b64decode(content_string)
|
|
|
166 |
temp_file = temp_file.name
|
167 |
logger.info(f"Uploaded file saved: {temp_file}")
|
168 |
|
169 |
+
# Get file info for uploaded files
|
170 |
+
file_info = get_file_info(temp_file)
|
171 |
+
if not file_info:
|
172 |
+
return "Unable to process file: Could not determine file type", False
|
173 |
|
174 |
+
logger.info(f"File info: {json.dumps(file_info, indent=2)}")
|
175 |
|
176 |
+
# Determine if it's audio or video
|
177 |
+
is_audio = any(stream['codec_type'] == 'audio' for stream in file_info['streams'])
|
178 |
+
is_video = any(stream['codec_type'] == 'video' for stream in file_info['streams'])
|
179 |
|
180 |
# Convert to WAV using ffmpeg
|
181 |
wav_path = tempfile.NamedTemporaryFile(delete=False, suffix='.wav').name
|