musicbrainz-api 0.7.0 → 0.7.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.
package/README.md CHANGED
@@ -32,7 +32,7 @@ If you plan to use this module for submitting metadata, please ensure you comply
32
32
 
33
33
  Import the module
34
34
  JavaScript example, how to import 'musicbrainz-api:
35
- ```javascript
35
+ ```js
36
36
  const MusicBrainzApi = require('musicbrainz-api').MusicBrainzApi;
37
37
 
38
38
  const mbApi = new MusicBrainzApi({
@@ -43,7 +43,7 @@ const mbApi = new MusicBrainzApi({
43
43
  ```
44
44
 
45
45
  In TypeScript you it would look like this:
46
- ```javascript
46
+ ```js
47
47
  import {MusicBrainzApi} from 'musicbrainz-api';
48
48
 
49
49
  const mbApi = new MusicBrainzApi({
@@ -54,7 +54,7 @@ const mbApi = new MusicBrainzApi({
54
54
  ```
55
55
 
56
56
  The following configuration settings can be passed
57
- ```javascript
57
+ ```js
58
58
  import {MusicBrainzApi} from '../src/musicbrainz-api';
59
59
 
60
60
  const config = {
@@ -93,49 +93,55 @@ Arguments:
93
93
  * entity: `'artist'` | `'label'` | `'recording'` | `'release'` | `'release-group'` | `'work'` | `'area'` | `'url'`
94
94
  * MBID [(MusicBrainz identifier)](https://wiki.musicbrainz.org/MusicBrainz_Identifier)
95
95
 
96
- ```javascript
97
- const artist = await mbApi.getEntity('artist', 'ab2528d9-719f-4261-8098-21849222a0f2');
96
+ ```js
97
+ const artist = await mbApi.getEntity('artist', {query: 'ab2528d9-719f-4261-8098-21849222a0f2'});
98
98
  ```
99
99
 
100
100
  ### Lookup area
101
101
 
102
- ```javascript
103
- const area = await mbApi.getArea('ab2528d9-719f-4261-8098-21849222a0f2');
102
+ ```js
103
+ const area = await mbApi.getArea({query: 'ab2528d9-719f-4261-8098-21849222a0f2'});
104
104
  ```
105
105
 
106
106
  ### Lookup artist
107
107
 
108
108
  Lookup an `artist` and include their `releases`, `release-groups` and `aliases`
109
109
 
110
- ```javascript
111
- const artist = await mbApi.getArtist('ab2528d9-719f-4261-8098-21849222a0f2');
110
+ ```js
111
+ const artist = await mbApi.getArtist({query: 'ab2528d9-719f-4261-8098-21849222a0f2'});
112
+ ```
113
+
114
+ or use the browse API:
115
+
116
+ ```js
117
+ const artist = await mbApi.getArtist({artist: 'ab2528d9-719f-4261-8098-21849222a0f2'});
112
118
  ```
113
119
 
114
120
  The second argument can be used to pass [subqueries](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2#Subqueries), which will return more (nested) information:
115
- ```javascript
121
+ ```js
116
122
  const artist = await mbApi.getArtist('ab2528d9-719f-4261-8098-21849222a0f2', ['releases', 'recordings', 'url-rels']);
117
123
  ```
118
124
 
119
125
  ### Lookup recording
120
126
 
121
127
  The second argument can be used to pass [subqueries](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2#Subqueries):
122
- ```javascript
123
- const artist = await mbApi.getRecording('16afa384-174e-435e-bfa3-5591accda31c', ['artists', 'url-rels']);
128
+ ```js
129
+ const artist = await mbApi.getRecording({query: '16afa384-174e-435e-bfa3-5591accda31c'}, ['artists', 'url-rels']);
124
130
  ```
125
131
 
126
132
  ### Lookup release
127
- ```javascript
128
- const release = await mbApi.getRelease('976e0677-a480-4a5e-a177-6a86c1900bbf', ['artists', 'url-rels']);
133
+ ```js
134
+ const release = await mbApi.getRelease({query: '976e0677-a480-4a5e-a177-6a86c1900bbf'}, ['artists', 'url-rels']);
129
135
  ```
130
136
 
131
137
  ### Lookup release-group
132
- ```javascript
133
- const releaseGroup = await mbApi.getReleaseGroup('19099ea5-3600-4154-b482-2ec68815883e');
138
+ ```js
139
+ const releaseGroup = await mbApi.getReleaseGroup({query: '19099ea5-3600-4154-b482-2ec68815883e'});
134
140
  ```
135
141
 
136
142
  ### Lookup work
137
- ```javascript
138
- const work = await mbApi.getWork('b2aa02f4-6c95-43be-a426-aedb9f9a3805');
143
+ ```js
144
+ const work = await mbApi.getWork({query: 'b2aa02f4-6c95-43be-a426-aedb9f9a3805'});
139
145
  ```
140
146
 
141
147
  ## Search (query)
@@ -164,28 +170,28 @@ Arguments:
164
170
  * `limit.query`: optional, an integer value defining how many entries should be returned. Only values between 1 and 100 (both inclusive) are allowed. If not given, this defaults to 25.
165
171
 
166
172
  For example, to find any recordings of _'We Will Rock You'_ by Queen:
167
- ```javascript
173
+ ```js
168
174
  const query = 'query="We Will Rock You" AND arid:0383dadf-2a4e-4d10-a46a-e9e041da8eb3';
169
175
  const result = await mbApi.query<mb.IReleaseGroupList>('release-group', {query});
170
176
  ```
171
177
 
172
178
  ##### Example: search Île-de-France
173
179
 
174
- ```javascript
180
+ ```js
175
181
  mbApi.search('area', 'Île-de-France');
176
182
  ````
177
183
 
178
184
  ##### Example: search release by barcode
179
185
 
180
186
  Search a release with the barcode 602537479870:
181
- ```javascript
182
- mbApi.search('release', {barcode: 602537479870});
187
+ ```js
188
+ mbApi.search('release', {query: {barcode: 602537479870}});
183
189
  ````
184
190
 
185
191
  ##### Example: search by object
186
192
 
187
193
  Same as previous example, but automatically serialize parameters to search query
188
- ```javascript
194
+ ```js
189
195
  mbApi.search('release', 'barcode: 602537479870');
190
196
  ````
191
197
 
@@ -198,17 +204,17 @@ searchReleaseGroup(query: string | IFormData, offset?: number, limit?: number):
198
204
  ```
199
205
 
200
206
  Search artist:
201
- ```javascript
202
- const result = await mbApi.searchArtist('Stromae');
207
+ ```js
208
+ const result = await mbApi.searchArtist({query: 'Stromae'});
203
209
  ```
204
210
 
205
211
  Search release-group:
206
- ```javascript
207
- const result = await mbApi.searchReleaseGroup('Racine carrée');
212
+ ```js
213
+ const result = await mbApi.searchReleaseGroup({query: 'Racine carrée'});
208
214
  ```
209
215
 
210
216
  Search a combination of a release-group and an artist.
211
- ```javascript
217
+ ```js
212
218
  const result = await mbApi.searchReleaseGroup({artist: 'Racine carrée', releasegroup: 'Stromae'});
213
219
  ```
214
220
 
@@ -220,7 +226,7 @@ const result = await mbApi.searchReleaseGroup({artist: 'Racine carrée', release
220
226
 
221
227
  Using the [XML ISRC submission](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2#ISRC_submission) API.
222
228
 
223
- ```javascript
229
+ ```js
224
230
  const mbid_Formidable = '16afa384-174e-435e-bfa3-5591accda31c';
225
231
  const isrc_Formidable = 'BET671300161';
226
232
 
@@ -239,7 +245,7 @@ For all of the following function you need to use a dedicated bot account.
239
245
  <img width="150" src="http://www.clker.com/cliparts/i/w/L/q/u/1/work-in-progress.svg"/>
240
246
  Use with caution, and only on a test server, it may clear existing metadata as side effect.
241
247
 
242
- ```javascript
248
+ ```js
243
249
 
244
250
  const mbid_Formidable = '16afa384-174e-435e-bfa3-5591accda31c';
245
251
  const isrc_Formidable = 'BET671300161';
@@ -257,7 +263,7 @@ await mbApi.addIsrc(recording, isrc_Formidable);
257
263
 
258
264
  ### Submit recording URL
259
265
 
260
- ```javascript
266
+ ```js
261
267
  const recording = await mbApi.getRecording('16afa384-174e-435e-bfa3-5591accda31c');
262
268
 
263
269
  const succeed = await mbApi.login();
@@ -270,7 +276,7 @@ await mbApi.addUrlToRecording(recording, {
270
276
  ```
271
277
 
272
278
  Actually a Spotify-track-ID can be submitted easier:
273
- ```javascript
279
+ ```js
274
280
  const recording = await mbApi.getRecording('16afa384-174e-435e-bfa3-5591accda31c');
275
281
 
276
282
  const succeed = await mbApi.login();
@@ -135,10 +135,9 @@ export declare class MusicBrainzApi {
135
135
  * Search an entity using a search query
136
136
  * @param query e.g.: '" artist: Madonna, track: Like a virgin"' or object with search terms: {artist: Madonna}
137
137
  * @param entity e.g. 'recording'
138
- * @param offset
139
- * @param limit
138
+ * @param query Arguments
140
139
  */
141
- search<T extends mb.ISearchResult>(entity: mb.EntityType, query: string | IFormData, offset?: number, limit?: number): Promise<T>;
140
+ search<T extends mb.ISearchResult>(entity: mb.EntityType, query: mb.ISearchQuery): Promise<T>;
142
141
  /**
143
142
  * Add Spotify-ID to MusicBrainz recording.
144
143
  * This function will automatically lookup the recording title, which is required to submit the recording URL
@@ -147,11 +146,11 @@ export declare class MusicBrainzApi {
147
146
  * @param editNote Comment to add.
148
147
  */
149
148
  addSpotifyIdToRecording(recording: mb.IRecording, spotifyId: string, editNote: string): Promise<void>;
150
- searchArtist(query: string | IFormData, offset?: number, limit?: number): Promise<mb.IArtistList>;
151
- searchRelease(query: string | IFormData, offset?: number, limit?: number): Promise<mb.IReleaseList>;
152
- searchReleaseGroup(query: string | IFormData, offset?: number, limit?: number): Promise<mb.IReleaseGroupList>;
153
- searchArea(query: string | IFormData, offset?: number, limit?: number): Promise<mb.IAreaList>;
154
- searchUrl(query: string | IFormData, offset?: number, limit?: number): Promise<mb.IUrlList>;
149
+ searchArea(query: mb.ISearchQuery & mb.ILinkedEntitiesArea): Promise<mb.IAreaList>;
150
+ searchArtist(query: mb.ISearchQuery & mb.ILinkedEntitiesArtist): Promise<mb.IArtistList>;
151
+ searchRelease(query: mb.ISearchQuery & mb.ILinkedEntitiesRelease): Promise<mb.IReleaseList>;
152
+ searchReleaseGroup(query: mb.ISearchQuery & mb.ILinkedEntitiesReleaseGroup): Promise<mb.IReleaseGroupList>;
153
+ searchUrl(query: mb.ISearchQuery & mb.ILinkedEntitiesUrl): Promise<mb.IUrlList>;
155
154
  private getSession;
156
155
  }
157
156
  export declare function makeAndQueryString(keyValuePairs: IFormData): string;
@@ -332,14 +332,14 @@ class MusicBrainzApi {
332
332
  * Search an entity using a search query
333
333
  * @param query e.g.: '" artist: Madonna, track: Like a virgin"' or object with search terms: {artist: Madonna}
334
334
  * @param entity e.g. 'recording'
335
- * @param offset
336
- * @param limit
335
+ * @param query Arguments
337
336
  */
338
- search(entity, query, offset, limit) {
339
- if (typeof query === 'object') {
340
- query = makeAndQueryString(query);
337
+ search(entity, query) {
338
+ const urlQuery = Object.assign({}, query);
339
+ if (typeof query.query === 'object') {
340
+ urlQuery.query = makeAndQueryString(query.query);
341
341
  }
342
- return this.restGet('/' + entity + '/', { query, offset, limit });
342
+ return this.restGet('/' + entity + '/', urlQuery);
343
343
  }
344
344
  // -----------------------------------------------------------------------------------------------------------------
345
345
  // Helper functions
@@ -358,20 +358,20 @@ class MusicBrainzApi {
358
358
  text: 'https://open.spotify.com/track/' + spotifyId
359
359
  }, editNote);
360
360
  }
361
- searchArtist(query, offset, limit) {
362
- return this.search('artist', query, offset, limit);
361
+ searchArea(query) {
362
+ return this.search('area', query);
363
363
  }
364
- searchRelease(query, offset, limit) {
365
- return this.search('release', query, offset, limit);
364
+ searchArtist(query) {
365
+ return this.search('artist', query);
366
366
  }
367
- searchReleaseGroup(query, offset, limit) {
368
- return this.search('release-group', query, offset, limit);
367
+ searchRelease(query) {
368
+ return this.search('release', query);
369
369
  }
370
- searchArea(query, offset, limit) {
371
- return this.search('area', query, offset, limit);
370
+ searchReleaseGroup(query) {
371
+ return this.search('release-group', query);
372
372
  }
373
- searchUrl(query, offset, limit) {
374
- return this.search('url', query, offset, limit);
373
+ searchUrl(query) {
374
+ return this.search('url', query);
375
375
  }
376
376
  async getSession(url) {
377
377
  const response = await got_1.default.get('login', Object.assign({ followRedirect: false, responseType: 'text' }, this.options));
@@ -1,4 +1,5 @@
1
1
  import DateTimeFormat = Intl.DateTimeFormat;
2
+ import { IFormData, Includes } from './musicbrainz-api';
2
3
  export interface IPeriod {
3
4
  'begin': string;
4
5
  'ended': boolean;
@@ -249,5 +250,130 @@ export interface ISearchQuery extends IPagination {
249
250
  /**
250
251
  * Lucene search query, this is mandatory
251
252
  */
252
- query: string;
253
+ query?: string | IFormData;
254
+ inc?: Includes[];
255
+ }
256
+ /**
257
+ * https://musicbrainz.org/doc/MusicBrainz_API#Browse
258
+ * /ws/2/area collection
259
+ */
260
+ export interface ILinkedEntitiesArea {
261
+ collection?: string;
262
+ }
263
+ /**
264
+ * https://musicbrainz.org/doc/MusicBrainz_API#Browse
265
+ * /ws/2/artist area, collection, recording, release, release-group, work
266
+ */
267
+ export interface ILinkedEntitiesArtist {
268
+ area?: string;
269
+ collection?: string;
270
+ recording?: string;
271
+ release?: string;
272
+ 'release-group'?: string;
273
+ work?: string;
274
+ }
275
+ /**
276
+ * https://musicbrainz.org/doc/MusicBrainz_API#Browse
277
+ * /ws/2/collection area, artist, editor, event, label, place, recording, release, release-group, work
278
+ */
279
+ export interface ILinkedEntitiesCollection {
280
+ area?: string;
281
+ artist?: string;
282
+ editor?: string;
283
+ event?: string;
284
+ label?: string;
285
+ place?: string;
286
+ recording?: string;
287
+ release?: string;
288
+ 'release-group'?: string;
289
+ work?: string;
290
+ }
291
+ /**
292
+ * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
293
+ * /ws/2/event area, artist, collection, place
294
+ */
295
+ export interface ILinkedEntitiesEvent {
296
+ area?: string;
297
+ artist?: string;
298
+ collection?: string;
299
+ place?: string;
300
+ }
301
+ /**
302
+ * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
303
+ * /ws/2/instrument collection
304
+ */
305
+ export interface ILinkedEntitiesInstrument {
306
+ collection?: string;
307
+ }
308
+ /**
309
+ * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
310
+ * /ws/2/label area, collection, release
311
+ */
312
+ export interface ILinkedEntitiesLabel {
313
+ area?: string;
314
+ collection?: string;
315
+ release?: string;
316
+ }
317
+ /**
318
+ * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
319
+ * /ws/2/place area, collection
320
+ */
321
+ export interface IBrowseArgumentPlace {
322
+ area?: string;
323
+ collection?: string;
324
+ }
325
+ /**
326
+ * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
327
+ * /ws/2/recording artist, collection, release, work
328
+ */
329
+ export interface ILinkedEntitiesRecording {
330
+ area?: string;
331
+ collection?: string;
332
+ release?: string;
333
+ work?: string;
334
+ }
335
+ /**
336
+ * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
337
+ * /ws/2/release area, artist, collection, label, track, track_artist, recording, release-group
338
+ */
339
+ export interface ILinkedEntitiesRelease {
340
+ area?: string;
341
+ artist?: string;
342
+ collection?: string;
343
+ label?: string;
344
+ track?: string;
345
+ track_artist?: string;
346
+ recording?: string;
347
+ 'release-group'?: string;
348
+ }
349
+ /**
350
+ * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
351
+ * /ws/2/release-group artist, collection, release
352
+ */
353
+ export interface ILinkedEntitiesReleaseGroup {
354
+ artist?: string;
355
+ collection?: string;
356
+ release?: string;
357
+ }
358
+ /**
359
+ * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
360
+ * /ws/2/series collection
361
+ */
362
+ export interface ILinkedEntitiesSeries {
363
+ collection?: string;
364
+ }
365
+ /**
366
+ * https://musicbrainz.org/doc/MusicBrainz_API#Browse
367
+ * /ws/2/work artist, collection
368
+ */
369
+ export interface ILinkedEntitiesWork {
370
+ artist?: string;
371
+ collection?: string;
372
+ }
373
+ /**
374
+ * https://musicbrainz.org/doc/MusicBrainz_API#Browse
375
+ * /ws/2/url resource
376
+ */
377
+ export interface ILinkedEntitiesUrl {
378
+ resource?: string;
253
379
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musicbrainz-api",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "MusicBrainz API client for reading and submitting metadata",
5
5
  "main": "lib/musicbrainz-api",
6
6
  "types": "lib/musicbrainz-api",