From c472f4caf635d97a43b23cf959e3701af25c28e1 Mon Sep 17 00:00:00 2001 From: Jc2k Date: Mon, 10 Jun 2024 22:59:51 +0100 Subject: [PATCH] Jellyfin: Don't fail entire sync if a single track or album have an invalid mbid (#1338) --- .../server/providers/jellyfin/__init__.py | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/music_assistant/server/providers/jellyfin/__init__.py b/music_assistant/server/providers/jellyfin/__init__.py index 13459f27f..f2a7a78bf 100644 --- a/music_assistant/server/providers/jellyfin/__init__.py +++ b/music_assistant/server/providers/jellyfin/__init__.py @@ -318,11 +318,16 @@ async def _parse_album(self, jellyfin_album: dict[str, Any]) -> Album: if ITEM_KEY_OVERVIEW in current_jellyfin_album: album.metadata.description = current_jellyfin_album[ITEM_KEY_OVERVIEW] if ITEM_KEY_MUSICBRAINZ_RELEASE_GROUP in current_jellyfin_album[ITEM_KEY_PROVIDER_IDS]: - musicbrainzid = current_jellyfin_album[ITEM_KEY_PROVIDER_IDS][ - ITEM_KEY_MUSICBRAINZ_RELEASE_GROUP - ] - if len(musicbrainzid.split("-")) == 5: - album.mbid = musicbrainzid + try: + album.mbid = current_jellyfin_album[ITEM_KEY_PROVIDER_IDS][ + ITEM_KEY_MUSICBRAINZ_RELEASE_GROUP + ] + except InvalidDataError as error: + self.logger.warning( + "Jellyfin has an invalid musicbrainz id for album %s", + album.name, + exc_info=error if self.logger.isEnabledFor(logging.DEBUG) else None, + ) if ITEM_KEY_SORT_NAME in current_jellyfin_album: album.sort_name = current_jellyfin_album[ITEM_KEY_SORT_NAME] if ITEM_KEY_ALBUM_ARTIST in current_jellyfin_album: @@ -482,7 +487,15 @@ async def _parse_track(self, jellyfin_track: dict[str, Any]) -> Track: ) # 10000000 ticks per millisecond track.track_number = current_jellyfin_track.get(ITEM_KEY_INDEX_NUMBER, 99) if ITEM_KEY_MUSICBRAINZ_TRACK in current_jellyfin_track[ITEM_KEY_PROVIDER_IDS]: - track.mbid = current_jellyfin_track[ITEM_KEY_PROVIDER_IDS][ITEM_KEY_MUSICBRAINZ_TRACK] + track_mbid = current_jellyfin_track[ITEM_KEY_PROVIDER_IDS][ITEM_KEY_MUSICBRAINZ_TRACK] + try: + track.mbid = track_mbid + except InvalidDataError as error: + self.logger.warning( + "Jellyfin has an invalid musicbrainz id for track %s", + track.name, + exc_info=error if self.logger.isEnabledFor(logging.DEBUG) else None, + ) return track async def _parse_playlist(self, jellyfin_playlist: dict[str, Any]) -> Playlist: