Surn commited on
Commit
7eeb76c
·
1 Parent(s): 79a1f04

Refactor yt_dlp options and Deno check logic

Browse files

Refactored compat_opts initialization and Deno check to occur before ydl_opts creation. Updated 'format' to 'bestaudio/best' and commented out unused yt_dlp options. Improved code clarity and maintainability.

Files changed (1) hide show
  1. modules/yt_audio_get_tracks.py +11 -10
modules/yt_audio_get_tracks.py CHANGED
@@ -15,11 +15,16 @@ def download_audio(url, video_id, progress_callback=None):
15
  temp_dir = 'separated'
16
  os.makedirs(temp_dir, exist_ok=True)
17
  _emit_progress(progress_callback, 'Downloading audio from YouTube...')
 
 
 
 
 
18
  ydl_opts = {
19
- 'format': 'ba/bw', # best audio only, falls back to best webm/m4a
20
  'outtmpl': os.path.join(temp_dir, f'{video_id}.%(ext)s'),
21
  'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav'}],
22
- 'keepvideo': True, # Don't keep video file (saves disk space)
23
  'quiet': False,
24
  'no_warnings': False,
25
  'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
@@ -29,16 +34,12 @@ def download_audio(url, video_id, progress_callback=None):
29
  'socket_timeout': 30,
30
  'retry_sleep': [1, 2, 5, 10],
31
  'max_retries': 3,
32
- 'extractor_args': {'youtube': {'player_client': ['android', 'web', 'ios']}},
33
- 'impersonate': 'chrome',
34
- 'cookiefile': cookie_path,
35
- 'compat_opts': ['no-youtube-unavailable-videoplayback'],
36
  }
37
 
38
- if shutil.which('deno') is None:
39
- print("⚠️ Deno not found.")
40
- ydl_opts['compat_opts'].append('no-youtube-js')
41
-
42
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
43
  ydl.download([url])
44
  _emit_progress(progress_callback, 'Converting downloaded audio to WAV...')
 
15
  temp_dir = 'separated'
16
  os.makedirs(temp_dir, exist_ok=True)
17
  _emit_progress(progress_callback, 'Downloading audio from YouTube...')
18
+ compat_opts = ['no-youtube-unavailable-videoplayback']
19
+ if shutil.which('deno') is None:
20
+ print("⚠️ Deno not found.")
21
+ compat_opts.append('no-youtube-js')
22
+
23
  ydl_opts = {
24
+ 'format': 'bestaudio/best',
25
  'outtmpl': os.path.join(temp_dir, f'{video_id}.%(ext)s'),
26
  'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav'}],
27
+ 'keepvideo': True,
28
  'quiet': False,
29
  'no_warnings': False,
30
  'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
 
34
  'socket_timeout': 30,
35
  'retry_sleep': [1, 2, 5, 10],
36
  'max_retries': 3,
37
+ # 'extractor_args': {'youtube': {'player_client': ['android', 'web', 'ios']}},
38
+ # 'impersonate': 'chrome',
39
+ # 'cookiefile': cookie_path,
40
+ 'compat_opts': compat_opts,
41
  }
42
 
 
 
 
 
43
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
44
  ydl.download([url])
45
  _emit_progress(progress_callback, 'Converting downloaded audio to WAV...')