Reputation: 11
When I first wrote this code it worked fine and would download me the 160kbps OPUS WEBM file for the URL selected but now for some reason will only download lower a quality than asked for and I can't work out why.
My code is;
from pytube import YouTube
from sys import argv
link = argv[1]
yt = YouTube(link)
print("Title: ", yt.title)
print("Ciew:", yt.views)
print(yt.streams.filter(only_audio=True))
video = yt.streams.filter(only_audio=True).last()
print(video)
video.download(r'E:\Users\XXXX\Desktop\YTDTEST')
print("DONE")
and the terminal output is
PS E:\Users\XXX\Desktop\PyTube> python pydl2.py "https://www.youtube.com/watch?v=GaJcBJQi7bY"
Title: Prince & The Revolution - Purple Rain (Official Video), HD (Digitally Remastered and Upscaled)
Ciew: 56547
[<Stream: itag="139" mime_type="audio/mp4" abr="48kbps" acodec="mp4a.40.5" progressive="False" type="audio">, <Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2" progressive="False" type="audio">, <Stream: itag="249" mime_type="audio/webm" abr="50kbps" acodec="opus" progressive="False" type="audio">, <Stream: itag="250" mime_type="audio/webm" abr="70kbps" acodec="opus" progressive="False" type="audio">, <Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus" progressive="False" type="audio">]
<Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus" progressive="False" type="audio">
DONE
for some reason it just downloads a 64kbps version of the audio even though as we see from the output I believe have used the right code so can't work out whats gone wrong.
Upvotes: 1
Views: 259
Reputation: 11
With your code you should get the opus 160kbps. If not, you can try to get always the audio with more bitrate.
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=GaJcBJQi7bY')
yt.streams.filter(only_audio=True).order_by('bitrate').desc().first().download()
Upvotes: 0