javascript-ampache 0.0.1

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 (89) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +44 -0
  3. package/dist/albums/index.d.ts +62 -0
  4. package/dist/albums/types.d.ts +29 -0
  5. package/dist/artists/index.d.ts +64 -0
  6. package/dist/artists/types.d.ts +29 -0
  7. package/dist/auth/index.d.ts +47 -0
  8. package/dist/auth/types.d.ts +22 -0
  9. package/dist/base.d.ts +28 -0
  10. package/dist/bookmarks/index.d.ts +70 -0
  11. package/dist/bookmarks/types.d.ts +8 -0
  12. package/dist/catalogs/index.d.ts +51 -0
  13. package/dist/catalogs/types.d.ts +14 -0
  14. package/dist/genres/index.d.ts +30 -0
  15. package/dist/genres/types.d.ts +15 -0
  16. package/dist/index.d.ts +24 -0
  17. package/dist/index.js +2 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/index.m.js +2 -0
  20. package/dist/index.m.js.map +1 -0
  21. package/dist/index.modern.js +2 -0
  22. package/dist/index.modern.js.map +1 -0
  23. package/dist/index.umd.js +2 -0
  24. package/dist/index.umd.js.map +1 -0
  25. package/dist/labels/index.d.ts +32 -0
  26. package/dist/labels/types.d.ts +13 -0
  27. package/dist/licenses/index.d.ts +32 -0
  28. package/dist/licenses/types.d.ts +7 -0
  29. package/dist/live-streams/index.d.ts +32 -0
  30. package/dist/live-streams/types.d.ts +9 -0
  31. package/dist/playlists/index.d.ts +145 -0
  32. package/dist/playlists/types.d.ts +12 -0
  33. package/dist/podcasts/index.d.ts +125 -0
  34. package/dist/podcasts/types.d.ts +57 -0
  35. package/dist/preferences/index.d.ts +84 -0
  36. package/dist/preferences/types.d.ts +11 -0
  37. package/dist/shares/index.d.ts +69 -0
  38. package/dist/shares/types.d.ts +18 -0
  39. package/dist/shouts/index.d.ts +17 -0
  40. package/dist/shouts/types.d.ts +8 -0
  41. package/dist/songs/index.d.ts +140 -0
  42. package/dist/songs/types.d.ts +62 -0
  43. package/dist/system/index.d.ts +267 -0
  44. package/dist/system/types.d.ts +9 -0
  45. package/dist/users/index.d.ts +134 -0
  46. package/dist/users/types.d.ts +29 -0
  47. package/dist/utils.d.ts +2 -0
  48. package/dist/videos/index.d.ts +37 -0
  49. package/dist/videos/types.d.ts +27 -0
  50. package/package.json +40 -0
  51. package/src/albums/index.ts +80 -0
  52. package/src/albums/types.ts +31 -0
  53. package/src/artists/index.ts +82 -0
  54. package/src/artists/types.ts +31 -0
  55. package/src/auth/index.ts +91 -0
  56. package/src/auth/types.ts +22 -0
  57. package/src/base.ts +64 -0
  58. package/src/bookmarks/index.ts +94 -0
  59. package/src/bookmarks/types.ts +9 -0
  60. package/src/catalogs/index.ts +71 -0
  61. package/src/catalogs/types.ts +15 -0
  62. package/src/genres/index.ts +39 -0
  63. package/src/genres/types.ts +17 -0
  64. package/src/index.ts +26 -0
  65. package/src/labels/index.ts +42 -0
  66. package/src/labels/types.ts +14 -0
  67. package/src/licenses/index.ts +42 -0
  68. package/src/licenses/types.ts +8 -0
  69. package/src/live-streams/index.ts +42 -0
  70. package/src/live-streams/types.ts +10 -0
  71. package/src/playlists/index.ts +198 -0
  72. package/src/playlists/types.ts +13 -0
  73. package/src/podcasts/index.ts +174 -0
  74. package/src/podcasts/types.ts +60 -0
  75. package/src/preferences/index.ts +118 -0
  76. package/src/preferences/types.ts +12 -0
  77. package/src/shares/index.ts +94 -0
  78. package/src/shares/types.ts +19 -0
  79. package/src/shouts/index.ts +22 -0
  80. package/src/shouts/types.ts +9 -0
  81. package/src/songs/index.ts +191 -0
  82. package/src/songs/types.ts +64 -0
  83. package/src/system/index.ts +483 -0
  84. package/src/system/types.ts +11 -0
  85. package/src/users/index.ts +179 -0
  86. package/src/users/types.ts +32 -0
  87. package/src/utils.ts +25 -0
  88. package/src/videos/index.ts +53 -0
  89. package/src/videos/types.ts +29 -0
@@ -0,0 +1,483 @@
1
+ import qs from 'querystringify';
2
+ import { Song } from "../songs/types";
3
+ import { Artist } from "../artists/types";
4
+ import { Base, BinaryBoolean, Pagination, Success, UID } from '../base';
5
+ import { Album } from '../albums/types';
6
+ import { Video } from '../videos/types';
7
+ import { Playlist } from '../playlists/types';
8
+ import { Podcast, PodcastEpisode } from '../podcasts/types';
9
+ import { LiveStream } from "../live-streams/types";
10
+ import { Label } from "../labels/types";
11
+ import { Genre } from "../genres/types";
12
+ import { User } from "../users/types";
13
+
14
+ export class System extends Base {
15
+ /**
16
+ * Check Ampache for updates and run the update if there is one.
17
+ * @remarks MINIMUM_API_VERSION=5.0.0
18
+ * @see {@link https://ampache.org/api/api-json-methods#system_update}
19
+ */
20
+ systemUpdate () {
21
+ let query = 'system_update';
22
+ return this.request<Success>(query);
23
+ }
24
+
25
+ /**
26
+ * This takes a collection of inputs and returns ID + name for the object type
27
+ * @remarks MINIMUM_API_VERSION=400001
28
+ * @param params.type type of object to find
29
+ * @param [params.filter] search the name of the object_type
30
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
31
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
32
+ * @param [params.include] 0, 1 (include songs in a playlist or episodes in a podcast)
33
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
34
+ * @param [params.offset]
35
+ * @param [params.limit]
36
+ * @see {@link https://ampache.org/api/api-json-methods#get_indexes}
37
+ */
38
+ async getIndexes (params: {
39
+ type: 'song' | 'album' | 'artist' | 'album_artist' | 'playlist' | 'podcast' | 'podcast_episode' | 'live_stream',
40
+ filter?: string,
41
+ add?: Date,
42
+ update?: Date,
43
+ include?: BinaryBoolean,
44
+ hide_search?: number
45
+ } & Pagination) {
46
+ let query = 'get_indexes';
47
+ query += qs.stringify(params, '&');
48
+ let data;
49
+
50
+ switch (params.type) {
51
+ case "song":
52
+ data = await this.request<{song: Song[]}>(query);
53
+ return (data.song) ? data.song : data;
54
+ case "album":
55
+ data = await this.request<{album: Album[]}>(query);
56
+ return (data.album) ? data.album : data;
57
+ case "artist":
58
+ case "album_artist":
59
+ data = await this.request<{artist: Artist[]}>(query);
60
+ return (data.artist) ? data.artist : data;
61
+ case "playlist":
62
+ data = await this.request<{playlist: Playlist[]}>(query);
63
+ return (data.playlist) ? data.playlist : data;
64
+ case "podcast":
65
+ data = await this.request<{podcast: Podcast[]}>(query);
66
+ return (data.podcast) ? data.podcast : data;
67
+ case "podcast_episode":
68
+ data = await this.request<{podcast_episode: PodcastEpisode[]}>(query);
69
+ return (data.podcast_episode) ? data.podcast_episode : data;
70
+ case "live_stream":
71
+ data = await this.request<{live_stream: LiveStream[]}>(query);
72
+ return (data.live_stream) ? data.live_stream : data;
73
+ default:
74
+ return false;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Return similar artist IDs or similar song IDs compared to the input filter
80
+ * @remarks MINIMUM_API_VERSION=420000
81
+ * @param params.type type of object to check against
82
+ * @param params.filter UID to find
83
+ * @param [params.offset]
84
+ * @param [params.limit]
85
+ * @see {@link https://ampache.org/api/api-json-methods#get_similar}
86
+ */
87
+ async getSimilar (params: {
88
+ type: 'song' | 'artist',
89
+ filter: UID,
90
+ } & Pagination) {
91
+ let query = 'get_similar';
92
+ query += qs.stringify(params, '&');
93
+ let data;
94
+
95
+ switch (params.type) {
96
+ case "song":
97
+ data = await this.request<{song: Song[]}>(query);
98
+ return (data.song) ? data.song : data;
99
+ case "artist":
100
+ data = await this.request<{artist: Artist[]}>(query);
101
+ return (data.artist) ? data.artist : data;
102
+ default:
103
+ return false;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Get some items based on some simple search types and filters. (Random by default)
109
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400001
110
+ * @param params.type Object type
111
+ * @param [params.filter] newest, highest, frequent, recent, forgotten, flagged, random
112
+ * @param [params.user_id] Filter results to a certain user by UID
113
+ * @param [params.username] Filter results to a certain user by username
114
+ * @param [params.offset]
115
+ * @param [params.limit]
116
+ * @see {@link https://ampache.org/api/api-json-methods#stats}
117
+ */
118
+ async stats (params: {
119
+ type: 'song' | 'album' | 'artist' | 'video' | 'playlist' | 'podcast' | 'podcast_episode',
120
+ filter?: 'newest' | 'highest' | 'frequent' | 'recent' | 'forgotten' | 'flagged' | 'random',
121
+ user_id?: number,
122
+ username?: string,
123
+ } & Pagination) {
124
+ let query = 'stats';
125
+ query += qs.stringify(params, '&');
126
+ let data;
127
+
128
+ switch (params.type) {
129
+ case "song":
130
+ data = await this.request<{song: Song[]}>(query);
131
+ return (data.song) ? data.song : data;
132
+ case "album":
133
+ data = await this.request<{album: Album[]}>(query);
134
+ return (data.album) ? data.album : data;
135
+ case "artist":
136
+ data = await this.request<{artist: Artist[]}>(query);
137
+ return (data.artist) ? data.artist : data;
138
+ case "video":
139
+ data = await this.request<{video: Video[]}>(query);
140
+ return (data.video) ? data.video : data;
141
+ case "playlist":
142
+ data = await this.request<{playlist: Playlist[]}>(query);
143
+ return (data.playlist) ? data.playlist : data;
144
+ case "podcast":
145
+ data = await this.request<{podcast: Podcast[]}>(query);
146
+ return (data.podcast) ? data.podcast : data;
147
+ case "podcast_episode":
148
+ data = await this.request<{podcast_episode: PodcastEpisode[]}>(query);
149
+ return (data.podcast_episode) ? data.podcast_episode : data;
150
+ default:
151
+ return false;
152
+ }
153
+ }
154
+
155
+ /**
156
+ * This rates a library item
157
+ * @remarks MINIMUM_API_VERSION=380001
158
+ * @param params.type Object type
159
+ * @param params.id UID to find
160
+ * @param params.rating Rating to apply
161
+ * @see {@link https://ampache.org/api/api-json-methods#rate}
162
+ */
163
+ rate (params: {
164
+ type: 'song' | 'album' | 'artist' | 'playlist' | 'podcast' | 'podcast_episode' | 'video' | 'tvshow' | 'tvshow_season',
165
+ id: UID,
166
+ rating: 0 | 1 | 2 | 3 | 4 | 5,
167
+ }) {
168
+ let query = 'rate';
169
+ query += qs.stringify(params, '&');
170
+ return this.request<Success>(query);
171
+ }
172
+
173
+ /**
174
+ * This flags a library item as a favorite
175
+ * @remarks MINIMUM_API_VERSION=400001
176
+ * @param params.type Object type
177
+ * @param params.id UID to find
178
+ * @param params.flag 0, 1
179
+ * @see {@link https://ampache.org/api/api-json-methods#flag}
180
+ */
181
+ flag (params: {
182
+ type: 'song' | 'album' | 'artist' | 'playlist' | 'podcast' | 'podcast_episode' | 'video' | 'tvshow' | 'tvshow_season',
183
+ id: UID,
184
+ flag: BinaryBoolean,
185
+ }) {
186
+ let query = 'flag';
187
+ query += qs.stringify(params, '&');
188
+ return this.request<Success>(query);
189
+ }
190
+
191
+ /**
192
+ * 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.
193
+ * If you don't supply a user id (optional) then just fall back to you.
194
+ * ACCESS REQUIRED: 100 (Admin) permission to change another user's play history
195
+ * @remarks MINIMUM_API_VERSION=400001
196
+ * @param params.id UID of song
197
+ * @param [params.user] UID of user
198
+ * @param [params.client] Client string
199
+ * @param [params.date] UNIXTIME
200
+ * @see {@link https://ampache.org/api/api-json-methods#record_play}
201
+ */
202
+ recordPlay (params: {
203
+ id: UID,
204
+ user?: UID,
205
+ client?: string,
206
+ date?: number,
207
+ }) {
208
+ let query = 'record_play';
209
+ query += qs.stringify(params, '&');
210
+ return this.request<Success>(query);
211
+ }
212
+
213
+ /**
214
+ * Search for a song using text info and then record a play if found. This allows other sources to record play history to ampache
215
+ * @remarks MINIMUM_API_VERSION=400001
216
+ * @param params.song HTML encoded string
217
+ * @param params.artist HTML encoded string
218
+ * @param params.album HTML encoded string
219
+ * @param [params.songmbid] Song MBID
220
+ * @param [params.artistmbid] Artist MBID
221
+ * @param [params.albummbid] Album MBID
222
+ * @param [params.song_mbid] Alias of songmbid
223
+ * @param [params.artist_mbid] Alias of artistmbid
224
+ * @param [params.album_mbid] Alias of albummbid
225
+ * @param [params.date] UNIXTIME
226
+ * @param [params.client] Client string
227
+ * @see {@link https://ampache.org/api/api-json-methods#scrobble}
228
+ */
229
+ scrobble (params: {
230
+ song: string,
231
+ artist: string,
232
+ album: string,
233
+ songmbid?: string,
234
+ artistmbid?: string,
235
+ albummbid?: string,
236
+ song_mbid?: string,
237
+ artist_mbid?: string,
238
+ album_mbid?: string,
239
+ date?: number,
240
+ client?: string,
241
+ }) {
242
+ let query = 'scrobble';
243
+ query += qs.stringify(params, '&');
244
+ return this.request<Success>(query);
245
+ }
246
+
247
+ /**
248
+ * Update a single album, artist, song from the tag data
249
+ * @remarks MINIMUM_API_VERSION=400001
250
+ * @param params.type Object type
251
+ * @param params.id UID to find
252
+ * @see {@link https://ampache.org/api/api-json-methods#update_from_tags}
253
+ */
254
+ updateFromTags (params: {
255
+ type: 'song' | 'artist' | 'album',
256
+ id: UID,
257
+ }) {
258
+ let query = 'update_from_tags';
259
+ query += qs.stringify(params, '&');
260
+ return this.request<Success>(query);
261
+ }
262
+
263
+ /**
264
+ * Update artist information and fetch similar artists from last.fm
265
+ * Make sure lastfm_API_key is set in your configuration file
266
+ * ACCESS REQUIRED: 75 (Catalog Manager)
267
+ * @remarks MINIMUM_API_VERSION=400001
268
+ * @param params.id UID to find
269
+ * @see {@link https://ampache.org/api/api-json-methods#update_artist_info}
270
+ */
271
+ updateArtistInfo (params: {
272
+ id: UID,
273
+ }) {
274
+ let query = 'update_artist_info';
275
+ query += qs.stringify(params, '&');
276
+ return this.request<Success>(query);
277
+ }
278
+
279
+ /**
280
+ * Updates a single album, artist, song running the gather_art process.
281
+ * Doesn't overwrite existing art by default.
282
+ * ACCESS REQUIRED: 75 (Catalog Manager)
283
+ * @remarks MINIMUM_API_VERSION=400001
284
+ * @param params.id UID to update
285
+ * @param params.type Object type
286
+ * @param [params.overwrite]
287
+ * @see {@link https://ampache.org/api/api-json-methods#update_art}
288
+ */
289
+ updateArt (params: {
290
+ id: UID,
291
+ type: 'artist' | 'album' | 'song',
292
+ overwrite?: BinaryBoolean,
293
+ }) {
294
+ let query = 'update_art';
295
+ query += qs.stringify(params, '&');
296
+ return this.request<Success>(query);
297
+ }
298
+
299
+ /**
300
+ * Streams a given media file. Takes the file id in parameter with optional max bit rate, file format, time offset,
301
+ * size and estimate content length option.
302
+ * NOTE search and playlist will only stream a random object from the list.
303
+ * @remarks MINIMUM_API_VERSION=400001
304
+ * @param params.id UID to find
305
+ * @param params.type Object type
306
+ * @param [params.bitrate] Max bitrate for transcoding
307
+ * @param [params.format] mp3, ogg, raw, etc (raw returns the original format)
308
+ * @param [params.offset] Time offset
309
+ * @param [params.length] 0, 1 (estimate content length)
310
+ * @see {@link https://ampache.org/api/api-json-methods#stream}
311
+ */
312
+ stream (params: {
313
+ id: UID,
314
+ type: 'song' | 'podcast_episode' | 'search' | 'playlist',
315
+ bitrate?: number,
316
+ format?: string,
317
+ offset?: number,
318
+ length?: BinaryBoolean,
319
+ }) {
320
+ let query = 'stream';
321
+ query += qs.stringify(params, '&');
322
+ return this.request(query);
323
+ }
324
+
325
+ /**
326
+ * Downloads a given media file. set format=raw to download the full file
327
+ * NOTE search and playlist will only download a random object from the list
328
+ * @remarks MINIMUM_API_VERSION=400001
329
+ * @param params.id UID to find
330
+ * @param params.type Object type
331
+ * @param [params.format] mp3, ogg, raw, etc (raw returns the original format)
332
+ * @see {@link https://ampache.org/api/api-json-methods#download}
333
+ */
334
+ download (params: {
335
+ id: UID,
336
+ type: 'song' | 'podcast_episode' | 'search' | 'playlist',
337
+ format?: string,
338
+ }) {
339
+ let query = 'download';
340
+ query += qs.stringify(params, '&');
341
+ return this.request(query);
342
+ }
343
+
344
+ /**
345
+ * Get an art image file.
346
+ * @remarks MINIMUM_API_VERSION=400001
347
+ * @param params.id UID to find
348
+ * @param params.type Object type
349
+ * @see {@link https://ampache.org/api/api-json-methods#get_art}
350
+ */
351
+ getArt (params: {
352
+ id: UID,
353
+ type: 'song' | 'artist' | 'album' | 'playlist' | 'search' | 'podcast',
354
+ }) {
355
+ let query = 'get_art';
356
+ query += qs.stringify(params, '&');
357
+ return this.request(query);
358
+ }
359
+
360
+ /**
361
+ * This is for controlling localplay
362
+ * @param params.command The command to send to the localplay controller
363
+ * @param [params.oid] Object UID
364
+ * @param [params.type] Object type
365
+ * @param [params.clear] 0, 1 (Clear the current playlist before adding)
366
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=5.0.0
367
+ * @see {@link https://ampache.org/api/api-json-methods#localplay}
368
+ */
369
+ localplay (params: {
370
+ command: 'next' | 'prev' | 'stop' | 'play' | 'pause' | 'add' | 'volume_up' | 'volume_down' | 'volume_mute' | 'delete_all' | 'skip' | 'status',
371
+ oid?: number,
372
+ type?: 'song' | 'video' | 'podcast_episode' | 'channel' | 'broadcast' | 'democratic' | 'live_stream',
373
+ clear?: BinaryBoolean,
374
+ }) {
375
+ let query = 'localplay';
376
+ query += qs.stringify(params, '&');
377
+ return this.request(query);
378
+ }
379
+
380
+ /**
381
+ * Get the list of songs in your localplay playlist
382
+ * @remarks MINIMUM_API_VERSION=5.0.0
383
+ * @see {@link https://ampache.org/api/api-json-methods#localplay_songs}
384
+ */
385
+ localplaySongs () {
386
+ let query = 'localplay_songs';
387
+ return this.request(query);
388
+ }
389
+
390
+ /**
391
+ * This is for controlling democratic play (Songs only). VOTE: +1 vote for the oid. DEVOTE: -1 vote for the oid.
392
+ * PLAYLIST: Return an array of song items with an additional VOTE COUNT element.
393
+ * PLAY: Returns the URL for playing democratic play.
394
+ * @remarks MINIMUM_API_VERSION=380001
395
+ * @param params.oid UID of song
396
+ * @param params.method vote, devote, playlist, play
397
+ * @see {@link https://ampache.org/api/api-json-methods#democratic}
398
+ */
399
+ democratic (params: {
400
+ oid: UID,
401
+ method: 'vote' | 'devote' | 'playlist' | 'play',
402
+ }) {
403
+ let query = 'democratic';
404
+ query += qs.stringify(params, '&');
405
+ return this.request(query);
406
+ }
407
+
408
+ /**
409
+ * Perform an advanced search given passed rules.
410
+ * You'll want to consult the docs for this.
411
+ * @remarks MINIMUM_API_VERSION=380001
412
+ * @param params.operator and, or (whether to match one rule or all)
413
+ * @param params.type Object type to return
414
+ * @param params.rules An array of rules
415
+ * @param [params.random] 0, 1 (random order of results; default to 0)
416
+ * @param [params.offset]
417
+ * @param [params.limit]
418
+ * @see {@link https://ampache.org/api/api-json-methods#advanced_search}
419
+ */
420
+ async advancedSearch (params: {
421
+ operator: 'and' | 'or',
422
+ type: 'song' | 'album' | 'artist' | 'label' | 'playlist' | 'podcast' | 'podcast_episode' | 'genre' | 'user' | 'video',
423
+ rules: Array<Array<string>>,
424
+ random?: BinaryBoolean,
425
+ } & Pagination) {
426
+ let query = 'advanced_search';
427
+
428
+ for (let i = 0; i < params.rules.length; i++) {
429
+ const thisRule = params.rules[i];
430
+ const ruleNumber = i + 1;
431
+
432
+ params['rule_' + ruleNumber] = thisRule[0];
433
+ params['rule_' + ruleNumber + '_operator'] = thisRule[1];
434
+ params['rule_' + ruleNumber + '_input'] = thisRule[2];
435
+
436
+ if (thisRule[0] === 'metadata') {
437
+ params['rule_' + ruleNumber + '_subtype'] = thisRule[3];
438
+ }
439
+ }
440
+
441
+ // drop the initial 'rules' as it was split into its parts
442
+ delete params.rules;
443
+
444
+ query += qs.stringify(params, '&');
445
+
446
+ let data;
447
+
448
+ switch (params.type) {
449
+ case "song":
450
+ data = await this.request<{song: Song[]}>(query);
451
+ return (data.song) ? data.song : data;
452
+ case "album":
453
+ data = await this.request<{album: Album[]}>(query);
454
+ return (data.album) ? data.album : data;
455
+ case "artist":
456
+ data = await this.request<{artist: Artist[]}>(query);
457
+ return (data.artist) ? data.artist : data;
458
+ case "label":
459
+ data = await this.request<{label: Label[]}>(query);
460
+ return (data.label) ? data.label : data;
461
+ case "playlist":
462
+ data = await this.request<{playlist: Playlist[]}>(query);
463
+ return (data.playlist) ? data.playlist : data;
464
+ case "podcast":
465
+ data = await this.request<{podcast: Podcast[]}>(query);
466
+ return (data.podcast) ? data.podcast : data;
467
+ case "podcast_episode":
468
+ data = await this.request<{podcast_episode: PodcastEpisode[]}>(query);
469
+ return (data.podcast_episode) ? data.podcast_episode : data;
470
+ case "genre":
471
+ data = await this.request<{genre: Genre[]}>(query);
472
+ return (data.genre) ? data.genre : data;
473
+ case "user":
474
+ data = await this.request<{user: User[]}>(query);
475
+ return (data.user) ? data.user : data;
476
+ case "video":
477
+ data = await this.request<{video: Video[]}>(query);
478
+ return (data.video) ? data.video : data;
479
+ default:
480
+ return false;
481
+ }
482
+ }
483
+ }
@@ -0,0 +1,11 @@
1
+ import { Song } from "../songs/types";
2
+ import { Album } from "../albums/types";
3
+ import { Artist } from "../artists/types";
4
+ import { Playlist } from "../playlists/types";
5
+ import { Podcast, PodcastEpisode } from "../podcasts/types";
6
+ import { LiveStream } from "../live-streams/types";
7
+ import { Video } from "../videos/types";
8
+
9
+ export type IndexType = Song | Album | Artist | Playlist | Podcast | PodcastEpisode | LiveStream;
10
+
11
+ export type StatsType = Song | Album | Artist | Video | Playlist | Podcast | PodcastEpisode;
@@ -0,0 +1,179 @@
1
+ import qs from 'querystringify';
2
+ import { User, UserSummary, Activity } from './types';
3
+ import { Base, BinaryBoolean, Success } from '../base';
4
+
5
+ export class Users extends Base {
6
+ /**
7
+ * Get ids and usernames for your site
8
+ * @remarks MINIMUM_API_VERSION=5.0.0
9
+ * @see {@link https://ampache.org/api/api-json-methods#users}
10
+ */
11
+ async users() {
12
+ let query = 'users';
13
+ let data = await this.request<{user: UserSummary[]}>(query);
14
+ return (data.user) ? data.user : data;
15
+ }
16
+
17
+ /**
18
+ * This get a user's public information
19
+ * @remarks MINIMUM_API_VERSION=380001
20
+ * @param params.username UID to find
21
+ * @see {@link https://ampache.org/api/api-json-methods#user}
22
+ */
23
+ async user (params: {
24
+ username: string
25
+ }) {
26
+ let query = 'user';
27
+ query += qs.stringify(params, '&');
28
+ return await this.request<User>(query);
29
+ }
30
+
31
+ /**
32
+ * Create a new user
33
+ * ACCESS REQUIRED: 100 (Admin)
34
+ * @remarks MINIMUM_API_VERSION=400001
35
+ * @param params.username Username
36
+ * @param params.password SHA256 hashed password
37
+ * @param params.email Email
38
+ * @param [params.fullname] Full Name
39
+ * @param [params.disable] 0, 1
40
+ * @param [params.catalog_filter_group] Catalog filter group, default = 0
41
+ * @see {@link https://ampache.org/api/api-json-methods#user_create}
42
+ */
43
+ userCreate (params: {
44
+ username: string,
45
+ password: string,
46
+ email: string,
47
+ fullname?: string,
48
+ disable?: BinaryBoolean,
49
+ catalog_filter_group?: number
50
+ }) {
51
+ let query = 'user_create';
52
+ query += qs.stringify(params, '&');
53
+ return this.request<Success>(query);
54
+ }
55
+
56
+ /**
57
+ * Update an existing user
58
+ * ACCESS REQUIRED: 100 (Admin)
59
+ * @remarks MINIMUM_API_VERSION=400001
60
+ * @param params.username Username
61
+ * @param [params.password] Password
62
+ * @param [params.email] Email
63
+ * @param [params.fullname] Full Name
64
+ * @param [params.website] Website
65
+ * @param [params.state] State
66
+ * @param [params.city] City
67
+ * @param [params.disable] 0, 1
68
+ * @param [params.maxbitrate] Max bitrate for transcoding
69
+ * @see {@link https://ampache.org/api/api-json-methods#user_update}
70
+ */
71
+ userUpdate (params: {
72
+ username: string,
73
+ password?: string,
74
+ email?: string,
75
+ fullname?: string,
76
+ website?: string,
77
+ state?: string,
78
+ city?: string,
79
+ disable?: BinaryBoolean,
80
+ maxbitrate?: string
81
+ }) {
82
+ let query = 'user_update';
83
+ query += qs.stringify(params, '&');
84
+ return this.request<Success>(query);
85
+ }
86
+
87
+ /**
88
+ * Delete an existing user.
89
+ * ACCESS REQUIRED: 100 (Admin)
90
+ * @remarks MINIMUM_API_VERSION=400001
91
+ * @param params.filter UID of user to delete
92
+ * @see {@link https://ampache.org/api/api-json-methods#user_delete}
93
+ */
94
+ userDelete (params: {
95
+ filter: string,
96
+ }) {
97
+ let query = 'user_delete';
98
+ query += qs.stringify(params, '&');
99
+ return this.request<Success>(query);
100
+ }
101
+
102
+ /**
103
+ * This gets the followers for the requested username
104
+ * @remarks MINIMUM_API_VERSION=380001
105
+ * @param params.username UID to find
106
+ * @see {@link https://ampache.org/api/api-json-methods#followers}
107
+ */
108
+ async followers (params: {
109
+ username: string,
110
+ }) {
111
+ let query = 'followers';
112
+ query += qs.stringify(params, '&');
113
+ let data = await this.request<{user: UserSummary[]}>(query);
114
+ return (data.user) ? data.user : data;
115
+ }
116
+
117
+ /**
118
+ * Get a list of people that this user follows
119
+ * @remarks MINIMUM_API_VERSION=380001
120
+ * @see {@link https://ampache.org/api/api-json-methods#following}
121
+ */
122
+ async following (params: {
123
+ username: string,
124
+ }) {
125
+ let query = 'following';
126
+ query += qs.stringify(params, '&');
127
+ let data = await this.request<{user: UserSummary[]}>(query);
128
+ return (data.user) ? data.user : data;
129
+ }
130
+
131
+ /**
132
+ * This will follow/unfollow a user
133
+ * @param params.username Username string to find
134
+ * @see {@link https://ampache.org/api/api-json-methods#toggle_follow}
135
+ */
136
+ toggleFollow(params: {
137
+ username: string,
138
+ }) {
139
+ let query = 'toggle_follow';
140
+ query += qs.stringify(params, '&');
141
+ return this.request<Success>(query);
142
+ }
143
+
144
+ /**
145
+ * This get a user timeline
146
+ * @remarks MINIMUM_API_VERSION=380001
147
+ * @param params.username Username to find
148
+ * @param [params.limit] Max results to return
149
+ * @param [params.since] UNIXTIME
150
+ * @see {@link https://ampache.org/api/api-json-methods#timeline}
151
+ */
152
+ async timeline (params: {
153
+ username: string,
154
+ limit?: number,
155
+ since?: number,
156
+ }) {
157
+ let query = 'timeline';
158
+ query += qs.stringify(params, '&');
159
+ let data = await this.request<{activity: Activity[]}>(query);
160
+ return (data.activity) ? data.activity : data;
161
+ }
162
+
163
+ /**
164
+ * This get current user friends timeline
165
+ * @remarks MINIMUM_API_VERSION=380001
166
+ * @param [params.limit] Max results to return
167
+ * @param [params.since] UNIXTIME
168
+ * @see {@link https://ampache.org/api/api-json-methods#friends_timeline}
169
+ */
170
+ async friendsTimeline (params?: {
171
+ limit?: number,
172
+ since?: number,
173
+ }) {
174
+ let query = 'friends_timeline';
175
+ query += qs.stringify(params, '&');
176
+ let data = await this.request<{activity: Activity[]}>(query);
177
+ return (data.activity) ? data.activity : data;
178
+ }
179
+ }