/
/
/
1"""Yandex Music provider support for Music Assistant."""
2
3from __future__ import annotations
4
5from typing import TYPE_CHECKING, cast
6
7from music_assistant_models.config_entries import ConfigEntry, ConfigValueOption, ConfigValueType
8from music_assistant_models.enums import ConfigEntryType, ProviderFeature
9
10from .constants import (
11 CONF_ACTION_CLEAR_AUTH,
12 CONF_QUALITY,
13 CONF_TOKEN,
14 QUALITY_HIGH,
15 QUALITY_LOSSLESS,
16)
17from .provider import YandexMusicProvider
18
19if TYPE_CHECKING:
20 from music_assistant_models.config_entries import ProviderConfig
21 from music_assistant_models.provider import ProviderManifest
22
23 from music_assistant.mass import MusicAssistant
24 from music_assistant.models import ProviderInstanceType
25
26
27SUPPORTED_FEATURES = {
28 ProviderFeature.LIBRARY_ARTISTS,
29 ProviderFeature.LIBRARY_ALBUMS,
30 ProviderFeature.LIBRARY_TRACKS,
31 ProviderFeature.LIBRARY_PLAYLISTS,
32 ProviderFeature.ARTIST_ALBUMS,
33 ProviderFeature.ARTIST_TOPTRACKS,
34 ProviderFeature.SEARCH,
35 ProviderFeature.LIBRARY_ARTISTS_EDIT,
36 ProviderFeature.LIBRARY_ALBUMS_EDIT,
37 ProviderFeature.LIBRARY_TRACKS_EDIT,
38 ProviderFeature.BROWSE,
39 ProviderFeature.SIMILAR_TRACKS,
40 ProviderFeature.RECOMMENDATIONS,
41}
42
43
44async def setup(
45 mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
46) -> ProviderInstanceType:
47 """Initialize provider(instance) with given configuration."""
48 return YandexMusicProvider(mass, manifest, config, SUPPORTED_FEATURES)
49
50
51async def get_config_entries(
52 mass: MusicAssistant, # noqa: ARG001
53 instance_id: str | None = None, # noqa: ARG001
54 action: str | None = None,
55 values: dict[str, ConfigValueType] | None = None,
56) -> tuple[ConfigEntry, ...]:
57 """Return Config entries to setup this provider."""
58 if values is None:
59 values = {}
60
61 # Handle clear auth action
62 if action == CONF_ACTION_CLEAR_AUTH:
63 values[CONF_TOKEN] = None
64
65 # Check if user is authenticated
66 is_authenticated = bool(values.get(CONF_TOKEN))
67
68 return (
69 ConfigEntry(
70 key=CONF_TOKEN,
71 type=ConfigEntryType.SECURE_STRING,
72 label="Yandex Music Token",
73 description="Enter your Yandex Music OAuth token. "
74 "See the documentation for how to obtain it.",
75 required=True,
76 hidden=is_authenticated,
77 value=cast("str", values.get(CONF_TOKEN)) if values else None,
78 ),
79 ConfigEntry(
80 key=CONF_ACTION_CLEAR_AUTH,
81 type=ConfigEntryType.ACTION,
82 label="Reset authentication",
83 description="Clear the current authentication details.",
84 action=CONF_ACTION_CLEAR_AUTH,
85 hidden=not is_authenticated,
86 ),
87 ConfigEntry(
88 key=CONF_QUALITY,
89 type=ConfigEntryType.STRING,
90 label="Audio quality",
91 description="Select preferred audio quality.",
92 options=[
93 ConfigValueOption("High (320 kbps)", QUALITY_HIGH),
94 ConfigValueOption("Lossless (FLAC)", QUALITY_LOSSLESS),
95 ],
96 default_value=QUALITY_HIGH,
97 ),
98 )
99