forked from music-assistant/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enums.py
434 lines (352 loc) · 12.4 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
"""All enums used by the Music Assistant models."""
from __future__ import annotations
import contextlib
from enum import EnumType, StrEnum
class MediaTypeMeta(EnumType):
"""Class properties for MediaType."""
@property
def ALL(cls) -> list[MediaType]: # noqa: N802
"""All MediaTypes."""
return [
MediaType.ARTIST,
MediaType.ALBUM,
MediaType.TRACK,
MediaType.PLAYLIST,
MediaType.RADIO,
]
class MediaType(StrEnum, metaclass=MediaTypeMeta):
"""Enum for MediaType."""
ARTIST = "artist"
ALBUM = "album"
TRACK = "track"
PLAYLIST = "playlist"
RADIO = "radio"
FOLDER = "folder"
ANNOUNCEMENT = "announcement"
FLOW_STREAM = "flow_stream"
UNKNOWN = "unknown"
@classmethod
def _missing_(cls, value: object) -> MediaType: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.UNKNOWN
class ExternalID(StrEnum):
"""Enum with External ID types."""
MB_ARTIST = "musicbrainz_artistid" # MusicBrainz Artist ID (or AlbumArtist ID)
MB_ALBUM = "musicbrainz_albumid" # MusicBrainz Album ID
MB_RELEASEGROUP = "musicbrainz_releasegroupid" # MusicBrainz ReleaseGroupID
MB_TRACK = "musicbrainz_trackid" # MusicBrainz Track ID
MB_RECORDING = "musicbrainz_recordingid" # MusicBrainz Recording ID
ISRC = "isrc" # used to identify unique recordings
BARCODE = "barcode" # EAN-13 barcode for identifying albums
ACOUSTID = "acoustid" # unique fingerprint (id) for a recording
ASIN = "asin" # amazon unique number to identify albums
DISCOGS = "discogs" # id for media item on discogs
TADB = "tadb" # the audio db id
UNKNOWN = "unknown"
@classmethod
def _missing_(cls, value: object) -> ExternalID: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.UNKNOWN
@property
def is_unique(self) -> bool:
"""Return if the ExternalID is unique."""
return self.is_musicbrainz or self in (
ExternalID.ACOUSTID,
ExternalID.DISCOGS,
ExternalID.TADB,
)
@property
def is_musicbrainz(self) -> bool:
"""Return if the ExternalID is a MusicBrainz identifier."""
return self in (
ExternalID.MB_RELEASEGROUP,
ExternalID.MB_ALBUM,
ExternalID.MB_TRACK,
ExternalID.MB_ARTIST,
ExternalID.MB_RECORDING,
)
class LinkType(StrEnum):
"""Enum 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"
UNKNOWN = "unknown"
@classmethod
def _missing_(cls, value: object) -> LinkType: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.UNKNOWN
class ImageType(StrEnum):
"""Enum with image types."""
THUMB = "thumb"
LANDSCAPE = "landscape"
FANART = "fanart"
LOGO = "logo"
CLEARART = "clearart"
BANNER = "banner"
CUTOUT = "cutout"
BACK = "back"
DISCART = "discart"
OTHER = "other"
@classmethod
def _missing_(cls, value: object) -> ImageType: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.OTHER
class AlbumType(StrEnum):
"""Enum 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"
MP4 = "mp4"
M4B = "m4b"
DSF = "dsf"
OPUS = "opus"
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)
UNKNOWN = "?"
@classmethod
def _missing_(cls, value: object) -> ContentType: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.UNKNOWN
@classmethod
def try_parse(cls, 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):
with contextlib.suppress(ValueError):
parsed = cls(val.strip())
if parsed != ContentType.UNKNOWN:
return parsed
tempstr = tempstr.split("?")[0]
tempstr = tempstr.split("&")[0]
tempstr = tempstr.split(";")[0]
tempstr = tempstr.replace("mp4", "m4a")
tempstr = tempstr.replace("mp4a", "m4a")
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,
ContentType.ALAC,
ContentType.WAVPACK,
)
@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):
"""Enum 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):
"""Enum for the (playback)state of a player."""
IDLE = "idle"
PAUSED = "paused"
PLAYING = "playing"
class PlayerType(StrEnum):
"""Enum with possible Player Types.
player: A regular player.
stereo_pair: Same as player but a dedicated stereo pair of 2 speakers.
group: A (dedicated) group player or (universal) playergroup.
sync_group: A group/preset of players that can be synced together.
"""
PLAYER = "player"
STEREO_PAIR = "stereo_pair"
GROUP = "group"
SYNC_GROUP = "sync_group"
UNKNOWN = "unknown"
@classmethod
def _missing_(cls, value: object) -> PlayerType: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.UNKNOWN
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.
queue: The player supports (en)queuing of media items natively.
"""
POWER = "power"
VOLUME_SET = "volume_set"
VOLUME_MUTE = "volume_mute"
PAUSE = "pause"
SYNC = "sync"
SEEK = "seek"
ENQUEUE_NEXT = "enqueue_next"
PLAY_ANNOUNCEMENT = "play_announcement"
UNKNOWN = "unknown"
@classmethod
def _missing_(cls, value: object) -> PlayerFeature: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.UNKNOWN
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"
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"
UNKNOWN = "unknown"
@classmethod
def _missing_(cls, value: object) -> EventType: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.UNKNOWN
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
#
PLAYER_GROUP_CREATE = "player_group_create"
SYNC_PLAYERS = "sync_players"
#
# METADATAPROVIDER FEATURES
#
ARTIST_METADATA = "artist_metadata"
ALBUM_METADATA = "album_metadata"
TRACK_METADATA = "track_metadata"
#
# PLUGIN FEATURES
#
UNKNOWN = "unknown"
@classmethod
def _missing_(cls, value: object) -> ProviderFeature: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.UNKNOWN
class ProviderType(StrEnum):
"""Enum with supported provider types."""
MUSIC = "music"
PLAYER = "player"
METADATA = "metadata"
PLUGIN = "plugin"
CORE = "core"
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"
INTEGER_TUPLE = "integer_tuple"
DIVIDER = "divider"
ACTION = "action"
ICON = "icon"
ALERT = "alert"
UNKNOWN = "unknown"
@classmethod
def _missing_(cls, value: object) -> ConfigEntryType: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return cls.UNKNOWN
class StreamType(StrEnum):
"""Enum for the type of streamdetails."""
HTTP = "http" # regular http stream
ENCRYPTED_HTTP = "encrypted_http" # encrypted http stream
HLS = "hls" # http HLS stream
ICY = "icy" # http stream with icy metadata
LOCAL_FILE = "local_file"
CUSTOM = "custom"