pytube.exceptions.RegexMatchError:get_transform_object:找不到 var for={(.*?)} 的匹配项;

2023-12-29

使用以下代码使用 PyTube 库下载视频时:

yt.streams.get_highest_resolution().download("PATH", f"PATH.mp4")

我收到错误:

raise RegexMatchError(caller="get_transform_object", pattern=pattern)
pytube.exceptions.RegexMatchError: get_transform_object: could not find match for var for={(.*?)};

我在 Stack Overflow 和 PyTube 的 Git 存储库中看到了很多修复,但它们似乎涉及到不同的部分cypher.py。我想知道如何替代get_transform_object上课于cypher.py以匹配正则表达式检查。


这是库更新期间的快速修复。

-> 在文件 .venv/lib/python3.10/site-packages/pytube/cipher.py 中 我使用的是 python 3.10,我的虚拟环境称为 .venv 您现在只需找到 pytube 库并转到文件 cipher.py 并编辑其源代码即可。

-> 找到方法 get_transform_object 并将其替换为如下

def get_transform_object(js: str, var: str) -> List[str]:
    pattern = r"var %s={(.*?)};" % re.escape(var)
    logger.debug("getting transform object")
    regex = re.compile(pattern, flags=re.DOTALL)
    transform_match = regex.search(js)
    
    if not transform_match:
        # i commented out the line raising the error
        # raise RegexMatchError(caller="get_transform_object", pattern=pattern)
        return []  # Return an empty list if no match is found

    return transform_match.group(1).replace("\n", " ").split(", ")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

pytube.exceptions.RegexMatchError:get_transform_object:找不到 var for={(.*?)} 的匹配项; 的相关文章

随机推荐