bahaeddinmselmi commited on
Commit
04f78af
·
1 Parent(s): 1b9a388

fix: update yt-dlp and improve logging

Browse files
app/services/downloader.py CHANGED
@@ -436,7 +436,11 @@ def stream_extract_frames(url: str, job_id: str, max_frames: int = 5, duration:
436
  )
437
 
438
  if result.returncode != 0:
439
- print(f"FFmpeg stderr: {result.stderr.decode()[:500]}")
 
 
 
 
440
 
441
  # Find extracted frames
442
  frames = sorted(glob.glob(os.path.join(TEMP_DIR, f"{job_id}_frame_*.jpg")))
@@ -484,7 +488,11 @@ def stream_extract_audio(url: str, job_id: str, duration: int = 30) -> str:
484
  result = subprocess.run(cmd, capture_output=True, timeout=60)
485
 
486
  if result.returncode != 0:
487
- print(f"Audio extraction stderr: {result.stderr.decode()[:300]}")
 
 
 
 
488
 
489
  return audio_path if os.path.exists(audio_path) else None
490
 
 
436
  )
437
 
438
  if result.returncode != 0:
439
+ stderr = result.stderr.decode()
440
+ print(f"[{job_id}] FFmpeg Error (Return Code {result.returncode}):")
441
+ print(f"[{job_id}] FFmpeg stderr (first 500 chars): {stderr[:500]}")
442
+ else:
443
+ print(f"[{job_id}] FFmpeg extraction successful")
444
 
445
  # Find extracted frames
446
  frames = sorted(glob.glob(os.path.join(TEMP_DIR, f"{job_id}_frame_*.jpg")))
 
488
  result = subprocess.run(cmd, capture_output=True, timeout=60)
489
 
490
  if result.returncode != 0:
491
+ stderr = result.stderr.decode()
492
+ print(f"[{job_id}] Audio extraction Error (Return Code {result.returncode}):")
493
+ print(f"[{job_id}] Audio stderr (first 300 chars): {stderr[:300]}")
494
+ else:
495
+ print(f"[{job_id}] Audio extraction successful")
496
 
497
  return audio_path if os.path.exists(audio_path) else None
498
 
app/services/pipeline.py CHANGED
@@ -84,20 +84,28 @@ async def run_analysis_pipeline(job_id: str, url: str, uploaded_file_path: str,
84
 
85
  # PATH A: URL
86
  if url and not uploaded_file_path:
 
87
  frame_paths = stream_extract_frames(url, job_id, max_frames=8, duration=30)
88
 
89
  if not frame_paths:
 
90
  video_path = download_video(url, job_id)
91
  if video_path and os.path.exists(video_path):
 
92
  frame_paths = extract_frames(video_path, job_id, fps=0.5, max_frames=8)
93
  audio_path = extract_audio(video_path, job_id)
94
  elif is_youtube_url(url):
 
95
  frame_paths = download_youtube_thumbnail(url, job_id)
96
  thumbnail_only = True
97
- else:
98
- jobs_db[job_id] = {"status": "failed", "error": "Could not download video or extract frames"}
 
 
 
99
  return
100
  else:
 
101
  audio_path = stream_extract_audio(url, job_id, duration=30)
102
 
103
  # PATH B: Upload
 
84
 
85
  # PATH A: URL
86
  if url and not uploaded_file_path:
87
+ print(f"[{job_id}] Path A: URL analysis")
88
  frame_paths = stream_extract_frames(url, job_id, max_frames=8, duration=30)
89
 
90
  if not frame_paths:
91
+ print(f"[{job_id}] Streaming failed, falling back to full download")
92
  video_path = download_video(url, job_id)
93
  if video_path and os.path.exists(video_path):
94
+ print(f"[{job_id}] Full download successful, extracting frames")
95
  frame_paths = extract_frames(video_path, job_id, fps=0.5, max_frames=8)
96
  audio_path = extract_audio(video_path, job_id)
97
  elif is_youtube_url(url):
98
+ print(f"[{job_id}] Full download failed for YouTube, trying thumbnail fallback")
99
  frame_paths = download_youtube_thumbnail(url, job_id)
100
  thumbnail_only = True
101
+
102
+ if not frame_paths:
103
+ error_msg = "Could not download video or extract frames (All layers failed)"
104
+ print(f"[{job_id}] ERROR: {error_msg}")
105
+ jobs_db[job_id] = {"status": "failed", "error": error_msg}
106
  return
107
  else:
108
+ print(f"[{job_id}] Streaming successful, extracting audio")
109
  audio_path = stream_extract_audio(url, job_id, duration=30)
110
 
111
  # PATH B: Upload
requirements.txt CHANGED
@@ -3,6 +3,6 @@ uvicorn[standard]>=0.32.0
3
  python-dotenv>=1.0.0
4
  pydantic-settings>=2.6.0
5
  requests>=2.32.0
6
- yt-dlp>=2024.12.0
7
  slowapi>=0.1.9
8
  python-multipart>=0.0.9
 
3
  python-dotenv>=1.0.0
4
  pydantic-settings>=2.6.0
5
  requests>=2.32.0
6
+ yt-dlp>=2025.1.15
7
  slowapi>=0.1.9
8
  python-multipart>=0.0.9