Erfan commited on
Commit
cc2fcfa
·
1 Parent(s): b5e074c

fix: use android player client to bypass yt bot detection

Browse files
Files changed (1) hide show
  1. bot/youtube.py +10 -3
bot/youtube.py CHANGED
@@ -16,19 +16,26 @@ def _cookies_opts():
16
  return {}
17
 
18
 
 
 
 
 
 
 
 
 
19
  def _get_ydl_opts(format_spec: str, ext: str):
20
  opts = {
21
  "format": format_spec,
22
  "outtmpl": os.path.join(DOWNLOAD_DIR, f"{uuid.uuid4()}.%(ext)s"),
23
- "quiet": True,
24
- "no_warnings": True,
25
  }
 
26
  opts.update(_cookies_opts())
27
  return opts
28
 
29
 
30
  async def get_video_info(url: str):
31
- ydl_opts = {"quiet": True, "no_warnings": True}
32
  ydl_opts.update(_cookies_opts())
33
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
34
  info = ydl.extract_info(url, download=False)
 
16
  return {}
17
 
18
 
19
+ def _base_opts():
20
+ return {
21
+ "quiet": True,
22
+ "no_warnings": True,
23
+ "extractor_args": {"youtube": {"player_client": ["android", "web"]}},
24
+ }
25
+
26
+
27
  def _get_ydl_opts(format_spec: str, ext: str):
28
  opts = {
29
  "format": format_spec,
30
  "outtmpl": os.path.join(DOWNLOAD_DIR, f"{uuid.uuid4()}.%(ext)s"),
 
 
31
  }
32
+ opts.update(_base_opts())
33
  opts.update(_cookies_opts())
34
  return opts
35
 
36
 
37
  async def get_video_info(url: str):
38
+ ydl_opts = _base_opts()
39
  ydl_opts.update(_cookies_opts())
40
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
41
  info = ydl.extract_info(url, download=False)