fix: abs - recommendation, series handling (#2093)
authorFabian Munkes <105975993+fmunkes@users.noreply.github.com>
Tue, 1 Apr 2025 23:52:43 +0000 (01:52 +0200)
committerGitHub <noreply@github.com>
Tue, 1 Apr 2025 23:52:43 +0000 (01:52 +0200)
fix: series shelf might be ShelfBook

music_assistant/providers/audiobookshelf/__init__.py

index 261247d8f1770ece83654a7fdc18ccec41ce2db5..44642f014ad534f6e1cc5e5846e13abad2c4c38d 100644 (file)
@@ -729,25 +729,36 @@ class Audiobookshelf(MusicProvider):
                         if item is not None:
                             items.append(item)
                 case AbsShelfId.RECENT_SERIES | AbsShelfId.CONTINUE_SERIES:
-                    # we jump into a browse folder here, set path up as if browse function
-                    # used.
-                    for entity in shelf.entities:
-                        assert isinstance(entity, SeriesShelf)
-                        if len(entity.books) == 0:
-                            continue
-                        path = (
-                            f"{self.instance_id}://"
-                            f"{AbsBrowsePaths.LIBRARIES_BOOK} {library_id}/"
-                            f"{AbsBrowsePaths.SERIES}/{entity.id_}"
-                        )
-                        items.append(
-                            BrowseFolder(
+                    # We jump into a browse folder here if we have SeriesShelf, set path up as if
+                    # browse function used.
+                    if isinstance(shelf, ShelfSeries):
+                        for entity in shelf.entities:
+                            assert isinstance(entity, SeriesShelf)
+                            if len(entity.books) == 0:
+                                continue
+                            path = (
+                                f"{self.instance_id}://"
+                                f"{AbsBrowsePaths.LIBRARIES_BOOK} {library_id}/"
+                                f"{AbsBrowsePaths.SERIES}/{entity.id_}"
+                            )
+                            items.append(
+                                BrowseFolder(
+                                    item_id=entity.id_,
+                                    name=entity.name,
+                                    provider=self.lookup_key,
+                                    path=path,
+                                )
+                            )
+                    elif isinstance(shelf, ShelfBook) and media_type == MediaType.AUDIOBOOK:
+                        # Single books, must be audiobooks
+                        for entity in shelf.entities:
+                            item = await self.mass.music.get_library_item_by_prov_id(
+                                media_type=media_type,
+                                provider_instance_id_or_domain=self.instance_id,
                                 item_id=entity.id_,
-                                name=entity.name,
-                                provider=self.lookup_key,
-                                path=path,
                             )
-                        )
+                            if item is not None:
+                                items.append(item)
                 case AbsShelfId.NEWEST_AUTHORS:
                     # same as for series, use a folder
                     for entity in shelf.entities: