sort provider mappings - local first at all times
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 19 Sep 2024 21:32:16 +0000 (23:32 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 19 Sep 2024 21:32:16 +0000 (23:32 +0200)
music_assistant/server/controllers/metadata.py

index 2022a413fd1e6f88db75c991bb9d28f1973b804a..dc76944a9b62faf8a83fd334363ac689e2ec1d32 100644 (file)
@@ -447,9 +447,12 @@ class MetaDataController(CoreController):
             # ensure the item is matched to all providers
             await self.mass.music.artists.match_providers(artist)
 
-            # collect metadata from all (streaming) music providers
-            # NOTE: local providers have already pushed their metadata in the sync
-            for prov_mapping in artist.provider_mappings:
+            # collect metadata from all music providers
+            # note that we sort the providers by priority so that we always
+            # prefer local providers over online providers
+            for prov_mapping in sorted(
+                artist.provider_mappings, key=lambda x: x.priority, reverse=True
+            ):
                 if (prov := self.mass.get_provider(prov_mapping.provider_instance)) is None:
                     continue
                 if prov.lookup_key in unique_keys:
@@ -507,10 +510,13 @@ class MetaDataController(CoreController):
             # ensure the item is matched to all providers (will also get other quality versions)
             await self.mass.music.albums.match_providers(album)
 
-            # collect metadata from all (streaming) music providers
-            # NOTE: local providers have already pushed their metadata in the sync
+            # collect metadata from all music providers
+            # note that we sort the providers by priority so that we always
+            # prefer local providers over online providers
             unique_keys: set[str] = set()
-            for prov_mapping in album.provider_mappings:
+            for prov_mapping in sorted(
+                album.provider_mappings, key=lambda x: x.priority, reverse=True
+            ):
                 if (prov := self.mass.get_provider(prov_mapping.provider_instance)) is None:
                     continue
                 if prov.lookup_key in unique_keys: