Search code examples
pythonpython-3.xpytube

get_highest_resolution function doesn't work in pytube


when i tried to use get_highest_resolution() function to get the highest resolution of the video while downloading with pytube. although it worked fine a week ago but it results in a error now.

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

AttributeError : 'nonetype' object has no attribute download

while this works fine :

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

does anyone know the reason why there is a error while using get_highest_resolution().


Solution

  • 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