Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: mypy for fanart.tv
Browse files Browse the repository at this point in the history
Jc2k committed Jan 13, 2025
1 parent a9e7d40 commit 21fb4e7
Showing 2 changed files with 23 additions and 24 deletions.
46 changes: 23 additions & 23 deletions music_assistant/providers/fanarttv/__init__.py
Original file line number Diff line number Diff line change
@@ -3,15 +3,15 @@
from __future__ import annotations

from json import JSONDecodeError
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any, cast

import aiohttp.client_exceptions
from music_assistant_models.config_entries import ConfigEntry
from music_assistant_models.enums import ConfigEntryType, ExternalID, ImageType, ProviderFeature
from music_assistant_models.media_items import MediaItemImage, MediaItemMetadata
from music_assistant_models.media_items import MediaItemImage, MediaItemMetadata, UniqueList

from music_assistant.controllers.cache import use_cache
from music_assistant.helpers.app_vars import app_var
from music_assistant.helpers.app_vars import app_var # type: ignore[attr-defined]
from music_assistant.helpers.throttle_retry import Throttler
from music_assistant.models.metadata_provider import MetadataProvider

@@ -20,7 +20,7 @@
from music_assistant_models.media_items import Album, Artist
from music_assistant_models.provider import ProviderManifest

from music_assistant import MusicAssistant
from music_assistant.mass import MusicAssistant
from music_assistant.models import ProviderInstanceType

SUPPORTED_FEATURES = {
@@ -114,7 +114,7 @@ async def get_artist_metadata(self, artist: Artist) -> MediaItemMetadata | None:
self.logger.debug("Fetching metadata for Artist %s on Fanart.tv", artist.name)
if data := await self._get_data(f"music/{artist.mbid}"):
metadata = MediaItemMetadata()
metadata.images = []
metadata.images = UniqueList()
for key, img_type in IMG_MAPPING.items():
items = data.get(key)
if not items:
@@ -140,27 +140,27 @@ async def get_album_metadata(self, album: Album) -> MediaItemMetadata | None:
self.logger.debug("Fetching metadata for Album %s on Fanart.tv", album.name)
if data := await self._get_data(f"music/albums/{mbid}"):
if data and data.get("albums"):
data = data["albums"][mbid]
metadata = MediaItemMetadata()
metadata.images = []
for key, img_type in IMG_MAPPING.items():
items = data.get(key)
if not items:
continue
for item in items:
metadata.images.append(
MediaItemImage(
type=img_type,
path=item["url"],
provider=self.domain,
remotely_accessible=True,
if album := data["albums"][mbid]:
metadata = MediaItemMetadata()
metadata.images = UniqueList()
for key, img_type in IMG_MAPPING.items():
items = album.get(key)
if not items:
continue
for item in items:
metadata.images.append(
MediaItemImage(
type=img_type,
path=item["url"],
provider=self.domain,
remotely_accessible=True,
)
)
)
return metadata
return metadata
return None

@use_cache(86400 * 30)
async def _get_data(self, endpoint, **kwargs) -> dict | None:
async def _get_data(self, endpoint: str, **kwargs: str) -> dict[str, Any] | None:
"""Get data from api."""
url = f"http://webservice.fanart.tv/v3/{endpoint}"
headers = {
@@ -191,4 +191,4 @@ async def _get_data(self, endpoint, **kwargs) -> dict | None:
if "error" in result and "limit" in result["error"]:
self.logger.warning(result["error"])
return None
return result
return cast(dict[str, Any], result)
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -130,7 +130,6 @@ exclude = [
'^music_assistant/providers/chromecast/.*$',
'^music_assistant/providers/deezer/.*$',
'^music_assistant/providers/dlna/.*$',
'^music_assistant/providers/fanarttv/.*$',
'^music_assistant/providers/hass/.*$',
'^music_assistant/providers/hass_players/.*$',
'^music_assistant/providers/player_group/.*$',

0 comments on commit 21fb4e7

Please sign in to comment.