javascript-ampache 1.1.3 → 1.1.5

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.
@@ -1,689 +1,843 @@
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
- }
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
+ PodcastsResponse,
17
+ PodcastEpisodesResponse,
18
+ PodcastResponse,
19
+ PodcastEpisodeResponse,
20
+ } from "../podcasts/types";
21
+ import { 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, NowPlayingResponse } from "./types";
26
+
27
+ export class System extends Base {
28
+ /**
29
+ * Check Ampache for updates and run the update if there is one.
30
+ * @remarks MINIMUM_API_VERSION=5.0.0
31
+ * @see {@link https://ampache.org/api/api-json-methods#system_update}
32
+ */
33
+ systemUpdate() {
34
+ let query = "system_update";
35
+ return this.request<Success>(query);
36
+ }
37
+
38
+ /**
39
+ * This takes a collection of inputs and returns ID + name for the object type
40
+ * @remarks MINIMUM_API_VERSION=400001
41
+ * @param params.type type of object to find
42
+ * @param [params.filter] search the name of the object_type
43
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
44
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
45
+ * @param [params.include] 0, 1 (include songs in a playlist or episodes in a podcast)
46
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
47
+ * @param [params.offset]
48
+ * @param [params.limit]
49
+ * @param [params.cond]
50
+ * @param [params.sort]
51
+ * @see {@link https://ampache.org/api/api-json-methods#get_indexes}
52
+ * @deprecated Being removed in 7.0.0. Use `list` instead.
53
+ */
54
+ getIndexes(
55
+ params: {
56
+ type:
57
+ | "song"
58
+ | "album"
59
+ | "artist"
60
+ | "album_artist"
61
+ | "playlist"
62
+ | "podcast"
63
+ | "podcast_episode"
64
+ | "live_stream"
65
+ | "catalog"
66
+ | "song_artist";
67
+ filter?: string;
68
+ add?: Date;
69
+ update?: Date;
70
+ include?: BinaryBoolean;
71
+ hide_search?: BinaryBoolean;
72
+ } & ExtendedPagination,
73
+ ) {
74
+ let query = "get_indexes";
75
+ query += qs.stringify(params, "&");
76
+ let data;
77
+
78
+ switch (params.type) {
79
+ case "song":
80
+ data = this.request<SongsResponse>(query);
81
+ break;
82
+ case "album":
83
+ data = this.request<AlbumsResponse>(query);
84
+ break;
85
+ case "artist":
86
+ case "album_artist":
87
+ data = this.request<ArtistsResponse>(query);
88
+ break;
89
+ case "playlist":
90
+ data = this.request<PlaylistsResponse>(query);
91
+ break;
92
+ case "podcast":
93
+ data = this.request<PodcastsResponse>(query);
94
+ break;
95
+ case "podcast_episode":
96
+ data = this.request<PodcastEpisodesResponse>(query);
97
+ break;
98
+ case "live_stream":
99
+ data = this.request<LiveStreamsResponse>(query);
100
+ break;
101
+ default:
102
+ return false;
103
+ }
104
+
105
+ return data;
106
+ }
107
+
108
+ /**
109
+ * This takes a named array of objects and returning `id`, `name`, `prefix` and `basename`
110
+ * @remarks MINIMUM_API_VERSION=6.0.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.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
114
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
115
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
116
+ * @param [params.offset]
117
+ * @param [params.limit]
118
+ * @param [params.cond]
119
+ * @param [params.sort]
120
+ * @see {@link https://ampache.org/api/api-json-methods#list}
121
+ */
122
+ list(
123
+ params: {
124
+ type:
125
+ | "song"
126
+ | "album"
127
+ | "artist"
128
+ | "album_artist"
129
+ | "playlist"
130
+ | "podcast"
131
+ | "podcast_episode"
132
+ | "live_stream"
133
+ | "catalog"
134
+ | "song_artist";
135
+ filter?: string;
136
+ add?: Date;
137
+ update?: Date;
138
+ hide_search?: BinaryBoolean;
139
+ } & ExtendedPagination,
140
+ ) {
141
+ let query = "list";
142
+ query += qs.stringify(params, "&");
143
+ return this.request<{ list: IndexEntry[] }>(query);
144
+ }
145
+
146
+ /**
147
+ * This takes a collection of inputs and return ID's for the object type.
148
+ * @remarks MINIMUM_API_VERSION=6.3.0
149
+ * @param params.type type of object to find
150
+ * @param [params.filter] Value is Alpha Match for returned results, may be more than one letter/number
151
+ * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
152
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
153
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
154
+ * @param [params.include] 0, 1, (include child objects)
155
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
156
+ * @param [params.offset]
157
+ * @param [params.limit]
158
+ * @param [params.cond]
159
+ * @param [params.sort]
160
+ * @see {@link https://ampache.org/api/api-json-methods#index}
161
+ */
162
+ index(
163
+ params: {
164
+ type:
165
+ | "catalog"
166
+ | "song"
167
+ | "album"
168
+ | "artist"
169
+ | "album_artist"
170
+ | "song_artist"
171
+ | "playlist"
172
+ | "podcast"
173
+ | "podcast_episode"
174
+ | "share"
175
+ | "video"
176
+ | "live_stream";
177
+ filter?: string;
178
+ exact?: BinaryBoolean;
179
+ add?: Date;
180
+ update?: Date;
181
+ include?: BinaryBoolean;
182
+ hide_search?: BinaryBoolean;
183
+ } & ExtendedPagination,
184
+ ) {
185
+ let query = "index";
186
+ query += qs.stringify(params, "&");
187
+ return this.request<{ index: [] }>(query);
188
+ }
189
+
190
+ /**
191
+ * Return children of a parent object in a folder traversal/browse style
192
+ * If you don't send any parameters you'll get a catalog list (the 'root' path)
193
+ * @remarks MINIMUM_API_VERSION=6.0.0
194
+ * @param [params.filter] object_id
195
+ * @param [params.type] type of object to find
196
+ * @param [params.catalog] catalog ID you are browsing (required on 'artist', 'album', 'podcast')
197
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
198
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
199
+ * @param [params.offset]
200
+ * @param [params.limit]
201
+ * @param [params.cond]
202
+ * @param [params.sort]
203
+ * @see {@link https://ampache.org/api/api-json-methods#browse}
204
+ */
205
+ browse(
206
+ params: {
207
+ filter?: UID;
208
+ type?: "root" | "catalog" | "artist" | "album" | "podcast";
209
+ catalog?: number;
210
+ add?: Date;
211
+ update?: Date;
212
+ } & ExtendedPagination,
213
+ ) {
214
+ let query = "browse";
215
+ query += qs.stringify(params, "&");
216
+ return this.request<{ browse: IndexEntry[] }>(query);
217
+ }
218
+
219
+ /**
220
+ * Return similar artist IDs or similar song IDs compared to the input filter
221
+ * @remarks MINIMUM_API_VERSION=420000
222
+ * @param params.type type of object to check against
223
+ * @param params.filter UID to find
224
+ * @param [params.offset]
225
+ * @param [params.limit]
226
+ * @see {@link https://ampache.org/api/api-json-methods#get_similar}
227
+ */
228
+ getSimilar(
229
+ params: {
230
+ type: "song" | "artist";
231
+ filter: UID;
232
+ } & Pagination,
233
+ ) {
234
+ let query = "get_similar";
235
+ query += qs.stringify(params, "&");
236
+ let data;
237
+
238
+ switch (params.type) {
239
+ case "song":
240
+ data = this.request<SongsResponse>(query);
241
+ break;
242
+ case "artist":
243
+ data = this.request<ArtistsResponse>(query);
244
+ break;
245
+ default:
246
+ return false;
247
+ }
248
+
249
+ return data;
250
+ }
251
+
252
+ /**
253
+ * Get some items based on some simple search types and filters. (Random by default)
254
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400001
255
+ * @param params.type Object type
256
+ * @param [params.filter] newest, highest, frequent, recent, forgotten, flagged, random
257
+ * @param [params.user_id] Filter results to a certain user by UID
258
+ * @param [params.username] Filter results to a certain user by username
259
+ * @param [params.offset]
260
+ * @param [params.limit]
261
+ * @see {@link https://ampache.org/api/api-json-methods#stats}
262
+ */
263
+ stats(
264
+ params: {
265
+ type:
266
+ | "song"
267
+ | "album"
268
+ | "artist"
269
+ | "video"
270
+ | "playlist"
271
+ | "podcast"
272
+ | "podcast_episode";
273
+ filter?:
274
+ | "newest"
275
+ | "highest"
276
+ | "frequent"
277
+ | "recent"
278
+ | "forgotten"
279
+ | "flagged"
280
+ | "random";
281
+ user_id?: number;
282
+ username?: string;
283
+ } & Pagination,
284
+ ) {
285
+ let query = "stats";
286
+ query += qs.stringify(params, "&");
287
+ let data;
288
+
289
+ switch (params.type) {
290
+ case "song":
291
+ data = this.request<SongsResponse>(query);
292
+ break;
293
+ case "album":
294
+ data = this.request<AlbumsResponse>(query);
295
+ break;
296
+ case "artist":
297
+ data = this.request<ArtistsResponse>(query);
298
+ break;
299
+ case "video":
300
+ data = this.request<VideosResponse>(query);
301
+ break;
302
+ case "playlist":
303
+ data = this.request<PlaylistsResponse>(query);
304
+ break;
305
+ case "podcast":
306
+ data = this.request<PodcastsResponse>(query);
307
+ break;
308
+ case "podcast_episode":
309
+ data = this.request<PodcastEpisodesResponse>(query);
310
+ break;
311
+ default:
312
+ return false;
313
+ }
314
+
315
+ return data;
316
+ }
317
+
318
+ /**
319
+ * This rates a library item
320
+ * @remarks MINIMUM_API_VERSION=380001
321
+ * @param params.type Object type
322
+ * @param params.id UID to find
323
+ * @param params.rating Rating to apply
324
+ * @see {@link https://ampache.org/api/api-json-methods#rate}
325
+ */
326
+ rate(params: {
327
+ type:
328
+ | "song"
329
+ | "album"
330
+ | "artist"
331
+ | "playlist"
332
+ | "podcast"
333
+ | "podcast_episode"
334
+ | "video"
335
+ | "tvshow"
336
+ | "tvshow_season";
337
+ id: UID;
338
+ rating: 0 | 1 | 2 | 3 | 4 | 5;
339
+ }) {
340
+ let query = "rate";
341
+ query += qs.stringify(params, "&");
342
+ return this.request<Success>(query);
343
+ }
344
+
345
+ /**
346
+ * This flags a library item as a favorite
347
+ * @remarks MINIMUM_API_VERSION=400001
348
+ * @param params.type Object type
349
+ * @param params.id UID to find
350
+ * @param params.flag 0, 1
351
+ * @param [params.date] UNIXTIME
352
+ * @see {@link https://ampache.org/api/api-json-methods#flag}
353
+ */
354
+ flag(params: {
355
+ type:
356
+ | "song"
357
+ | "album"
358
+ | "artist"
359
+ | "playlist"
360
+ | "podcast"
361
+ | "podcast_episode"
362
+ | "video"
363
+ | "tvshow"
364
+ | "tvshow_season";
365
+ id: UID;
366
+ flag: BinaryBoolean;
367
+ date?: number;
368
+ }) {
369
+ let query = "flag";
370
+ query += qs.stringify(params, "&");
371
+ return this.request<Success>(query);
372
+ }
373
+
374
+ /**
375
+ * 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.
376
+ * If you don't supply a user id (optional) then just fall back to you.
377
+ * ACCESS REQUIRED: 100 (Admin) permission to change another user's play history
378
+ * @remarks MINIMUM_API_VERSION=400001
379
+ * @param params.id UID of song
380
+ * @param [params.user] UID of user
381
+ * @param [params.client] Client string
382
+ * @param [params.date] UNIXTIME
383
+ * @see {@link https://ampache.org/api/api-json-methods#record_play}
384
+ */
385
+ recordPlay(params: { id: UID; user?: UID; client?: string; date?: number }) {
386
+ let query = "record_play";
387
+ query += qs.stringify(params, "&");
388
+ return this.request<Success>(query);
389
+ }
390
+
391
+ /**
392
+ * Search for a song using text info and then record a play if found. This allows other sources to record play history to ampache
393
+ * @remarks MINIMUM_API_VERSION=400001
394
+ * @param params.song HTML encoded string
395
+ * @param params.artist HTML encoded string
396
+ * @param params.album HTML encoded string
397
+ * @param [params.songmbid] Song MBID
398
+ * @param [params.artistmbid] Artist MBID
399
+ * @param [params.albummbid] Album MBID
400
+ * @param [params.song_mbid] Alias of songmbid
401
+ * @param [params.artist_mbid] Alias of artistmbid
402
+ * @param [params.album_mbid] Alias of albummbid
403
+ * @param [params.date] UNIXTIME
404
+ * @param [params.client] Client string
405
+ * @see {@link https://ampache.org/api/api-json-methods#scrobble}
406
+ */
407
+ scrobble(params: {
408
+ song: string;
409
+ artist: string;
410
+ album: string;
411
+ songmbid?: string;
412
+ artistmbid?: string;
413
+ albummbid?: string;
414
+ song_mbid?: string;
415
+ artist_mbid?: string;
416
+ album_mbid?: string;
417
+ date?: number;
418
+ client?: string;
419
+ }) {
420
+ let query = "scrobble";
421
+ query += qs.stringify(params, "&");
422
+ return this.request<Success>(query);
423
+ }
424
+
425
+ /**
426
+ * Update a single album, artist, song from the tag data
427
+ * @remarks MINIMUM_API_VERSION=400001
428
+ * @param params.type Object type
429
+ * @param params.id UID to find
430
+ * @see {@link https://ampache.org/api/api-json-methods#update_from_tags}
431
+ */
432
+ updateFromTags(params: { type: "song" | "artist" | "album"; id: UID }) {
433
+ let query = "update_from_tags";
434
+ query += qs.stringify(params, "&");
435
+ return this.request<Success>(query);
436
+ }
437
+
438
+ /**
439
+ * Update artist information and fetch similar artists from last.fm
440
+ * Make sure lastfm_API_key is set in your configuration file
441
+ * ACCESS REQUIRED: 75 (Catalog Manager)
442
+ * @remarks MINIMUM_API_VERSION=400001
443
+ * @param params.id UID to find
444
+ * @see {@link https://ampache.org/api/api-json-methods#update_artist_info}
445
+ */
446
+ updateArtistInfo(params: { id: UID }) {
447
+ let query = "update_artist_info";
448
+ query += qs.stringify(params, "&");
449
+ return this.request<Success>(query);
450
+ }
451
+
452
+ /**
453
+ * Updates a single album, artist, song running the gather_art process.
454
+ * Doesn't overwrite existing art by default.
455
+ * ACCESS REQUIRED: 75 (Catalog Manager)
456
+ * @remarks MINIMUM_API_VERSION=400001
457
+ * @param params.id UID to update
458
+ * @param params.type Object type
459
+ * @param [params.overwrite]
460
+ * @see {@link https://ampache.org/api/api-json-methods#update_art}
461
+ */
462
+ updateArt(params: {
463
+ id: UID;
464
+ type: "artist" | "album" | "song";
465
+ overwrite?: BinaryBoolean;
466
+ }) {
467
+ let query = "update_art";
468
+ query += qs.stringify(params, "&");
469
+ return this.request<Success>(query);
470
+ }
471
+
472
+ /**
473
+ * Streams a given media file. Takes the file id in parameter with optional max bit rate, file format, time offset,
474
+ * size and estimate content length option.
475
+ * NOTE search and playlist will only stream a random object from the list.
476
+ * @remarks MINIMUM_API_VERSION=400001
477
+ * @param params.id UID to find
478
+ * @param params.type Object type
479
+ * @param [params.bitrate] Max bitrate for transcoding
480
+ * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
481
+ * @param [params.offset] Time offset
482
+ * @param [params.length] 0, 1 (estimate content length)
483
+ * @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
484
+ * @see {@link https://ampache.org/api/api-json-methods#stream}
485
+ */
486
+ stream(params: {
487
+ id: UID;
488
+ type: "song" | "podcast_episode" | "search" | "playlist";
489
+ bitrate?: number;
490
+ format?: string;
491
+ offset?: number;
492
+ length?: BinaryBoolean;
493
+ stats?: BinaryBoolean;
494
+ }) {
495
+ let query = "stream";
496
+ query += qs.stringify(params, "&");
497
+ return this.binary(query);
498
+ }
499
+
500
+ /**
501
+ * Downloads a given media file. set format=raw to download the full file
502
+ * NOTE search and playlist will only download a random object from the list
503
+ * @remarks MINIMUM_API_VERSION=400001
504
+ * @param params.id UID to find
505
+ * @param params.type Object type
506
+ * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
507
+ * @param [params.bitrate] max bitrate for transcoding in bytes (e.g 192000=192Kb)
508
+ * @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
509
+ * @see {@link https://ampache.org/api/api-json-methods#download}
510
+ */
511
+ download(params: {
512
+ id: UID;
513
+ type: "song" | "podcast_episode" | "search" | "playlist";
514
+ format?: string;
515
+ bitrate?: number;
516
+ stats?: BinaryBoolean;
517
+ }) {
518
+ let query = "download";
519
+ query += qs.stringify(params, "&");
520
+ return this.binary(query);
521
+ }
522
+
523
+ /**
524
+ * Get an art image file.
525
+ * @remarks MINIMUM_API_VERSION=400001
526
+ * @param params.id UID to find
527
+ * @param params.type Object type
528
+ * @see {@link https://ampache.org/api/api-json-methods#get_art}
529
+ */
530
+ getArt(params: {
531
+ id: UID;
532
+ type: "song" | "artist" | "album" | "playlist" | "search" | "podcast";
533
+ }) {
534
+ let query = "get_art";
535
+ query += qs.stringify(params, "&");
536
+ return this.binary(query);
537
+ }
538
+
539
+ /**
540
+ * This is for controlling localplay
541
+ * @param params.command The command to send to the localplay controller
542
+ * @param [params.oid] Object UID
543
+ * @param [params.type] Object type
544
+ * @param [params.clear] 0, 1 (Clear the current playlist before adding)
545
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=5.0.0
546
+ * @see {@link https://ampache.org/api/api-json-methods#localplay}
547
+ */
548
+ localplay(params: {
549
+ command:
550
+ | "next"
551
+ | "prev"
552
+ | "stop"
553
+ | "play"
554
+ | "pause"
555
+ | "add"
556
+ | "volume_up"
557
+ | "volume_down"
558
+ | "volume_mute"
559
+ | "delete_all"
560
+ | "skip"
561
+ | "status";
562
+ oid?: number;
563
+ type?:
564
+ | "song"
565
+ | "video"
566
+ | "podcast_episode"
567
+ | "channel"
568
+ | "broadcast"
569
+ | "democratic"
570
+ | "live_stream";
571
+ clear?: BinaryBoolean;
572
+ }) {
573
+ let query = "localplay";
574
+ query += qs.stringify(params, "&");
575
+ return this.request(query);
576
+ }
577
+
578
+ /**
579
+ * Get the list of songs in your localplay playlist
580
+ * @remarks MINIMUM_API_VERSION=5.0.0
581
+ * @see {@link https://ampache.org/api/api-json-methods#localplay_songs}
582
+ */
583
+ localplaySongs() {
584
+ let query = "localplay_songs";
585
+ return this.request(query);
586
+ }
587
+
588
+ /**
589
+ * This is for controlling democratic play (Songs only). VOTE: +1 vote for the oid. DEVOTE: -1 vote for the oid.
590
+ * PLAYLIST: Return an array of song items with an additional VOTE COUNT element.
591
+ * PLAY: Returns the URL for playing democratic play.
592
+ * @remarks MINIMUM_API_VERSION=380001
593
+ * @param params.oid UID of song
594
+ * @param params.method vote, devote, playlist, play
595
+ * @see {@link https://ampache.org/api/api-json-methods#democratic}
596
+ */
597
+ democratic(params: {
598
+ oid: UID;
599
+ method: "vote" | "devote" | "playlist" | "play";
600
+ }) {
601
+ let query = "democratic";
602
+ query += qs.stringify(params, "&");
603
+ return this.request(query);
604
+ }
605
+
606
+ /**
607
+ * Get what is currently being played by all users.
608
+ * @remarks MINIMUM_API_VERSION=6.3.1
609
+ * @see {@link https://ampache.org/api/api-json-methods#now_playing}
610
+ */
611
+ nowPlaying() {
612
+ let query = "now_playing";
613
+ return this.request<{ now_playing: NowPlayingResponse[] }>(query);
614
+ }
615
+
616
+ /**
617
+ * Inform the server about the state of your client. (Song you are playing, Play/Pause state, etc.)
618
+ * @remarks MINIMUM_API_VERSION=6.4.0
619
+ * @param params.filter $object_id currently playing/stopping
620
+ * @param [params.type] song, video, podcast_episode (Default: song)
621
+ * @param [params.state] play, stop (Default: play)
622
+ * @param [params.time] current play time in whole seconds (Default: 0)
623
+ * @param [params.client] agent/client name
624
+ * @see {@link https://ampache.org/api/api-json-methods#player}
625
+ */
626
+ player(params: {
627
+ filter: UID;
628
+ type?: "song" | "video" | "podcast_episode";
629
+ state?: "play" | "stop";
630
+ time?: number;
631
+ client?: string;
632
+ }) {
633
+ let query = "player";
634
+ query += qs.stringify(params, "&");
635
+ return this.request<{ now_playing: NowPlayingResponse[] }>(query);
636
+ }
637
+
638
+ /**
639
+ * Perform an advanced search given passed rules.
640
+ * You'll want to consult the docs for this.
641
+ * @remarks MINIMUM_API_VERSION=380001
642
+ * @param params.operator and, or (whether to match one rule or all)
643
+ * @param params.type Object type to return
644
+ * @param params.rules An array of rules
645
+ * @param [params.random] 0, 1 (random order of results; default to 0)
646
+ * @param [params.offset]
647
+ * @param [params.limit]
648
+ * @see {@link https://ampache.org/api/api-json-methods#advanced_search}
649
+ */
650
+ advancedSearch(
651
+ params: {
652
+ operator: "and" | "or";
653
+ type:
654
+ | "song"
655
+ | "album"
656
+ | "album_disk"
657
+ | "artist"
658
+ | "album_artist"
659
+ | "song_artist"
660
+ | "label"
661
+ | "playlist"
662
+ | "podcast"
663
+ | "podcast_episode"
664
+ | "genre"
665
+ | "user"
666
+ | "video";
667
+ rules: Array<Array<string>>;
668
+ random?: BinaryBoolean;
669
+ } & Pagination,
670
+ ) {
671
+ let query = "advanced_search";
672
+
673
+ for (let i = 0; i < params.rules.length; i++) {
674
+ const thisRule = params.rules[i];
675
+ const ruleNumber = i + 1;
676
+
677
+ params["rule_" + ruleNumber] = thisRule[0];
678
+ params["rule_" + ruleNumber + "_operator"] = thisRule[1];
679
+ params["rule_" + ruleNumber + "_input"] = thisRule[2];
680
+
681
+ if (thisRule[0] === "metadata") {
682
+ params["rule_" + ruleNumber + "_subtype"] = thisRule[3];
683
+ }
684
+ }
685
+
686
+ // drop the initial 'rules' as it was split into its parts
687
+ delete params.rules;
688
+
689
+ query += qs.stringify(params, "&");
690
+
691
+ let data;
692
+
693
+ switch (params.type) {
694
+ case "song":
695
+ data = this.request<SongsResponse>(query);
696
+ break;
697
+ case "album":
698
+ data = this.request<AlbumsResponse>(query);
699
+ break;
700
+ case "artist":
701
+ case "album_artist":
702
+ case "song_artist":
703
+ data = this.request<ArtistsResponse>(query);
704
+ break;
705
+ case "label":
706
+ data = this.request<LabelsResponse>(query);
707
+ break;
708
+ case "playlist":
709
+ data = this.request<PlaylistsResponse>(query);
710
+ break;
711
+ case "podcast":
712
+ data = this.request<PodcastsResponse>(query);
713
+ break;
714
+ case "podcast_episode":
715
+ data = this.request<PodcastEpisodesResponse>(query);
716
+ break;
717
+ case "genre":
718
+ data = this.request<GenresResponse>(query);
719
+ break;
720
+ case "user":
721
+ data = this.request<UsersResponse>(query);
722
+ break;
723
+ case "video":
724
+ data = this.request<VideosResponse>(query);
725
+ break;
726
+ default:
727
+ return false;
728
+ }
729
+
730
+ return data;
731
+ }
732
+
733
+ // alias of advanced_search
734
+ search = this.advancedSearch;
735
+
736
+ /**
737
+ * Perform a search given passed rules and return matching objects in a group.
738
+ * If the rules do not exist for the object type or would return the entire table they will not return objects
739
+ * You'll want to consult the docs for this.
740
+ * @remarks MINIMUM_API_VERSION=6.3.0
741
+ * @param params.operator and, or (whether to match one rule or all)
742
+ * @param params.rules An array of rules
743
+ * @param [params.type] Object type to return (all, music, song_artist, album_artist, podcast, video; all by default)
744
+ * @param [params.random] 0, 1 (random order of results; default to 0)
745
+ * @param [params.offset]
746
+ * @param [params.limit]
747
+ * @see {@link https://ampache.org/api/api-json-methods#search_group}
748
+ */
749
+ searchGroup(
750
+ params: {
751
+ operator: "and" | "or";
752
+ rules: Array<Array<string>>;
753
+ type?:
754
+ | "all"
755
+ | "music"
756
+ | "song_artist"
757
+ | "album_artist"
758
+ | "podcast"
759
+ | "video";
760
+ random?: BinaryBoolean;
761
+ } & Pagination,
762
+ ) {
763
+ let query = "search_group";
764
+
765
+ for (let i = 0; i < params.rules.length; i++) {
766
+ const thisRule = params.rules[i];
767
+ const ruleNumber = i + 1;
768
+
769
+ params["rule_" + ruleNumber] = thisRule[0];
770
+ params["rule_" + ruleNumber + "_operator"] = thisRule[1];
771
+ params["rule_" + ruleNumber + "_input"] = thisRule[2];
772
+
773
+ if (thisRule[0] === "metadata") {
774
+ params["rule_" + ruleNumber + "_subtype"] = thisRule[3];
775
+ }
776
+ }
777
+
778
+ // drop the initial 'rules' as it was split into its parts
779
+ delete params.rules;
780
+
781
+ query += qs.stringify(params, "&");
782
+
783
+ let data;
784
+
785
+ switch (params.type) {
786
+ case "music":
787
+ data = this.request<{ search: {
788
+ song: SongResponse[];
789
+ album: AlbumResponse[];
790
+ artist: ArtistResponse[];
791
+ }
792
+ }>(query);
793
+ break;
794
+ case "song_artist":
795
+ data = this.request<{ search: {
796
+ song: SongResponse[];
797
+ album: AlbumResponse[];
798
+ song_artist: ArtistResponse[];
799
+ }
800
+ }>(query);
801
+ break;
802
+ case "album_artist":
803
+ data = this.request<{ search: {
804
+ song: SongResponse[];
805
+ album: AlbumResponse[];
806
+ album_artist: ArtistResponse[];
807
+ }
808
+ }>(query);
809
+ break;
810
+ case "podcast":
811
+ data = this.request<{ search: {
812
+ podcast: PodcastResponse[];
813
+ podcast_episode: PodcastEpisodeResponse[];
814
+ }
815
+ }>(query);
816
+ break;
817
+ case "video":
818
+ data = this.request<{ search: {
819
+ video: VideoResponse[];
820
+ }
821
+ }>(query);
822
+ break;
823
+ case "all":
824
+ default:
825
+ data = this.request<{ search: {
826
+ song: SongResponse[];
827
+ album: AlbumResponse[];
828
+ artist: ArtistResponse[];
829
+ song_artist: ArtistResponse[];
830
+ album_artist: ArtistResponse[];
831
+ label: LabelResponse[];
832
+ playlist: PlaylistResponse[];
833
+ podcast: PodcastResponse[];
834
+ podcast_episode: PodcastEpisodeResponse[];
835
+ genre: GenreResponse[];
836
+ user: UserResponse[];
837
+ }
838
+ }>(query);
839
+ }
840
+
841
+ return data;
842
+ }
843
+ }