Improve metadata handling (#1553)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 11 Aug 2024 15:39:34 +0000 (17:39 +0200)
committerGitHub <noreply@github.com>
Sun, 11 Aug 2024 15:39:34 +0000 (17:39 +0200)
music_assistant/server/controllers/metadata.py
music_assistant/server/helpers/api.py

index 84fb4a6b4ef58ab1d95b81fb10daae273a772790..d5fc57b0bd2f21a334a8b7f200766c67acdf426c 100644 (file)
@@ -151,7 +151,9 @@ class MetaDataController(CoreController):
                 "This will allow Music Assistant to fetch additional metadata from (enabled) "
                 "metadata providers, such as The Audio DB and Fanart.tv.\n\n"
                 "Note that these online sources are only queried when no information is already "
-                "available from local files or the music providers.\n\n"
+                "available from local files or the music providers and local artwork/metadata "
+                "will always have preference over online sources so consider metadata from online "
+                "sources as complementary only.\n\n"
                 "The retrieval of additional rich metadata is a process that is executed slowly "
                 "in the background to not overload these free services with requests. "
                 "You can speedup the process by storing the images and other metadata locally.",
index 0b24b5ccfe1de237395edde015ad3184247dc57c..c5b782e73146945d4c381a4ab9d9b4eba5813041 100644 (file)
@@ -30,10 +30,19 @@ class APICommandHandler:
         cls, command: str, func: Callable[..., Coroutine[Any, Any, Any]]
     ) -> APICommandHandler:
         """Parse APICommandHandler by providing a function."""
+        type_hints = get_type_hints(func)
+        # workaround for generic typevar ItemCls that needs to be resolved
+        # to the real media item type. TODO: find a better way to do this
+        # without this hack
+        for key, value in type_hints.items():
+            if not hasattr(value, "__name__"):
+                continue
+            if value.__name__ == "ItemCls":
+                type_hints[key] = func.__self__.item_cls
         return APICommandHandler(
             command=command,
             signature=inspect.signature(func),
-            type_hints=get_type_hints(func),
+            type_hints=type_hints,
             target=func,
         )
 
@@ -148,6 +157,7 @@ def parse_value(name: str, value: Any, value_type: Any, default: Any = MISSING)
         return float(value)
     if value_type is int and isinstance(value, str) and value.isnumeric():
         return int(value)
+
     if not isinstance(value, value_type):  # type: ignore[arg-type]
         msg = (
             f"Value {value} of type {type(value)} is invalid for {name}, "