Search code examples
python-3.xhttp-status-code-404pytube

Is there a way to get the URL of the stream from Pytube?


Hello I'm new to Pytube I started a super basic scrip that downloads a bunch of videos from a Youtube Playlist but I wanted the highest Quality so I manually selected the tag I wanted, but there are videos listed in stream as Available but when i start the download i get an HTTP 404 response, is there a way to get that URL so I can check is the response is valid otherwise i will select another tag.

This is My code pretty simple

for item in range(len(playlist_links)):       
yt = YouTube(playlist_links[item])
print(yt.title)    
yt.streams.get_by_itag(137).download()
print(yt.title + " Downloaded")

As you can see its basic but I want to get the URL of the stream so I can select Another Tag if the response is HTTP 404

Thanks in Advance


Solution

  • Stream objects have a 'url' data memeber. So yt.streams.get_by_itag(137).url will fetch you the stream's url.