/
/
/
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, Artist
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
40
41def parse_artist_nfo(artist: Artist, nfo_artist: dict[Any, Any], source: str | None = None) -> None:
42 """
43 Enrich artist metadata from NFO file.
44
45 :param artist: The artist to enrich.
46 :param nfo_artist: The parsed 'artist' element from the NFO file.
47 :param source: Origin of the NFO data (e.g. file path), included in log messages.
48 """
49 if title := nfo_artist.get("title") or nfo_artist.get("name"):
50 artist.name = title
51 if sort_name := nfo_artist.get("sortname"):
52 artist.sort_name = sort_name
53 if mbid := clean_mbid(nfo_artist.get("musicbrainzartistid"), source):
54 artist.mbid = mbid
55 if description := nfo_artist.get("biography"):
56 artist.metadata.description = description
57 if genre := nfo_artist.get("genre"):
58 artist.metadata.genres = set(split_items(genre))
59