# merge duplicates using a dict
final_items: Dict[str, Track] = {}
for track in tracks:
- if track.disc_number is None or track.track_number is None:
- key = f"{track.name}.{track.version}"
- else:
- key = f"{track.disc_number}.{track.track_number}"
+ key = f".{track.name}.{track.version}"
+ if track.disc_number and track.track_number:
+ key += f".{track.disc_number}.{track.track_number}"
+
if key in final_items:
final_items[key].provider_ids.update(track.provider_ids)
else:
self.get_provider_artist_toptracks(item.item_id, item.prov_id)
for item in artist.provider_ids
]
- # use intermediate set to remove duplicates
+ # use intermediate set to remove (some) duplicates
return list(set(itertools.chain.from_iterable(await asyncio.gather(*coros))))
async def albums(
self.get_provider_artist_albums(item.item_id, item.prov_id)
for item in artist.provider_ids
]
- # use intermediate set to remove duplicates
+ # use intermediate set to remove (some) duplicates
return list(set(itertools.chain.from_iterable(await asyncio.gather(*coros))))
async def add(self, item: Artist) -> Artist:
in_library=True,
)
- # try to guess the album type
- if name.lower() == track.album.name.lower():
- track.album.album_type = AlbumType.SINGLE
- elif track.album.artist not in (x.name for x in track.artists):
- track.album.album_type = AlbumType.COMPILATION
- else:
- track.album.album_type = AlbumType.ALBUM
-
if (
track.album
and track.album.artist
artist.metadata.genres = set(split_items(genre))
# find local images
images = []
- for _filename in os.listdir(artist_path):
+ async for _path in scantree(artist_path):
+ _filename = _path.path
ext = _filename.split(".")[-1]
if ext not in ("jpg", "png"):
continue
album.metadata.genres = set(split_items(genre))
# parse name/version
album.name, album.version = parse_title_and_version(album.name)
+
+ # try to guess the album type
+ album_tracks = [
+ x async for x in scantree(album_path) if TinyTag.is_supported(x.path)
+ ]
+ if artist and artist.sort_name == "variousartists":
+ album.album_type = AlbumType.COMPILATION
+ elif len(album_tracks) <= 5:
+ album.album_type = AlbumType.SINGLE
+ else:
+ album.album_type = AlbumType.ALBUM
+
# find local images
images = []
- for _filename in os.listdir(album_path):
+ async for _path in scantree(album_path):
+ _filename = _path.path
ext = _filename.split(".")[-1]
if ext not in ("jpg", "png"):
continue
from music_assistant.mass import MusicAssistant
-SCHEMA_VERSION = 12
+SCHEMA_VERSION = 13
TABLE_PROV_MAPPINGS = "provider_mappings"
TABLE_TRACK_LOUDNESS = "track_loudness"
# always create db tables if they don't exist to prevent errors trying to access them later
await self.__create_database_tables(db)
- if prev_version < 12:
+ if prev_version < 13:
# fixed nasty bugs in file provider, start clean just in case.
await db.execute(f"DROP TABLE IF EXISTS {TABLE_ARTISTS}")
await db.execute(f"DROP TABLE IF EXISTS {TABLE_ALBUMS}")