Skip to content

Commit

Permalink
Fix: Subsonic: Use any parent link when enumerating songs (#1966)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Marcel van der Veldt <[email protected]>
  • Loading branch information
khers and marcelveldt authored Feb 18, 2025
1 parent 722c714 commit a658369
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions music_assistant/providers/opensubsonic/sonic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,11 @@ async def get_library_tracks(self) -> AsyncGenerator[Track, None]:
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(
Expand Down Expand Up @@ -570,7 +571,10 @@ async def get_track(self, prov_track_id: str) -> Track:
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]:
Expand Down Expand Up @@ -660,10 +664,13 @@ async def get_playlist_tracks(self, prov_playlist_id: str, page: int = 0) -> lis
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)
Expand Down

0 comments on commit a658369

Please sign in to comment.