quality += 1
return quality
- def __post_init__(self) -> None:
- """Call after init."""
- # having items for unavailable providers can have all sorts
- # of unpredictable results so ensure we have accurate availability status
+ def __post_serialize__(self, d: dict[Any, Any]) -> dict[Any, Any]:
+ """Execute action(s) on serialization."""
+ # prevent sending back unavailable items in the api if a provider has been disabled.
+ # by overriding the available flag here.
if not (available_providers := get_global_cache_value("unique_providers")):
# this is probably the client
- self.available = self.available
- return
+ return d
if TYPE_CHECKING:
available_providers = cast(set[str], available_providers)
- if not available_providers.intersection({self.provider_domain, self.provider_instance}):
- self.available = False
+ if not available_providers.intersection({d["provider_domain"], d["provider_instance"]}):
+ d["available"] = False
+ return d
def __hash__(self) -> int:
"""Return custom hash."""
from contextlib import suppress
from itertools import zip_longest
from math import inf
-from typing import TYPE_CHECKING, Final
+from typing import TYPE_CHECKING, Final, cast
from music_assistant.common.helpers.datetime import utc_timestamp
from music_assistant.common.helpers.global_cache import get_global_cache_value
ctrl = self.get_controller(media_type)
is_library_item = media_item.provider == "library"
+ available_providers = get_global_cache_value("unique_providers")
+ if TYPE_CHECKING:
+ available_providers = cast(set[str], available_providers)
+
# fetch the first (available) provider item
for prov_mapping in media_item.provider_mappings:
provider = prov_mapping.provider_instance
+ if provider not in available_providers:
+ continue
item_id = prov_mapping.item_id
if prov_mapping.available:
break