javascript-ampache 1.1.10 → 2.0.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 (108) hide show
  1. package/README.md +16 -6
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.m.js +1 -1
  5. package/dist/index.m.js.map +1 -1
  6. package/dist/index.modern.mjs +1 -1
  7. package/dist/index.modern.mjs.map +1 -1
  8. package/dist/index.umd.js +1 -1
  9. package/dist/index.umd.js.map +1 -1
  10. package/package.json +8 -7
  11. package/src/albums.js +106 -0
  12. package/src/artists.js +105 -0
  13. package/src/auth.js +142 -0
  14. package/src/base.js +145 -0
  15. package/src/bookmarks.js +106 -0
  16. package/src/catalogs.js +133 -0
  17. package/src/genres.js +57 -0
  18. package/src/index.js +30 -0
  19. package/src/labels.js +53 -0
  20. package/src/licenses.js +47 -0
  21. package/src/live-streams.js +97 -0
  22. package/src/playlists.js +241 -0
  23. package/src/podcasts.js +230 -0
  24. package/src/preferences.js +114 -0
  25. package/src/shares.js +99 -0
  26. package/src/shouts.js +24 -0
  27. package/src/songs.js +273 -0
  28. package/src/system.js +510 -0
  29. package/src/users.js +224 -0
  30. package/src/{utils.ts → utils.js} +16 -16
  31. package/src/videos.js +84 -0
  32. package/dist/albums/index.d.ts +0 -64
  33. package/dist/albums/types.d.ts +0 -37
  34. package/dist/artists/index.d.ts +0 -64
  35. package/dist/artists/types.d.ts +0 -35
  36. package/dist/auth/index.d.ts +0 -56
  37. package/dist/auth/types.d.ts +0 -32
  38. package/dist/base.d.ts +0 -47
  39. package/dist/bookmarks/index.d.ts +0 -91
  40. package/dist/bookmarks/types.d.ts +0 -13
  41. package/dist/catalogs/index.d.ts +0 -87
  42. package/dist/catalogs/types.d.ts +0 -19
  43. package/dist/genres/index.d.ts +0 -28
  44. package/dist/genres/types.d.ts +0 -22
  45. package/dist/index.d.ts +0 -24
  46. package/dist/labels/index.d.ts +0 -32
  47. package/dist/labels/types.d.ts +0 -18
  48. package/dist/licenses/index.d.ts +0 -32
  49. package/dist/licenses/types.d.ts +0 -12
  50. package/dist/live-streams/index.d.ts +0 -80
  51. package/dist/live-streams/types.d.ts +0 -14
  52. package/dist/playlists/index.d.ts +0 -204
  53. package/dist/playlists/types.d.ts +0 -26
  54. package/dist/podcasts/index.d.ts +0 -121
  55. package/dist/podcasts/types.d.ts +0 -79
  56. package/dist/preferences/index.d.ts +0 -80
  57. package/dist/preferences/types.d.ts +0 -18
  58. package/dist/shares/index.d.ts +0 -69
  59. package/dist/shares/types.d.ts +0 -23
  60. package/dist/shouts/index.d.ts +0 -17
  61. package/dist/shouts/types.d.ts +0 -10
  62. package/dist/songs/index.d.ts +0 -143
  63. package/dist/songs/types.d.ts +0 -73
  64. package/dist/system/index.d.ts +0 -407
  65. package/dist/system/types.d.ts +0 -24
  66. package/dist/users/index.d.ts +0 -190
  67. package/dist/users/types.d.ts +0 -34
  68. package/dist/utils.d.ts +0 -4
  69. package/dist/videos/index.d.ts +0 -33
  70. package/dist/videos/types.d.ts +0 -38
  71. package/src/albums/index.ts +0 -88
  72. package/src/albums/types.ts +0 -40
  73. package/src/artists/index.ts +0 -88
  74. package/src/artists/types.ts +0 -38
  75. package/src/auth/index.ts +0 -118
  76. package/src/auth/types.ts +0 -32
  77. package/src/base.ts +0 -133
  78. package/src/bookmarks/index.ts +0 -116
  79. package/src/bookmarks/types.ts +0 -15
  80. package/src/catalogs/index.ts +0 -130
  81. package/src/catalogs/types.ts +0 -27
  82. package/src/genres/index.ts +0 -39
  83. package/src/genres/types.ts +0 -25
  84. package/src/index.ts +0 -63
  85. package/src/labels/index.ts +0 -43
  86. package/src/labels/types.ts +0 -20
  87. package/src/licenses/index.ts +0 -43
  88. package/src/licenses/types.ts +0 -14
  89. package/src/live-streams/index.ts +0 -104
  90. package/src/live-streams/types.ts +0 -16
  91. package/src/playlists/index.ts +0 -280
  92. package/src/playlists/types.ts +0 -29
  93. package/src/podcasts/index.ts +0 -174
  94. package/src/podcasts/types.ts +0 -85
  95. package/src/preferences/index.ts +0 -114
  96. package/src/preferences/types.ts +0 -20
  97. package/src/shares/index.ts +0 -100
  98. package/src/shares/types.ts +0 -25
  99. package/src/shouts/index.ts +0 -18
  100. package/src/shouts/types.ts +0 -11
  101. package/src/songs/index.ts +0 -221
  102. package/src/songs/types.ts +0 -77
  103. package/src/system/index.ts +0 -845
  104. package/src/system/types.ts +0 -42
  105. package/src/users/index.ts +0 -227
  106. package/src/users/types.ts +0 -38
  107. package/src/videos/index.ts +0 -49
  108. package/src/videos/types.ts +0 -42
package/src/system.js ADDED
@@ -0,0 +1,510 @@
1
+ /**
2
+ * @typedef {import("./songs.js").SongResponse|import("./albums.js").AlbumResponse|import("./artists.js").ArtistResponse|import("./playlists.js").PlaylistResponse|import("./podcasts.js").PodcastResponse|import("./podcasts.js").PodcastEpisodeResponse|import("./live-streams.js").LiveStreamResponse} IndexType
3
+ */
4
+
5
+ /**
6
+ * @typedef {import("./songs.js").SongResponse|import("./albums.js").AlbumResponse|import("./artists.js").ArtistResponse|import("./videos.js").VideoResponse|import("./playlists.js").PlaylistResponse|import("./podcasts.js").PodcastResponse|import("./podcasts.js").PodcastEpisodeResponse} StatsType
7
+ */
8
+
9
+ /**
10
+ * @typedef {Object} IndexEntry
11
+ * @property {import("./base.js").UID} id
12
+ * @property {string} name
13
+ * @property {string} prefix
14
+ * @property {string} basename
15
+ */
16
+
17
+ /**
18
+ * @typedef {Object} NowPlayingResponse
19
+ * @property {import("./base.js").UID} id
20
+ * @property {"song"|"podcast_episode"|"video"} type
21
+ * @property {string} client
22
+ * @property {number} expire
23
+ * @property {import("./users.js").UserSummary} user
24
+ */
25
+
26
+ /**
27
+ * @typedef {Object} RuleResponse
28
+ * @property {string} name
29
+ * @property {string} label
30
+ * @property {string} type
31
+ * @property {string} title
32
+ * @property {string[]} widget
33
+ */
34
+
35
+ import qs from "querystringify";
36
+
37
+ const GET_INDEXES_TYPES = new Set([
38
+ "song",
39
+ "album",
40
+ "artist",
41
+ "album_artist",
42
+ "song_artist",
43
+ "playlist",
44
+ "podcast",
45
+ "podcast_episode",
46
+ "live_stream",
47
+ "catalog",
48
+ ]);
49
+ const GET_SIMILAR_TYPES = new Set(["song", "artist"]);
50
+ const STATS_TYPES = new Set([
51
+ "song",
52
+ "album",
53
+ "artist",
54
+ "video",
55
+ "playlist",
56
+ "podcast",
57
+ "podcast_episode",
58
+ ]);
59
+ const ADVANCED_SEARCH_TYPES = new Set([
60
+ "song",
61
+ "album",
62
+ "artist",
63
+ "album_artist",
64
+ "song_artist",
65
+ "label",
66
+ "playlist",
67
+ "podcast",
68
+ "podcast_episode",
69
+ "genre",
70
+ "user",
71
+ "video",
72
+ ]);
73
+
74
+ export const systemMethods = {
75
+ /**
76
+ * Check Ampache for updates and run the update if there is one.
77
+ * @remarks MINIMUM_API_VERSION=5.0.0
78
+ * @see {@link https://ampache.org/api/api-json-methods#system_update}
79
+ */
80
+ systemUpdate() {
81
+ return this.call("system_update");
82
+ },
83
+
84
+ /**
85
+ * This takes a collection of inputs and returns ID + name for the object type
86
+ * @remarks MINIMUM_API_VERSION=400001
87
+ * @param params.type type of object to find
88
+ * @param [params.filter] search the name of the object_type
89
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
90
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
91
+ * @param [params.include] 0, 1 (include songs in a playlist or episodes in a podcast)
92
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
93
+ * @param [params.offset]
94
+ * @param [params.limit]
95
+ * @param [params.cond]
96
+ * @param [params.sort]
97
+ * @see {@link https://ampache.org/api/api-json-methods#get_indexes}
98
+ * @deprecated Being removed in 7.0.0. Use `list` instead.
99
+ */
100
+ getIndexes(params) {
101
+ if (!GET_INDEXES_TYPES.has(params.type)) {
102
+ return false;
103
+ }
104
+ const query = "get_indexes" + qs.stringify(params, "&");
105
+ return this.request(query);
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(params) {
123
+ return this.call("list", params);
124
+ },
125
+
126
+ /**
127
+ * This takes a collection of inputs and return ID's for the object type.
128
+ * @remarks MINIMUM_API_VERSION=6.3.0
129
+ * @param params.type type of object to find
130
+ * @param [params.filter] Value is Alpha Match for returned results, may be more than one letter/number
131
+ * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
132
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
133
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
134
+ * @param [params.include] 0, 1, (include child objects)
135
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
136
+ * @param [params.offset]
137
+ * @param [params.limit]
138
+ * @param [params.cond]
139
+ * @param [params.sort]
140
+ * @see {@link https://ampache.org/api/api-json-methods#index}
141
+ */
142
+ index(params) {
143
+ return this.call("index", params);
144
+ },
145
+
146
+ /**
147
+ * Return children of a parent object in a folder traversal/browse style
148
+ * If you don't send any parameters you'll get a catalog list (the 'root' path)
149
+ * @remarks MINIMUM_API_VERSION=6.0.0
150
+ * @param [params.filter] object_id
151
+ * @param [params.type] type of object to find
152
+ * @param [params.catalog] catalog ID you are browsing (required on 'artist', 'album', 'podcast')
153
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
154
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
155
+ * @param [params.offset]
156
+ * @param [params.limit]
157
+ * @param [params.cond]
158
+ * @param [params.sort]
159
+ * @see {@link https://ampache.org/api/api-json-methods#browse}
160
+ */
161
+ browse(params) {
162
+ return this.call("browse", params);
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
+ getSimilar(params) {
175
+ if (!GET_SIMILAR_TYPES.has(params.type)) {
176
+ return false;
177
+ }
178
+ const query = "get_similar" + qs.stringify(params, "&");
179
+ return this.request(query);
180
+ },
181
+
182
+ /**
183
+ * Get some items based on some simple search types and filters. (Random by default)
184
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400001
185
+ * @param params.type Object type
186
+ * @param [params.filter] newest, highest, frequent, recent, forgotten, flagged, random
187
+ * @param [params.user_id] Filter results to a certain user by UID
188
+ * @param [params.username] Filter results to a certain user by username
189
+ * @param [params.offset]
190
+ * @param [params.limit]
191
+ * @see {@link https://ampache.org/api/api-json-methods#stats}
192
+ */
193
+ stats(params) {
194
+ if (!STATS_TYPES.has(params.type)) {
195
+ return false;
196
+ }
197
+ const query = "stats" + qs.stringify(params, "&");
198
+ return this.request(query);
199
+ },
200
+
201
+ /**
202
+ * This rates a library item
203
+ * @remarks MINIMUM_API_VERSION=380001
204
+ * @param params.type Object type
205
+ * @param params.id UID to find
206
+ * @param params.rating Rating to apply
207
+ * @see {@link https://ampache.org/api/api-json-methods#rate}
208
+ */
209
+ rate(params) {
210
+ return this.call("rate", params);
211
+ },
212
+
213
+ /**
214
+ * This flags a library item as a favorite
215
+ * @remarks MINIMUM_API_VERSION=400001
216
+ * @param params.type Object type
217
+ * @param params.id UID to find
218
+ * @param {import("./base.js").UID} [params.filter] Alias of id (Ampache 7.9.0+)
219
+ * @param params.flag 0, 1
220
+ * @see {@link https://ampache.org/api/api-json-methods#flag}
221
+ */
222
+ flag(params) {
223
+ return this.call("flag", params);
224
+ },
225
+
226
+ /**
227
+ * 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.
228
+ * If you don't supply a user id (optional) then just fall back to you.
229
+ * ACCESS REQUIRED: 100 (Admin) permission to change another user's play history
230
+ * @remarks MINIMUM_API_VERSION=400001
231
+ * @param params.id UID of song
232
+ * @param {import("./base.js").UID} [params.filter] Alias of id (Ampache 7.9.0+)
233
+ * @param [params.user] UID of user
234
+ * @param [params.client] Client string
235
+ * @param [params.date] UNIXTIME
236
+ * @see {@link https://ampache.org/api/api-json-methods#record_play}
237
+ */
238
+ recordPlay(params) {
239
+ return this.call("record_play", params);
240
+ },
241
+
242
+ /**
243
+ * Search for a song using text info and then record a play if found. This allows other sources to record play history to ampache
244
+ * @remarks MINIMUM_API_VERSION=400001
245
+ * @param params.song HTML encoded string
246
+ * @param params.artist HTML encoded string
247
+ * @param params.album HTML encoded string
248
+ * @param [params.songmbid] Song MBID
249
+ * @param [params.artistmbid] Artist MBID
250
+ * @param [params.albummbid] Album MBID
251
+ * @param [params.song_mbid] Alias of songmbid
252
+ * @param [params.artist_mbid] Alias of artistmbid
253
+ * @param [params.album_mbid] Alias of albummbid
254
+ * @param [params.date] UNIXTIME
255
+ * @param [params.client] Client string
256
+ * @see {@link https://ampache.org/api/api-json-methods#scrobble}
257
+ */
258
+ scrobble(params) {
259
+ return this.call("scrobble", params);
260
+ },
261
+
262
+ /**
263
+ * Update a single album, artist, song from the tag data
264
+ * @remarks MINIMUM_API_VERSION=400001
265
+ * @param params.type Object type
266
+ * @param params.id UID to find
267
+ * @param {import("./base.js").UID} [params.filter] Alias of id (Ampache 7.9.0+)
268
+ * @see {@link https://ampache.org/api/api-json-methods#update_from_tags}
269
+ */
270
+ updateFromTags(params) {
271
+ return this.call("update_from_tags", params);
272
+ },
273
+
274
+ /**
275
+ * Update artist information and fetch similar artists from last.fm
276
+ * Make sure lastfm_API_key is set in your configuration file
277
+ * ACCESS REQUIRED: 75 (Catalog Manager)
278
+ * @remarks MINIMUM_API_VERSION=400001
279
+ * @param params.id UID to find
280
+ * @param {import("./base.js").UID} [params.filter] Alias of id (Ampache 7.9.0+)
281
+ * @see {@link https://ampache.org/api/api-json-methods#update_artist_info}
282
+ */
283
+ updateArtistInfo(params) {
284
+ return this.call("update_artist_info", params);
285
+ },
286
+
287
+ /**
288
+ * Updates a single album, artist, song running the gather_art process.
289
+ * Doesn't overwrite existing art by default.
290
+ * ACCESS REQUIRED: 75 (Catalog Manager)
291
+ * @remarks MINIMUM_API_VERSION=400001
292
+ * @param params.id UID to update
293
+ * @param {import("./base.js").UID} [params.filter] Alias of id (Ampache 7.9.0+)
294
+ * @param params.type Object type
295
+ * @param [params.overwrite]
296
+ * @see {@link https://ampache.org/api/api-json-methods#update_art}
297
+ */
298
+ updateArt(params) {
299
+ return this.call("update_art", params);
300
+ },
301
+
302
+ /**
303
+ * Streams a given media file. Takes the file id in parameter with optional max bit rate, file format, time offset,
304
+ * size and estimate content length option.
305
+ * NOTE search and playlist will only stream a random object from the list.
306
+ * @remarks MINIMUM_API_VERSION=400001
307
+ * @param params.id UID to find
308
+ * @param {import("./base.js").UID} [params.filter] Alias of id (Ampache 7.9.0+)
309
+ * @param params.type Object type
310
+ * @param [params.bitrate] Max bitrate for transcoding
311
+ * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
312
+ * @param [params.offset] Time offset
313
+ * @param [params.length] 0, 1 (estimate content length)
314
+ * @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
315
+ * @see {@link https://ampache.org/api/api-json-methods#stream}
316
+ */
317
+ stream(params) {
318
+ const query = "stream" + (params != null ? qs.stringify(params, "&") : "");
319
+ return this.binary(query);
320
+ },
321
+
322
+ /**
323
+ * Downloads a given media file. set format=raw to download the full file
324
+ * NOTE search and playlist will only download a random object from the list
325
+ * @remarks MINIMUM_API_VERSION=400001
326
+ * @param params.id UID to find
327
+ * @param {import("./base.js").UID} [params.filter] Alias of id (Ampache 7.9.0+)
328
+ * @param params.type Object type
329
+ * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
330
+ * @param [params.bitrate] max bitrate for transcoding in bytes (e.g 192000=192Kb)
331
+ * @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
332
+ * @see {@link https://ampache.org/api/api-json-methods#download}
333
+ */
334
+ download(params) {
335
+ const query = "download" + (params != null ? qs.stringify(params, "&") : "");
336
+ return this.binary(query);
337
+ },
338
+
339
+ /**
340
+ * Get an art image file.
341
+ * @remarks MINIMUM_API_VERSION=400001
342
+ * @param params.id UID to find
343
+ * @param {import("./base.js").UID} [params.filter] Alias of id (Ampache 7.9.0+)
344
+ * @param params.type Object type
345
+ * @param [params.size] width x height (e.g. '640x480')
346
+ * @see {@link https://ampache.org/api/api-json-methods#get_art}
347
+ */
348
+ getArt(params) {
349
+ const query = "get_art" + (params != null ? qs.stringify(params, "&") : "");
350
+ return this.binary(query);
351
+ },
352
+
353
+ /**
354
+ * This is for controlling localplay
355
+ * @param params.command The command to send to the localplay controller
356
+ * @param [params.oid] Object UID
357
+ * @param {import("./base.js").UID} [params.filter] Alias of oid (Ampache 7.9.0+)
358
+ * @param [params.type] Object type
359
+ * @param [params.clear] 0, 1 (Clear the current playlist before adding)
360
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=5.0.0
361
+ * @see {@link https://ampache.org/api/api-json-methods#localplay}
362
+ */
363
+ localplay(params) {
364
+ return this.call("localplay", params);
365
+ },
366
+
367
+ /**
368
+ * Get the list of songs in your localplay playlist
369
+ * @remarks MINIMUM_API_VERSION=5.0.0
370
+ * @see {@link https://ampache.org/api/api-json-methods#localplay_songs}
371
+ */
372
+ localplaySongs() {
373
+ return this.call("localplay_songs");
374
+ },
375
+
376
+ /**
377
+ * This is for controlling democratic play (Songs only). VOTE: +1 vote for the oid. DEVOTE: -1 vote for the oid.
378
+ * PLAYLIST: Return an array of song items with an additional VOTE COUNT element.
379
+ * PLAY: Returns the URL for playing democratic play.
380
+ * @remarks MINIMUM_API_VERSION=380001
381
+ * @param params.oid UID of song
382
+ * @param params.method vote, devote, playlist, play
383
+ * @see {@link https://ampache.org/api/api-json-methods#democratic}
384
+ */
385
+ democratic(params) {
386
+ return this.call("democratic", params);
387
+ },
388
+
389
+ /**
390
+ * Get what is currently being played by all users.
391
+ * @remarks MINIMUM_API_VERSION=6.3.1
392
+ * @see {@link https://ampache.org/api/api-json-methods#now_playing}
393
+ */
394
+ nowPlaying() {
395
+ return this.call("now_playing");
396
+ },
397
+
398
+ /**
399
+ * Inform the server about the state of your client. (Song you are playing, Play/Pause state, etc.)
400
+ * @remarks MINIMUM_API_VERSION=6.4.0
401
+ * @param params.filter $object_id currently playing/stopping
402
+ * @param [params.type] song, video, podcast_episode (Default: song)
403
+ * @param [params.state] play, stop (Default: play)
404
+ * @param [params.time] current play time in whole seconds (Default: 0)
405
+ * @param [params.client] agent/client name
406
+ * @see {@link https://ampache.org/api/api-json-methods#player}
407
+ */
408
+ player(params) {
409
+ return this.call("player", params);
410
+ },
411
+
412
+ /**
413
+ * Return external plugin metadata searching by object id and type
414
+ * @remarks MINIMUM_API_VERSION=6.0.0
415
+ * @param {Object} params
416
+ * @param {import("./base.js").UID} params.filter Object id to find
417
+ * @param {"song"|"album"|"artist"|"label"} params.type Object type
418
+ * @returns {Promise<*>}
419
+ * @see {@link https://ampache.org/api/api-json-methods#get_external_metadata}
420
+ */
421
+ getExternalMetadata(params) {
422
+ return this.call("get_external_metadata", params);
423
+ },
424
+
425
+ /**
426
+ * Print a list of valid search rules for your search type
427
+ * @remarks MINIMUM_API_VERSION=6.8.0
428
+ * @param params.filter Object type
429
+ * @see {@link https://ampache.org/api/api-json-methods#search_rules}
430
+ */
431
+ searchRules(params) {
432
+ return this.call("search_rules", params);
433
+ },
434
+
435
+ /**
436
+ * Perform an advanced search given passed rules.
437
+ * You'll want to consult the docs for this.
438
+ * @remarks MINIMUM_API_VERSION=380001
439
+ * @param params.operator and, or (whether to match one rule or all)
440
+ * @param params.type Object type to return
441
+ * @param params.rules An array of rules
442
+ * @param [params.random] 0, 1 (random order of results; default to 0)
443
+ * @param [params.offset]
444
+ * @param [params.limit]
445
+ * @see {@link https://ampache.org/api/api-json-methods#advanced_search}
446
+ */
447
+ advancedSearch(params) {
448
+ for (let i = 0; i < params.rules.length; i++) {
449
+ const thisRule = params.rules[i];
450
+ const ruleNumber = i + 1;
451
+
452
+ params["rule_" + ruleNumber] = thisRule[0];
453
+ params["rule_" + ruleNumber + "_operator"] = thisRule[1];
454
+ params["rule_" + ruleNumber + "_input"] = thisRule[2];
455
+
456
+ if (thisRule[0] === "metadata") {
457
+ params["rule_" + ruleNumber + "_subtype"] = thisRule[3];
458
+ }
459
+ }
460
+
461
+ delete params.rules;
462
+
463
+ if (!ADVANCED_SEARCH_TYPES.has(params.type)) {
464
+ return false;
465
+ }
466
+ const query = "advanced_search" + qs.stringify(params, "&");
467
+ return this.request(query);
468
+ },
469
+
470
+ /**
471
+ * Alias of advancedSearch
472
+ * @see advancedSearch
473
+ */
474
+ search(params) {
475
+ return this.advancedSearch(params);
476
+ },
477
+
478
+ /**
479
+ * Perform a search given passed rules and return matching objects in a group.
480
+ * If the rules do not exist for the object type or would return the entire table they will not return objects
481
+ * You'll want to consult the docs for this.
482
+ * @remarks MINIMUM_API_VERSION=6.3.0
483
+ * @param params.operator and, or (whether to match one rule or all)
484
+ * @param params.rules An array of rules
485
+ * @param [params.type] Object type to return (all, music, song_artist, album_artist, podcast, video; all by default)
486
+ * @param [params.random] 0, 1 (random order of results; default to 0)
487
+ * @param [params.offset]
488
+ * @param [params.limit]
489
+ * @see {@link https://ampache.org/api/api-json-methods#search_group}
490
+ */
491
+ searchGroup(params) {
492
+ for (let i = 0; i < params.rules.length; i++) {
493
+ const thisRule = params.rules[i];
494
+ const ruleNumber = i + 1;
495
+
496
+ params["rule_" + ruleNumber] = thisRule[0];
497
+ params["rule_" + ruleNumber + "_operator"] = thisRule[1];
498
+ params["rule_" + ruleNumber + "_input"] = thisRule[2];
499
+
500
+ if (thisRule[0] === "metadata") {
501
+ params["rule_" + ruleNumber + "_subtype"] = thisRule[3];
502
+ }
503
+ }
504
+
505
+ delete params.rules;
506
+
507
+ const query = "search_group" + qs.stringify(params, "&");
508
+ return this.request(query);
509
+ },
510
+ };