在 Pytube 中过滤流时出现 AttributeError

问题描述 投票:0回答:1

我正在尝试使用

pytube
库下载 YouTube 视频。但是,我在尝试过滤流时遇到错误。这是我正在使用的代码(只是其中的必要部分):

from pytube import YouTube
from moviepy.editor import VideoFileClip, AudioFileClip
import os

link = input("Enter link here: ")
filename = input("Enter desired filename here: ")

filename = filename.replace('"', '').replace('&', 'and')

url = YouTube(link)

print("downloading....")

video = url.streams.filter(res="2160p", mime_type="video/webm").first() 

当我运行此代码时,出现以下错误:

  File "C:\Users\user\Desktop\YouTube.py", line 15, in <module>
    video = url.streams.filter(res="2160p", mime_type="video/webm").first()
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pytube\__main__.py", line 296, in streams
    return StreamQuery(self.fmt_streams)
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pytube\__main__.py", line 181, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pytube\cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pytube\cipher.py", line 411, in get_throttling_plan
    transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)
AttributeError: 'NoneType' object has no attribute 'span'
python attributeerror pytube
1个回答
0
投票

对我来说,当我在观看 Youtube 视频时在“检查视图”(Chrome)中搜索视频链接,然后将其粘贴到您的程序中时,它就起作用了

例如此链接:https://www.youtube.com/e4aa1f20-23f1-4fed-b31c-a81c8a33d1ec" 而不是这个:https://www.youtube.com/watch?v=l-nMKJ5J3Uc&ab_channel=MrBeast

© www.soinside.com 2019 - 2024. All rights reserved.