JuanBindez/pytubefix

Add channel string representation

Closed this issue · 0 comments

mi01 commented

When running the following code i get an exception, because Channel is extending Playlist, but does not override its repr function.

url = f"https://www.youtube.com/c/{foo}"
ch = Channel(url)
print(str(ch))
  File "/.../venv/lib/python3.12/site-packages/pytubefix/contrib/playlist.py", line 319, in __repr__
    return f'<pytube.contrib.Playlist object: playlistId={self.playlist_id}>'
                                                          ^^^^^^^^^^^^^^^^
  File "/.../venv/lib/python3.12/site-packages/pytubefix/contrib/playlist.py", line 39, in playlist_id
    self._playlist_id = extract.playlist_id(self._input_url)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../venv/lib/python3.12/site-packages/pytubefix/extract.py", line 151, in playlist_id
    return parse_qs(parsed.query)['list'][0]
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'list'

Would be great to fix this by adding a custom repr function for the Channel class.