/
/
1"""Parsers for the local filesystem provider."""
2
3from typing import TYPE_CHECKING, Any
4
5from music_assistant_models.enums import ExternalID
6
7from music_assistant.helpers.tags import clean_mbid, split_items
8from music_assistant.helpers.util import parse_title_and_version
9
10if TYPE_CHECKING:
11 from music_assistant_models.media_items import Album
12
13
14def parse_album_nfo(album: Album, nfo_album: dict[Any, Any], source: str | None = None) -> None:
15 """
16 Enrich album metadata from NFO file.
17
18 :param album: The album to enrich.
19 :param nfo_album: The parsed 'album' element from the NFO file.
20 :param source: Origin of the NFO data (e.g. file path), included in log messages.
21 """
22 if title := nfo_album.get("title") or nfo_album.get("name"):
23 album.name, album.version = parse_title_and_version(title)
24 if sort_name := nfo_album.get("sortname"):
25 album.sort_name = sort_name
26 if releasegroup_id := clean_mbid(nfo_album.get("musicbrainzreleasegroupid"), source):
27 album.add_external_id(ExternalID.MB_RELEASEGROUP, releasegroup_id)
28 if album_id := clean_mbid(nfo_album.get("musicbrainzalbumid"), source):
29 album.add_external_id(ExternalID.MB_ALBUM, album_id)
30 if mb_artist_id := clean_mbid(nfo_album.get("musicbrainzalbumartistid"), source):
31 if album.artists and not album.artists[0].mbid:
32 album.artists[0].mbid = mb_artist_id
33 if description := nfo_album.get("review"):
34 album.metadata.description = description
35 if year := nfo_album.get("year"):
36 album.year = int(year)
37 if genre := nfo_album.get("genre"):
38 album.metadata.genres = set(split_items(genre))
39