Add manual mediaitem linking to genre (#3248)
authorJozef Kruszynski <60214390+jozefKruszynski@users.noreply.github.com>
Thu, 26 Feb 2026 08:02:18 +0000 (09:02 +0100)
committerGitHub <noreply@github.com>
Thu, 26 Feb 2026 08:02:18 +0000 (09:02 +0100)
feat(genres): manual mediaitem linking to genre

music_assistant/controllers/media/genres.py

index 1d26d8e780d2a338fb9d16276905e0930d456649..14f5cd993930d115601326e3a231d9fa59153d0a 100644 (file)
@@ -868,15 +868,23 @@ class GenreController(MediaControllerBase[Genre]):
         return updated
 
     async def add_media_mapping(
-        self, genre_id: str | int, media_type: MediaType, media_id: str | int, alias: str
+        self,
+        genre_id: str | int,
+        media_type: MediaType,
+        media_id: str | int,
+        alias: str | None = None,
     ) -> None:
         """Map a media item to a genre.
 
         :param genre_id: Database ID of the genre.
         :param media_type: Type of media item (track, album, artist).
         :param media_id: Database ID of the media item.
-        :param alias: The alias string that caused this mapping.
+        :param alias: The alias string that caused this mapping. If not provided,
+            the genre's primary name is used.
         """
+        if alias is None:
+            genre = await self.get_library_item(int(genre_id))
+            alias = genre.name
         await self.mass.music.database.insert(
             DB_TABLE_GENRE_MEDIA_ITEM_MAPPING,
             {