【问题标题】:get_highest_resolution function doesn't work in pytubeget_highest_resolution 函数在 pytube 中不起作用
【发布时间】:2021-09-07 00:48:40
【问题描述】:

当我尝试使用 get_highest_resolution() 函数在使用 pytube 下载时获得最高分辨率的视频。虽然它在一周前运行良好,但现在却导致错误。

from pytube import YouTube
yt = YouTube('https://youtube.com/watch?v=2lAe1cqCOXo')
ys = yt.streams.get_highest_resolution()
ys.download()

AttributeError : 'nonetype' 对象没有属性下载

虽然这很好用:

from pytube import YouTube
yt = YouTube('https://youtube.com/watch?v=2lAe1cqCOXo')
ys = yt.streams.first()
ys.download()

有谁知道使用 get_highest_resolution() 时出错的原因。

【问题讨论】:

    标签: python python-3.x pytube


    【解决方案1】:

    我遇到了同样的问题,但我使用了progressive=true 并且成功了

     Label(root,text = 'Youtube Video Downloader', font ='arial 20 
     bold',bg="#336B87",pady=10).pack()
    
     link = StringVar()
    
     Label(root, text = 'Paste Link Here:', font = 'arial 15 
     bold',bg="#336B87",pady=0).place(x= 150 , y = 60)
     link_enter = Entry(root, width = 70,textvariable = link).place(x = 
     32, y = 90)
    
     def Downloader():     
     url =YouTube(str(link.get()))
     video = url.streams.filter(progressive=True).last()
     video.download()
     Label(root, text = 'DOWNLOADED', font = 'arial 15').place(x= 180 , y 
     = 210) 
    

    【讨论】:

    • 您能否将您的代码行放在上下文中。更广泛的代码示例可能会有所帮助
    【解决方案2】:
    import pytube
    a = '=' * 23
    
    print(f"{a}\n\033[0;31mBAIXAR VÍDEO DO YOUTUBE\033[0;0m\n{a}")
    
    video = pytube.YouTube(input('Digite a URL do vídeo: '))
    resolucoes = video.streams.all()
    
    for i in resolucoes:  # mostra as resoluções disponíveis
        print(i)
    
    video.streams.get_by_itag(137).download("D:\Downloads YouTube")  # salva na pasta
    

    【讨论】:

    • 请用国际语言(英文)解释答案
    【解决方案3】:

    ..您尝试使用另一个网址?

    遇到同样的问题,我认识到 pytubes get_highest_resolution() 似乎不适用于每个 youtube 网址,但大多数.. (60/40) [如果您的网址都不起作用,请尝试 https://pypi.org/ project/pytube3/] 认为只有异常处理才能“修复”这个问题。

    祝大家 2021 年过得愉快!

    【讨论】:

      猜你喜欢
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2020-12-24
      • 2011-12-13
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多