forked from music-assistant/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enums.py
333 lines (268 loc) · 8.99 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
"""All enums used by the Music Assistant models."""
from __future__ import annotations
from enum import StrEnum
class MediaType(StrEnum):
"""Enum for MediaType."""
ARTIST = "artist"
ALBUM = "album"
TRACK = "track"
PLAYLIST = "playlist"
RADIO = "radio"
FOLDER = "folder"
UNKNOWN = "unknown"
@classmethod
@property
def ALL(cls) -> tuple[MediaType, ...]: # noqa: N802
"""Return all (default) MediaTypes as tuple."""
return (
MediaType.ARTIST,
MediaType.ALBUM,
MediaType.TRACK,
MediaType.PLAYLIST,
MediaType.RADIO,
)
class ExternalID(StrEnum):
"""Enum with External ID types."""
# musicbrainz:
# for tracks this is the RecordingID
# for albums this is the ReleaseGroupID (NOT the release ID!)
# for artists this is the ArtistID
MUSICBRAINZ = "musicbrainz"
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
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"
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"
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"
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)
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):
"""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.
group: A (dedicated) group player or (universal) playergroup.
sync_group: A group/preset of players that can be synced together.
"""
PLAYER = "player"
GROUP = "group"
SYNC_GROUP = "sync_group"
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"
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
#
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
#
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"
DIVIDER = "divider"
ACTION = "action"