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
@@ -1,845 +0,0 @@
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
- * @param [params.size] width x height (e.g. '640x480')
529
- * @see {@link https://ampache.org/api/api-json-methods#get_art}
530
- */
531
- getArt(params: {
532
- id: UID;
533
- type: "song" | "artist" | "album" | "playlist" | "search" | "podcast";
534
- size?: string;
535
- }) {
536
- let query = "get_art";
537
- query += qs.stringify(params, "&");
538
- return this.binary(query);
539
- }
540
-
541
- /**
542
- * This is for controlling localplay
543
- * @param params.command The command to send to the localplay controller
544
- * @param [params.oid] Object UID
545
- * @param [params.type] Object type
546
- * @param [params.clear] 0, 1 (Clear the current playlist before adding)
547
- * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=5.0.0
548
- * @see {@link https://ampache.org/api/api-json-methods#localplay}
549
- */
550
- localplay(params: {
551
- command:
552
- | "next"
553
- | "prev"
554
- | "stop"
555
- | "play"
556
- | "pause"
557
- | "add"
558
- | "volume_up"
559
- | "volume_down"
560
- | "volume_mute"
561
- | "delete_all"
562
- | "skip"
563
- | "status";
564
- oid?: number;
565
- type?:
566
- | "song"
567
- | "video"
568
- | "podcast_episode"
569
- | "channel"
570
- | "broadcast"
571
- | "democratic"
572
- | "live_stream";
573
- clear?: BinaryBoolean;
574
- }) {
575
- let query = "localplay";
576
- query += qs.stringify(params, "&");
577
- return this.request(query);
578
- }
579
-
580
- /**
581
- * Get the list of songs in your localplay playlist
582
- * @remarks MINIMUM_API_VERSION=5.0.0
583
- * @see {@link https://ampache.org/api/api-json-methods#localplay_songs}
584
- */
585
- localplaySongs() {
586
- let query = "localplay_songs";
587
- return this.request(query);
588
- }
589
-
590
- /**
591
- * This is for controlling democratic play (Songs only). VOTE: +1 vote for the oid. DEVOTE: -1 vote for the oid.
592
- * PLAYLIST: Return an array of song items with an additional VOTE COUNT element.
593
- * PLAY: Returns the URL for playing democratic play.
594
- * @remarks MINIMUM_API_VERSION=380001
595
- * @param params.oid UID of song
596
- * @param params.method vote, devote, playlist, play
597
- * @see {@link https://ampache.org/api/api-json-methods#democratic}
598
- */
599
- democratic(params: {
600
- oid: UID;
601
- method: "vote" | "devote" | "playlist" | "play";
602
- }) {
603
- let query = "democratic";
604
- query += qs.stringify(params, "&");
605
- return this.request(query);
606
- }
607
-
608
- /**
609
- * Get what is currently being played by all users.
610
- * @remarks MINIMUM_API_VERSION=6.3.1
611
- * @see {@link https://ampache.org/api/api-json-methods#now_playing}
612
- */
613
- nowPlaying() {
614
- let query = "now_playing";
615
- return this.request<{ now_playing: NowPlayingResponse[] }>(query);
616
- }
617
-
618
- /**
619
- * Inform the server about the state of your client. (Song you are playing, Play/Pause state, etc.)
620
- * @remarks MINIMUM_API_VERSION=6.4.0
621
- * @param params.filter $object_id currently playing/stopping
622
- * @param [params.type] song, video, podcast_episode (Default: song)
623
- * @param [params.state] play, stop (Default: play)
624
- * @param [params.time] current play time in whole seconds (Default: 0)
625
- * @param [params.client] agent/client name
626
- * @see {@link https://ampache.org/api/api-json-methods#player}
627
- */
628
- player(params: {
629
- filter: UID;
630
- type?: "song" | "video" | "podcast_episode";
631
- state?: "play" | "stop";
632
- time?: number;
633
- client?: string;
634
- }) {
635
- let query = "player";
636
- query += qs.stringify(params, "&");
637
- return this.request<{ now_playing: NowPlayingResponse[] }>(query);
638
- }
639
-
640
- /**
641
- * Perform an advanced search given passed rules.
642
- * You'll want to consult the docs for this.
643
- * @remarks MINIMUM_API_VERSION=380001
644
- * @param params.operator and, or (whether to match one rule or all)
645
- * @param params.type Object type to return
646
- * @param params.rules An array of rules
647
- * @param [params.random] 0, 1 (random order of results; default to 0)
648
- * @param [params.offset]
649
- * @param [params.limit]
650
- * @see {@link https://ampache.org/api/api-json-methods#advanced_search}
651
- */
652
- advancedSearch(
653
- params: {
654
- operator: "and" | "or";
655
- type:
656
- | "song"
657
- | "album"
658
- | "album_disk"
659
- | "artist"
660
- | "album_artist"
661
- | "song_artist"
662
- | "label"
663
- | "playlist"
664
- | "podcast"
665
- | "podcast_episode"
666
- | "genre"
667
- | "user"
668
- | "video";
669
- rules: Array<Array<string>>;
670
- random?: BinaryBoolean;
671
- } & Pagination,
672
- ) {
673
- let query = "advanced_search";
674
-
675
- for (let i = 0; i < params.rules.length; i++) {
676
- const thisRule = params.rules[i];
677
- const ruleNumber = i + 1;
678
-
679
- params["rule_" + ruleNumber] = thisRule[0];
680
- params["rule_" + ruleNumber + "_operator"] = thisRule[1];
681
- params["rule_" + ruleNumber + "_input"] = thisRule[2];
682
-
683
- if (thisRule[0] === "metadata") {
684
- params["rule_" + ruleNumber + "_subtype"] = thisRule[3];
685
- }
686
- }
687
-
688
- // drop the initial 'rules' as it was split into its parts
689
- delete params.rules;
690
-
691
- query += qs.stringify(params, "&");
692
-
693
- let data;
694
-
695
- switch (params.type) {
696
- case "song":
697
- data = this.request<SongsResponse>(query);
698
- break;
699
- case "album":
700
- data = this.request<AlbumsResponse>(query);
701
- break;
702
- case "artist":
703
- case "album_artist":
704
- case "song_artist":
705
- data = this.request<ArtistsResponse>(query);
706
- break;
707
- case "label":
708
- data = this.request<LabelsResponse>(query);
709
- break;
710
- case "playlist":
711
- data = this.request<PlaylistsResponse>(query);
712
- break;
713
- case "podcast":
714
- data = this.request<PodcastsResponse>(query);
715
- break;
716
- case "podcast_episode":
717
- data = this.request<PodcastEpisodesResponse>(query);
718
- break;
719
- case "genre":
720
- data = this.request<GenresResponse>(query);
721
- break;
722
- case "user":
723
- data = this.request<UsersResponse>(query);
724
- break;
725
- case "video":
726
- data = this.request<VideosResponse>(query);
727
- break;
728
- default:
729
- return false;
730
- }
731
-
732
- return data;
733
- }
734
-
735
- // alias of advanced_search
736
- search = this.advancedSearch;
737
-
738
- /**
739
- * Perform a search given passed rules and return matching objects in a group.
740
- * If the rules do not exist for the object type or would return the entire table they will not return objects
741
- * You'll want to consult the docs for this.
742
- * @remarks MINIMUM_API_VERSION=6.3.0
743
- * @param params.operator and, or (whether to match one rule or all)
744
- * @param params.rules An array of rules
745
- * @param [params.type] Object type to return (all, music, song_artist, album_artist, podcast, video; all by default)
746
- * @param [params.random] 0, 1 (random order of results; default to 0)
747
- * @param [params.offset]
748
- * @param [params.limit]
749
- * @see {@link https://ampache.org/api/api-json-methods#search_group}
750
- */
751
- searchGroup(
752
- params: {
753
- operator: "and" | "or";
754
- rules: Array<Array<string>>;
755
- type?:
756
- | "all"
757
- | "music"
758
- | "song_artist"
759
- | "album_artist"
760
- | "podcast"
761
- | "video";
762
- random?: BinaryBoolean;
763
- } & Pagination,
764
- ) {
765
- let query = "search_group";
766
-
767
- for (let i = 0; i < params.rules.length; i++) {
768
- const thisRule = params.rules[i];
769
- const ruleNumber = i + 1;
770
-
771
- params["rule_" + ruleNumber] = thisRule[0];
772
- params["rule_" + ruleNumber + "_operator"] = thisRule[1];
773
- params["rule_" + ruleNumber + "_input"] = thisRule[2];
774
-
775
- if (thisRule[0] === "metadata") {
776
- params["rule_" + ruleNumber + "_subtype"] = thisRule[3];
777
- }
778
- }
779
-
780
- // drop the initial 'rules' as it was split into its parts
781
- delete params.rules;
782
-
783
- query += qs.stringify(params, "&");
784
-
785
- let data;
786
-
787
- switch (params.type) {
788
- case "music":
789
- data = this.request<{ search: {
790
- song: SongResponse[];
791
- album: AlbumResponse[];
792
- artist: ArtistResponse[];
793
- }
794
- }>(query);
795
- break;
796
- case "song_artist":
797
- data = this.request<{ search: {
798
- song: SongResponse[];
799
- album: AlbumResponse[];
800
- song_artist: ArtistResponse[];
801
- }
802
- }>(query);
803
- break;
804
- case "album_artist":
805
- data = this.request<{ search: {
806
- song: SongResponse[];
807
- album: AlbumResponse[];
808
- album_artist: ArtistResponse[];
809
- }
810
- }>(query);
811
- break;
812
- case "podcast":
813
- data = this.request<{ search: {
814
- podcast: PodcastResponse[];
815
- podcast_episode: PodcastEpisodeResponse[];
816
- }
817
- }>(query);
818
- break;
819
- case "video":
820
- data = this.request<{ search: {
821
- video: VideoResponse[];
822
- }
823
- }>(query);
824
- break;
825
- case "all":
826
- default:
827
- data = this.request<{ search: {
828
- song: SongResponse[];
829
- album: AlbumResponse[];
830
- artist: ArtistResponse[];
831
- song_artist: ArtistResponse[];
832
- album_artist: ArtistResponse[];
833
- label: LabelResponse[];
834
- playlist: PlaylistResponse[];
835
- podcast: PodcastResponse[];
836
- podcast_episode: PodcastEpisodeResponse[];
837
- genre: GenreResponse[];
838
- user: UserResponse[];
839
- }
840
- }>(query);
841
- }
842
-
843
- return data;
844
- }
845
- }