music-assistant / hass-music-assistant

Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players.
Apache License 2.0
1.21k stars 44 forks source link

Apple Music - IndexError: list index out of range #2431

Closed xmirakulix closed 2 days ago

xmirakulix commented 3 weeks ago

What version of Music Assistant has the issue?

2.1.0b2

What version of the Home Assistant Integration have you got installed?

2024.5.1

Have you tried everything in the Troubleshooting FAQ and reviewed the Open and Closed Issues and Discussions to resolve this yourself?

The problem

The Apple Music sync process exits with an error: "IndexError: list index out of range"

File "/usr/local/lib/python3.12/site-packages/music_assistant/server/providers/apple_music/__init__.py", line 486, in _parse_track
  track.album = self._parse_album(albums["data"][0])
                                  ~~~~~~~~~~~~~~^^^

It might have to something with the many "Skipping sync of item apple_music://.... because it is unavailable" that occur before the error:

2024-06-09 19:11:17.041 DEBUG (MainThread) [music_assistant.providers.apple_music] Skipping sync of item apple_music://track/i.AWPNN46tLXd92N because it is unavailable
2024-06-09 19:11:17.041 DEBUG (MainThread) [music_assistant.providers.apple_music] Skipping sync of item apple_music://track/i.1YBNNrGiq1Yog7 because it is unavailable
2024-06-09 19:11:17.045 DEBUG (MainThread) [music_assistant.providers.apple_music] Skipping sync of item apple_music://track/i.6xpKle7tvaR84Y because it is unavailable

How to reproduce

Activate the apple music provider and wait for the sync to happen.

Music Providers

Apple Music <-- affected RadioBrowser <-- works

Player Providers

Sonos

Full log output

log.txt

Additional information

No response

What version of Home Assistant Core are your running

2024.6.1

What type of installation are you running?

Home Assistant OS

On what type of hardware are you running?

Linux

MarvinSchenkel commented 3 weeks ago

Interesting. Looks like there's an album in your library that cannot be found in the catalog. I'll try to find some time this week to dive into it!

MarvinSchenkel commented 2 weeks ago

Can you retest this with beta 4? Please do a fresh install of the beta addon. If you hit the same error, is there any way to figure out which album this is happening to?

xmirakulix commented 2 weeks ago

We made it a bit further :-)

  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/providers/apple_music/__init__.py", line 204, in get_library_tracks
    song_catalog_ids.append(item["relationships"]["catalog"]["data"][0]["id"])
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
xmirakulix commented 2 weeks ago

If you hit the same error, is there any way to figure out which album this is happening to?

You could add a verbose trace, right now I can't tell which track it is happening to.

MarvinSchenkel commented 2 weeks ago

Yeah I'll see if I can add that. Do you have any custom tracks in your library that you uploaded yourself? The error hints there's no catalog version of the track

xmirakulix commented 2 weeks ago

Might be, years ago when apple music came out it scanned my local library and added the songs iirc.

MarvinSchenkel commented 1 week ago

How is this working on beta 5 or later?

xmirakulix commented 6 days ago

I updated to b8 today, no change:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/controllers/music.py", line 700, in run_sync
    await provider.sync_library(media_types)
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/models/music_provider.py", line 396, in sync_library
    async for prov_item in self._get_library_gen(media_type):
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/providers/apple_music/__init__.py", line 204, in get_library_tracks
    song_catalog_ids.append(item["relationships"]["catalog"]["data"][0]["id"])
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

I tried setting up a MA build environment, but when saving the applemusic token I am hitting an error, that I am missing a widevine binary: FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/bin/widevine_cdm/client_id.bin' Do you have a tipp, where to get it? Maybe the devcontainer setup script needs an adjustment now too?

MarvinSchenkel commented 5 days ago

I updated to b8 today, no change:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/controllers/music.py", line 700, in run_sync
    await provider.sync_library(media_types)
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/models/music_provider.py", line 396, in sync_library
    async for prov_item in self._get_library_gen(media_type):
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/providers/apple_music/__init__.py", line 204, in get_library_tracks
    song_catalog_ids.append(item["relationships"]["catalog"]["data"][0]["id"])
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

I tried setting up a MA build environment, but when saving the applemusic token I am hitting an error, that I am missing a widevine binary: FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/bin/widevine_cdm/client_id.bin' Do you have a tipp, where to get it? Maybe the devcontainer setup script needs an adjustment now too?

I did fix both errors and created a PR, so they should be fixed in the next beta. Regarding your issue with the missing client files. Those are missing because we do not publicly provide widevine client binaries, which are used to decrypt audio for playback. I did leave some instructions for you to get your own, if you're feeling adventurous ;-) https://github.com/music-assistant/server/tree/dependabot/pip/ytmusicapi-1.7.3/music_assistant/server/providers/apple_music/bin

xmirakulix commented 5 days ago

Ah yes, I thought I read about it somewhere when I browsed the repository weeks ago, thank you for pointing me to it.

Will test the changes when the next beta is released and report back 👍🏻