Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ValueError when a playlist has no views #1846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

realshouzy
Copy link

Problem:

pytube raises a ValueError when accessing the views property of a playlist with no views.
Same problem as in #1052, which was fixed in #1058, but only in \contrib\search.py and not in \contrib\playlist.py.

Example code:

from pytube import Playlist
print(Playlist("https://www.youtube.com/playlist?list=PLyyu7uBtEOmvZkMNuAWK6dNhREPFPRnOK").views)

Error message:

Traceback (most recent call last):
  File "C:\Users\user\Desktop\Code\pytube\test.py", line 2, in <module>
    print(Playlist("https://www.youtube.com/playlist?list=PLyyu7uBtEOmvZkMNuAWK6dNhREPFPRnOK").views)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\Desktop\Code\pytube\pytube\contrib\playlist.py", line 385, in views
    return int(count_text)
           ^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'No'

Solution:

Check for "No views" and return 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant