-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathspotify-types.ts
399 lines (366 loc) · 10.1 KB
/
spotify-types.ts
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
/**
* @todo https://developer.spotify.com/documentation/web-playback-sdk/reference/
*/
/**
* Generic method type.
*/
export type SpotifyWebPlaybackMethod<T = void, R = void> = (args: T) => R;
/** @hidden */
export type SpotifyOAuthCallback = SpotifyWebPlaybackMethod<string, Promise<void>>;
/**
* Status events.
*/
export type SpotifyWebPlaybackStatusType = 'ready' | 'not_ready';
/**
* State change event.
*/
export type SpotifyWebPlaybackStateType = 'player_state_changed';
/**
* Error events.
*/
export type SpotifyWebPlaybackErrorType =
| 'initialization_error'
| 'authentication_error'
| 'account_error'
| 'playback_error';
/** @hidden */
export interface SpotifyWebPlaybackError {
message: SpotifyWebPlaybackErrorType;
}
/** @hidden */
export interface SpotifyWebPlaybackReady {
device_id: string;
}
/** @hidden */
export interface SpotifyWebPlaybackState {
bitrate: number;
context: {
metadata: Record<string, unknown>;
uri: null;
};
disallows: {
resuming: boolean;
skipping_prev: boolean;
};
duration: number;
paused: boolean;
position: number;
repeat_mode: number;
restrictions: {
disallow_resuming_reasons: [];
disallow_skipping_prev_reasons: [];
};
shuffle: boolean;
timestamp: number;
track_window: {
current_track: SpotifyWebPlaybackTrack;
next_tracks: SpotifyWebPlaybackTrack[];
previous_tracks: SpotifyWebPlaybackTrack[];
};
}
/** @hidden */
export interface SpotifyWebPlaybackArtist {
name: string;
uri: string;
}
/** @hidden */
export interface SpotifyWebPlaybackImage {
height: number;
url: string;
width: number;
}
/** @hidden */
export interface SpotifyWebPlaybackAlbum {
images: SpotifyWebPlaybackImage[];
name: string;
uri: string;
}
/** @hidden */
export interface SpotifyWebPlaybackTrack {
album: SpotifyWebPlaybackAlbum;
artists: SpotifyWebPlaybackArtist[];
duration_ms: number;
id: string;
is_playable: boolean;
linked_from: {
uri: null | string;
id: null | string;
};
linked_from_uri: null | string;
media_type: string;
name: string;
type: string;
uri: string;
}
/**
* Event callbacks.
*/
export type SpotifyListenerType = 'error' | 'state' | 'ready';
/**
* An event listener for when an error occurs.
*/
export type SpotifyErrorListener = SpotifyWebPlaybackMethod<SpotifyWebPlaybackErrorType>;
/**
* An event listener for when the playback state changes.
*/
export type SpotifyStateListener = SpotifyWebPlaybackMethod<SpotifyWebPlaybackState | null>;
/**
* An event listener for when the player status changes.
*/
export type SpotifyStatusListener = SpotifyWebPlaybackMethod<SpotifyWebPlaybackStatusType>;
/**
* Event listeners.
*/
export type SpotifyListener = SpotifyErrorListener | SpotifyStateListener | SpotifyStatusListener;
/** @hidden */
export type SpotifyErrorCallback = SpotifyWebPlaybackMethod<SpotifyWebPlaybackError>;
/** @hidden */
export type SpotifyStateCallback = SpotifyWebPlaybackMethod<SpotifyWebPlaybackState | null>;
/** @hidden */
export type SpotifyStatusCallback = SpotifyWebPlaybackMethod<SpotifyWebPlaybackReady>;
/** @hidden */
export interface SpotifyWebPlaybackPlayer {
_options: {
getOAuthToken: SpotifyOAuthCallback;
name: string;
id: string;
volume: number;
};
addListener: {
(event: SpotifyWebPlaybackErrorType, callback: SpotifyErrorCallback): boolean;
(event: SpotifyWebPlaybackStateType, callback: SpotifyStateCallback): boolean;
(event: SpotifyWebPlaybackStatusType, callback: SpotifyStatusCallback): boolean;
};
connect: SpotifyWebPlaybackMethod<void, boolean>;
activateElement: SpotifyWebPlaybackMethod<void, Promise<void>>;
disconnect: SpotifyWebPlaybackMethod;
getCurrentState: SpotifyWebPlaybackMethod<void, Promise<SpotifyWebPlaybackState | null>>;
getVolume: SpotifyWebPlaybackMethod<void, number>;
pause: SpotifyWebPlaybackMethod;
nextTrack: SpotifyWebPlaybackMethod;
previousTrack: SpotifyWebPlaybackMethod;
removeListener: (
event: SpotifyWebPlaybackErrorType | SpotifyWebPlaybackStateType | SpotifyWebPlaybackStatusType,
callback?: SpotifyWebPlaybackMethod,
) => boolean;
resume: SpotifyWebPlaybackMethod;
seek: (positionMS: number) => Promise<void>;
setName: (name: string) => Promise<void>;
setVolume: (volume: number) => Promise<void>;
togglePlay: SpotifyWebPlaybackMethod;
}
/**
* Different Spotify devices.
*/
export enum SpotifyDeviceType {
/** The Spotify web player. */
Computer = 'Computer',
/** The Spotify app running on a tablet device. */
Tablet = 'Tablet',
/** The Spotify app running on a smartphone */
Smartphone = 'Smartphone',
/** A speaker with Spotify built in. */
Speaker = 'Speaker',
/** A smart TV with Spotify. */
TV = 'TV',
/** AV Receiver. */
AVR = 'AVR',
/** Set-top Box. */
STB = 'STB',
/** Spotify Connect. */
AudioDongle = 'AudioDongle',
/** Video game console. */
GameConsole = 'GameConsole',
/** Chromecast audio. */
CastVideo = 'CastVideo',
/** Chromecast video. */
CastAudio = 'CastAudio',
/** Automobile. */
Automobile = 'Automobile',
/** Unknown. */
Unknown = 'Unknown'
};
/**
* Represents a single Spotify device capable of streaming music.
*/
export interface SpotifyDevice {
/** Device ID. */
id: string;
/** Device name. */
name: string;
/** Device type, such as "Computer", "Smartphone", or "Speaker". */
type: SpotifyDeviceType;
/** Volume level (as a percentage between `0` and `100`). */
volume_percent: number;
/** Indicates if this device is the user's currently active device. */
is_active: boolean;
/** Indicates if this device is currently in a private session. */
is_private_session: boolean;
/** Indicates if this device is restricted from accepting Web API commands. */
is_restricted: boolean;
}
/**
* An artist on Spotify.
*/
export interface SpotifyArtist {
/** A list of the genres the artist is associated with. */
genres: string[];
/** The Web API endpoint providing full details of the artist. */
href: string;
/** The Spotify ID for the artist. */
id: string;
/** The name of the artist. */
name: string;
/** The Spotify URI for the artist. */
uri: string;
}
/**
* The image of an album/song/artist from Spotify.
*/
export interface SpotifyImage {
/** Image width. */
width: number;
/** Image height. */
height: number;
/** Image URL. */
url: string;
}
/**
* A Spotify album.
*/
export interface SpotifyAlbum {
/** Album ID. */
id: string;
/** Album name. */
name: string;
/** Album type. */
album_type: 'album' | 'single' | 'compilation';
/** List of artists for this album. */
artists: SpotifyArtist[];
/** List of markets this track is available in. */
available_markets: string[];
/** The api.spotify.com URL. */
href: string;
/** List of images for this album. */
images: SpotifyImage[];
/** Release date (YYYY-MM-DD). */
release_date: string;
/** The precision with which the release date is known. */
release_date_precision: 'year' | 'month' | 'day';
/** Number of tracks in this album. */
total_tracks: number;
/** The Spotify URI for this album. */
uri: string;
};
interface SpotifyTrack {
/** Album information. */
album: SpotifyAlbum;
/** List of artists. */
artists: SpotifyArtist[];
/** List of markets this track is available in. */
available_markets: string[];
/** The disc number (set to 1 unless the album has more than one disc). */
disc_number: number;
/** Track length in milliseconds. */
duration_ms: number;
/** Indicates if this track has explicit material. */
explicit: boolean;
/** A link to the Web API endpoint providing full details of the track. */
href: string;
/** The Spotify ID for the track. */
id: string;
/** Indicates if this track is a local file or not. */
is_local: boolean;
/** The name of the track. */
name: string;
/** The popularity of this album (`0` to `100`). */
popularity: number;
/** A link to a 30 second preview (MP3 format) of the track. Can be `null`. */
preview_url: string | null;
/** The number of the track. If an album has several discs, the track number is the number on the specified disc. */
track_number: number;
/** The object type. Will always be `track`. */
type: string;
/** The Spotify URI for the track. */
uri: string;
};
/**
* Status of a Spotify player.
*/
export interface SpotifyPlayerStatus {
name: string;
actions: {
/** Indicates which actions are not allowed. */
disallows: {
resuming: boolean;
skipping_prev: boolean;
};
};
/** The object type of the currently playing item. */
currently_playing_type: 'track' | 'episode' | 'ad' | 'unknown';
/** Current device. */
device: SpotifyDevice;
/** Indicates if something is currently playing. */
is_playing: boolean;
/** The currently active track. */
item: SpotifyTrack;
/** Progress (in milliseconds). */
progress_ms: number;
/** What (if anything) is being repeated. */
repeat_state: 'off' | 'track' | 'context';
/** Indicates if shuffle mode is on. */
shuffle_state: false;
/** Timestamp. */
timestamp: number;
}
/**
* A Spotify track.
*/
export interface SpotifyPlayerTrack {
/** List of artist names. */
artists: string[];
/** Duration in milliseconds. */
duration: number;
/** Track unique ID. */
id: string;
/** Track image URL. */
image: string;
/** Track name. */
name: string;
/** The Spotify URI for the track. */
uri: string;
}
/**
* The Artist of an album.
*/
export interface SpotifyPlaylistArtist {
/** The Spotify ID for the artist. */
id: string;
/** Name of this artist. */
name: string;
}
/**
* A single track in a playlist.
*
* Use `uri` for playing tracks with the Web Playback SDK.
*/
export interface SpotifyPlaylistTrack {
/** List of artists. */
artists: SpotifyPlaylistArtist[];
/** Duration in milliseconds. */
duration: number;
/** Spotify ID. */
id: string;
/** Album image. */
image: SpotifyImage;
/** Track name. */
name: string;
/** The Spotify URI for the track. */
uri: string;
};
export interface SpotifyPlaylist {
/** The name of the playlist. */
name: string;
/** Playlist items. */
tracks: SpotifyPlaylistTrack[];
};