bluenevus commited on
Commit
237cc21
·
verified ·
1 Parent(s): 64832c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
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
- logger.info(f"URL content downloaded: {temp_file}")
 
 
 
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
- # Get file info
162
- file_info = get_file_info(temp_file)
163
- if not file_info:
164
- return "Unable to process file: Could not determine file type", False
165
 
166
- logger.info(f"File info: {json.dumps(file_info, indent=2)}")
167
 
168
- # Determine if it's audio or video
169
- is_audio = any(stream['codec_type'] == 'audio' for stream in file_info['streams'])
170
- is_video = any(stream['codec_type'] == 'video' for stream in file_info['streams'])
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