Fix: Use Deezer record_type to set the album type of Deezer albums (#1905)
authorawhiemstra <ahiemstra@heimr.nl>
Thu, 23 Jan 2025 22:20:34 +0000 (23:20 +0100)
committerGitHub <noreply@github.com>
Thu, 23 Jan 2025 22:20:34 +0000 (23:20 +0100)
music_assistant/providers/deezer/__init__.py

index 181f3f54bf1f21d368e683f4c9009b1b85fb2b79..fcf12d124a76007c5288d5c824bb130a0c19af35 100644 (file)
@@ -573,7 +573,7 @@ class DeezerProvider(MusicProvider):
     def parse_album(self, album: deezer.Album) -> Album:
         """Parse the deezer-python album to a Music Assistant album."""
         return Album(
-            album_type=AlbumType(album.type),
+            album_type=self.get_album_type(album),
             item_id=str(album.id),
             provider=self.lookup_key,
             name=album.title,
@@ -688,6 +688,23 @@ class DeezerProvider(MusicProvider):
             return track.title_short
         return track.title
 
+    def get_album_type(self, album: deezer.Album) -> AlbumType:
+        """Read and convert the Deezer album type."""
+        if not hasattr(album, "record_type"):
+            return AlbumType.UNKNOWN
+
+        match album.record_type:
+            case "album":
+                return AlbumType.ALBUM
+            case "single":
+                return AlbumType.SINGLE
+            case "ep":
+                return AlbumType.EP
+            case "compile":
+                return AlbumType.COMPILATION
+            case _:
+                return AlbumType.UNKNOWN
+
     ### SEARCH AND PARSE FUNCTIONS ###
     async def search_and_parse_tracks(
         self, query: str, user_country: str, limit: int = 20