javascript-ampache 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +50 -47
  2. package/dist/base.d.ts +6 -0
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.m.js +1 -1
  6. package/dist/index.m.js.map +1 -1
  7. package/dist/index.modern.mjs +1 -1
  8. package/dist/index.modern.mjs.map +1 -1
  9. package/dist/index.umd.js +1 -1
  10. package/dist/index.umd.js.map +1 -1
  11. package/package.json +38 -38
  12. package/src/albums/index.ts +86 -86
  13. package/src/albums/types.ts +38 -32
  14. package/src/artists/index.ts +88 -88
  15. package/src/artists/types.ts +38 -32
  16. package/src/auth/index.ts +103 -103
  17. package/src/auth/types.ts +25 -25
  18. package/src/base.ts +134 -97
  19. package/src/bookmarks/index.ts +115 -122
  20. package/src/bookmarks/types.ts +15 -9
  21. package/src/catalogs/index.ts +130 -119
  22. package/src/catalogs/types.ts +27 -15
  23. package/src/genres/index.ts +39 -40
  24. package/src/genres/types.ts +23 -17
  25. package/src/index.ts +63 -26
  26. package/src/labels/index.ts +43 -44
  27. package/src/labels/types.ts +20 -14
  28. package/src/licenses/index.ts +43 -44
  29. package/src/licenses/types.ts +14 -8
  30. package/src/live-streams/index.ts +104 -107
  31. package/src/live-streams/types.ts +16 -10
  32. package/src/playlists/index.ts +264 -269
  33. package/src/playlists/types.ts +20 -14
  34. package/src/podcasts/index.ts +174 -177
  35. package/src/podcasts/types.ts +85 -67
  36. package/src/preferences/index.ts +114 -116
  37. package/src/preferences/types.ts +18 -12
  38. package/src/shares/index.ts +100 -96
  39. package/src/shares/types.ts +25 -19
  40. package/src/shouts/index.ts +18 -22
  41. package/src/shouts/types.ts +9 -9
  42. package/src/songs/index.ts +208 -203
  43. package/src/songs/types.ts +77 -65
  44. package/src/system/index.ts +689 -572
  45. package/src/system/types.ts +33 -19
  46. package/src/users/index.ts +227 -245
  47. package/src/users/types.ts +38 -32
  48. package/src/utils.ts +25 -25
  49. package/src/videos/index.ts +49 -53
  50. package/src/videos/types.ts +42 -30
@@ -1,572 +1,689 @@
1
- import qs from 'querystringify';
2
- import { Song } from "../songs/types";
3
- import { Artist } from "../artists/types";
4
- import {Base, BinaryBoolean, ExtendedPagination, Pagination, Success, UID} from '../base';
5
- import { Album } from '../albums/types';
6
- import { Video } from '../videos/types';
7
- import { Playlist } from '../playlists/types';
8
- import { Podcast, PodcastEpisode } from '../podcasts/types';
9
- import { LiveStream } from "../live-streams/types";
10
- import { Label } from "../labels/types";
11
- import { Genre } from "../genres/types";
12
- import { User } from "../users/types";
13
- import { IndexEntry } from "./types";
14
-
15
- export class System extends Base {
16
- /**
17
- * Check Ampache for updates and run the update if there is one.
18
- * @remarks MINIMUM_API_VERSION=5.0.0
19
- * @see {@link https://ampache.org/api/api-json-methods#system_update}
20
- */
21
- systemUpdate () {
22
- let query = 'system_update';
23
- return this.request<Success>(query);
24
- }
25
-
26
- /**
27
- * This takes a collection of inputs and returns ID + name for the object type
28
- * @remarks MINIMUM_API_VERSION=400001
29
- * @param params.type type of object to find
30
- * @param [params.filter] search the name of the object_type
31
- * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
32
- * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
33
- * @param [params.include] 0, 1 (include songs in a playlist or episodes in a podcast)
34
- * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
35
- * @param [params.offset]
36
- * @param [params.limit]
37
- * @param [params.cond]
38
- * @param [params.sort]
39
- * @see {@link https://ampache.org/api/api-json-methods#get_indexes}
40
- * @deprecated Being removed in 7.0.0. Use `list` instead.
41
- */
42
- async getIndexes (params: {
43
- type: 'song' | 'album' | 'artist' | 'album_artist' | 'playlist' | 'podcast' | 'podcast_episode' | 'live_stream',
44
- filter?: string,
45
- add?: Date,
46
- update?: Date,
47
- include?: BinaryBoolean,
48
- hide_search?: BinaryBoolean
49
- } & ExtendedPagination) {
50
- let query = 'get_indexes';
51
- query += qs.stringify(params, '&');
52
- let data;
53
-
54
- switch (params.type) {
55
- case "song":
56
- data = await this.request<{song: Song[]}>(query);
57
- return (data.song) ? data.song : data;
58
- case "album":
59
- data = await this.request<{album: Album[]}>(query);
60
- return (data.album) ? data.album : data;
61
- case "artist":
62
- case "album_artist":
63
- data = await this.request<{artist: Artist[]}>(query);
64
- return (data.artist) ? data.artist : data;
65
- case "playlist":
66
- data = await this.request<{playlist: Playlist[]}>(query);
67
- return (data.playlist) ? data.playlist : data;
68
- case "podcast":
69
- data = await this.request<{podcast: Podcast[]}>(query);
70
- return (data.podcast) ? data.podcast : data;
71
- case "podcast_episode":
72
- data = await this.request<{podcast_episode: PodcastEpisode[]}>(query);
73
- return (data.podcast_episode) ? data.podcast_episode : data;
74
- case "live_stream":
75
- data = await this.request<{live_stream: LiveStream[]}>(query);
76
- return (data.live_stream) ? data.live_stream : data;
77
- default:
78
- return false;
79
- }
80
- }
81
-
82
- /**
83
- * This takes a named array of objects and returning `id`, `name`, `prefix` and `basename`
84
- * @remarks MINIMUM_API_VERSION=6.0.0
85
- * @param params.type type of object to find
86
- * @param [params.filter] Value is Alpha Match for returned results, may be more than one letter/number
87
- * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
88
- * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
89
- * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
90
- * @param [params.offset]
91
- * @param [params.limit]
92
- * @param [params.cond]
93
- * @param [params.sort]
94
- * @see {@link https://ampache.org/api/api-json-methods#list}
95
- */
96
- async list (params: {
97
- type: 'song' | 'album' | 'artist' | 'album_artist' | 'playlist' | 'podcast' | 'podcast_episode' | 'live_stream',
98
- filter?: string,
99
- add?: Date,
100
- update?: Date,
101
- hide_search?: BinaryBoolean
102
- } & ExtendedPagination) {
103
- let query = 'list';
104
- query += qs.stringify(params, '&');
105
- return this.request<{list: IndexEntry[]}>(query);
106
- }
107
-
108
- /**
109
- * This takes a collection of inputs and return ID's for the object type.
110
- * @remarks MINIMUM_API_VERSION=6.3.0
111
- * @param params.type type of object to find
112
- * @param [params.filter] Value is Alpha Match for returned results, may be more than one letter/number
113
- * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
114
- * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
115
- * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
116
- * @param [params.include] 0, 1, (include child objects)
117
- * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
118
- * @param [params.offset]
119
- * @param [params.limit]
120
- * @param [params.cond]
121
- * @param [params.sort]
122
- * @see {@link https://ampache.org/api/api-json-methods#index}
123
- */
124
- async index (params: {
125
- type: 'catalog' | 'song' | 'album' | 'artist' | 'album_artist' | 'song_artist' | 'playlist' | 'podcast' | 'podcast_episode' | 'share' | 'video' | 'live_stream'
126
- filter?: string,
127
- exact?: BinaryBoolean,
128
- add?: Date,
129
- update?: Date,
130
- include?: BinaryBoolean,
131
- hide_search?: BinaryBoolean
132
- } & ExtendedPagination) {
133
- let query = 'index';
134
- query += qs.stringify(params, '&');
135
- return this.request<{index: []}>(query);
136
- }
137
-
138
- /**
139
- * Return children of a parent object in a folder traversal/browse style
140
- * If you don't send any parameters you'll get a catalog list (the 'root' path)
141
- * @remarks MINIMUM_API_VERSION=6.0.0
142
- * @param [params.filter] object_id
143
- * @param [params.type] type of object to find
144
- * @param [params.catalog] catalog ID you are browsing (required on 'artist', 'album', 'podcast')
145
- * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
146
- * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
147
- * @param [params.offset]
148
- * @param [params.limit]
149
- * @param [params.cond]
150
- * @param [params.sort]
151
- * @see {@link https://ampache.org/api/api-json-methods#browse}
152
- */
153
- async browse (params: {
154
- filter?: UID,
155
- type?: 'root' | 'catalog' | 'artist' | 'album' | 'podcast',
156
- catalog?: number,
157
- add?: Date,
158
- update?: Date,
159
- } & ExtendedPagination) {
160
- let query = 'browse';
161
- query += qs.stringify(params, '&');
162
- return this.request<{browse: IndexEntry[]}>(query);
163
- }
164
-
165
- /**
166
- * Return similar artist IDs or similar song IDs compared to the input filter
167
- * @remarks MINIMUM_API_VERSION=420000
168
- * @param params.type type of object to check against
169
- * @param params.filter UID to find
170
- * @param [params.offset]
171
- * @param [params.limit]
172
- * @see {@link https://ampache.org/api/api-json-methods#get_similar}
173
- */
174
- async getSimilar (params: {
175
- type: 'song' | 'artist',
176
- filter: UID,
177
- } & Pagination) {
178
- let query = 'get_similar';
179
- query += qs.stringify(params, '&');
180
- let data;
181
-
182
- switch (params.type) {
183
- case "song":
184
- data = await this.request<{song: Song[]}>(query);
185
- return (data.song) ? data.song : data;
186
- case "artist":
187
- data = await this.request<{artist: Artist[]}>(query);
188
- return (data.artist) ? data.artist : data;
189
- default:
190
- return false;
191
- }
192
- }
193
-
194
- /**
195
- * Get some items based on some simple search types and filters. (Random by default)
196
- * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400001
197
- * @param params.type Object type
198
- * @param [params.filter] newest, highest, frequent, recent, forgotten, flagged, random
199
- * @param [params.user_id] Filter results to a certain user by UID
200
- * @param [params.username] Filter results to a certain user by username
201
- * @param [params.offset]
202
- * @param [params.limit]
203
- * @see {@link https://ampache.org/api/api-json-methods#stats}
204
- */
205
- async stats (params: {
206
- type: 'song' | 'album' | 'artist' | 'video' | 'playlist' | 'podcast' | 'podcast_episode',
207
- filter?: 'newest' | 'highest' | 'frequent' | 'recent' | 'forgotten' | 'flagged' | 'random',
208
- user_id?: number,
209
- username?: string,
210
- } & Pagination) {
211
- let query = 'stats';
212
- query += qs.stringify(params, '&');
213
- let data;
214
-
215
- switch (params.type) {
216
- case "song":
217
- data = await this.request<{song: Song[]}>(query);
218
- return (data.song) ? data.song : data;
219
- case "album":
220
- data = await this.request<{album: Album[]}>(query);
221
- return (data.album) ? data.album : data;
222
- case "artist":
223
- data = await this.request<{artist: Artist[]}>(query);
224
- return (data.artist) ? data.artist : data;
225
- case "video":
226
- data = await this.request<{video: Video[]}>(query);
227
- return (data.video) ? data.video : data;
228
- case "playlist":
229
- data = await this.request<{playlist: Playlist[]}>(query);
230
- return (data.playlist) ? data.playlist : data;
231
- case "podcast":
232
- data = await this.request<{podcast: Podcast[]}>(query);
233
- return (data.podcast) ? data.podcast : data;
234
- case "podcast_episode":
235
- data = await this.request<{podcast_episode: PodcastEpisode[]}>(query);
236
- return (data.podcast_episode) ? data.podcast_episode : data;
237
- default:
238
- return false;
239
- }
240
- }
241
-
242
- /**
243
- * This rates a library item
244
- * @remarks MINIMUM_API_VERSION=380001
245
- * @param params.type Object type
246
- * @param params.id UID to find
247
- * @param params.rating Rating to apply
248
- * @see {@link https://ampache.org/api/api-json-methods#rate}
249
- */
250
- rate (params: {
251
- type: 'song' | 'album' | 'artist' | 'playlist' | 'podcast' | 'podcast_episode' | 'video' | 'tvshow' | 'tvshow_season',
252
- id: UID,
253
- rating: 0 | 1 | 2 | 3 | 4 | 5,
254
- }) {
255
- let query = 'rate';
256
- query += qs.stringify(params, '&');
257
- return this.request<Success>(query);
258
- }
259
-
260
- /**
261
- * This flags a library item as a favorite
262
- * @remarks MINIMUM_API_VERSION=400001
263
- * @param params.type Object type
264
- * @param params.id UID to find
265
- * @param params.flag 0, 1
266
- * @see {@link https://ampache.org/api/api-json-methods#flag}
267
- */
268
- flag (params: {
269
- type: 'song' | 'album' | 'artist' | 'playlist' | 'podcast' | 'podcast_episode' | 'video' | 'tvshow' | 'tvshow_season',
270
- id: UID,
271
- flag: BinaryBoolean,
272
- }) {
273
- let query = 'flag';
274
- query += qs.stringify(params, '&');
275
- return this.request<Success>(query);
276
- }
277
-
278
- /**
279
- * Take a song_id and update the object_count and user_activity table with a play. This allows other sources to record play history to Ampache.
280
- * If you don't supply a user id (optional) then just fall back to you.
281
- * ACCESS REQUIRED: 100 (Admin) permission to change another user's play history
282
- * @remarks MINIMUM_API_VERSION=400001
283
- * @param params.id UID of song
284
- * @param [params.user] UID of user
285
- * @param [params.client] Client string
286
- * @param [params.date] UNIXTIME
287
- * @see {@link https://ampache.org/api/api-json-methods#record_play}
288
- */
289
- recordPlay (params: {
290
- id: UID,
291
- user?: UID,
292
- client?: string,
293
- date?: number,
294
- }) {
295
- let query = 'record_play';
296
- query += qs.stringify(params, '&');
297
- return this.request<Success>(query);
298
- }
299
-
300
- /**
301
- * Search for a song using text info and then record a play if found. This allows other sources to record play history to ampache
302
- * @remarks MINIMUM_API_VERSION=400001
303
- * @param params.song HTML encoded string
304
- * @param params.artist HTML encoded string
305
- * @param params.album HTML encoded string
306
- * @param [params.songmbid] Song MBID
307
- * @param [params.artistmbid] Artist MBID
308
- * @param [params.albummbid] Album MBID
309
- * @param [params.song_mbid] Alias of songmbid
310
- * @param [params.artist_mbid] Alias of artistmbid
311
- * @param [params.album_mbid] Alias of albummbid
312
- * @param [params.date] UNIXTIME
313
- * @param [params.client] Client string
314
- * @see {@link https://ampache.org/api/api-json-methods#scrobble}
315
- */
316
- scrobble (params: {
317
- song: string,
318
- artist: string,
319
- album: string,
320
- songmbid?: string,
321
- artistmbid?: string,
322
- albummbid?: string,
323
- song_mbid?: string,
324
- artist_mbid?: string,
325
- album_mbid?: string,
326
- date?: number,
327
- client?: string,
328
- }) {
329
- let query = 'scrobble';
330
- query += qs.stringify(params, '&');
331
- return this.request<Success>(query);
332
- }
333
-
334
- /**
335
- * Update a single album, artist, song from the tag data
336
- * @remarks MINIMUM_API_VERSION=400001
337
- * @param params.type Object type
338
- * @param params.id UID to find
339
- * @see {@link https://ampache.org/api/api-json-methods#update_from_tags}
340
- */
341
- updateFromTags (params: {
342
- type: 'song' | 'artist' | 'album',
343
- id: UID,
344
- }) {
345
- let query = 'update_from_tags';
346
- query += qs.stringify(params, '&');
347
- return this.request<Success>(query);
348
- }
349
-
350
- /**
351
- * Update artist information and fetch similar artists from last.fm
352
- * Make sure lastfm_API_key is set in your configuration file
353
- * ACCESS REQUIRED: 75 (Catalog Manager)
354
- * @remarks MINIMUM_API_VERSION=400001
355
- * @param params.id UID to find
356
- * @see {@link https://ampache.org/api/api-json-methods#update_artist_info}
357
- */
358
- updateArtistInfo (params: {
359
- id: UID,
360
- }) {
361
- let query = 'update_artist_info';
362
- query += qs.stringify(params, '&');
363
- return this.request<Success>(query);
364
- }
365
-
366
- /**
367
- * Updates a single album, artist, song running the gather_art process.
368
- * Doesn't overwrite existing art by default.
369
- * ACCESS REQUIRED: 75 (Catalog Manager)
370
- * @remarks MINIMUM_API_VERSION=400001
371
- * @param params.id UID to update
372
- * @param params.type Object type
373
- * @param [params.overwrite]
374
- * @see {@link https://ampache.org/api/api-json-methods#update_art}
375
- */
376
- updateArt (params: {
377
- id: UID,
378
- type: 'artist' | 'album' | 'song',
379
- overwrite?: BinaryBoolean,
380
- }) {
381
- let query = 'update_art';
382
- query += qs.stringify(params, '&');
383
- return this.request<Success>(query);
384
- }
385
-
386
- /**
387
- * Streams a given media file. Takes the file id in parameter with optional max bit rate, file format, time offset,
388
- * size and estimate content length option.
389
- * NOTE search and playlist will only stream a random object from the list.
390
- * @remarks MINIMUM_API_VERSION=400001
391
- * @param params.id UID to find
392
- * @param params.type Object type
393
- * @param [params.bitrate] Max bitrate for transcoding
394
- * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
395
- * @param [params.offset] Time offset
396
- * @param [params.length] 0, 1 (estimate content length)
397
- * @see {@link https://ampache.org/api/api-json-methods#stream}
398
- */
399
- stream (params: {
400
- id: UID,
401
- type: 'song' | 'podcast_episode' | 'search' | 'playlist',
402
- bitrate?: number,
403
- format?: string,
404
- offset?: number,
405
- length?: BinaryBoolean,
406
- }) {
407
- let query = 'stream';
408
- query += qs.stringify(params, '&');
409
- return this.binary(query);
410
- }
411
-
412
- /**
413
- * Downloads a given media file. set format=raw to download the full file
414
- * NOTE search and playlist will only download a random object from the list
415
- * @remarks MINIMUM_API_VERSION=400001
416
- * @param params.id UID to find
417
- * @param params.type Object type
418
- * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
419
- * @see {@link https://ampache.org/api/api-json-methods#download}
420
- */
421
- download (params: {
422
- id: UID,
423
- type: 'song' | 'podcast_episode' | 'search' | 'playlist',
424
- format?: string,
425
- }) {
426
- let query = 'download';
427
- query += qs.stringify(params, '&');
428
- return this.binary(query);
429
- }
430
-
431
- /**
432
- * Get an art image file.
433
- * @remarks MINIMUM_API_VERSION=400001
434
- * @param params.id UID to find
435
- * @param params.type Object type
436
- * @see {@link https://ampache.org/api/api-json-methods#get_art}
437
- */
438
- getArt (params: {
439
- id: UID,
440
- type: 'song' | 'artist' | 'album' | 'playlist' | 'search' | 'podcast',
441
- }) {
442
- let query = 'get_art';
443
- query += qs.stringify(params, '&');
444
- return this.binary(query);
445
- }
446
-
447
- /**
448
- * This is for controlling localplay
449
- * @param params.command The command to send to the localplay controller
450
- * @param [params.oid] Object UID
451
- * @param [params.type] Object type
452
- * @param [params.clear] 0, 1 (Clear the current playlist before adding)
453
- * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=5.0.0
454
- * @see {@link https://ampache.org/api/api-json-methods#localplay}
455
- */
456
- localplay (params: {
457
- command: 'next' | 'prev' | 'stop' | 'play' | 'pause' | 'add' | 'volume_up' | 'volume_down' | 'volume_mute' | 'delete_all' | 'skip' | 'status',
458
- oid?: number,
459
- type?: 'song' | 'video' | 'podcast_episode' | 'channel' | 'broadcast' | 'democratic' | 'live_stream',
460
- clear?: BinaryBoolean,
461
- }) {
462
- let query = 'localplay';
463
- query += qs.stringify(params, '&');
464
- return this.request(query);
465
- }
466
-
467
- /**
468
- * Get the list of songs in your localplay playlist
469
- * @remarks MINIMUM_API_VERSION=5.0.0
470
- * @see {@link https://ampache.org/api/api-json-methods#localplay_songs}
471
- */
472
- localplaySongs () {
473
- let query = 'localplay_songs';
474
- return this.request(query);
475
- }
476
-
477
- /**
478
- * This is for controlling democratic play (Songs only). VOTE: +1 vote for the oid. DEVOTE: -1 vote for the oid.
479
- * PLAYLIST: Return an array of song items with an additional VOTE COUNT element.
480
- * PLAY: Returns the URL for playing democratic play.
481
- * @remarks MINIMUM_API_VERSION=380001
482
- * @param params.oid UID of song
483
- * @param params.method vote, devote, playlist, play
484
- * @see {@link https://ampache.org/api/api-json-methods#democratic}
485
- */
486
- democratic (params: {
487
- oid: UID,
488
- method: 'vote' | 'devote' | 'playlist' | 'play',
489
- }) {
490
- let query = 'democratic';
491
- query += qs.stringify(params, '&');
492
- return this.request(query);
493
- }
494
-
495
- /**
496
- * Perform an advanced search given passed rules.
497
- * You'll want to consult the docs for this.
498
- * @remarks MINIMUM_API_VERSION=380001
499
- * @param params.operator and, or (whether to match one rule or all)
500
- * @param params.type Object type to return
501
- * @param params.rules An array of rules
502
- * @param [params.random] 0, 1 (random order of results; default to 0)
503
- * @param [params.offset]
504
- * @param [params.limit]
505
- * @see {@link https://ampache.org/api/api-json-methods#advanced_search}
506
- */
507
- async advancedSearch (params: {
508
- operator: 'and' | 'or',
509
- type: 'song' | 'album' | 'album_disk' | 'artist' | 'album_artist' | 'song_artist' | 'label' | 'playlist' | 'podcast' | 'podcast_episode' | 'genre' | 'user' | 'video',
510
- rules: Array<Array<string>>,
511
- random?: BinaryBoolean,
512
- } & Pagination) {
513
- let query = 'advanced_search';
514
-
515
- for (let i = 0; i < params.rules.length; i++) {
516
- const thisRule = params.rules[i];
517
- const ruleNumber = i + 1;
518
-
519
- params['rule_' + ruleNumber] = thisRule[0];
520
- params['rule_' + ruleNumber + '_operator'] = thisRule[1];
521
- params['rule_' + ruleNumber + '_input'] = thisRule[2];
522
-
523
- if (thisRule[0] === 'metadata') {
524
- params['rule_' + ruleNumber + '_subtype'] = thisRule[3];
525
- }
526
- }
527
-
528
- // drop the initial 'rules' as it was split into its parts
529
- delete params.rules;
530
-
531
- query += qs.stringify(params, '&');
532
-
533
- let data;
534
-
535
- switch (params.type) {
536
- case "song":
537
- data = await this.request<{song: Song[]}>(query);
538
- return (data.song) ? data.song : data;
539
- case "album":
540
- data = await this.request<{album: Album[]}>(query);
541
- return (data.album) ? data.album : data;
542
- case "artist":
543
- case "album_artist":
544
- case "song_artist":
545
- data = await this.request<{artist: Artist[]}>(query);
546
- return (data.artist) ? data.artist : data;
547
- case "label":
548
- data = await this.request<{label: Label[]}>(query);
549
- return (data.label) ? data.label : data;
550
- case "playlist":
551
- data = await this.request<{playlist: Playlist[]}>(query);
552
- return (data.playlist) ? data.playlist : data;
553
- case "podcast":
554
- data = await this.request<{podcast: Podcast[]}>(query);
555
- return (data.podcast) ? data.podcast : data;
556
- case "podcast_episode":
557
- data = await this.request<{podcast_episode: PodcastEpisode[]}>(query);
558
- return (data.podcast_episode) ? data.podcast_episode : data;
559
- case "genre":
560
- data = await this.request<{genre: Genre[]}>(query);
561
- return (data.genre) ? data.genre : data;
562
- case "user":
563
- data = await this.request<{user: User[]}>(query);
564
- return (data.user) ? data.user : data;
565
- case "video":
566
- data = await this.request<{video: Video[]}>(query);
567
- return (data.video) ? data.video : data;
568
- default:
569
- return false;
570
- }
571
- }
572
- }
1
+ import qs from "querystringify";
2
+ import { SongResponse, SongsResponse } from "../songs/types";
3
+ import { ArtistResponse, ArtistsResponse } from "../artists/types";
4
+ import {
5
+ Base,
6
+ BinaryBoolean,
7
+ ExtendedPagination,
8
+ Pagination,
9
+ Success,
10
+ UID,
11
+ } from "../base";
12
+ import { AlbumResponse, AlbumsResponse } from "../albums/types";
13
+ import { VideoResponse, VideosResponse } from "../videos/types";
14
+ import { PlaylistResponse, PlaylistsResponse } from "../playlists/types";
15
+ import {
16
+ PodcastResponse,
17
+ PodcastEpisodeResponse,
18
+ PodcastsResponse,
19
+ PodcastEpisodesResponse,
20
+ } from "../podcasts/types";
21
+ import { LiveStreamResponse, LiveStreamsResponse } from "../live-streams/types";
22
+ import { LabelResponse, LabelsResponse } from "../labels/types";
23
+ import { GenreResponse, GenresResponse } from "../genres/types";
24
+ import { UserResponse, UsersResponse } from "../users/types";
25
+ import { IndexEntry } from "./types";
26
+ import { Albums } from "../albums";
27
+
28
+ export class System extends Base {
29
+ /**
30
+ * Check Ampache for updates and run the update if there is one.
31
+ * @remarks MINIMUM_API_VERSION=5.0.0
32
+ * @see {@link https://ampache.org/api/api-json-methods#system_update}
33
+ */
34
+ systemUpdate() {
35
+ let query = "system_update";
36
+ return this.request<Success>(query);
37
+ }
38
+
39
+ /**
40
+ * This takes a collection of inputs and returns ID + name for the object type
41
+ * @remarks MINIMUM_API_VERSION=400001
42
+ * @param params.type type of object to find
43
+ * @param [params.filter] search the name of the object_type
44
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
45
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
46
+ * @param [params.include] 0, 1 (include songs in a playlist or episodes in a podcast)
47
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
48
+ * @param [params.offset]
49
+ * @param [params.limit]
50
+ * @param [params.cond]
51
+ * @param [params.sort]
52
+ * @see {@link https://ampache.org/api/api-json-methods#get_indexes}
53
+ * @deprecated Being removed in 7.0.0. Use `list` instead.
54
+ */
55
+ getIndexes(
56
+ params: {
57
+ type:
58
+ | "song"
59
+ | "album"
60
+ | "artist"
61
+ | "album_artist"
62
+ | "playlist"
63
+ | "podcast"
64
+ | "podcast_episode"
65
+ | "live_stream";
66
+ filter?: string;
67
+ add?: Date;
68
+ update?: Date;
69
+ include?: BinaryBoolean;
70
+ hide_search?: BinaryBoolean;
71
+ } & ExtendedPagination,
72
+ ) {
73
+ let query = "get_indexes";
74
+ query += qs.stringify(params, "&");
75
+ let data;
76
+
77
+ switch (params.type) {
78
+ case "song":
79
+ data = this.request<SongsResponse>(query);
80
+ break;
81
+ case "album":
82
+ data = this.request<AlbumsResponse>(query);
83
+ break;
84
+ case "artist":
85
+ case "album_artist":
86
+ data = this.request<ArtistsResponse>(query);
87
+ break;
88
+ case "playlist":
89
+ data = this.request<PlaylistsResponse>(query);
90
+ break;
91
+ case "podcast":
92
+ data = this.request<PodcastsResponse>(query);
93
+ break;
94
+ case "podcast_episode":
95
+ data = this.request<PodcastEpisodesResponse>(query);
96
+ break;
97
+ case "live_stream":
98
+ data = this.request<LiveStreamsResponse>(query);
99
+ break;
100
+ default:
101
+ return false;
102
+ }
103
+
104
+ return data;
105
+ }
106
+
107
+ /**
108
+ * This takes a named array of objects and returning `id`, `name`, `prefix` and `basename`
109
+ * @remarks MINIMUM_API_VERSION=6.0.0
110
+ * @param params.type type of object to find
111
+ * @param [params.filter] Value is Alpha Match for returned results, may be more than one letter/number
112
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
113
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
114
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
115
+ * @param [params.offset]
116
+ * @param [params.limit]
117
+ * @param [params.cond]
118
+ * @param [params.sort]
119
+ * @see {@link https://ampache.org/api/api-json-methods#list}
120
+ */
121
+ list(
122
+ params: {
123
+ type:
124
+ | "song"
125
+ | "album"
126
+ | "artist"
127
+ | "album_artist"
128
+ | "playlist"
129
+ | "podcast"
130
+ | "podcast_episode"
131
+ | "live_stream";
132
+ filter?: string;
133
+ add?: Date;
134
+ update?: Date;
135
+ hide_search?: BinaryBoolean;
136
+ } & ExtendedPagination,
137
+ ) {
138
+ let query = "list";
139
+ query += qs.stringify(params, "&");
140
+ return this.request<{ list: IndexEntry[] }>(query);
141
+ }
142
+
143
+ /**
144
+ * This takes a collection of inputs and return ID's for the object type.
145
+ * @remarks MINIMUM_API_VERSION=6.3.0
146
+ * @param params.type type of object to find
147
+ * @param [params.filter] Value is Alpha Match for returned results, may be more than one letter/number
148
+ * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
149
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
150
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
151
+ * @param [params.include] 0, 1, (include child objects)
152
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
153
+ * @param [params.offset]
154
+ * @param [params.limit]
155
+ * @param [params.cond]
156
+ * @param [params.sort]
157
+ * @see {@link https://ampache.org/api/api-json-methods#index}
158
+ */
159
+ index(
160
+ params: {
161
+ type:
162
+ | "catalog"
163
+ | "song"
164
+ | "album"
165
+ | "artist"
166
+ | "album_artist"
167
+ | "song_artist"
168
+ | "playlist"
169
+ | "podcast"
170
+ | "podcast_episode"
171
+ | "share"
172
+ | "video"
173
+ | "live_stream";
174
+ filter?: string;
175
+ exact?: BinaryBoolean;
176
+ add?: Date;
177
+ update?: Date;
178
+ include?: BinaryBoolean;
179
+ hide_search?: BinaryBoolean;
180
+ } & ExtendedPagination,
181
+ ) {
182
+ let query = "index";
183
+ query += qs.stringify(params, "&");
184
+ return this.request<{ index: [] }>(query);
185
+ }
186
+
187
+ /**
188
+ * Return children of a parent object in a folder traversal/browse style
189
+ * If you don't send any parameters you'll get a catalog list (the 'root' path)
190
+ * @remarks MINIMUM_API_VERSION=6.0.0
191
+ * @param [params.filter] object_id
192
+ * @param [params.type] type of object to find
193
+ * @param [params.catalog] catalog ID you are browsing (required on 'artist', 'album', 'podcast')
194
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
195
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
196
+ * @param [params.offset]
197
+ * @param [params.limit]
198
+ * @param [params.cond]
199
+ * @param [params.sort]
200
+ * @see {@link https://ampache.org/api/api-json-methods#browse}
201
+ */
202
+ browse(
203
+ params: {
204
+ filter?: UID;
205
+ type?: "root" | "catalog" | "artist" | "album" | "podcast";
206
+ catalog?: number;
207
+ add?: Date;
208
+ update?: Date;
209
+ } & ExtendedPagination,
210
+ ) {
211
+ let query = "browse";
212
+ query += qs.stringify(params, "&");
213
+ return this.request<{ browse: IndexEntry[] }>(query);
214
+ }
215
+
216
+ /**
217
+ * Return similar artist IDs or similar song IDs compared to the input filter
218
+ * @remarks MINIMUM_API_VERSION=420000
219
+ * @param params.type type of object to check against
220
+ * @param params.filter UID to find
221
+ * @param [params.offset]
222
+ * @param [params.limit]
223
+ * @see {@link https://ampache.org/api/api-json-methods#get_similar}
224
+ */
225
+ getSimilar(
226
+ params: {
227
+ type: "song" | "artist";
228
+ filter: UID;
229
+ } & Pagination,
230
+ ) {
231
+ let query = "get_similar";
232
+ query += qs.stringify(params, "&");
233
+ let data;
234
+
235
+ switch (params.type) {
236
+ case "song":
237
+ data = this.request<SongsResponse>(query);
238
+ break;
239
+ case "artist":
240
+ data = this.request<ArtistsResponse>(query);
241
+ break;
242
+ default:
243
+ return false;
244
+ }
245
+
246
+ return data;
247
+ }
248
+
249
+ /**
250
+ * Get some items based on some simple search types and filters. (Random by default)
251
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400001
252
+ * @param params.type Object type
253
+ * @param [params.filter] newest, highest, frequent, recent, forgotten, flagged, random
254
+ * @param [params.user_id] Filter results to a certain user by UID
255
+ * @param [params.username] Filter results to a certain user by username
256
+ * @param [params.offset]
257
+ * @param [params.limit]
258
+ * @see {@link https://ampache.org/api/api-json-methods#stats}
259
+ */
260
+ stats(
261
+ params: {
262
+ type:
263
+ | "song"
264
+ | "album"
265
+ | "artist"
266
+ | "video"
267
+ | "playlist"
268
+ | "podcast"
269
+ | "podcast_episode";
270
+ filter?:
271
+ | "newest"
272
+ | "highest"
273
+ | "frequent"
274
+ | "recent"
275
+ | "forgotten"
276
+ | "flagged"
277
+ | "random";
278
+ user_id?: number;
279
+ username?: string;
280
+ } & Pagination,
281
+ ) {
282
+ let query = "stats";
283
+ query += qs.stringify(params, "&");
284
+ let data;
285
+
286
+ switch (params.type) {
287
+ case "song":
288
+ data = this.request<SongsResponse>(query);
289
+ break;
290
+ case "album":
291
+ data = this.request<AlbumsResponse>(query);
292
+ break;
293
+ case "artist":
294
+ data = this.request<ArtistsResponse>(query);
295
+ break;
296
+ case "video":
297
+ data = this.request<VideosResponse>(query);
298
+ break;
299
+ case "playlist":
300
+ data = this.request<PlaylistsResponse>(query);
301
+ break;
302
+ case "podcast":
303
+ data = this.request<PodcastsResponse>(query);
304
+ break;
305
+ case "podcast_episode":
306
+ data = this.request<PodcastEpisodesResponse>(query);
307
+ break;
308
+ default:
309
+ return false;
310
+ }
311
+
312
+ return data;
313
+ }
314
+
315
+ /**
316
+ * This rates a library item
317
+ * @remarks MINIMUM_API_VERSION=380001
318
+ * @param params.type Object type
319
+ * @param params.id UID to find
320
+ * @param params.rating Rating to apply
321
+ * @see {@link https://ampache.org/api/api-json-methods#rate}
322
+ */
323
+ rate(params: {
324
+ type:
325
+ | "song"
326
+ | "album"
327
+ | "artist"
328
+ | "playlist"
329
+ | "podcast"
330
+ | "podcast_episode"
331
+ | "video"
332
+ | "tvshow"
333
+ | "tvshow_season";
334
+ id: UID;
335
+ rating: 0 | 1 | 2 | 3 | 4 | 5;
336
+ }) {
337
+ let query = "rate";
338
+ query += qs.stringify(params, "&");
339
+ return this.request<Success>(query);
340
+ }
341
+
342
+ /**
343
+ * This flags a library item as a favorite
344
+ * @remarks MINIMUM_API_VERSION=400001
345
+ * @param params.type Object type
346
+ * @param params.id UID to find
347
+ * @param params.flag 0, 1
348
+ * @see {@link https://ampache.org/api/api-json-methods#flag}
349
+ */
350
+ flag(params: {
351
+ type:
352
+ | "song"
353
+ | "album"
354
+ | "artist"
355
+ | "playlist"
356
+ | "podcast"
357
+ | "podcast_episode"
358
+ | "video"
359
+ | "tvshow"
360
+ | "tvshow_season";
361
+ id: UID;
362
+ flag: BinaryBoolean;
363
+ }) {
364
+ let query = "flag";
365
+ query += qs.stringify(params, "&");
366
+ return this.request<Success>(query);
367
+ }
368
+
369
+ /**
370
+ * Take a song_id and update the object_count and user_activity table with a play. This allows other sources to record play history to Ampache.
371
+ * If you don't supply a user id (optional) then just fall back to you.
372
+ * ACCESS REQUIRED: 100 (Admin) permission to change another user's play history
373
+ * @remarks MINIMUM_API_VERSION=400001
374
+ * @param params.id UID of song
375
+ * @param [params.user] UID of user
376
+ * @param [params.client] Client string
377
+ * @param [params.date] UNIXTIME
378
+ * @see {@link https://ampache.org/api/api-json-methods#record_play}
379
+ */
380
+ recordPlay(params: { id: UID; user?: UID; client?: string; date?: number }) {
381
+ let query = "record_play";
382
+ query += qs.stringify(params, "&");
383
+ return this.request<Success>(query);
384
+ }
385
+
386
+ /**
387
+ * Search for a song using text info and then record a play if found. This allows other sources to record play history to ampache
388
+ * @remarks MINIMUM_API_VERSION=400001
389
+ * @param params.song HTML encoded string
390
+ * @param params.artist HTML encoded string
391
+ * @param params.album HTML encoded string
392
+ * @param [params.songmbid] Song MBID
393
+ * @param [params.artistmbid] Artist MBID
394
+ * @param [params.albummbid] Album MBID
395
+ * @param [params.song_mbid] Alias of songmbid
396
+ * @param [params.artist_mbid] Alias of artistmbid
397
+ * @param [params.album_mbid] Alias of albummbid
398
+ * @param [params.date] UNIXTIME
399
+ * @param [params.client] Client string
400
+ * @see {@link https://ampache.org/api/api-json-methods#scrobble}
401
+ */
402
+ scrobble(params: {
403
+ song: string;
404
+ artist: string;
405
+ album: string;
406
+ songmbid?: string;
407
+ artistmbid?: string;
408
+ albummbid?: string;
409
+ song_mbid?: string;
410
+ artist_mbid?: string;
411
+ album_mbid?: string;
412
+ date?: number;
413
+ client?: string;
414
+ }) {
415
+ let query = "scrobble";
416
+ query += qs.stringify(params, "&");
417
+ return this.request<Success>(query);
418
+ }
419
+
420
+ /**
421
+ * Update a single album, artist, song from the tag data
422
+ * @remarks MINIMUM_API_VERSION=400001
423
+ * @param params.type Object type
424
+ * @param params.id UID to find
425
+ * @see {@link https://ampache.org/api/api-json-methods#update_from_tags}
426
+ */
427
+ updateFromTags(params: { type: "song" | "artist" | "album"; id: UID }) {
428
+ let query = "update_from_tags";
429
+ query += qs.stringify(params, "&");
430
+ return this.request<Success>(query);
431
+ }
432
+
433
+ /**
434
+ * Update artist information and fetch similar artists from last.fm
435
+ * Make sure lastfm_API_key is set in your configuration file
436
+ * ACCESS REQUIRED: 75 (Catalog Manager)
437
+ * @remarks MINIMUM_API_VERSION=400001
438
+ * @param params.id UID to find
439
+ * @see {@link https://ampache.org/api/api-json-methods#update_artist_info}
440
+ */
441
+ updateArtistInfo(params: { id: UID }) {
442
+ let query = "update_artist_info";
443
+ query += qs.stringify(params, "&");
444
+ return this.request<Success>(query);
445
+ }
446
+
447
+ /**
448
+ * Updates a single album, artist, song running the gather_art process.
449
+ * Doesn't overwrite existing art by default.
450
+ * ACCESS REQUIRED: 75 (Catalog Manager)
451
+ * @remarks MINIMUM_API_VERSION=400001
452
+ * @param params.id UID to update
453
+ * @param params.type Object type
454
+ * @param [params.overwrite]
455
+ * @see {@link https://ampache.org/api/api-json-methods#update_art}
456
+ */
457
+ updateArt(params: {
458
+ id: UID;
459
+ type: "artist" | "album" | "song";
460
+ overwrite?: BinaryBoolean;
461
+ }) {
462
+ let query = "update_art";
463
+ query += qs.stringify(params, "&");
464
+ return this.request<Success>(query);
465
+ }
466
+
467
+ /**
468
+ * Streams a given media file. Takes the file id in parameter with optional max bit rate, file format, time offset,
469
+ * size and estimate content length option.
470
+ * NOTE search and playlist will only stream a random object from the list.
471
+ * @remarks MINIMUM_API_VERSION=400001
472
+ * @param params.id UID to find
473
+ * @param params.type Object type
474
+ * @param [params.bitrate] Max bitrate for transcoding
475
+ * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
476
+ * @param [params.offset] Time offset
477
+ * @param [params.length] 0, 1 (estimate content length)
478
+ * @see {@link https://ampache.org/api/api-json-methods#stream}
479
+ */
480
+ stream(params: {
481
+ id: UID;
482
+ type: "song" | "podcast_episode" | "search" | "playlist";
483
+ bitrate?: number;
484
+ format?: string;
485
+ offset?: number;
486
+ length?: BinaryBoolean;
487
+ }) {
488
+ let query = "stream";
489
+ query += qs.stringify(params, "&");
490
+ return this.binary(query);
491
+ }
492
+
493
+ /**
494
+ * Downloads a given media file. set format=raw to download the full file
495
+ * NOTE search and playlist will only download a random object from the list
496
+ * @remarks MINIMUM_API_VERSION=400001
497
+ * @param params.id UID to find
498
+ * @param params.type Object type
499
+ * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
500
+ * @see {@link https://ampache.org/api/api-json-methods#download}
501
+ */
502
+ download(params: {
503
+ id: UID;
504
+ type: "song" | "podcast_episode" | "search" | "playlist";
505
+ format?: string;
506
+ }) {
507
+ let query = "download";
508
+ query += qs.stringify(params, "&");
509
+ return this.binary(query);
510
+ }
511
+
512
+ /**
513
+ * Get an art image file.
514
+ * @remarks MINIMUM_API_VERSION=400001
515
+ * @param params.id UID to find
516
+ * @param params.type Object type
517
+ * @see {@link https://ampache.org/api/api-json-methods#get_art}
518
+ */
519
+ getArt(params: {
520
+ id: UID;
521
+ type: "song" | "artist" | "album" | "playlist" | "search" | "podcast";
522
+ }) {
523
+ let query = "get_art";
524
+ query += qs.stringify(params, "&");
525
+ return this.binary(query);
526
+ }
527
+
528
+ /**
529
+ * This is for controlling localplay
530
+ * @param params.command The command to send to the localplay controller
531
+ * @param [params.oid] Object UID
532
+ * @param [params.type] Object type
533
+ * @param [params.clear] 0, 1 (Clear the current playlist before adding)
534
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=5.0.0
535
+ * @see {@link https://ampache.org/api/api-json-methods#localplay}
536
+ */
537
+ localplay(params: {
538
+ command:
539
+ | "next"
540
+ | "prev"
541
+ | "stop"
542
+ | "play"
543
+ | "pause"
544
+ | "add"
545
+ | "volume_up"
546
+ | "volume_down"
547
+ | "volume_mute"
548
+ | "delete_all"
549
+ | "skip"
550
+ | "status";
551
+ oid?: number;
552
+ type?:
553
+ | "song"
554
+ | "video"
555
+ | "podcast_episode"
556
+ | "channel"
557
+ | "broadcast"
558
+ | "democratic"
559
+ | "live_stream";
560
+ clear?: BinaryBoolean;
561
+ }) {
562
+ let query = "localplay";
563
+ query += qs.stringify(params, "&");
564
+ return this.request(query);
565
+ }
566
+
567
+ /**
568
+ * Get the list of songs in your localplay playlist
569
+ * @remarks MINIMUM_API_VERSION=5.0.0
570
+ * @see {@link https://ampache.org/api/api-json-methods#localplay_songs}
571
+ */
572
+ localplaySongs() {
573
+ let query = "localplay_songs";
574
+ return this.request(query);
575
+ }
576
+
577
+ /**
578
+ * This is for controlling democratic play (Songs only). VOTE: +1 vote for the oid. DEVOTE: -1 vote for the oid.
579
+ * PLAYLIST: Return an array of song items with an additional VOTE COUNT element.
580
+ * PLAY: Returns the URL for playing democratic play.
581
+ * @remarks MINIMUM_API_VERSION=380001
582
+ * @param params.oid UID of song
583
+ * @param params.method vote, devote, playlist, play
584
+ * @see {@link https://ampache.org/api/api-json-methods#democratic}
585
+ */
586
+ democratic(params: {
587
+ oid: UID;
588
+ method: "vote" | "devote" | "playlist" | "play";
589
+ }) {
590
+ let query = "democratic";
591
+ query += qs.stringify(params, "&");
592
+ return this.request(query);
593
+ }
594
+
595
+ /**
596
+ * Perform an advanced search given passed rules.
597
+ * You'll want to consult the docs for this.
598
+ * @remarks MINIMUM_API_VERSION=380001
599
+ * @param params.operator and, or (whether to match one rule or all)
600
+ * @param params.type Object type to return
601
+ * @param params.rules An array of rules
602
+ * @param [params.random] 0, 1 (random order of results; default to 0)
603
+ * @param [params.offset]
604
+ * @param [params.limit]
605
+ * @see {@link https://ampache.org/api/api-json-methods#advanced_search}
606
+ */
607
+ advancedSearch(
608
+ params: {
609
+ operator: "and" | "or";
610
+ type:
611
+ | "song"
612
+ | "album"
613
+ | "album_disk"
614
+ | "artist"
615
+ | "album_artist"
616
+ | "song_artist"
617
+ | "label"
618
+ | "playlist"
619
+ | "podcast"
620
+ | "podcast_episode"
621
+ | "genre"
622
+ | "user"
623
+ | "video";
624
+ rules: Array<Array<string>>;
625
+ random?: BinaryBoolean;
626
+ } & Pagination,
627
+ ) {
628
+ let query = "advanced_search";
629
+
630
+ for (let i = 0; i < params.rules.length; i++) {
631
+ const thisRule = params.rules[i];
632
+ const ruleNumber = i + 1;
633
+
634
+ params["rule_" + ruleNumber] = thisRule[0];
635
+ params["rule_" + ruleNumber + "_operator"] = thisRule[1];
636
+ params["rule_" + ruleNumber + "_input"] = thisRule[2];
637
+
638
+ if (thisRule[0] === "metadata") {
639
+ params["rule_" + ruleNumber + "_subtype"] = thisRule[3];
640
+ }
641
+ }
642
+
643
+ // drop the initial 'rules' as it was split into its parts
644
+ delete params.rules;
645
+
646
+ query += qs.stringify(params, "&");
647
+
648
+ let data;
649
+
650
+ switch (params.type) {
651
+ case "song":
652
+ data = this.request<SongsResponse>(query);
653
+ break;
654
+ case "album":
655
+ data = this.request<AlbumsResponse>(query);
656
+ break;
657
+ case "artist":
658
+ case "album_artist":
659
+ case "song_artist":
660
+ data = this.request<ArtistsResponse>(query);
661
+ break;
662
+ case "label":
663
+ data = this.request<LabelsResponse>(query);
664
+ break;
665
+ case "playlist":
666
+ data = this.request<PlaylistsResponse>(query);
667
+ break;
668
+ case "podcast":
669
+ data = this.request<PodcastsResponse>(query);
670
+ break;
671
+ case "podcast_episode":
672
+ data = this.request<PodcastEpisodesResponse>(query);
673
+ break;
674
+ case "genre":
675
+ data = this.request<GenresResponse>(query);
676
+ break;
677
+ case "user":
678
+ data = this.request<UsersResponse>(query);
679
+ break;
680
+ case "video":
681
+ data = this.request<VideosResponse>(query);
682
+ break;
683
+ default:
684
+ return false;
685
+ }
686
+
687
+ return data;
688
+ }
689
+ }