javascript-ampache 1.1.4 → 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,4 +1,4 @@
1
- import { PlaylistResponse, PlaylistsResponse } from "./types";
1
+ import { HashResponse, PlaylistResponse, PlaylistsResponse } from "./types";
2
2
  import { SongsResponse } from "../songs/types";
3
3
  import { Base, BinaryBoolean, ExtendedPagination, Pagination, Success, UID } from "../base";
4
4
  export declare class Playlists extends Base {
@@ -11,6 +11,7 @@ export declare class Playlists extends Base {
11
11
  * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
12
12
  * @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
13
13
  * @param [params.show_dupes] 0, 1 (if true ignore 'api_hide_dupe_searches' setting)
14
+ * @param [params.include] 0, 1 (if true include the objects in the playlist)
14
15
  * @param [params.offset]
15
16
  * @param [params.limit]
16
17
  * @param [params.cond]
@@ -24,6 +25,7 @@ export declare class Playlists extends Base {
24
25
  update?: Date;
25
26
  hide_search?: BinaryBoolean;
26
27
  show_dupes?: BinaryBoolean;
28
+ include?: BinaryBoolean;
27
29
  } & ExtendedPagination): Promise<PlaylistsResponse>;
28
30
  /**
29
31
  * This returns smartlists based on the specified filter. NOTE: Filtered from Playlists() so pagination is invalid.
@@ -190,4 +192,13 @@ export declare class Playlists extends Base {
190
192
  flag?: BinaryBoolean;
191
193
  format?: "song" | "index" | "id";
192
194
  } & Pagination): Promise<SongsResponse>;
195
+ /**
196
+ * This returns the md5 hash for the songs in a playlist
197
+ * @remarks MINIMUM_API_VERSION=6.6.0
198
+ * @param params.filter string UID of Playlist
199
+ * @see {@link https://ampache.org/api/api-json-methods#playlist_hash}
200
+ */
201
+ playlistHash(params: {
202
+ filter: UID;
203
+ }): Promise<HashResponse>;
193
204
  }
@@ -1,4 +1,5 @@
1
1
  import { UID } from "../base";
2
+ import { UserSummary } from "../users/types";
2
3
  export type PlaylistResponse = {
3
4
  id: UID;
4
5
  name: string;
@@ -10,9 +11,16 @@ export type PlaylistResponse = {
10
11
  flag: boolean;
11
12
  rating: number | null;
12
13
  averagerating: number | null;
14
+ user: UserSummary;
15
+ has_access: boolean;
16
+ has_collaborate: boolean;
17
+ last_update: number;
13
18
  };
14
19
  export type PlaylistsResponse = {
15
20
  total_count: number;
16
21
  md5: string;
17
22
  playlist: PlaylistResponse[];
18
23
  };
24
+ export type HashResponse = {
25
+ md5: string;
26
+ };
@@ -8,6 +8,8 @@ export type PreferenceResponse = {
8
8
  type: string;
9
9
  category: string;
10
10
  subcategory: string | null;
11
+ has_access: boolean;
12
+ values?: string;
11
13
  };
12
14
  export type PreferencesResponse = {
13
15
  total_count: number;
@@ -5,4 +5,6 @@ export type ShoutResponse = {
5
5
  date: number;
6
6
  text: string;
7
7
  user: UserSummary;
8
+ object_type: "song" | "album" | "artist" | "playlist";
9
+ object_id: UID;
8
10
  };
@@ -105,6 +105,13 @@ export declare class Songs extends Base {
105
105
  songDelete(params: {
106
106
  filter: UID;
107
107
  }): Promise<Success>;
108
+ /**
109
+ * Get the full song file tags using VaInfo
110
+ * This is used to get tags for remote catalogs to allow maximum data to be returned
111
+ * @remarks MINIMUM_API_VERSION=7.5.0
112
+ * @param params.filter UID of song to fetch
113
+ * @see {@link https://ampache.org/api/api-json-methods#song_tags}
114
+ */
108
115
  /**
109
116
  * This takes a URL and returns the song object in question
110
117
  * @remarks MINIMUM_API_VERSION=380001
@@ -1,5 +1,5 @@
1
1
  import { Base, BinaryBoolean, ExtendedPagination, Pagination, Success, UID } from "../base";
2
- import { IndexEntry } from "./types";
2
+ import { IndexEntry, NowPlayingResponse } from "./types";
3
3
  export declare class System extends Base {
4
4
  /**
5
5
  * Check Ampache for updates and run the update if there is one.
@@ -24,7 +24,7 @@ export declare class System extends Base {
24
24
  * @deprecated Being removed in 7.0.0. Use `list` instead.
25
25
  */
26
26
  getIndexes(params: {
27
- type: "song" | "album" | "artist" | "album_artist" | "playlist" | "podcast" | "podcast_episode" | "live_stream";
27
+ type: "song" | "album" | "artist" | "album_artist" | "playlist" | "podcast" | "podcast_episode" | "live_stream" | "catalog" | "song_artist";
28
28
  filter?: string;
29
29
  add?: Date;
30
30
  update?: Date;
@@ -46,7 +46,7 @@ export declare class System extends Base {
46
46
  * @see {@link https://ampache.org/api/api-json-methods#list}
47
47
  */
48
48
  list(params: {
49
- type: "song" | "album" | "artist" | "album_artist" | "playlist" | "podcast" | "podcast_episode" | "live_stream";
49
+ type: "song" | "album" | "artist" | "album_artist" | "playlist" | "podcast" | "podcast_episode" | "live_stream" | "catalog" | "song_artist";
50
50
  filter?: string;
51
51
  add?: Date;
52
52
  update?: Date;
@@ -154,12 +154,14 @@ export declare class System extends Base {
154
154
  * @param params.type Object type
155
155
  * @param params.id UID to find
156
156
  * @param params.flag 0, 1
157
+ * @param [params.date] UNIXTIME
157
158
  * @see {@link https://ampache.org/api/api-json-methods#flag}
158
159
  */
159
160
  flag(params: {
160
161
  type: "song" | "album" | "artist" | "playlist" | "podcast" | "podcast_episode" | "video" | "tvshow" | "tvshow_season";
161
162
  id: UID;
162
163
  flag: BinaryBoolean;
164
+ date?: number;
163
165
  }): Promise<Success>;
164
166
  /**
165
167
  * 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.
@@ -255,6 +257,7 @@ export declare class System extends Base {
255
257
  * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
256
258
  * @param [params.offset] Time offset
257
259
  * @param [params.length] 0, 1 (estimate content length)
260
+ * @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
258
261
  * @see {@link https://ampache.org/api/api-json-methods#stream}
259
262
  */
260
263
  stream(params: {
@@ -264,6 +267,7 @@ export declare class System extends Base {
264
267
  format?: string;
265
268
  offset?: number;
266
269
  length?: BinaryBoolean;
270
+ stats?: BinaryBoolean;
267
271
  }): Promise<Blob>;
268
272
  /**
269
273
  * Downloads a given media file. set format=raw to download the full file
@@ -272,12 +276,16 @@ export declare class System extends Base {
272
276
  * @param params.id UID to find
273
277
  * @param params.type Object type
274
278
  * @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
279
+ * @param [params.bitrate] max bitrate for transcoding in bytes (e.g 192000=192Kb)
280
+ * @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
275
281
  * @see {@link https://ampache.org/api/api-json-methods#download}
276
282
  */
277
283
  download(params: {
278
284
  id: UID;
279
285
  type: "song" | "podcast_episode" | "search" | "playlist";
280
286
  format?: string;
287
+ bitrate?: number;
288
+ stats?: BinaryBoolean;
281
289
  }): Promise<Blob>;
282
290
  /**
283
291
  * Get an art image file.
@@ -324,6 +332,33 @@ export declare class System extends Base {
324
332
  oid: UID;
325
333
  method: "vote" | "devote" | "playlist" | "play";
326
334
  }): Promise<unknown>;
335
+ /**
336
+ * Get what is currently being played by all users.
337
+ * @remarks MINIMUM_API_VERSION=6.3.1
338
+ * @see {@link https://ampache.org/api/api-json-methods#now_playing}
339
+ */
340
+ nowPlaying(): Promise<{
341
+ now_playing: NowPlayingResponse[];
342
+ }>;
343
+ /**
344
+ * Inform the server about the state of your client. (Song you are playing, Play/Pause state, etc.)
345
+ * @remarks MINIMUM_API_VERSION=6.4.0
346
+ * @param params.filter $object_id currently playing/stopping
347
+ * @param [params.type] song, video, podcast_episode (Default: song)
348
+ * @param [params.state] play, stop (Default: play)
349
+ * @param [params.time] current play time in whole seconds (Default: 0)
350
+ * @param [params.client] agent/client name
351
+ * @see {@link https://ampache.org/api/api-json-methods#player}
352
+ */
353
+ player(params: {
354
+ filter: UID;
355
+ type?: "song" | "video" | "podcast_episode";
356
+ state?: "play" | "stop";
357
+ time?: number;
358
+ client?: string;
359
+ }): Promise<{
360
+ now_playing: NowPlayingResponse[];
361
+ }>;
327
362
  /**
328
363
  * Perform an advanced search given passed rules.
329
364
  * You'll want to consult the docs for this.
@@ -342,4 +377,29 @@ export declare class System extends Base {
342
377
  rules: Array<Array<string>>;
343
378
  random?: BinaryBoolean;
344
379
  } & Pagination): any;
380
+ search: (params: {
381
+ operator: "and" | "or";
382
+ type: "song" | "album" | "album_disk" | "artist" | "album_artist" | "song_artist" | "label" | "playlist" | "podcast" | "podcast_episode" | "genre" | "user" | "video";
383
+ rules: Array<Array<string>>;
384
+ random?: BinaryBoolean;
385
+ } & Pagination) => any;
386
+ /**
387
+ * Perform a search given passed rules and return matching objects in a group.
388
+ * If the rules do not exist for the object type or would return the entire table they will not return objects
389
+ * You'll want to consult the docs for this.
390
+ * @remarks MINIMUM_API_VERSION=6.3.0
391
+ * @param params.operator and, or (whether to match one rule or all)
392
+ * @param params.rules An array of rules
393
+ * @param [params.type] Object type to return (all, music, song_artist, album_artist, podcast, video; all by default)
394
+ * @param [params.random] 0, 1 (random order of results; default to 0)
395
+ * @param [params.offset]
396
+ * @param [params.limit]
397
+ * @see {@link https://ampache.org/api/api-json-methods#search_group}
398
+ */
399
+ searchGroup(params: {
400
+ operator: "and" | "or";
401
+ rules: Array<Array<string>>;
402
+ type?: "all" | "music" | "song_artist" | "album_artist" | "podcast" | "video";
403
+ random?: BinaryBoolean;
404
+ } & Pagination): any;
345
405
  }
@@ -6,6 +6,7 @@ import { PodcastResponse, PodcastEpisodeResponse } from "../podcasts/types";
6
6
  import { LiveStreamResponse } from "../live-streams/types";
7
7
  import { VideoResponse } from "../videos/types";
8
8
  import { UID } from "../base";
9
+ import { UserSummary } from "../users/types";
9
10
  export type IndexType = SongResponse | AlbumResponse | ArtistResponse | PlaylistResponse | PodcastResponse | PodcastEpisodeResponse | LiveStreamResponse;
10
11
  export type StatsType = SongResponse | AlbumResponse | ArtistResponse | VideoResponse | PlaylistResponse | PodcastResponse | PodcastEpisodeResponse;
11
12
  export type IndexEntry = {
@@ -14,3 +15,10 @@ export type IndexEntry = {
14
15
  prefix: string;
15
16
  basename: string;
16
17
  };
18
+ export type NowPlayingResponse = {
19
+ id: UID;
20
+ type: "song" | "podcast_episode" | "video";
21
+ client: string;
22
+ expire: number;
23
+ user: UserSummary;
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-ampache",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "A JS library for the Ampache API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.m.js",
package/src/base.ts CHANGED
@@ -1,134 +1,134 @@
1
- import fetch from "isomorphic-unfetch";
2
- import qs from "querystringify";
3
-
4
- type Config = {
5
- url: string;
6
- sessionKey?: string;
7
- debug?: boolean;
8
- };
9
-
10
- export type Success = {
11
- success: string;
12
- };
13
-
14
- /**
15
- * @param [offset] Return results starting from this index position
16
- * @param [limit] Maximum number of results to return
17
- */
18
- export type Pagination = {
19
- offset?: number;
20
- limit?: number;
21
- };
22
-
23
- /**
24
- * @param [offset] Return results starting from this index position
25
- * @param [limit] Maximum number of results to return
26
- * @param [cond] Apply additional filters to the browse using ; separated comma string pairs (e.g. 'filter1,value1;filter2,value2')
27
- * @param [sort] Sort name or comma-separated key pair. (e.g. 'name,order') Default order 'ASC' (e.g. 'name,ASC' == 'name')
28
- */
29
- export type ExtendedPagination = Pagination & {
30
- cond?: string;
31
- sort?: string;
32
- };
33
-
34
- export type BinaryBoolean = 0 | 1;
35
-
36
- export type UID = string | number;
37
-
38
- export abstract class Base {
39
- sessionKey: string;
40
- url: string;
41
- version: string = "6.6.8";
42
- debug: boolean;
43
-
44
- constructor(config: Config) {
45
- this.sessionKey = config.sessionKey || null;
46
- this.url = config.url;
47
- this.debug = config.debug || false;
48
- }
49
-
50
- protected request<T>(endpoint: string): Promise<T> {
51
- let url =
52
- this.url +
53
- "/server/json.server.php?action=" +
54
- endpoint +
55
- "&version=" +
56
- this.version;
57
-
58
- if (this.debug) {
59
- console.debug(
60
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
61
- "color: black; font-style: italic; background-color: orange;padding: 2px",
62
- );
63
- }
64
-
65
- return fetch(url, {
66
- method: "GET",
67
- headers: {
68
- Authorization: "Bearer " + this.sessionKey,
69
- },
70
- }).then((r) => {
71
- if (r.ok) {
72
- return r.json();
73
- }
74
- throw new Error(r.statusText);
75
- });
76
- }
77
-
78
- protected binary<T>(endpoint: string): Promise<Blob> {
79
- let url =
80
- this.url +
81
- "/server/json.server.php?action=" +
82
- endpoint +
83
- "&version=" +
84
- this.version;
85
-
86
- if (this.debug) {
87
- console.debug(
88
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
89
- "color: black; font-style: italic; background-color: orange;padding: 2px",
90
- );
91
- }
92
-
93
- return fetch(url, {
94
- method: "GET",
95
- headers: {
96
- Authorization: "Bearer " + this.sessionKey,
97
- },
98
- })
99
- .then((response) => response.blob())
100
- .then((r) => {
101
- return r;
102
- });
103
- }
104
-
105
- public setSessionKey(sessionKey: string) {
106
- this.sessionKey = sessionKey;
107
- }
108
-
109
- /**
110
- * Construct and return a URL
111
- * @param endpoint
112
- * @param [params]
113
- */
114
- public rawURL(endpoint: string, params?: {}) {
115
- let query = endpoint;
116
- query += qs.stringify(params, "&");
117
-
118
- let url =
119
- this.url +
120
- "/server/json.server.php?action=" +
121
- query +
122
- "&version=" +
123
- this.version;
124
-
125
- if (this.debug) {
126
- console.debug(
127
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
128
- "color: black; font-style: italic; background-color: orange;padding: 2px",
129
- );
130
- }
131
-
132
- return url;
133
- }
134
- }
1
+ import fetch from "isomorphic-unfetch";
2
+ import qs from "querystringify";
3
+
4
+ type Config = {
5
+ url: string;
6
+ sessionKey?: string;
7
+ debug?: boolean;
8
+ };
9
+
10
+ export type Success = {
11
+ success: string;
12
+ };
13
+
14
+ /**
15
+ * @param [offset] Return results starting from this index position
16
+ * @param [limit] Maximum number of results to return
17
+ */
18
+ export type Pagination = {
19
+ offset?: number;
20
+ limit?: number;
21
+ };
22
+
23
+ /**
24
+ * @param [offset] Return results starting from this index position
25
+ * @param [limit] Maximum number of results to return
26
+ * @param [cond] Apply additional filters to the browse using ; separated comma string pairs (e.g. 'filter1,value1;filter2,value2')
27
+ * @param [sort] Sort name or comma-separated key pair. (e.g. 'name,order') Default order 'ASC' (e.g. 'name,ASC' == 'name')
28
+ */
29
+ export type ExtendedPagination = Pagination & {
30
+ cond?: string;
31
+ sort?: string;
32
+ };
33
+
34
+ export type BinaryBoolean = 0 | 1;
35
+
36
+ export type UID = string | number;
37
+
38
+ export abstract class Base {
39
+ sessionKey: string;
40
+ url: string;
41
+ version: string = "6.6.8";
42
+ debug: boolean;
43
+
44
+ constructor(config: Config) {
45
+ this.sessionKey = config.sessionKey || null;
46
+ this.url = config.url;
47
+ this.debug = config.debug || false;
48
+ }
49
+
50
+ protected request<T>(endpoint: string): Promise<T> {
51
+ let url =
52
+ this.url +
53
+ "/server/json.server.php?action=" +
54
+ endpoint +
55
+ "&version=" +
56
+ this.version;
57
+
58
+ if (this.debug) {
59
+ console.debug(
60
+ "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
61
+ "color: black; font-style: italic; background-color: orange;padding: 2px",
62
+ );
63
+ }
64
+
65
+ return fetch(url, {
66
+ method: "GET",
67
+ headers: {
68
+ Authorization: "Bearer " + this.sessionKey,
69
+ },
70
+ }).then((r) => {
71
+ if (r.ok) {
72
+ return r.json();
73
+ }
74
+ throw new Error(r.statusText);
75
+ });
76
+ }
77
+
78
+ protected binary<T>(endpoint: string): Promise<Blob> {
79
+ let url =
80
+ this.url +
81
+ "/server/json.server.php?action=" +
82
+ endpoint +
83
+ "&version=" +
84
+ this.version;
85
+
86
+ if (this.debug) {
87
+ console.debug(
88
+ "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
89
+ "color: black; font-style: italic; background-color: orange;padding: 2px",
90
+ );
91
+ }
92
+
93
+ return fetch(url, {
94
+ method: "GET",
95
+ headers: {
96
+ Authorization: "Bearer " + this.sessionKey,
97
+ },
98
+ })
99
+ .then((response) => response.blob())
100
+ .then((r) => {
101
+ return r;
102
+ });
103
+ }
104
+
105
+ public setSessionKey(sessionKey: string) {
106
+ this.sessionKey = sessionKey;
107
+ }
108
+
109
+ /**
110
+ * Construct and return a URL
111
+ * @param endpoint
112
+ * @param [params]
113
+ */
114
+ public rawURL(endpoint: string, params?: {}) {
115
+ let query = endpoint;
116
+ query += qs.stringify(params, "&");
117
+
118
+ let url =
119
+ this.url +
120
+ "/server/json.server.php?action=" +
121
+ query +
122
+ "&version=" +
123
+ this.version;
124
+
125
+ if (this.debug) {
126
+ console.debug(
127
+ "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
128
+ "color: black; font-style: italic; background-color: orange;padding: 2px",
129
+ );
130
+ }
131
+
132
+ return url;
133
+ }
134
+ }
@@ -35,7 +35,7 @@ export type IndexEntry = {
35
35
 
36
36
  export type NowPlayingResponse = {
37
37
  id: UID;
38
- type: "song" | "podcast_episode" | "live_stream" | "video";
38
+ type: "song" | "podcast_episode" | "video";
39
39
  client: string;
40
40
  expire: number;
41
41
  user: UserSummary;