JuanBindez / pytubefix

Python3 library for downloading YouTube Videos.
https://pytubefix.readthedocs.io
MIT License
722 stars 100 forks source link

.get_audio_only() results in a 48kbps quality file, not the highest audio quality by default #321

Closed TyrelCB closed 1 week ago

TyrelCB commented 1 week ago

:exclamation: DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE :exclamation:

lack of information will lead to closure of the issue


Describe the bug

Instead of the expected 128kbps file, all .get_audio_only() streams are 48kbps


code that was used that resulted in the bug

from pytubefix import YouTube
from pytubefix.cli import on_progress

url = "url" # any 

yt = YouTube(url, on_progress_callback = on_progress)
print(yt.title)

ys = yt.streams.get_audio_only()
ys.download(mp3=True)

Expected behavior

128kbps AAC


Screenshots

Not needed


Desktop (please complete the following information):


Additional context

This will pull pull the highest quality audio stream

yt.streams.filter(only_audio=True, audio_codec="mp4a.40.2").order_by('abr')[-1].download()
JuanBindez commented 1 week ago

try without the mp3

TyrelCB commented 1 week ago

same results in audio quality with or without mp3

NannoSilver commented 1 week ago

same results in audio quality with or without mp3

To have better control on what you are downloading, you have to download specifying the itag. For example: itag = 140 download in 128 kbps.

yt = YouTube('http://youtube.com/watch?v=mZkHwI7cX4Y')

print(yt.streams.filter(only_audio=True))

stream = yt.streams.get_by_itag(140)
stream.download(filename='mZkHwI7cX4Y.m4a')
NannoSilver commented 1 week ago

Also, be aware that there are no MP3 audio files available at Youtube. If you want in MP3, you have to convert it.

The mp3=True option of pytubefix does not provide in real MP3 codec, but only rename the file extension to MP3.

TyrelCB commented 1 week ago

guys the fix is specifying an audio codec, this provides 128kbps AAC, which is the most versitile:

yt.streams.filter(only_audio=True, audio_codec="mp4a.40.2").order_by('abr')[-1].download()

I'll submit a PR to modify the .get_audio_only() method