alexmercerind/youtube-search-python

Error on Playlist.getInfo

Closed this issue ยท 10 comments

Playlist.getInfo gave me a keyError : 'sidebar'

>>> play.getInfo(play.info['info']['link'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/linzo/Desktop/senstream-api/env/lib/python3.6/site-packages/youtubesearchpython/extras.py", line 1200, in getInfo
    ps.sync_create()
  File "/home/linzo/Desktop/senstream-api/env/lib/python3.6/site-packages/youtubesearchpython/core/playlist.py", line 40, in sync_create
    self.post_processing()
  File "/home/linzo/Desktop/senstream-api/env/lib/python3.6/site-packages/youtubesearchpython/core/playlist.py", line 31, in post_processing
    self.__getComponents()
  File "/home/linzo/Desktop/senstream-api/env/lib/python3.6/site-packages/youtubesearchpython/core/playlist.py", line 131, in __getComponents
    inforenderer = self.responseSource["sidebar"]["playlistSidebarRenderer"]["items"][0]["playlistSidebarPrimaryInfoRenderer"]
KeyError: 'sidebar'
>>> 
mytja commented

Hey, may you try to update to latest version: pip install git+https://github.com/alexmercerind/youtube-search-python
I released some (more stable) patches to it.

i've tried but still the same error

mytja commented

What about a minimum reproducible example? Can you give me a Video Playlist ID?

@mytja I think this happens when the URL is of a song with a playlist on the side, example:

https://www.youtube.com/watch?v=bplUXwTTgbI&list=PL6edxAMqu2xfxgbf7Q09hSg1qCMfDI7IZ

I personally fixed it for my use case with this

url = "https://www.youtube.com/watch?v=bplUXwTTgbI&list=PL6edxAMqu2xfxgbf7Q09hSg1qCMfDI7IZ"
playlist_id = url.split("&list=")[1]
url = f"https://www.youtube.com/playlist?list={playlist_id}"

a = youtubesearchpython.Playlist.get(url)

But it's far from ideal

mytja commented

I see. I will have a look on what I can do.

I think this also depends on the playlist too. For example:

from youtubesearchpython import *

playlist = Playlist.get("https://www.youtube.com/playlist?list=OLAK5uy_kiI98E8aoAoozErLEkJzW4-i2QvB4YDU4")  # or Playlist.getInfo

The URL above appears to be in the "correct" format but gives the following error:

Traceback (most recent call last):
  File "/Users/dan/Google Drive/Programming/ytp/test.py", line 29, in <module>
    playlist = Playlist.get(
  File "/usr/local/lib/python3.10/site-packages/youtubesearchpython/extras.py", line 1129, in get
    pc.sync_create()
  File "/usr/local/lib/python3.10/site-packages/youtubesearchpython/core/playlist.py", line 40, in sync_create
    self.post_processing()
  File "/usr/local/lib/python3.10/site-packages/youtubesearchpython/core/playlist.py", line 31, in post_processing
    self.__getComponents()
  File "/usr/local/lib/python3.10/site-packages/youtubesearchpython/core/playlist.py", line 132, in __getComponents
    channelrenderer = self.responseSource["sidebar"]["playlistSidebarRenderer"]["items"][1]["playlistSidebarSecondaryInfoRenderer"]["videoOwner"]["videoOwnerRenderer"]
IndexError: list index out of range
mytja commented

This is really interesting.
Thanks to everyone for contributing examples, I'll fix it as soon as possible.

Playlist.get or Playlist.getInfo produces the keyError: 'sidebar' when the url doesn't start with https
also the link in Playlist.info['info']['link'] after a Playlist.get doesn't start with https that's why i got the error when i tried to do

play.getInfo(play.info['info']['link'])
mytja commented

Here is what I found out about your Playlists

@dscrofts
Your Playlist somehow doesn't have channel name:
image

Normal Playlist does have it in sidebar:
image

We don't get the channel name sidebar property, and that's why it's failing.

@Jestemkioskiem
Your Playlist is not actually the link we require. We require Playlist links in this format: /playlist?list=playlistid, you provided a /watch?list=playlistid link. Don't worry, I'm not saying I won't fix this.
As you said, your solution wasn't optimized, so I created a RegEx, that will parse ANY URL given to Playlist class and extract ID from it (as this is all we need).

@Linzo99
As you haven't given me a Playlist link, I cannot do anything. I hope fixes that were introduced by patch will help you, otherwise please comment here and post a playlist link, you find not working.

Thanks to everyone for contributing minimum reproducible examples.
The patch will be pushed, merged into main branch and published to PyPi within 24 hours, but if you want to test it ASAP, you can do it pip install git+https://github.com/alexmercerind/youtube-search-python@playlists

mytja commented

Package has been published to PyPi. Please upgrade to latest version using pip install youtube-search-python --upgrade

Happy YouTube searching, everyone.