javascript-ampache 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,262 +1,280 @@
1
- import qs from "querystringify";
2
- import { PlaylistResponse, PlaylistsResponse } from "./types";
3
- import { SongsResponse } from "../songs/types";
4
- import {
5
- Base,
6
- BinaryBoolean,
7
- ExtendedPagination,
8
- Pagination,
9
- Success,
10
- UID,
11
- } from "../base";
12
-
13
- export class Playlists extends Base {
14
- /**
15
- * This returns playlists based on the specified filter
16
- * @remarks MINIMUM_API_VERSION=380001
17
- * @param [params.filter] Filter results to match this string
18
- * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
19
- * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
20
- * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
21
- * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
22
- * @param [params.show_dupes] 0, 1 (if true ignore 'api_hide_dupe_searches' setting)
23
- * @param [params.offset]
24
- * @param [params.limit]
25
- * @param [params.cond]
26
- * @param [params.sort]
27
- * @see {@link https://ampache.org/api/api-json-methods#playlists}
28
- */
29
- playlists(
30
- params?: {
31
- filter?: string;
32
- exact?: BinaryBoolean;
33
- add?: Date;
34
- update?: Date;
35
- hide_search?: BinaryBoolean;
36
- show_dupes?: BinaryBoolean;
37
- } & ExtendedPagination,
38
- ) {
39
- let query = "playlists";
40
- query += qs.stringify(params, "&");
41
- return this.request<PlaylistsResponse>(query);
42
- }
43
-
44
- /**
45
- * This returns smartlists based on the specified filter. NOTE: Filtered from Playlists() so pagination is invalid.
46
- * @remarks MINIMUM_API_VERSION=380001
47
- * @param [params.filter] Filter results to match this string
48
- * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
49
- * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
50
- * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
51
- * @param [params.show_dupes] 0, 1 (if true ignore 'api_hide_dupe_searches' setting)
52
- * @see {@link https://ampache.org/api/api-json-methods#playlists}
53
- */
54
- smartlists(params?: {
55
- filter?: string;
56
- exact?: BinaryBoolean;
57
- add?: Date;
58
- update?: Date;
59
- show_dupes?: BinaryBoolean;
60
- }) {
61
- let query = "playlists";
62
- query += qs.stringify(params, "&");
63
- return this.request<PlaylistsResponse>(query).then((response) => {
64
- // filter out regular playlists
65
- if (Array.isArray(response.playlist)) {
66
- response.playlist = response.playlist.filter((item) =>
67
- item.id.toString().startsWith("smart_"),
68
- );
69
- }
70
- return response;
71
- });
72
- }
73
-
74
- /**
75
- * This returns a single playlist
76
- * @remarks MINIMUM_API_VERSION=380001
77
- * @param params.filter UID to find
78
- * @see {@link https://ampache.org/api/api-json-methods#playlist}
79
- */
80
- playlist(params: { filter: UID }) {
81
- let query = "playlist";
82
- query += qs.stringify(params, "&");
83
- return this.request<PlaylistResponse>(query);
84
- }
85
-
86
- /**
87
- * This returns a user's playlists based on the specified filter
88
- * @remarks MINIMUM_API_VERSION=6.3.0
89
- * @param [params.filter] Filter results to match this string
90
- * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
91
- * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
92
- * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
93
- * @param [params.offset]
94
- * @param [params.limit]
95
- * @param [params.cond]
96
- * @param [params.sort]
97
- * @see {@link https://ampache.org/api/api-json-methods#user_playlists}
98
- */
99
- userPlaylists(
100
- params?: {
101
- filter?: string;
102
- exact?: BinaryBoolean;
103
- add?: Date;
104
- update?: Date;
105
- } & ExtendedPagination,
106
- ) {
107
- let query = "user_playlists";
108
- query += qs.stringify(params, "&");
109
- return this.request<PlaylistsResponse>(query);
110
- }
111
-
112
- /**
113
- * This returns a user's smartlists based on the specified filter
114
- * @remarks MINIMUM_API_VERSION=6.3.0
115
- * @param [params.filter] Filter results to match this string
116
- * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
117
- * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
118
- * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
119
- * @param [params.offset]
120
- * @param [params.limit]
121
- * @param [params.cond]
122
- * @param [params.sort]
123
- * @see {@link https://ampache.org/api/api-json-methods#user_smartlists}
124
- */
125
- userSmartlists(
126
- params?: {
127
- filter?: string;
128
- exact?: BinaryBoolean;
129
- add?: Date;
130
- update?: Date;
131
- } & ExtendedPagination,
132
- ) {
133
- let query = "user_smartlists";
134
- query += qs.stringify(params, "&");
135
- return this.request<PlaylistsResponse>(query);
136
- }
137
-
138
- /**
139
- * This creates a new playlist and returns it
140
- * @remarks MINIMUM_API_VERSION=380001
141
- * @param params.name Playlist name
142
- * @param [params.type] public, private (Playlist type)
143
- * @see {@link https://ampache.org/api/api-json-methods#playlist_create}
144
- */
145
- playlistCreate(params: { name: string; type?: "public" | "private" }) {
146
- let query = "playlist_create";
147
- query += qs.stringify(params, "&");
148
- return this.request<PlaylistResponse>(query);
149
- }
150
-
151
- /**
152
- * This adds an item to a playlist
153
- * @remarks MINIMUM_API_VERSION=6.3.0
154
- * @param params.filter UID of Playlist
155
- * @param params.id UID of the object to add to playlist
156
- * @param params.type 'song', 'album', 'artist', 'playlist'
157
- * @see {@link https://ampache.org/api/api-json-methods#playlist_add}
158
- */
159
- playlistAdd(params: {
160
- filter: UID;
161
- id: UID;
162
- type: "song" | "album" | "artist" | "playlist";
163
- }) {
164
- let query = "playlist_add";
165
- query += qs.stringify(params, "&");
166
- return this.request<Success>(query);
167
- }
168
-
169
- /**
170
- * This modifies name and type of the playlist.
171
- * NOTE items and tracks must be sent together and be of equal length.
172
- * @remarks MINIMUM_API_VERSION=400001
173
- * @param params.filter UID to find
174
- * @param [params.name] Playlist name
175
- * @param [params.type] public, private (Playlist type)
176
- * @param [params.owner] Change playlist owner to the user id (-1 = System playlist)
177
- * @param [params.items] comma-separated song_id's (replaces existing items with a new id)
178
- * @param [params.tracks] comma-separated playlisttrack numbers matched to 'items' in order
179
- * @see {@link https://ampache.org/api/api-json-methods#playlist_edit}
180
- */
181
- playlistEdit(params: {
182
- filter: UID;
183
- name?: string;
184
- type?: "public" | "private";
185
- owner?: string;
186
- items?: string;
187
- tracks?: string;
188
- }) {
189
- let query = "playlist_edit";
190
- query += qs.stringify(params, "&");
191
- return this.request<Success>(query);
192
- }
193
-
194
- /**
195
- * This deletes a playlist
196
- * @remarks MINIMUM_API_VERSION=380001
197
- * @param params.filter UID of playlist to delete
198
- * @see {@link https://ampache.org/api/api-json-methods#playlist_delete}
199
- */
200
- playlistDelete(params: { filter: UID }) {
201
- let query = "playlist_delete";
202
- query += qs.stringify(params, "&");
203
- return this.request<Success>(query);
204
- }
205
-
206
- /**
207
- * This adds a song to a playlist
208
- * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400003
209
- * @param params.filter UID of Playlist
210
- * @param params.song UID of song to add to playlist
211
- * @param [params.check] 0, 1 Whether to check and ignore duplicates (default = 0)
212
- * @see {@link https://ampache.org/api/api-json-methods#playlist_add_song}
213
- * @deprecated Being removed in 7.0.0. Use `playlist_add` instead.
214
- */
215
- playlistAddSong(params: { filter: UID; song: UID; check?: BinaryBoolean }) {
216
- let query = "playlist_add_song";
217
- query += qs.stringify(params, "&");
218
- return this.request<Success>(query);
219
- }
220
-
221
- /**
222
- * This remove a song from a playlist
223
- * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400001
224
- * @param params.filter UID of Playlist
225
- * @param [params.song] UID of song to remove from playlist
226
- * @param [params.track] Track number to remove from playlist
227
- * @see {@link https://ampache.org/api/api-json-methods#playlist_remove_song}
228
- */
229
- playlistRemoveSong(params: { filter: UID; song?: UID; track?: number }) {
230
- let query = "playlist_remove_song";
231
- query += qs.stringify(params, "&");
232
- return this.request<Success>(query);
233
- }
234
-
235
- /**
236
- * Get a list of song JSON, indexes or id's based on some simple search criteria
237
- * @remarks MINIMUM_API_VERSION=400001; CHANGED_IN_API_VERSION=400002; 'recent' will search for tracks played after 'Popular Threshold' days; 'forgotten' will search for tracks played before 'Popular Threshold' days; 'unplayed' added in 400002 for searching unplayed tracks
238
- * @param [params.mode] (default = 'random')
239
- * @param [params.filter] string LIKE matched to song title
240
- * @param [params.album] UID of album
241
- * @param [params.artist] UID of artist
242
- * @param [params.flag] 0, 1 (get flagged songs only. default = 0)
243
- * @param [params.format] song, index, id (default = 'song')
244
- * @param [params.offset]
245
- * @param [params.limit]
246
- * @see {@link https://ampache.org/api/api-json-methods#playlist_generate}
247
- */
248
- playlistGenerate(
249
- params?: {
250
- mode?: "recent" | "forgotten" | "unplayed" | "random";
251
- filter?: string;
252
- album?: number;
253
- artist?: number;
254
- flag?: BinaryBoolean;
255
- format?: "song" | "index" | "id";
256
- } & Pagination,
257
- ) {
258
- let query = "playlist_generate";
259
- query += qs.stringify(params, "&");
260
- return this.request<SongsResponse>(query);
261
- }
262
- }
1
+ import qs from "querystringify";
2
+ import { HashResponse, PlaylistResponse, PlaylistsResponse } from "./types";
3
+ import { SongsResponse } from "../songs/types";
4
+ import {
5
+ Base,
6
+ BinaryBoolean,
7
+ ExtendedPagination,
8
+ Pagination,
9
+ Success,
10
+ UID,
11
+ } from "../base";
12
+
13
+ export class Playlists extends Base {
14
+ /**
15
+ * This returns playlists based on the specified filter
16
+ * @remarks MINIMUM_API_VERSION=380001
17
+ * @param [params.filter] Filter results to match this string
18
+ * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
19
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
20
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
21
+ * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
22
+ * @param [params.show_dupes] 0, 1 (if true ignore 'api_hide_dupe_searches' setting)
23
+ * @param [params.include] 0, 1 (if true include the objects in the playlist)
24
+ * @param [params.offset]
25
+ * @param [params.limit]
26
+ * @param [params.cond]
27
+ * @param [params.sort]
28
+ * @see {@link https://ampache.org/api/api-json-methods#playlists}
29
+ */
30
+ playlists(
31
+ params?: {
32
+ filter?: string;
33
+ exact?: BinaryBoolean;
34
+ add?: Date;
35
+ update?: Date;
36
+ hide_search?: BinaryBoolean;
37
+ show_dupes?: BinaryBoolean;
38
+ include?: BinaryBoolean;
39
+ } & ExtendedPagination,
40
+ ) {
41
+ let query = "playlists";
42
+ query += qs.stringify(params, "&");
43
+ return this.request<PlaylistsResponse>(query);
44
+ }
45
+
46
+ /**
47
+ * This returns smartlists based on the specified filter. NOTE: Filtered from Playlists() so pagination is invalid.
48
+ * @remarks MINIMUM_API_VERSION=380001
49
+ * @param [params.filter] Filter results to match this string
50
+ * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
51
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
52
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
53
+ * @param [params.show_dupes] 0, 1 (if true ignore 'api_hide_dupe_searches' setting)
54
+ * @see {@link https://ampache.org/api/api-json-methods#playlists}
55
+ */
56
+ smartlists(params?: {
57
+ filter?: string;
58
+ exact?: BinaryBoolean;
59
+ add?: Date;
60
+ update?: Date;
61
+ show_dupes?: BinaryBoolean;
62
+ }) {
63
+ let query = "playlists";
64
+ query += qs.stringify(params, "&");
65
+ return this.request<PlaylistsResponse>(query).then((response) => {
66
+ // filter out regular playlists
67
+ if (Array.isArray(response.playlist)) {
68
+ response.playlist = response.playlist.filter((item) =>
69
+ item.id.toString().startsWith("smart_"),
70
+ );
71
+ }
72
+ return response;
73
+ });
74
+ }
75
+
76
+ /**
77
+ * This returns a single playlist
78
+ * @remarks MINIMUM_API_VERSION=380001
79
+ * @param params.filter UID to find
80
+ * @see {@link https://ampache.org/api/api-json-methods#playlist}
81
+ */
82
+ playlist(params: { filter: UID }) {
83
+ let query = "playlist";
84
+ query += qs.stringify(params, "&");
85
+ return this.request<PlaylistResponse>(query);
86
+ }
87
+
88
+ /**
89
+ * This returns a user's playlists based on the specified filter
90
+ * @remarks MINIMUM_API_VERSION=6.3.0
91
+ * @param [params.filter] Filter results to match this string
92
+ * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
93
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
94
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
95
+ * @param [params.offset]
96
+ * @param [params.limit]
97
+ * @param [params.cond]
98
+ * @param [params.sort]
99
+ * @see {@link https://ampache.org/api/api-json-methods#user_playlists}
100
+ */
101
+ userPlaylists(
102
+ params?: {
103
+ filter?: string;
104
+ exact?: BinaryBoolean;
105
+ add?: Date;
106
+ update?: Date;
107
+ } & ExtendedPagination,
108
+ ) {
109
+ let query = "user_playlists";
110
+ query += qs.stringify(params, "&");
111
+ return this.request<PlaylistsResponse>(query);
112
+ }
113
+
114
+ /**
115
+ * This returns a user's smartlists based on the specified filter
116
+ * @remarks MINIMUM_API_VERSION=6.3.0
117
+ * @param [params.filter] Filter results to match this string
118
+ * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
119
+ * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
120
+ * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
121
+ * @param [params.offset]
122
+ * @param [params.limit]
123
+ * @param [params.cond]
124
+ * @param [params.sort]
125
+ * @see {@link https://ampache.org/api/api-json-methods#user_smartlists}
126
+ */
127
+ userSmartlists(
128
+ params?: {
129
+ filter?: string;
130
+ exact?: BinaryBoolean;
131
+ add?: Date;
132
+ update?: Date;
133
+ } & ExtendedPagination,
134
+ ) {
135
+ let query = "user_smartlists";
136
+ query += qs.stringify(params, "&");
137
+ return this.request<PlaylistsResponse>(query);
138
+ }
139
+
140
+ /**
141
+ * This creates a new playlist and returns it
142
+ * @remarks MINIMUM_API_VERSION=380001
143
+ * @param params.name Playlist name
144
+ * @param [params.type] public, private (Playlist type)
145
+ * @see {@link https://ampache.org/api/api-json-methods#playlist_create}
146
+ */
147
+ playlistCreate(params: { name: string; type?: "public" | "private" }) {
148
+ let query = "playlist_create";
149
+ query += qs.stringify(params, "&");
150
+ return this.request<PlaylistResponse>(query);
151
+ }
152
+
153
+ /**
154
+ * This adds an item to a playlist
155
+ * @remarks MINIMUM_API_VERSION=6.3.0
156
+ * @param params.filter UID of Playlist
157
+ * @param params.id UID of the object to add to playlist
158
+ * @param params.type 'song', 'album', 'artist', 'playlist'
159
+ * @see {@link https://ampache.org/api/api-json-methods#playlist_add}
160
+ */
161
+ playlistAdd(params: {
162
+ filter: UID;
163
+ id: UID;
164
+ type: "song" | "album" | "artist" | "playlist";
165
+ }) {
166
+ let query = "playlist_add";
167
+ query += qs.stringify(params, "&");
168
+ return this.request<Success>(query);
169
+ }
170
+
171
+ /**
172
+ * This modifies name and type of the playlist.
173
+ * NOTE items and tracks must be sent together and be of equal length.
174
+ * @remarks MINIMUM_API_VERSION=400001
175
+ * @param params.filter UID to find
176
+ * @param [params.name] Playlist name
177
+ * @param [params.type] public, private (Playlist type)
178
+ * @param [params.owner] Change playlist owner to the user id (-1 = System playlist)
179
+ * @param [params.items] comma-separated song_id's (replaces existing items with a new id)
180
+ * @param [params.tracks] comma-separated playlisttrack numbers matched to 'items' in order
181
+ * @see {@link https://ampache.org/api/api-json-methods#playlist_edit}
182
+ */
183
+ playlistEdit(params: {
184
+ filter: UID;
185
+ name?: string;
186
+ type?: "public" | "private";
187
+ owner?: string;
188
+ items?: string;
189
+ tracks?: string;
190
+ }) {
191
+ let query = "playlist_edit";
192
+ query += qs.stringify(params, "&");
193
+ return this.request<Success>(query);
194
+ }
195
+
196
+ /**
197
+ * This deletes a playlist
198
+ * @remarks MINIMUM_API_VERSION=380001
199
+ * @param params.filter UID of playlist to delete
200
+ * @see {@link https://ampache.org/api/api-json-methods#playlist_delete}
201
+ */
202
+ playlistDelete(params: { filter: UID }) {
203
+ let query = "playlist_delete";
204
+ query += qs.stringify(params, "&");
205
+ return this.request<Success>(query);
206
+ }
207
+
208
+ /**
209
+ * This adds a song to a playlist
210
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400003
211
+ * @param params.filter UID of Playlist
212
+ * @param params.song UID of song to add to playlist
213
+ * @param [params.check] 0, 1 Whether to check and ignore duplicates (default = 0)
214
+ * @see {@link https://ampache.org/api/api-json-methods#playlist_add_song}
215
+ * @deprecated Being removed in 7.0.0. Use `playlist_add` instead.
216
+ */
217
+ playlistAddSong(params: { filter: UID; song: UID; check?: BinaryBoolean }) {
218
+ let query = "playlist_add_song";
219
+ query += qs.stringify(params, "&");
220
+ return this.request<Success>(query);
221
+ }
222
+
223
+ /**
224
+ * This remove a song from a playlist
225
+ * @remarks MINIMUM_API_VERSION=380001; CHANGED_IN_API_VERSION=400001
226
+ * @param params.filter UID of Playlist
227
+ * @param [params.song] UID of song to remove from playlist
228
+ * @param [params.track] Track number to remove from playlist
229
+ * @see {@link https://ampache.org/api/api-json-methods#playlist_remove_song}
230
+ */
231
+ playlistRemoveSong(params: { filter: UID; song?: UID; track?: number }) {
232
+ let query = "playlist_remove_song";
233
+ query += qs.stringify(params, "&");
234
+ return this.request<Success>(query);
235
+ }
236
+
237
+ /**
238
+ * Get a list of song JSON, indexes or id's based on some simple search criteria
239
+ * @remarks MINIMUM_API_VERSION=400001; CHANGED_IN_API_VERSION=400002; 'recent' will search for tracks played after 'Popular Threshold' days; 'forgotten' will search for tracks played before 'Popular Threshold' days; 'unplayed' added in 400002 for searching unplayed tracks
240
+ * @param [params.mode] (default = 'random')
241
+ * @param [params.filter] string LIKE matched to song title
242
+ * @param [params.album] UID of album
243
+ * @param [params.artist] UID of artist
244
+ * @param [params.flag] 0, 1 (get flagged songs only. default = 0)
245
+ * @param [params.format] song, index, id (default = 'song')
246
+ * @param [params.offset]
247
+ * @param [params.limit]
248
+ * @see {@link https://ampache.org/api/api-json-methods#playlist_generate}
249
+ */
250
+ playlistGenerate(
251
+ params?: {
252
+ mode?: "recent" | "forgotten" | "unplayed" | "random";
253
+ filter?: string;
254
+ album?: number;
255
+ artist?: number;
256
+ flag?: BinaryBoolean;
257
+ format?: "song" | "index" | "id";
258
+ } & Pagination,
259
+ ) {
260
+ let query = "playlist_generate";
261
+ query += qs.stringify(params, "&");
262
+ return this.request<SongsResponse>(query);
263
+ }
264
+
265
+ /**
266
+ * This returns the md5 hash for the songs in a playlist
267
+ * @remarks MINIMUM_API_VERSION=6.6.0
268
+ * @param params.filter string UID of Playlist
269
+ * @see {@link https://ampache.org/api/api-json-methods#playlist_hash}
270
+ */
271
+ playlistHash(
272
+ params: {
273
+ filter: UID;
274
+ },
275
+ ) {
276
+ let query = "playlist_hash";
277
+ query += qs.stringify(params, "&");
278
+ return this.request<HashResponse>(query);
279
+ }
280
+ }
@@ -13,6 +13,9 @@ export type PlaylistResponse = {
13
13
  rating: number | null;
14
14
  averagerating: number | null;
15
15
  user: UserSummary;
16
+ has_access: boolean;
17
+ has_collaborate: boolean;
18
+ last_update: number;
16
19
  };
17
20
 
18
21
  export type PlaylistsResponse = {
@@ -20,3 +23,7 @@ export type PlaylistsResponse = {
20
23
  md5: string;
21
24
  playlist: PlaylistResponse[];
22
25
  };
26
+
27
+ export type HashResponse = {
28
+ md5: string;
29
+ };
@@ -6,4 +6,6 @@ export type ShoutResponse = {
6
6
  date: number;
7
7
  text: string;
8
8
  user: UserSummary;
9
+ object_type: "song" | "album" | "artist" | "playlist";
10
+ object_id: UID;
9
11
  };