Pytube: Error with order_by function

Created on 19 Nov 2019  路  3Comments  路  Source: pytube/pytube

I am having problems with sorting streams via order_by

OS: _ArchLinux x86_64_
Python: _3.8.0_

Callback:

Traceback (most recent call last):
  File "playlist download.py", line 52, in <module>
    video.streams.filter(only_video=True, adaptive=True).order_by("res").desc().first().download(filename="video")
  File "/usr/lib/python3.8/site-packages/pytube/query.py", line 181, in order_by
    fmt_streams = sorted(
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
stale

Most helpful comment

@ryze312 @vladiscripts fixed in my Python 3 only fork: https://github.com/hbmartin/pytube3

All 3 comments

Another problem of this method.

Some videos can have res="None":

y = YouTube('http://youtube.com/watch?v=9bZkp7q19f0')

y.streams.filter(only_video=True, subtype="mp4").all()

Out[24]: 
[<Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028">,
 <Stream: itag="136" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.4d401f">,
 <Stream: itag="398" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.05M.08">,
 <Stream: itag="135" mime_type="video/mp4" res="480p" fps="30fps" vcodec="avc1.4d401e">,
 <Stream: itag="397" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.04M.08">,
 <Stream: itag="134" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.4d401e">,
 <Stream: itag="396" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.01M.08">,
 <Stream: itag="133" mime_type="video/mp4" res="240p" fps="30fps" vcodec="avc1.4d4015">,
 <Stream: itag="395" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.00M.08">,
 <Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400c">,
 <Stream: itag="394" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.00M.08">]

order_by('resolution') raise error.

y.streams.filter(only_video=True, subtype="mp4").order_by('resolution').desc().all()

Traceback (most recent call last):
  File "/home/vladislav/anaconda3/envs/web37/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-30-2995d5b3dedb>", line 1, in <module>
    y.streams.filter(only_video=True, subtype="mp4", ).order_by('resolution').desc().all()
  File "/home/vladislav/anaconda3/envs/web37/lib/python3.7/site-packages/pytube/query.py", line 183, in order_by
    key=key,
  File "/home/vladislav/anaconda3/envs/web37/lib/python3.7/site-packages/pytube/query.py", line 176, in key
    return integer_attr_repr[getattr(s, attribute_name)]
KeyError: None

Also other filters, like by 'fps':

y.streams.filter(only_video=True, subtype="mp4").order_by('fps').desc().all()

Traceback (most recent call last):
  File "/home/vladislav/anaconda3/envs/web37/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-28-69f961e16515>", line 1, in <module>
    y.streams.filter(only_video=True, subtype="mp4", ).order_by('fps').desc().all()
  File "/home/vladislav/anaconda3/envs/web37/lib/python3.7/site-packages/pytube/query.py", line 170, in order_by
    num = ''.join(x for x in attr if x.isdigit())
TypeError: 'int' object is not iterable

@ryze312 @vladiscripts fixed in my Python 3 only fork: https://github.com/hbmartin/pytube3

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings