ALI7ADEL commited on
Commit
71c3369
·
verified ·
1 Parent(s): 61b1ed6

Update src/transcription/audio_downloader.py

Browse files
src/transcription/audio_downloader.py CHANGED
@@ -12,11 +12,12 @@ class YouTubeDownloader:
12
 
13
  def get_video_info(self, url: str) -> dict:
14
  try:
15
- logger.info(f"Fetching video info using yt-dlp for: {url}")
16
  ydl_opts = {
17
  'quiet': True,
18
  'no_warnings': True,
19
- 'extract_flat': True,
 
20
  }
21
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
22
  info = ydl.extract_info(url, download=False)
@@ -30,22 +31,27 @@ class YouTubeDownloader:
30
 
31
  def download_audio(self, url: str, task_id: str) -> Path:
32
  try:
33
- logger.info(f"Downloading audio using yt-dlp for task: {task_id}")
34
- # yt-dlp بيفضل صيغة m4a للصوت وهي ممتازة وسريعة
35
  filename = f"{task_id}.m4a"
36
  output_path = self.temp_dir / filename
37
 
38
  ydl_opts = {
39
  'format': 'bestaudio/best',
40
  'outtmpl': str(output_path),
41
- 'quiet': False, # سايبينها تطلع لوجز عشان لو في مشكلة نشوفها
42
  'no_warnings': False,
 
 
 
43
  }
44
 
45
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
46
  ydl.download([url])
47
 
48
- logger.info(f"✅ Audio downloaded successfully to: {output_path}")
 
 
 
49
  return output_path
50
 
51
  except Exception as e:
 
12
 
13
  def get_video_info(self, url: str) -> dict:
14
  try:
15
+ logger.info(f"Fetching video info for: {url}")
16
  ydl_opts = {
17
  'quiet': True,
18
  'no_warnings': True,
19
+ # إجبار yt-dlp على استخدام node لحل الشفرات
20
+ 'javascript_filter': 'node',
21
  }
22
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
23
  info = ydl.extract_info(url, download=False)
 
31
 
32
  def download_audio(self, url: str, task_id: str) -> Path:
33
  try:
34
+ logger.info(f"Downloading audio for task: {task_id}")
 
35
  filename = f"{task_id}.m4a"
36
  output_path = self.temp_dir / filename
37
 
38
  ydl_opts = {
39
  'format': 'bestaudio/best',
40
  'outtmpl': str(output_path),
41
+ 'quiet': False,
42
  'no_warnings': False,
43
+ # أهم سطرين عشان يتخطى حماية يوتيوب في السيرفر:
44
+ 'javascript_filter': 'node',
45
+ 'extractor_args': {'youtube': {'player_client': ['web', 'ios']}},
46
  }
47
 
48
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
49
  ydl.download([url])
50
 
51
+ if not output_path.exists():
52
+ raise Exception("File not found after download")
53
+
54
+ logger.info(f"✅ Audio downloaded successfully: {output_path}")
55
  return output_path
56
 
57
  except Exception as e: