Bug in StreamQuery object
Closed this issue · 9 comments
Hi, i've installed pytubefix 5.1.2 and compared to the release of a couple of weeks ago StreamQuery object have serious problem as it keep CPU at max usage for lots of seconds on every video when i ask to filter a stream. You can verify this in the following example tested on my pc with python 3.12.3 installed and on repl.it with the same problem executing the line vd = yt.streams
when the library extract streams. Thank you for support.
from pytubefix import YouTube
videos = ('https://www.youtube.com/watch?v=s7nQV6kOTlI',
'https://www.youtube.com/watch?v=ypJbX39HMGo',
'https://www.youtube.com/watch?v=k5vZdkaWeUo',
'https://www.youtube.com/watch?v=pw5WhYx7q4w',
'https://www.youtube.com/watch?v=_FXR2RDFnTk',
'https://www.youtube.com/watch?v=k9BL1-eq1Fw',
'https://www.youtube.com/watch?v=gzJ0iOu3N08',
'https://www.youtube.com/watch?v=3czorKu3I2I',
'https://www.youtube.com/watch?v=2fYOyfQwNpI')
def on_progress(stream, chunk, bytes_remaining):
size = stream.filesize
print(f'\r{(size - bytes_remaining)/size*100:.1f}%', end='')
for video in videos:
yt = YouTube(video)
yt.register_on_progress_callback(on_progress)
vd = yt.streams
vd = vd.filter(resolution='360p', progressive=True)
vd = vd.first()
# vd.download()
print('\r' + yt.title)
I have this issues too, when use yt.streams.filter , script will be stop for +10 seconds and that weird.
I am also having freezing for over 30 seconds. I could not investigate too much, but seems is happening while getting the video duration and/or downloading audio (itag=140).
I would like you to test this PR.
Test version available pytubefix==5.2rc1
Also yt.views
didn't exist on result of yt = YouTube(URL)
in pytubefix, but in pytube it's Ok and show count of views for video.
try pytubefix==5.2rc1
hi, i have read the code changes in pytubefix 5.2 but i am unable to grasp what was the problem that cause the cpu usable limit during streams fetching. can you kindly explain short? thanks a lot.
Hi @Angel756984, After the ANDROID
client became unstable, we switched to WEB
, but WEB-based clients need to decrypt two parameters in each stream #63, and this can be a bit costly, so we added the Android test client, which so far is working well.
@felipeucelli
I am testing Pytubefix 5.2 for a couple of hours and this is my feedback.
With the previous web-based client (Pytubefix 5.1x) the CPU of my system was frequently at 100% and having frequent crashes because of gunicorn processes not responding for more than 30 seconds; in some periods, one crash per minute.
With the new Android client on Pytubefix 5.2 the CPU never goes above 30%, and the system has no more crashes. So far I did not detected issues with the new Android client.