Audio download gets throttled to 31 KB/s when the download is done with the URL for Itag = 140
Closed this issue · 2 comments
Hi,
I am testing pytubefix and I am facing the same issue existing at pytube 15.0.0.
If I extract the URL to download the audio (ITAG = 140) to download the media with my browser, the download speed gets throttled by Youtube to 31 KB/s.
The problem does not happen to download videos (ITAG = 22).
Here is the code to test the issue:
from pytubefix import YouTube # https://pypi.org/project/pytubefix/
video_link = f'https://www.youtube.com/watch?v=0FX4jVAL1eg'
yt = YouTube(video_link)
title = yt.title
description = yt.description
duration = yt.length
thumbnail = yt.thumbnail_url
print(f'Video: {video_link}')
print(f'Title: {title}')
print(f'Duration {duration} seconds')
print(f'Thumbnail: {thumbnail}')
print(f'Description: {description}')
print(f'--------------------------------------------')
ITAG = 22
link = yt.streams.get_by_itag(ITAG).url
print(f'link to download with the browser (itag = {ITAG}): \n{link}')
ITAG = 140
link = yt.streams.get_by_itag(ITAG).url
print(f'\n\nlink to download with the browser (itag = {ITAG}): \n{link}')
The code will generate two links to download.
Click the links and observe the download speed for both cases.
Any idea on how to fix?
I think I may have found a workaround, and it's really easy:
You have to specify a range parameter at the end of the URL provided by pytubefix.
I honestly have no idea why it works, but it works.
the URL provided by this script worked for me and the download speed was back to normal:
from pytubefix import YouTube
yt = YouTube(
url='https://www.youtube.com/watch?v=0FX4jVAL1eg',
use_oauth=True,
allow_oauth_cache=True
)
url = yt.streams.get_by_itag(140).url
print(f'{url}&range=0-999999999999')
Thank you for the hint, @andrebore04 !
I am testing and for me it requests to go to a page and enter a code, and then requires login + password for a google account.
That is something that does not works for my needs.
I guess the same is happening for you, right?
And if I remove the auth code use_oauth=True, allow_oauth_cache=True
from the Youtube object, then it gets throttled even with the &range=0-999999999999
at the end of the URL.