/
/
/
1"""Open Subsonic music provider support for MusicAssistant."""
2
3from __future__ import annotations
4
5from typing import TYPE_CHECKING
6
7from music_assistant_models.config_entries import ConfigEntry, ConfigValueType, ProviderConfig
8from music_assistant_models.enums import ConfigEntryType, ProviderFeature
9
10from music_assistant.constants import CONF_PASSWORD, CONF_PATH, CONF_PORT, CONF_USERNAME
11
12from .sonic_provider import (
13 CONF_BASE_URL,
14 CONF_ENABLE_LEGACY_AUTH,
15 CONF_ENABLE_PODCASTS,
16 CONF_NEW_ALBUMS,
17 CONF_OVERRIDE_OFFSET,
18 CONF_PAGE_SIZE,
19 CONF_PLAYED_ALBUMS,
20 CONF_RECO_FAVES,
21 CONF_RECO_SIZE,
22 OpenSonicProvider,
23)
24
25if TYPE_CHECKING:
26 from music_assistant_models.provider import ProviderManifest
27
28 from music_assistant.mass import MusicAssistant
29 from music_assistant.models import ProviderInstanceType
30
31SUPPORTED_FEATURES = {
32 ProviderFeature.LIBRARY_ARTISTS,
33 ProviderFeature.LIBRARY_ALBUMS,
34 ProviderFeature.LIBRARY_TRACKS,
35 ProviderFeature.LIBRARY_PLAYLISTS,
36 ProviderFeature.LIBRARY_PLAYLISTS_EDIT,
37 ProviderFeature.BROWSE,
38 ProviderFeature.SEARCH,
39 ProviderFeature.RECOMMENDATIONS,
40 ProviderFeature.ARTIST_ALBUMS,
41 ProviderFeature.ARTIST_TOPTRACKS,
42 ProviderFeature.SIMILAR_TRACKS,
43 ProviderFeature.PLAYLIST_TRACKS_EDIT,
44 ProviderFeature.PLAYLIST_CREATE,
45 ProviderFeature.LIBRARY_PODCASTS,
46 ProviderFeature.LIBRARY_PODCASTS_EDIT,
47 ProviderFeature.FAVORITE_ALBUMS_EDIT,
48 ProviderFeature.FAVORITE_ARTISTS_EDIT,
49 ProviderFeature.FAVORITE_TRACKS_EDIT,
50}
51
52
53async def setup(
54 mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
55) -> ProviderInstanceType:
56 """Initialize provider(instance) with given configuration."""
57 return OpenSonicProvider(mass, manifest, config, SUPPORTED_FEATURES)
58
59
60async def get_config_entries(
61 mass: MusicAssistant, # noqa: ARG001
62 instance_id: str | None = None, # noqa: ARG001
63 action: str | None = None, # noqa: ARG001
64 values: dict[str, ConfigValueType] | None = None, # noqa: ARG001
65) -> tuple[ConfigEntry, ...]:
66 """Return Config entries to setup this provider."""
67 return (
68 ConfigEntry(
69 key=CONF_USERNAME,
70 type=ConfigEntryType.STRING,
71 label="Username",
72 required=True,
73 description="Your username for this Open Subsonic server",
74 ),
75 ConfigEntry(
76 key=CONF_PASSWORD,
77 type=ConfigEntryType.SECURE_STRING,
78 label="Password",
79 required=True,
80 description="The password associated with the username",
81 ),
82 ConfigEntry(
83 key=CONF_BASE_URL,
84 type=ConfigEntryType.STRING,
85 label="Base URL",
86 required=True,
87 description="Base URL for the server, e.g. https://subsonic.mydomain.tld",
88 ),
89 ConfigEntry(
90 key=CONF_PORT,
91 type=ConfigEntryType.INTEGER,
92 label="Port",
93 required=False,
94 description="Port Number for the server",
95 ),
96 ConfigEntry(
97 key=CONF_PATH,
98 type=ConfigEntryType.STRING,
99 label="Server Path",
100 required=False,
101 description="Path to append to the base URL for the Subsonic server, this is likely "
102 "empty unless you are path routing on a proxy",
103 ),
104 ConfigEntry(
105 key=CONF_ENABLE_PODCASTS,
106 type=ConfigEntryType.BOOLEAN,
107 label="Enable Podcasts",
108 required=True,
109 description="Should the provider query for podcasts as well as music?",
110 default_value=True,
111 ),
112 ConfigEntry(
113 key=CONF_ENABLE_LEGACY_AUTH,
114 type=ConfigEntryType.BOOLEAN,
115 label="Enable Legacy Auth",
116 required=True,
117 description='Enable OpenSubsonic "legacy" auth support',
118 default_value=False,
119 ),
120 ConfigEntry(
121 key=CONF_OVERRIDE_OFFSET,
122 type=ConfigEntryType.BOOLEAN,
123 label="Force Player Provider Seek",
124 required=True,
125 description="Some Subsonic implementations advertise that they support seeking when "
126 "they do not always. If seeking does not work for you, enable this.",
127 default_value=False,
128 ),
129 ConfigEntry(
130 key=CONF_RECO_FAVES,
131 type=ConfigEntryType.BOOLEAN,
132 label="Recommend Favorites",
133 required=True,
134 description="Should favorited (starred) items be included as recommendations.",
135 default_value=True,
136 ),
137 ConfigEntry(
138 key=CONF_NEW_ALBUMS,
139 type=ConfigEntryType.BOOLEAN,
140 label="Recommend New Albums",
141 required=True,
142 description="Should new albums be included as recommendations.",
143 default_value=True,
144 ),
145 ConfigEntry(
146 key=CONF_PLAYED_ALBUMS,
147 type=ConfigEntryType.BOOLEAN,
148 label="Recommend Most Played",
149 required=True,
150 description="Should most played albums be included as recommendations.",
151 default_value=True,
152 ),
153 ConfigEntry(
154 key=CONF_RECO_SIZE,
155 type=ConfigEntryType.INTEGER,
156 label="Recommendation Limit",
157 required=True,
158 description="How many recommendations from each enabled type should be included.",
159 default_value=10,
160 ),
161 ConfigEntry(
162 key=CONF_PAGE_SIZE,
163 type=ConfigEntryType.INTEGER,
164 label="Number of items included per server request.",
165 required=True,
166 description="When enumerating items from the server, how many should be in each "
167 "request. Smaller will require more requests but is better for low bandwidth "
168 "connections. The Open Subsonic spec says the max value for this is 500 items.",
169 default_value=200,
170 advanced=True,
171 ),
172 )
173