pytube.exceptions.RegexMatchError:get_throttling_function_name:找不到多个匹配项

新手上路,请多包涵

我曾经通过以下方式下载歌曲:

 from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=AWXvSBHB210')
video.streams.get_by_itag(251).download()

从今天开始出现这个错误:

 Traceback (most recent call last):
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube__main__.py", line 170, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 387, in get_throttling_plan
    raw_code = get_throttling_function_code(js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 293, in get_throttling_function_code
    name = re.escape(get_throttling_function_name(js))
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 278, in get_throttling_function_name
    raise RegexMatchError(
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Me\Documents\YouTubeDownloader.py", line 3, in <module>
    video.streams.get_by_itag(251).download()
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube__main__.py", line 285, in streams
    return StreamQuery(self.fmt_streams)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube__main__.py", line 177, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 387, in get_throttling_plan
    raw_code = get_throttling_function_code(js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 293, in get_throttling_function_code
    name = re.escape(get_throttling_function_name(js))
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 278, in get_throttling_function_name
    raise RegexMatchError(
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple

原文由 Sciveo 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 917
2 个回答

我在使用 pytube 11.0.0 时遇到了同样的问题

所以发现在 cipher.py 类的 pytube 库中存在正则表达式过滤器不匹配

function_patterns = [

    r'a\.C&&\(b=a\.get\("n"\)\)&&\(b=([^(]+)\(b\),a\.set\("n",b\)\)}};',
]

现在有pytube代码昨天更新到11.0.1

 function_patterns = [

    r'a\.[A-Z]&&\(b=a\.get\("n"\)\)&&\(b=([^(]+)\(b\)',
]

通过此代码更新,现在可以使用 pytube 下载 youtube 视频!!!

使用此命令更新您的 pytube 库:

 python3 -m pip install --upgrade pytube

原文由 Lavanya Rani 发布,翻译遵循 CC BY-SA 4.0 许可协议

因为 youtube 在它的末端改变了一些东西,现在你必须改变 pytube 的 cipher.py 的 get_throttling_function_name 变量 function_patterns 到以下

r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*'
r'\([a-z]\s*=\s*([a-zA-Z0-9$]{2,3})(\[\d+\])?\([a-z]\)'

您还必须将第 288 行更改为:

 nfunc=re.escape(function_match.group(1))),

在 pytube 正式发布修复程序之前,您必须使用此解决方法。

原文由 eroc1234 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题