From a658369609a1fb2d67d1ad8356c4c50858ac47c1 Mon Sep 17 00:00:00 2001 From: Eric Munson Date: Tue, 18 Feb 2025 09:59:42 -0500 Subject: [PATCH] Fix: Subsonic: Use any parent link when enumerating songs (#1966) Fix: Subonsic: Use any parent link when enumerating songs The LMS implementation does not use the parent field for album IDs. The spec allows for one or both of parent and albumId to be filled so we should accept both. Also fix typing info for the local staring the fetched album. Closes: music-assistant/support#3501 Signed-off-by: Eric B Munson Co-authored-by: Marcel van der Veldt --- .../providers/opensubsonic/sonic_provider.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/music_assistant/providers/opensubsonic/sonic_provider.py b/music_assistant/providers/opensubsonic/sonic_provider.py index 289acffa..731a6ab7 100644 --- a/music_assistant/providers/opensubsonic/sonic_provider.py +++ b/music_assistant/providers/opensubsonic/sonic_provider.py @@ -485,10 +485,11 @@ class OpenSonicProvider(MusicProvider): songCount=count, ) while results["songs"]: - album: SonicAlbum | None = None + album: Album | None = None for entry in results["songs"]: - if album is None or album.item_id != entry.parent: - album = await self.get_album(prov_album_id=entry.parent) + aid = entry.album_id if entry.album_id else entry.parent + if album is None or album.item_id != aid: + album = await self.get_album(prov_album_id=aid) yield self._parse_track(entry, album=album) offset += count results = await self._run_async( @@ -570,7 +571,10 @@ class OpenSonicProvider(MusicProvider): except (ParameterError, DataNotFoundError) as e: msg = f"Item {prov_track_id} not found" raise MediaNotFoundError(msg) from e - album: SonicAlbum = await self.get_album(prov_album_id=sonic_song.parent) + aid = sonic_song.album_id if sonic_song.album_id else sonic_song.parent + if not aid: + self.logger.warning("Unable to find album id for track %s", sonic_song.id) + album: Album = await self.get_album(prov_album_id=aid) return self._parse_track(sonic_song, album=album) async def get_artist_albums(self, prov_artist_id: str) -> list[Album]: @@ -660,10 +664,13 @@ class OpenSonicProvider(MusicProvider): msg = f"Playlist {prov_playlist_id} not found" raise MediaNotFoundError(msg) from e - album: SonicAlbum | None = None + album: Album | None = None for index, sonic_song in enumerate(sonic_playlist.songs, 1): - if not album or album.item_id != sonic_song.parent: - album = await self.get_album(prov_album_id=sonic_song.parent) + aid = sonic_song.album_id if sonic_song.album_id else sonic_song.parent + if not aid: + self.logger.warning("Unable to find albumd for track %s", sonic_song.id) + if not album or album.item_id != aid: + album = await self.get_album(prov_album_id=aid) track = self._parse_track(sonic_song, album=album) track.position = index result.append(track) -- 2.34.1