sigma67 / ytmusicapi

Unofficial API for YouTube Music
https://ytmusicapi.readthedocs.io
MIT License
1.77k stars 209 forks source link

Params key not in get_artist #387

Closed kalebbroo closed 1 year ago

kalebbroo commented 1 year ago

Describe the bug I am trying to return a list of all the albums from an artist using get_artist_albums. I cannot figure out how to get the perams key. I am only just learning how to code so this is most likely just a dumb mistake on my part. The api docs says to get params use get_artist but I am not able to return that key.

Error searching for artist albums: 'params' Traceback (most recent call last): File "C:\Users\kaleb\Desktop\projects\search_youtube\embed.py", line 46, in search_albums artist_albums_params = artist_data['albums']['params']


KeyError: 'params'

**To Reproduce**
I plan to make this a discord bot, I search for an artist I have been using "will smith" and "loona" for testing. The code will return an key error.

Here is my code: 
async def search_albums(ctx, artist_name: str):
    artist_name = artist_name.title()
    print(f"Searching for albums by artist: {artist_name}")

    ytmusic = YTMusic()

    try:
        search_result = ytmusic.search(artist_name, filter='artists', limit=1)
        print(f"Search Result: {search_result}")

        if not search_result:
            await ctx.send(f"No artist found for '{artist_name}'")
            return

        artist_id = search_result[0]['browseId']
        artist_data = ytmusic.get_artist(artist_id)
        print(f"Artist Data First: {artist_data}")
        artist_name = artist_data.get('name')
        artist_channel_id = artist_data.get('channelId')
        artist_data = ytmusic.get_artist(artist_channel_id)
        print(f"Artist Data: {artist_data}")
        print(f"Channel ID: {artist_channel_id}")
        artist_albums_params = artist_data['albums']['params']
        album_data = ytmusic.get_artist_albums(artist_channel_id, artist_albums_params)

**Additional context**
If this is something I am doing wrong in my code just let me know. I have been trying to figure this out all day :(
sigma67 commented 1 year ago

Hi, this doesn't work for all artists. Notably when there is no "More" button on the artist's page next to the albums, there won't be any params.

For example, for Will Smith, singles would work but albums would not:

image