Merge branch 'music-assistant:master' into master
authorMarvin Schenkel <marvinschenkel@gmail.com>
Wed, 6 Jul 2022 14:24:38 +0000 (16:24 +0200)
committerGitHub <noreply@github.com>
Wed, 6 Jul 2022 14:24:38 +0000 (16:24 +0200)
1  2 
music_assistant/controllers/music/__init__.py
music_assistant/controllers/music/artists.py
music_assistant/models/enums.py

index aeac4cd700311b9e5f8bb45a21bc582a3f08ff5c,2a1fb7b5219c05d3bd3c74420c42804008ecdf74..9b4ba3b8b13171f0002461ab5a9acbf996cbc50d
@@@ -176,34 -176,33 +176,36 @@@ class ArtistsController(MediaController
          self, item: Artist, overwrite_existing: bool = False
      ) -> Artist:
          """Add a new item record to the database."""
 -        assert item.provider_ids, "Album is missing provider id(s)"
 -        # always try to grab existing item by musicbrainz_id
 -        cur_item = None
 -        if item.musicbrainz_id:
 -            match = {"musicbrainz_id": item.musicbrainz_id}
 -            cur_item = await self.mass.database.get_row(self.db_table, match)
 -        if not cur_item:
 -            # fallback to exact name match
 -            # NOTE: we match an artist by name which could theoretically lead to collisions
 -            # but the chance is so small it is not worth the additional overhead of grabbing
 -            # the musicbrainz id upfront
 -            match = {"sort_name": item.sort_name}
 -            for row in await self.mass.database.get_rows(self.db_table, match):
 -                row_artist = Artist.from_db_row(row)
 -                if row_artist.sort_name == item.sort_name:
 -                    # just to be sure ?!
 -                    cur_item = row_artist
 -                    break
 -        if cur_item:
 -            # update existing
 -            return await self.update_db_item(
 -                cur_item.item_id, item, overwrite=overwrite_existing
 -            )
 +        assert item.provider_ids, "Artist is missing provider id(s)"
 +        async with self.mass.database.get_db(db) as db:
 +            # always try to grab existing item by musicbrainz_id
 +            cur_item = None
 +            if item.musicbrainz_id:
 +                match = {"musicbrainz_id": item.musicbrainz_id}
 +                cur_item = await self.mass.database.get_row(self.db_table, match, db=db)
 +            if not cur_item:
 +                # fallback to matching
 +                # NOTE: we match an artist by name which could theoretically lead to collisions
 +                # but the chance is so small it is not worth the additional overhead of grabbing
 +                # the musicbrainz id upfront
 +                match = {"sort_name": item.sort_name}
 +                for row in await self.mass.database.get_rows(
 +                    self.db_table, match, db=db
 +                ):
 +                    row_artist = Artist.from_db_row(row)
 +                    if row_artist.sort_name == item.sort_name:
 +                        # just to be sure ?!
 +                        cur_item = row_artist
 +                        break
 +            if cur_item:
 +                # update existing
 +                return await self.update_db_item(
 +                    cur_item.item_id, item, overwrite=overwrite_existing, db=db
 +                )
  
          # insert item
+         if item.in_library and not item.timestamp:
+             item.timestamp = int(time())
          new_item = await self.mass.database.insert(self.db_table, item.to_db_row())
          item_id = new_item["item_id"]
          self.logger.debug("added %s to database", item.name)
Simple merge