forked from music-assistant/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enums.py
353 lines (286 loc) · 9.7 KB
/
enums.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
"""All enums used by the Music Assistant models."""
from __future__ import annotations
from enum import Enum
from typing import Any, Self, TypeVar
# pylint:disable=ungrouped-imports
try:
from enum import StrEnum
except AttributeError:
# Python 3.10 compatibility for strenum
_StrEnumSelfT = TypeVar("_StrEnumSelfT", bound="StrEnum")
class StrEnum(str, Enum):
"""Partial backport of Python 3.11's StrEnum for our basic use cases."""
def __new__(
cls: type[_StrEnumSelfT], value: str, *args: Any, **kwargs: Any
) -> _StrEnumSelfT:
"""Create a new StrEnum instance."""
if not isinstance(value, str):
raise TypeError(f"{value!r} is not a string")
return super().__new__(cls, value, *args, **kwargs)
def __str__(self) -> str:
"""Return self."""
return str(self)
@staticmethod
def _generate_next_value_(
name: str, start: int, count: int, last_values: list[Any] # noqa
) -> Any:
"""Make `auto()` explicitly unsupported.
We may revisit this when it's very clear that Python 3.11's
`StrEnum.auto()` behavior will no longer change.
"""
raise TypeError("auto() is not supported by this implementation")
class MediaType(StrEnum):
"""StrEnum for MediaType."""
ARTIST = "artist"
ALBUM = "album"
TRACK = "track"
PLAYLIST = "playlist"
RADIO = "radio"
FOLDER = "folder"
UNKNOWN = "unknown"
@classmethod
@property
def ALL(cls: Self) -> tuple[MediaType, ...]: # noqa: N802
"""Return all (default) MediaTypes as tuple."""
return (
MediaType.ARTIST,
MediaType.ALBUM,
MediaType.TRACK,
MediaType.PLAYLIST,
MediaType.RADIO,
)
class LinkType(StrEnum):
"""StrEnum with link types."""
WEBSITE = "website"
FACEBOOK = "facebook"
TWITTER = "twitter"
LASTFM = "lastfm"
YOUTUBE = "youtube"
INSTAGRAM = "instagram"
SNAPCHAT = "snapchat"
TIKTOK = "tiktok"
DISCOGS = "discogs"
WIKIPEDIA = "wikipedia"
ALLMUSIC = "allmusic"
class ImageType(StrEnum):
"""StrEnum with image types."""
THUMB = "thumb"
LANDSCAPE = "landscape"
FANART = "fanart"
LOGO = "logo"
CLEARART = "clearart"
BANNER = "banner"
CUTOUT = "cutout"
BACK = "back"
DISCART = "discart"
OTHER = "other"
class AlbumType(StrEnum):
"""StrEnum for Album type."""
ALBUM = "album"
SINGLE = "single"
COMPILATION = "compilation"
EP = "ep"
PODCAST = "podcast"
AUDIOBOOK = "audiobook"
UNKNOWN = "unknown"
class ContentType(StrEnum):
"""Enum with audio content/container types supported by ffmpeg."""
OGG = "ogg"
FLAC = "flac"
MP3 = "mp3"
AAC = "aac"
MPEG = "mpeg"
ALAC = "alac"
WAV = "wav"
AIFF = "aiff"
WMA = "wma"
M4A = "m4a"
M4B = "m4b"
DSF = "dsf"
WAVPACK = "wv"
PCM_S16LE = "s16le" # PCM signed 16-bit little-endian
PCM_S24LE = "s24le" # PCM signed 24-bit little-endian
PCM_S32LE = "s32le" # PCM signed 32-bit little-endian
PCM_F32LE = "f32le" # PCM 32-bit floating-point little-endian
PCM_F64LE = "f64le" # PCM 64-bit floating-point little-endian
PCM = "pcm" # PCM generic (details determined later)
MPEG_DASH = "dash"
UNKNOWN = "?"
@classmethod
def try_parse(cls: ContentType, string: str) -> ContentType:
"""Try to parse ContentType from (url)string/extension."""
tempstr = string.lower()
if "audio/" in tempstr:
tempstr = tempstr.split("/")[1]
for splitter in (".", ","):
if splitter in tempstr:
for val in tempstr.split(splitter):
try:
return cls(val.strip())
except ValueError:
pass
tempstr = tempstr.split("?")[0]
tempstr = tempstr.split("&")[0]
tempstr = tempstr.split(";")[0]
tempstr = tempstr.replace("mp4", "m4a")
tempstr = tempstr.replace("mpd", "dash")
try:
return cls(tempstr)
except ValueError:
return cls.UNKNOWN
def is_pcm(self) -> bool:
"""Return if contentype is PCM."""
return self.name.startswith("PCM")
def is_lossless(self) -> bool:
"""Return if format is lossless."""
return self.is_pcm() or self in (
ContentType.DSF,
ContentType.FLAC,
ContentType.AIFF,
ContentType.WAV,
)
@classmethod
def from_bit_depth(cls, bit_depth: int, floating_point: bool = False) -> ContentType:
"""Return (PCM) Contenttype from PCM bit depth."""
if floating_point and bit_depth > 32:
return cls.PCM_F64LE
if floating_point:
return cls.PCM_F32LE
if bit_depth == 16:
return cls.PCM_S16LE
if bit_depth == 24:
return cls.PCM_S24LE
return cls.PCM_S32LE
class QueueOption(StrEnum):
"""StrEnum representation of the queue (play) options.
- PLAY -> Insert new item(s) in queue at the current position and start playing.
- REPLACE -> Replace entire queue contents with the new items and start playing from index 0.
- NEXT -> Insert item(s) after current playing/buffered item.
- REPLACE_NEXT -> Replace item(s) after current playing/buffered item.
- ADD -> Add new item(s) to the queue (at the end if shuffle is not enabled).
"""
PLAY = "play"
REPLACE = "replace"
NEXT = "next"
REPLACE_NEXT = "replace_next"
ADD = "add"
class RepeatMode(StrEnum):
"""Enum with repeat modes."""
OFF = "off" # no repeat at all
ONE = "one" # repeat one/single track
ALL = "all" # repeat entire queue
class PlayerState(StrEnum):
"""StrEnum for the (playback)state of a player."""
IDLE = "idle"
PAUSED = "paused"
PLAYING = "playing"
OFF = "off"
class PlayerType(StrEnum):
"""Enum with possible Player Types.
player: A regular player.
group: A (dedicated) group player or playergroup.
stereo_pair: Two speakers playing as one stereo pair.
"""
PLAYER = "player"
GROUP = "group"
STEREO_PAIR = "stereo_pair"
class PlayerFeature(StrEnum):
"""Enum with possible Player features.
power: The player has a dedicated power control.
volume: The player supports adjusting the volume.
mute: The player supports muting the volume.
sync: The player supports syncing with other players (of the same platform).
accurate_time: The player provides millisecond accurate timing information.
seek: The player supports seeking to a specific.
set_members: The PlayerGroup supports adding/removing members.
queue: The player supports (en)queuing of media items.
"""
POWER = "power"
VOLUME_SET = "volume_set"
VOLUME_MUTE = "volume_mute"
PAUSE = "pause"
SYNC = "sync"
ACCURATE_TIME = "accurate_time"
SEEK = "seek"
SET_MEMBERS = "set_members"
QUEUE = "queue"
CROSSFADE = "crossfade"
class EventType(StrEnum):
"""Enum with possible Events."""
PLAYER_ADDED = "player_added"
PLAYER_UPDATED = "player_updated"
PLAYER_REMOVED = "player_removed"
PLAYER_SETTINGS_UPDATED = "player_settings_updated"
QUEUE_ADDED = "queue_added"
QUEUE_UPDATED = "queue_updated"
QUEUE_ITEMS_UPDATED = "queue_items_updated"
QUEUE_TIME_UPDATED = "queue_time_updated"
QUEUE_SETTINGS_UPDATED = "queue_settings_updated"
SHUTDOWN = "application_shutdown"
MEDIA_ITEM_ADDED = "media_item_added"
MEDIA_ITEM_UPDATED = "media_item_updated"
MEDIA_ITEM_DELETED = "media_item_deleted"
PROVIDERS_UPDATED = "providers_updated"
PLAYER_CONFIG_UPDATED = "player_config_updated"
SYNC_TASKS_UPDATED = "sync_tasks_updated"
AUTH_SESSION = "auth_session"
class ProviderFeature(StrEnum):
"""Enum with features for a Provider."""
#
# MUSICPROVIDER FEATURES
#
# browse/explore/recommendations
BROWSE = "browse"
SEARCH = "search"
RECOMMENDATIONS = "recommendations"
# library feature per mediatype
LIBRARY_ARTISTS = "library_artists"
LIBRARY_ALBUMS = "library_albums"
LIBRARY_TRACKS = "library_tracks"
LIBRARY_PLAYLISTS = "library_playlists"
LIBRARY_RADIOS = "library_radios"
# additional library features
ARTIST_ALBUMS = "artist_albums"
ARTIST_TOPTRACKS = "artist_toptracks"
# library edit (=add/remove) feature per mediatype
LIBRARY_ARTISTS_EDIT = "library_artists_edit"
LIBRARY_ALBUMS_EDIT = "library_albums_edit"
LIBRARY_TRACKS_EDIT = "library_tracks_edit"
LIBRARY_PLAYLISTS_EDIT = "library_playlists_edit"
LIBRARY_RADIOS_EDIT = "library_radios_edit"
# if we can grab 'similar tracks' from the music provider
# used to generate dynamic playlists
SIMILAR_TRACKS = "similar_tracks"
# playlist-specific features
PLAYLIST_TRACKS_EDIT = "playlist_tracks_edit"
PLAYLIST_CREATE = "playlist_create"
#
# PLAYERPROVIDER FEATURES
#
# we currently have none ;-)
#
# METADATAPROVIDER FEATURES
#
ARTIST_METADATA = "artist_metadata"
ALBUM_METADATA = "album_metadata"
TRACK_METADATA = "track_metadata"
GET_ARTIST_MBID = "get_artist_mbid"
#
# PLUGIN FEATURES
#
class ProviderType(StrEnum):
"""Enum with supported provider types."""
MUSIC = "music"
PLAYER = "player"
METADATA = "metadata"
PLUGIN = "plugin"
class ConfigEntryType(StrEnum):
"""Enum for the type of a config entry."""
BOOLEAN = "boolean"
STRING = "string"
SECURE_STRING = "secure_string"
INTEGER = "integer"
FLOAT = "float"
LABEL = "label"
DIVIDER = "divider"
ACTION = "action"