python-3.x pytube.exceptions.RegexMatchError:get_throttling_function_name:无法找到多个的匹配项

ldfqzlk8  于 2023-08-08  发布在  Python
关注(0)|答案(8)|浏览(117)

我习惯用以下方式下载歌曲:

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

6za6bjd0

6za6bjd01#

因为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正式发布修复之前,您必须使用此解决方案。
编辑:这很可能在未来youtube更新他们的网站时再次被打破,请务必检查github的问题以获得可能的解决方案

pcrecxhr

pcrecxhr2#

我在使用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\)',
]


有了这个代码更新现在下载youtube视频与pytube工程!!!
使用以下命令更新你的pytube库:

python3 -m pip install --upgrade pytube

nbewdwxp

nbewdwxp3#

用这个更新你的(cipher.py -> get_throttling_function_name -> function_patterns),然后它就可以工作了。

function_patterns = [
    # https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
    # https://github.com/yt-dlp/yt-dlp/commit/48416bc4a8f1d5ff07d5977659cb8ece7640dcd8
    # var Bpa = [iha];
    # ...
    # a.C && (b = a.get("n")) && (b = Bpa[0](b), a.set("n", b),
    # Bpa.length || iha("")) }};
    # In the above case, `iha` is the relevant function name
    r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&.*?\|\|\s*([a-z]+)',
    r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)', ]

字符串

nnvyjq4y

nnvyjq4y4#

在Pytube版本15.0.0中,您只需要删除cipher.py文件第287行中的;
r'var {nfunc}\s*=\s*(\[.+?\];)'.format(更改为r'var {nfunc}\s*=\s*(\[.+?\])'.format(

5rgfhyps

5rgfhyps5#

更新的正则表达式:

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]\)'

字符串
如果只是从web复制/粘贴,上面的答案可能会被pycharm错误地解析。要修复,请尝试将两个字符串合并到一行中:

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


我发现这个修复了V12.0.0的问题

u7up0aaq

u7up0aaq6#

您可以使用yt-dlp:https://github.com/yt-dlp/yt-dlp

!pip install -U yt-dlp

字符串
然后,对于您的视频(mp4 + 1080 p),使用以下代码:

!yt-dlp -f "bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" "https://www.youtube.com/watch?v=AWXvSBHB210"

bfhwhh0e

bfhwhh0e7#

升级pytube
python3 -m pip install --升级pytube

9wbgstp7

9wbgstp78#

谢谢,这解决了error - pytube现在给出了各种其他错误,并通过在错误发生的行添加以下内容为我解决了它:
在417线附近。。

if(raw_code == ""):
    return ""

字符串
344号线附近

if(raw_code == ""):
    return []


第321章把它改成:

if(match != None):
    code_lines_list = find_object_from_startpoint(js, match.span()[1]).split('\n')
    joined_lines = "".join(code_lines_list)
    # Prepend function definition (e.g. `Dea=function(a)`)
    return match.group(0) + joined_lines
else:
    return ""


在这之后,它开始为我工作。

相关问题