javascript-ampache 1.2.0 → 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 -208
  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 -146
  63. package/dist/songs/types.d.ts +0 -73
  64. package/dist/system/index.d.ts +0 -419
  65. package/dist/system/types.d.ts +0 -31
  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 -284
  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 -860
  104. package/src/system/types.ts +0 -50
  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,860 +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, RuleResponse } 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
- cond?: string;
213
- } & ExtendedPagination,
214
- ) {
215
- let query = "browse";
216
- query += qs.stringify(params, "&");
217
- return this.request<{ browse: IndexEntry[] }>(query);
218
- }
219
-
220
- /**
221
- * Return similar artist IDs or similar song IDs compared to the input filter
222
- * @remarks MINIMUM_API_VERSION=420000
223
- * @param params.type type of object to check against
224
- * @param params.filter UID to find
225
- * @param [params.offset]
226
- * @param [params.limit]
227
- * @see {@link https://ampache.org/api/api-json-methods#get_similar}
228
- */
229
- getSimilar(
230
- params: {
231
- type: "song" | "artist";
232
- filter: UID;
233
- } & Pagination,
234
- ) {
235
- let query = "get_similar";
236
- query += qs.stringify(params, "&");
237
- let data;
238
-
239
- switch (params.type) {
240
- case "song":
241
- data = this.request<SongsResponse>(query);
242
- break;
243
- case "artist":
244
- data = this.request<ArtistsResponse>(query);
245
- break;
246
- default:
247
- return false;
248
- }
249
-
250
- return data;
251
- }
252
-
253
- /**
254
- * Get some items based on some simple search types and filters. (Random by default)
255
- * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400001
256
- * @param params.type Object type
257
- * @param [params.filter] newest, highest, frequent, recent, forgotten, flagged, random
258
- * @param [params.user_id] Filter results to a certain user by UID
259
- * @param [params.username] Filter results to a certain user by username
260
- * @param [params.offset]
261
- * @param [params.limit]
262
- * @see {@link https://ampache.org/api/api-json-methods#stats}
263
- */
264
- stats(
265
- params: {
266
- type:
267
- | "song"
268
- | "album"
269
- | "artist"
270
- | "video"
271
- | "playlist"
272
- | "podcast"
273
- | "podcast_episode";
274
- filter?:
275
- | "newest"
276
- | "highest"
277
- | "frequent"
278
- | "recent"
279
- | "forgotten"
280
- | "flagged"
281
- | "random";
282
- user_id?: number;
283
- username?: string;
284
- } & Pagination,
285
- ) {
286
- let query = "stats";
287
- query += qs.stringify(params, "&");
288
- let data;
289
-
290
- switch (params.type) {
291
- case "song":
292
- data = this.request<SongsResponse>(query);
293
- break;
294
- case "album":
295
- data = this.request<AlbumsResponse>(query);
296
- break;
297
- case "artist":
298
- data = this.request<ArtistsResponse>(query);
299
- break;
300
- case "video":
301
- data = this.request<VideosResponse>(query);
302
- break;
303
- case "playlist":
304
- data = this.request<PlaylistsResponse>(query);
305
- break;
306
- case "podcast":
307
- data = this.request<PodcastsResponse>(query);
308
- break;
309
- case "podcast_episode":
310
- data = this.request<PodcastEpisodesResponse>(query);
311
- break;
312
- default:
313
- return false;
314
- }
315
-
316
- return data;
317
- }
318
-
319
- /**
320
- * This rates a library item
321
- * @remarks MINIMUM_API_VERSION=380001
322
- * @param params.type Object type
323
- * @param params.id UID to find
324
- * @param params.rating Rating to apply
325
- * @see {@link https://ampache.org/api/api-json-methods#rate}
326
- */
327
- rate(params: {
328
- type:
329
- | "song"
330
- | "album"
331
- | "artist"
332
- | "playlist"
333
- | "podcast"
334
- | "podcast_episode"
335
- | "video"
336
- | "tvshow"
337
- | "tvshow_season";
338
- id: UID;
339
- rating: 0 | 1 | 2 | 3 | 4 | 5;
340
- }) {
341
- let query = "rate";
342
- query += qs.stringify(params, "&");
343
- return this.request<Success>(query);
344
- }
345
-
346
- /**
347
- * This flags a library item as a favorite
348
- * @remarks MINIMUM_API_VERSION=400001
349
- * @param params.type Object type
350
- * @param params.id UID to find
351
- * @param params.flag 0, 1
352
- * @param [params.date] UNIXTIME
353
- * @see {@link https://ampache.org/api/api-json-methods#flag}
354
- */
355
- flag(params: {
356
- type:
357
- | "song"
358
- | "album"
359
- | "artist"
360
- | "playlist"
361
- | "podcast"
362
- | "podcast_episode"
363
- | "video"
364
- | "tvshow"
365
- | "tvshow_season";
366
- id: UID;
367
- flag: BinaryBoolean;
368
- date?: number;
369
- }) {
370
- let query = "flag";
371
- query += qs.stringify(params, "&");
372
- return this.request<Success>(query);
373
- }
374
-
375
- /**
376
- * 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.
377
- * If you don't supply a user id (optional) then just fall back to you.
378
- * ACCESS REQUIRED: 100 (Admin) permission to change another user's play history
379
- * @remarks MINIMUM_API_VERSION=400001
380
- * @param params.id UID of song
381
- * @param [params.user] UID of user
382
- * @param [params.client] Client string
383
- * @param [params.date] UNIXTIME
384
- * @see {@link https://ampache.org/api/api-json-methods#record_play}
385
- */
386
- recordPlay(params: { id: UID; user?: UID; client?: string; date?: number }) {
387
- let query = "record_play";
388
- query += qs.stringify(params, "&");
389
- return this.request<Success>(query);
390
- }
391
-
392
- /**
393
- * Search for a song using text info and then record a play if found. This allows other sources to record play history to ampache
394
- * @remarks MINIMUM_API_VERSION=400001
395
- * @param params.song HTML encoded string
396
- * @param params.artist HTML encoded string
397
- * @param params.album HTML encoded string
398
- * @param [params.songmbid] Song MBID
399
- * @param [params.artistmbid] Artist MBID
400
- * @param [params.albummbid] Album MBID
401
- * @param [params.song_mbid] Alias of songmbid
402
- * @param [params.artist_mbid] Alias of artistmbid
403
- * @param [params.album_mbid] Alias of albummbid
404
- * @param [params.date] UNIXTIME
405
- * @param [params.client] Client string
406
- * @see {@link https://ampache.org/api/api-json-methods#scrobble}
407
- */
408
- scrobble(params: {
409
- song: string;
410
- artist: string;
411
- album: string;
412
- songmbid?: string;
413
- artistmbid?: string;
414
- albummbid?: string;
415
- song_mbid?: string;
416
- artist_mbid?: string;
417
- album_mbid?: string;
418
- date?: number;
419
- client?: string;
420
- }) {
421
- let query = "scrobble";
422
- query += qs.stringify(params, "&");
423
- return this.request<Success>(query);
424
- }
425
-
426
- /**
427
- * Update a single album, artist, song from the tag data
428
- * @remarks MINIMUM_API_VERSION=400001
429
- * @param params.type Object type
430
- * @param params.id UID to find
431
- * @see {@link https://ampache.org/api/api-json-methods#update_from_tags}
432
- */
433
- updateFromTags(params: { type: "song" | "artist" | "album"; id: UID }) {
434
- let query = "update_from_tags";
435
- query += qs.stringify(params, "&");
436
- return this.request<Success>(query);
437
- }
438
-
439
- /**
440
- * Update artist information and fetch similar artists from last.fm
441
- * Make sure lastfm_API_key is set in your configuration file
442
- * ACCESS REQUIRED: 75 (Catalog Manager)
443
- * @remarks MINIMUM_API_VERSION=400001
444
- * @param params.id UID to find
445
- * @see {@link https://ampache.org/api/api-json-methods#update_artist_info}
446
- */
447
- updateArtistInfo(params: { id: UID }) {
448
- let query = "update_artist_info";
449
- query += qs.stringify(params, "&");
450
- return this.request<Success>(query);
451
- }
452
-
453
- /**
454
- * Updates a single album, artist, song running the gather_art process.
455
- * Doesn't overwrite existing art by default.
456
- * ACCESS REQUIRED: 75 (Catalog Manager)
457
- * @remarks MINIMUM_API_VERSION=400001
458
- * @param params.id UID to update
459
- * @param params.type Object type
460
- * @param [params.overwrite]
461
- * @see {@link https://ampache.org/api/api-json-methods#update_art}
462
- */
463
- updateArt(params: {
464
- id: UID;
465
- type: "artist" | "album" | "song";
466
- overwrite?: BinaryBoolean;
467
- }) {
468
- let query = "update_art";
469
- query += qs.stringify(params, "&");
470
- return this.request<Success>(query);
471
- }
472
-
473
- /**
474
- * Streams a given media file. Takes the file id in parameter with optional max bit rate, file format, time offset,
475
- * size and estimate content length option.
476
- * NOTE search and playlist will only stream a random object from the list.
477
- * @remarks MINIMUM_API_VERSION=400001
478
- * @param params.id UID to find
479
- * @param params.type Object type
480
- * @param [params.bitrate] Max bitrate for transcoding
481
- * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
482
- * @param [params.offset] Time offset
483
- * @param [params.length] 0, 1 (estimate content length)
484
- * @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
485
- * @see {@link https://ampache.org/api/api-json-methods#stream}
486
- */
487
- stream(params: {
488
- id: UID;
489
- type: "song" | "podcast_episode" | "search" | "playlist";
490
- bitrate?: number;
491
- format?: string;
492
- offset?: number;
493
- length?: BinaryBoolean;
494
- stats?: BinaryBoolean;
495
- }) {
496
- let query = "stream";
497
- query += qs.stringify(params, "&");
498
- return this.binary(query);
499
- }
500
-
501
- /**
502
- * Downloads a given media file. set format=raw to download the full file
503
- * NOTE search and playlist will only download a random object from the list
504
- * @remarks MINIMUM_API_VERSION=400001
505
- * @param params.id UID to find
506
- * @param params.type Object type
507
- * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
508
- * @param [params.bitrate] max bitrate for transcoding in bytes (e.g 192000=192Kb)
509
- * @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
510
- * @see {@link https://ampache.org/api/api-json-methods#download}
511
- */
512
- download(params: {
513
- id: UID;
514
- type: "song" | "podcast_episode" | "search" | "playlist";
515
- format?: string;
516
- bitrate?: number;
517
- stats?: BinaryBoolean;
518
- }) {
519
- let query = "download";
520
- query += qs.stringify(params, "&");
521
- return this.binary(query);
522
- }
523
-
524
- /**
525
- * Get an art image file.
526
- * @remarks MINIMUM_API_VERSION=400001
527
- * @param params.id UID to find
528
- * @param params.type Object type
529
- * @param [params.size] width x height (e.g. '640x480')
530
- * @see {@link https://ampache.org/api/api-json-methods#get_art}
531
- */
532
- getArt(params: {
533
- id: UID;
534
- type: "song" | "artist" | "album" | "playlist" | "search" | "podcast";
535
- size?: string;
536
- }) {
537
- let query = "get_art";
538
- query += qs.stringify(params, "&");
539
- return this.binary(query);
540
- }
541
-
542
- /**
543
- * This is for controlling localplay
544
- * @param params.command The command to send to the localplay controller
545
- * @param [params.oid] Object UID
546
- * @param [params.type] Object type
547
- * @param [params.clear] 0, 1 (Clear the current playlist before adding)
548
- * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=5.0.0
549
- * @see {@link https://ampache.org/api/api-json-methods#localplay}
550
- */
551
- localplay(params: {
552
- command:
553
- | "next"
554
- | "prev"
555
- | "stop"
556
- | "play"
557
- | "pause"
558
- | "add"
559
- | "volume_up"
560
- | "volume_down"
561
- | "volume_mute"
562
- | "delete_all"
563
- | "skip"
564
- | "status";
565
- oid?: number;
566
- type?:
567
- | "song"
568
- | "video"
569
- | "podcast_episode"
570
- | "channel"
571
- | "broadcast"
572
- | "democratic"
573
- | "live_stream";
574
- clear?: BinaryBoolean;
575
- }) {
576
- let query = "localplay";
577
- query += qs.stringify(params, "&");
578
- return this.request(query);
579
- }
580
-
581
- /**
582
- * Get the list of songs in your localplay playlist
583
- * @remarks MINIMUM_API_VERSION=5.0.0
584
- * @see {@link https://ampache.org/api/api-json-methods#localplay_songs}
585
- */
586
- localplaySongs() {
587
- let query = "localplay_songs";
588
- return this.request(query);
589
- }
590
-
591
- /**
592
- * This is for controlling democratic play (Songs only). VOTE: +1 vote for the oid. DEVOTE: -1 vote for the oid.
593
- * PLAYLIST: Return an array of song items with an additional VOTE COUNT element.
594
- * PLAY: Returns the URL for playing democratic play.
595
- * @remarks MINIMUM_API_VERSION=380001
596
- * @param params.oid UID of song
597
- * @param params.method vote, devote, playlist, play
598
- * @see {@link https://ampache.org/api/api-json-methods#democratic}
599
- */
600
- democratic(params: {
601
- oid: UID;
602
- method: "vote" | "devote" | "playlist" | "play";
603
- }) {
604
- let query = "democratic";
605
- query += qs.stringify(params, "&");
606
- return this.request(query);
607
- }
608
-
609
- /**
610
- * Get what is currently being played by all users.
611
- * @remarks MINIMUM_API_VERSION=6.3.1
612
- * @see {@link https://ampache.org/api/api-json-methods#now_playing}
613
- */
614
- nowPlaying() {
615
- let query = "now_playing";
616
- return this.request<{ now_playing: NowPlayingResponse[] }>(query);
617
- }
618
-
619
- /**
620
- * Inform the server about the state of your client. (Song you are playing, Play/Pause state, etc.)
621
- * @remarks MINIMUM_API_VERSION=6.4.0
622
- * @param params.filter $object_id currently playing/stopping
623
- * @param [params.type] song, video, podcast_episode (Default: song)
624
- * @param [params.state] play, stop (Default: play)
625
- * @param [params.time] current play time in whole seconds (Default: 0)
626
- * @param [params.client] agent/client name
627
- * @see {@link https://ampache.org/api/api-json-methods#player}
628
- */
629
- player(params: {
630
- filter: UID;
631
- type?: "song" | "video" | "podcast_episode";
632
- state?: "play" | "stop";
633
- time?: number;
634
- client?: string;
635
- }) {
636
- let query = "player";
637
- query += qs.stringify(params, "&");
638
- return this.request<{ now_playing: NowPlayingResponse[] }>(query);
639
- }
640
-
641
- /**
642
- * Print a list of valid search rules for your search type
643
- * @remarks MINIMUM_API_VERSION=6.8.0
644
- * @param params.filter Object type
645
- * @see {@link https://ampache.org/api/api-json-methods#search_rules}
646
- */
647
- searchRules(params: {
648
- filter: "song" | "album" | "song_artist" | "album_artist" | "artist" | "label" | "playlist" | "podcast" | "podcast_episode" | "genre" | "user" | "video";
649
- }) {
650
- let query = "search_rules";
651
- query += qs.stringify(params, "&");
652
- return this.request<{ rule: RuleResponse[] }>(query);
653
- }
654
-
655
- /**
656
- * Perform an advanced search given passed rules.
657
- * You'll want to consult the docs for this.
658
- * @remarks MINIMUM_API_VERSION=380001
659
- * @param params.operator and, or (whether to match one rule or all)
660
- * @param params.type Object type to return
661
- * @param params.rules An array of rules
662
- * @param [params.random] 0, 1 (random order of results; default to 0)
663
- * @param [params.offset]
664
- * @param [params.limit]
665
- * @see {@link https://ampache.org/api/api-json-methods#advanced_search}
666
- */
667
- advancedSearch(
668
- params: {
669
- operator: "and" | "or";
670
- type:
671
- | "song"
672
- | "album"
673
- | "album_disk"
674
- | "artist"
675
- | "album_artist"
676
- | "song_artist"
677
- | "label"
678
- | "playlist"
679
- | "podcast"
680
- | "podcast_episode"
681
- | "genre"
682
- | "user"
683
- | "video";
684
- rules: Array<Array<string>>;
685
- random?: BinaryBoolean;
686
- } & Pagination,
687
- ) {
688
- let query = "advanced_search";
689
-
690
- for (let i = 0; i < params.rules.length; i++) {
691
- const thisRule = params.rules[i];
692
- const ruleNumber = i + 1;
693
-
694
- params["rule_" + ruleNumber] = thisRule[0];
695
- params["rule_" + ruleNumber + "_operator"] = thisRule[1];
696
- params["rule_" + ruleNumber + "_input"] = thisRule[2];
697
-
698
- if (thisRule[0] === "metadata") {
699
- params["rule_" + ruleNumber + "_subtype"] = thisRule[3];
700
- }
701
- }
702
-
703
- // drop the initial 'rules' as it was split into its parts
704
- delete params.rules;
705
-
706
- query += qs.stringify(params, "&");
707
-
708
- let data;
709
-
710
- switch (params.type) {
711
- case "song":
712
- data = this.request<SongsResponse>(query);
713
- break;
714
- case "album":
715
- data = this.request<AlbumsResponse>(query);
716
- break;
717
- case "artist":
718
- case "album_artist":
719
- case "song_artist":
720
- data = this.request<ArtistsResponse>(query);
721
- break;
722
- case "label":
723
- data = this.request<LabelsResponse>(query);
724
- break;
725
- case "playlist":
726
- data = this.request<PlaylistsResponse>(query);
727
- break;
728
- case "podcast":
729
- data = this.request<PodcastsResponse>(query);
730
- break;
731
- case "podcast_episode":
732
- data = this.request<PodcastEpisodesResponse>(query);
733
- break;
734
- case "genre":
735
- data = this.request<GenresResponse>(query);
736
- break;
737
- case "user":
738
- data = this.request<UsersResponse>(query);
739
- break;
740
- case "video":
741
- data = this.request<VideosResponse>(query);
742
- break;
743
- default:
744
- return false;
745
- }
746
-
747
- return data;
748
- }
749
-
750
- // alias of advanced_search
751
- search = this.advancedSearch;
752
-
753
- /**
754
- * Perform a search given passed rules and return matching objects in a group.
755
- * If the rules do not exist for the object type or would return the entire table they will not return objects
756
- * You'll want to consult the docs for this.
757
- * @remarks MINIMUM_API_VERSION=6.3.0
758
- * @param params.operator and, or (whether to match one rule or all)
759
- * @param params.rules An array of rules
760
- * @param [params.type] Object type to return (all, music, song_artist, album_artist, podcast, video; all by default)
761
- * @param [params.random] 0, 1 (random order of results; default to 0)
762
- * @param [params.offset]
763
- * @param [params.limit]
764
- * @see {@link https://ampache.org/api/api-json-methods#search_group}
765
- */
766
- searchGroup(
767
- params: {
768
- operator: "and" | "or";
769
- rules: Array<Array<string>>;
770
- type?:
771
- | "all"
772
- | "music"
773
- | "song_artist"
774
- | "album_artist"
775
- | "podcast"
776
- | "video";
777
- random?: BinaryBoolean;
778
- } & Pagination,
779
- ) {
780
- let query = "search_group";
781
-
782
- for (let i = 0; i < params.rules.length; i++) {
783
- const thisRule = params.rules[i];
784
- const ruleNumber = i + 1;
785
-
786
- params["rule_" + ruleNumber] = thisRule[0];
787
- params["rule_" + ruleNumber + "_operator"] = thisRule[1];
788
- params["rule_" + ruleNumber + "_input"] = thisRule[2];
789
-
790
- if (thisRule[0] === "metadata") {
791
- params["rule_" + ruleNumber + "_subtype"] = thisRule[3];
792
- }
793
- }
794
-
795
- // drop the initial 'rules' as it was split into its parts
796
- delete params.rules;
797
-
798
- query += qs.stringify(params, "&");
799
-
800
- let data;
801
-
802
- switch (params.type) {
803
- case "music":
804
- data = this.request<{ search: {
805
- song: SongResponse[];
806
- album: AlbumResponse[];
807
- artist: ArtistResponse[];
808
- }
809
- }>(query);
810
- break;
811
- case "song_artist":
812
- data = this.request<{ search: {
813
- song: SongResponse[];
814
- album: AlbumResponse[];
815
- song_artist: ArtistResponse[];
816
- }
817
- }>(query);
818
- break;
819
- case "album_artist":
820
- data = this.request<{ search: {
821
- song: SongResponse[];
822
- album: AlbumResponse[];
823
- album_artist: ArtistResponse[];
824
- }
825
- }>(query);
826
- break;
827
- case "podcast":
828
- data = this.request<{ search: {
829
- podcast: PodcastResponse[];
830
- podcast_episode: PodcastEpisodeResponse[];
831
- }
832
- }>(query);
833
- break;
834
- case "video":
835
- data = this.request<{ search: {
836
- video: VideoResponse[];
837
- }
838
- }>(query);
839
- break;
840
- case "all":
841
- default:
842
- data = this.request<{ search: {
843
- song: SongResponse[];
844
- album: AlbumResponse[];
845
- artist: ArtistResponse[];
846
- song_artist: ArtistResponse[];
847
- album_artist: ArtistResponse[];
848
- label: LabelResponse[];
849
- playlist: PlaylistResponse[];
850
- podcast: PodcastResponse[];
851
- podcast_episode: PodcastEpisodeResponse[];
852
- genre: GenreResponse[];
853
- user: UserResponse[];
854
- }
855
- }>(query);
856
- }
857
-
858
- return data;
859
- }
860
- }