Skip to content

Commit

Permalink
chore: mypy for template music provider (#1871)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc2k authored Jan 14, 2025
1 parent 54c4346 commit e0d8479
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
57 changes: 24 additions & 33 deletions music_assistant/providers/_template_music_provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@
from collections.abc import AsyncGenerator, Sequence
from typing import TYPE_CHECKING

from music_assistant_models.enums import (
ContentType,
MediaType,
ProviderFeature,
StreamType,
)
from music_assistant_models.enums import ContentType, MediaType, ProviderFeature, StreamType
from music_assistant_models.media_items import (
Album,
Artist,
Expand All @@ -63,14 +58,10 @@
from music_assistant.models.music_provider import MusicProvider

if TYPE_CHECKING:
from music_assistant_models.config_entries import (
ConfigEntry,
ConfigValueType,
ProviderConfig,
)
from music_assistant_models.config_entries import ConfigEntry, ConfigValueType, ProviderConfig
from music_assistant_models.provider import ProviderManifest

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


Expand Down Expand Up @@ -142,7 +133,7 @@ def supported_features(self) -> set[ProviderFeature]:
# you should return a tuple of provider-level features
# here that your player provider supports or an empty tuple if none.
# for example 'ProviderFeature.SYNC_PLAYERS' if you can sync players.
return (
return {
ProviderFeature.BROWSE,
ProviderFeature.SEARCH,
ProviderFeature.RECOMMENDATIONS,
Expand All @@ -158,7 +149,7 @@ def supported_features(self) -> set[ProviderFeature]:
ProviderFeature.LIBRARY_PLAYLISTS_EDIT,
ProviderFeature.SIMILAR_TRACKS,
# see the ProviderFeature enum for all available features
)
}

async def loaded_in_mass(self) -> None:
"""Call after the provider has been loaded."""
Expand Down Expand Up @@ -196,7 +187,7 @@ def is_streaming_provider(self) -> bool:
# For streaming providers return True here but for local file based providers return False.
return True

async def search(
async def search( # type: ignore[empty-body]
self,
search_query: str,
media_types: list[MediaType],
Expand Down Expand Up @@ -256,7 +247,7 @@ async def get_library_albums(self) -> AsyncGenerator[Album, None]:
# It allows retrieving the library/favorite albums from your provider.
# Warning: Async generator:
# You should yield Album objects for each album in the library.
yield # type: ignore
yield # type: ignore[misc]

async def get_library_tracks(self) -> AsyncGenerator[Track, None]:
"""Retrieve library tracks from the provider."""
Expand All @@ -266,7 +257,7 @@ async def get_library_tracks(self) -> AsyncGenerator[Track, None]:
# It allows retrieving the library/favorite tracks from your provider.
# Warning: Async generator:
# You should yield Track objects for each track in the library.
yield # type: ignore
yield # type: ignore[misc]

async def get_library_playlists(self) -> AsyncGenerator[Playlist, None]:
"""Retrieve library/subscribed playlists from the provider."""
Expand All @@ -276,7 +267,7 @@ async def get_library_playlists(self) -> AsyncGenerator[Playlist, None]:
# It allows retrieving the library/favorite playlists from your provider.
# Warning: Async generator:
# You should yield Playlist objects for each playlist in the library.
yield # type: ignore
yield # type: ignore[misc]

async def get_library_radios(self) -> AsyncGenerator[Radio, None]:
"""Retrieve library/subscribed radio stations from the provider."""
Expand All @@ -286,53 +277,53 @@ async def get_library_radios(self) -> AsyncGenerator[Radio, None]:
# It allows retrieving the library/favorite radio stations from your provider.
# Warning: Async generator:
# You should yield Radio objects for each radio station in the library.
yield
yield # type: ignore[misc]

async def get_artist(self, prov_artist_id: str) -> Artist:
async def get_artist(self, prov_artist_id: str) -> Artist: # type: ignore[empty-body]
"""Get full artist details by id."""
# Get full details of a single Artist.
# Mandatory only if you reported LIBRARY_ARTISTS in the supported_features.

async def get_artist_albums(self, prov_artist_id: str) -> list[Album]:
async def get_artist_albums(self, prov_artist_id: str) -> list[Album]: # type: ignore[empty-body]
"""Get a list of all albums for the given artist."""
# Get a list of all albums for the given artist.
# Mandatory only if you reported ARTIST_ALBUMS in the supported_features.

async def get_artist_toptracks(self, prov_artist_id: str) -> list[Track]:
async def get_artist_toptracks(self, prov_artist_id: str) -> list[Track]: # type: ignore[empty-body]
"""Get a list of most popular tracks for the given artist."""
# Get a list of most popular tracks for the given artist.
# Mandatory only if you reported ARTIST_TOPTRACKS in the supported_features.
# Note that (local) file based providers will simply return all artist tracks here.

async def get_album(self, prov_album_id: str) -> Album: # type: ignore[return]
async def get_album(self, prov_album_id: str) -> Album: # type: ignore[empty-body]
"""Get full album details by id."""
# Get full details of a single Album.
# Mandatory only if you reported LIBRARY_ALBUMS in the supported_features.

async def get_track(self, prov_track_id: str) -> Track: # type: ignore[return]
async def get_track(self, prov_track_id: str) -> Track: # type: ignore[empty-body]
"""Get full track details by id."""
# Get full details of a single Track.
# Mandatory only if you reported LIBRARY_TRACKS in the supported_features.

async def get_playlist(self, prov_playlist_id: str) -> Playlist: # type: ignore[return]
async def get_playlist(self, prov_playlist_id: str) -> Playlist: # type: ignore[empty-body]
"""Get full playlist details by id."""
# Get full details of a single Playlist.
# Mandatory only if you reported LIBRARY_PLAYLISTS in the supported

async def get_radio(self, prov_radio_id: str) -> Radio: # type: ignore[return]
async def get_radio(self, prov_radio_id: str) -> Radio: # type: ignore[empty-body]
"""Get full radio details by id."""
# Get full details of a single Radio station.
# Mandatory only if you reported LIBRARY_RADIOS in the supported_features.

async def get_album_tracks(
async def get_album_tracks( # type: ignore[empty-body]
self,
prov_album_id: str, # type: ignore[return]
prov_album_id: str,
) -> list[Track]:
"""Get album tracks for given album id."""
# Get all tracks for a given album.
# Mandatory only if you reported ARTIST_ALBUMS in the supported_features.

async def get_playlist_tracks(
async def get_playlist_tracks( # type: ignore[empty-body]
self,
prov_playlist_id: str,
page: int = 0,
Expand Down Expand Up @@ -365,12 +356,12 @@ async def remove_playlist_tracks(
# Remove track(s) from a playlist.
# This is only called if the provider supports the EDPLAYLIST_TRACKS_EDITIT feature.

async def create_playlist(self, name: str) -> Playlist: # type: ignore[return]
async def create_playlist(self, name: str) -> Playlist: # type: ignore[empty-body]
"""Create a new playlist on provider with given name."""
# Create a new playlist on the provider.
# This is only called if the provider supports the PLAYLIST_CREATE feature.

async def get_similar_tracks( # type: ignore[return]
async def get_similar_tracks( # type: ignore[empty-body]
self, prov_track_id: str, limit: int = 25
) -> list[Track]:
"""Retrieve a dynamic list of similar tracks based on the provided track."""
Expand Down Expand Up @@ -405,7 +396,7 @@ async def get_stream_details(
# but the above should be the mandatory fields to set.
)

async def get_audio_stream( # type: ignore[return]
async def get_audio_stream(
self, streamdetails: StreamDetails, seek_position: int = 0
) -> AsyncGenerator[bytes, None]:
"""
Expand All @@ -417,7 +408,7 @@ async def get_audio_stream( # type: ignore[return]
# for the given streamdetails. You can use this to provide a custom
# stream generator for the audio stream. This is only called when the
# stream_type is set to CUSTOM in the get_stream_details method.
yield # type: ignore
yield # type: ignore[misc]

async def on_streamed(
self,
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ exclude = [
'^music_assistant/controllers/.*$',
'^music_assistant/helpers/.*$',
'^music_assistant/models/.*$',
'^music_assistant/providers/_template_music_provider/.*$',
'^music_assistant/providers/_template_player_provider/.*$',
'^music_assistant/providers/apple_music/.*$',
'^music_assistant/providers/bluesound/.*$',
Expand Down

0 comments on commit e0d8479

Please sign in to comment.