pytube / pytube

A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.
https://pytube.io
The Unlicense
12.35k stars 2.52k forks source link

[BUG]Accessing video length runs into error #2015

Open krisyang1125 opened 3 months ago

krisyang1125 commented 3 months ago

Version: 15.0.0

Bug Description When accessing length attribute of Youtube object, runs into error below that indicates lack of None handling: File "/.venv/lib/python3.11/site-packages/pytube/__main__.py", line 383, in length return int(self.vid_info.get('videoDetails', {}).get('lengthSeconds')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

To Reproduce Create a Youtube object with provided URL, and access video length. This will run into error above. pytube.Youtube(video_url).length

Expected behavior A number in seconds indicating video length is returned, if not available returns None

Output File "/.venv/lib/python3.11/site-packages/pytube/__main__.py", line 383, in length return int(self.vid_info.get('videoDetails', {}).get('lengthSeconds')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

System information Please provide the following information:

github-actions[bot] commented 3 months ago

Thank you for contributing to PyTube. Please remember to reference Contributing.md

cluster-coder commented 1 month ago

This bug hit pretty hard one of my scripts, oh god how sudden ;-;