Fix: Subsonic: Use any parent link when enumerating songs (#1966)
authorEric Munson <eric@munsonfam.org>
Tue, 18 Feb 2025 14:59:42 +0000 (09:59 -0500)
committerGitHub <noreply@github.com>
Tue, 18 Feb 2025 14:59:42 +0000 (15:59 +0100)
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 <eric@munsonfam.org>
Co-authored-by: Marcel van der Veldt <m.vanderveldt@outlook.com>
music_assistant/providers/opensubsonic/sonic_provider.py

index 289acffaeb56230e1882772257e94e251c80f0b8..731a6ab7c12cda1b85c88af8f8c2153da90a2b8d 100644 (file)
@@ -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)