From 28b39214e6da9b8ca38780539e246bc94cc5df12 Mon Sep 17 00:00:00 2001 From: Borewit Date: Wed, 15 Nov 2023 22:03:52 +0100 Subject: [PATCH] Simplify lookup, browse and search function --- README.md | 152 +++------------- lib/musicbrainz-api.ts | 334 +++++++---------------------------- lib/musicbrainz.types.ts | 22 ++- test/test-musicbrainz-api.ts | 240 +++++++++++++------------ 4 files changed, 231 insertions(+), 517 deletions(-) diff --git a/README.md b/README.md index 74403779..a140dab0 100644 --- a/README.md +++ b/README.md @@ -82,106 +82,14 @@ MusicBrainz API documentation: [XML Web Service/Version 2 Lookups](https://wiki. ### Generic lookup function Arguments: -* entity: `'artist'` | `'label'` | `'recording'` | `'release'` | `'release-group'` | `'work'` | `'area'` | `'url'` +* entity: `'area'` | `'artist'` | `'collection'` | `'instrument'` | `'label'` | `'place'` | `'release'` | `'release-group'` | `'recording'` | `'series'` | `'work'` | `'url'` | `'event'` * MBID [(MusicBrainz identifier)](https://wiki.musicbrainz.org/MusicBrainz_Identifier) +* query ```js -const artist = await mbApi.lookupEntity('artist', 'ab2528d9-719f-4261-8098-21849222a0f2'); +const artist = await mbApi.lookup('artist', 'ab2528d9-719f-4261-8098-21849222a0f2'); ``` -### Lookup area - -```js -const area = await mbApi.lookupArea('ab2528d9-719f-4261-8098-21849222a0f2'); -``` - -### Lookup artist - -Lookup an `artist` and include their `releases`, `release-groups` and `aliases` - -```js -const artist = await mbApi.lookupArtist('ab2528d9-719f-4261-8098-21849222a0f2'); -``` - -### Lookup collection - -Lookup an instrument - -```js -const collection = await mbApi.lookupCollection('de4fdfc4-53aa-458a-b463-8761cc7f5af8'); -``` - -Lookup an event - -```js -const event = await mbApi.lookupEvent('6d32c658-151e-45ec-88c4-fb8787524d61'); -``` - -### Lookup instrument - -Lookup an instrument - -```js -const instrument = await mbApi.lookupInstrument('b3eac5f9-7859-4416-ac39-7154e2e8d348'); -``` - -### Lookup label - -Lookup a label - -```js -const label = await mbApi.lookupLabel('25dda9f9-f069-4898-82f0-59330a106c7f'); -``` - -### Lookup place - -```js -const place = await mbApi.lookupPlace('e6cfb74d-d69b-44c3-b890-1b3f509816e4'); -``` - -```js -const place = await mbApi.lookupSeries('1ae6c9bc-2931-4d75-bee4-3dc53dfd246a'); -``` - -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: -```js -const artist = await mbApi.lookupArtist('ab2528d9-719f-4261-8098-21849222a0f2', ['releases', 'recordings', 'url-rels']); -``` - -### Lookup recording - -The second argument can be used to pass [subqueries](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2#Subqueries): -```js -const recording = await mbApi.lookupRecording('16afa384-174e-435e-bfa3-5591accda31c', ['artists', 'url-rels']); -``` - -### Lookup release -```js -const release = await mbApi.lookupRelease('976e0677-a480-4a5e-a177-6a86c1900bbf', ['artists', 'url-rels']); -``` - -### Lookup release-group -```js -const releaseGroup = await mbApi.lookupReleaseGroup('19099ea5-3600-4154-b482-2ec68815883e'); -``` - -### Lookup work -```js -const work = await mbApi.lookupWork('b2aa02f4-6c95-43be-a426-aedb9f9a3805'); -``` - -### Lookup URL -```js -const url = await mbApi.lookupUrl('c69556a6-7ded-4c54-809c-afb45a1abe7d'); -``` - -## Browse entities - -### Browse area - -```js -const area = await browseAreas(query); -```` | Query argument | Query value | |-----------------------|-----------------| @@ -190,7 +98,7 @@ const area = await browseAreas(query); ### Browse artist ```js -const artist = await browseArtist(query); +const artists = await browse('artist', query); ```` | Query argument | Query value | @@ -204,7 +112,7 @@ const artist = await browseArtist(query); ### Browse collection ```js -const artist = await browseCollection(query); +const collections = await browse('collection', query); ```` | Query argument | Query value | @@ -222,7 +130,7 @@ const artist = await browseCollection(query); ### Browse events ```js -const events = await browseEvents(query); +const events = await browse('event', query); ```` | Query argument | Query value | @@ -234,7 +142,7 @@ const events = await browseEvents(query); ### Browse instruments ```js -const instruments = await browseEvents(query); +const instruments = await browse('event', query); ```` | Query argument | Query value | @@ -243,7 +151,7 @@ const instruments = await browseEvents(query); ### Browse labels ```js -const labels = await browseLabels(query); +const labels = await browse('label', query); ```` | Query argument | Query value | @@ -254,7 +162,7 @@ const labels = await browseLabels(query); ### Browse places ```js -const places = await browsePlaces(query); +const places = await browse('place', query); ```` | Query argument | Query value | @@ -264,7 +172,7 @@ const places = await browsePlaces(query); ### Browse recordings ```js -const recordings = await browseRecordings(query); +const recordings = await browse('recording', query); ```` | Query argument | Query value | @@ -276,7 +184,7 @@ const recordings = await browseRecordings(query); ### Browse releases ```js -const places = await browseReleases(query); +const releases = await browse('release', query); ```` | Query argument | Query value | @@ -294,7 +202,7 @@ const places = await browseReleases(query); ### Browse release-groups ```js -const places = await browseReleaseGroups(query); +const releaseGroups = await browse('release-group',query); ``` | Query argument | Query value | @@ -305,7 +213,7 @@ const places = await browseReleaseGroups(query); ### Browse series ```js -const places = await browseSeries(); +const series = await browse('series'); ```` | Query argument | Query value | @@ -323,7 +231,7 @@ const places = await browseSeries(); ### Browse works ```js -const places = await browseWorks(); +const works = await browse('work'); ```` | Query argument | Query value | @@ -333,7 +241,7 @@ const places = await browseWorks(); ### Browse urls ```js -const urls = await browseUrls(); +const urls = await browse('url'); ```` | Query argument | Query value | @@ -347,9 +255,9 @@ Implements [XML Web Service/Version 2/Search](https://wiki.musicbrainz.org/Devel There are different search fields depending on the entity. -### Generic search function +### Search function -Searches can be performed using the generic search function: `query(entity: mb.EntityType, query: string | IFormData, offset?: number, limit?: number)` +Searches can be performed using the generic search function: `query(entity: mb.EntityType, query: string | IFormData, offset?: number, limit?: number): Promise` Arguments: * Entity type, which can be one of: @@ -392,27 +300,25 @@ Same as previous example, but automatically serialize parameters to search query mbApi.search('release', 'barcode: 602537479870'); ```` -### Entity specific search functions - -The following entity specific search functions are available: -```TypeScript -searchArtist(query: string | IFormData, offset?: number, limit?: number): Promise -searchReleaseGroup(query: string | IFormData, offset?: number, limit?: number): Promise` -``` +##### Example: search artist by artist name Search artist: ```js -const result = await mbApi.searchArtist({query: 'Stromae'}); +const result = await mbApi.search('artist', {query: 'Stromae'}); ``` +##### Example: search release-group by artist name + Search release-group: ```js -const result = await mbApi.searchReleaseGroup({query: 'Racine carrée'}); +const result = await mbApi.search('release-group', {query: 'Racine carrée'}); ``` +##### Example: search release-group by release-group and an artist + Search a combination of a release-group and an artist. ```js -const result = await mbApi.searchReleaseGroup({artist: 'Racine carrée', releasegroup: 'Stromae'}); +const result = await mbApi.search('release-group', {artist: 'Racine carrée', releasegroup: 'Stromae'}); ``` # Submitting data via XML POST @@ -439,7 +345,7 @@ For all of the following function you need to use a dedicated bot account. ## Submitting ISRC via post user form-data - +Work in progress Use with caution, and only on a test server, it may clear existing metadata as side effect. ```js @@ -448,7 +354,7 @@ const mbid_Formidable = '16afa384-174e-435e-bfa3-5591accda31c'; const isrc_Formidable = 'BET671300161'; -const recording = await mbApi.lookupRecording(mbid_Formidable); +const recording = await mbApi.lookup('recording', mbid_Formidable); // Authentication the http-session against MusicBrainz (as defined in config.baseUrl) const succeed = await mbApi.login(); @@ -461,7 +367,7 @@ await mbApi.addIsrc(recording, isrc_Formidable); ### Submit recording URL ```js -const recording = await mbApi.lookupRecording('16afa384-174e-435e-bfa3-5591accda31c'); +const recording = await mbApi.lookup('recording', '16afa384-174e-435e-bfa3-5591accda31c'); const succeed = await mbApi.login(); assert.isTrue(succeed, 'Login successful'); @@ -474,7 +380,7 @@ await mbApi.addUrlToRecording(recording, { Actually a Spotify-track-ID can be submitted easier: ```js -const recording = await mbApi.lookupRecording('16afa384-174e-435e-bfa3-5591accda31c'); +const recording = await mbApi.lookup('recording', '16afa384-174e-435e-bfa3-5591accda31c'); const succeed = await mbApi.login(); assert.isTrue(succeed, 'Login successful'); diff --git a/lib/musicbrainz-api.ts b/lib/musicbrainz-api.ts index d0fc879a..957aa0c5 100644 --- a/lib/musicbrainz-api.ts +++ b/lib/musicbrainz-api.ts @@ -106,7 +106,7 @@ export type RecordingIncludes = | 'releases' | 'isrcs'; -export type ReleasesIncludes = +export type ReleaseIncludes = MiscIncludes | SubQueryIncludes | RelationsIncludes @@ -266,254 +266,80 @@ export class MusicBrainzApi { return response.body; } - // ----------------------------------------------------------------------------------------------------------------- - // Lookup functions - // ----------------------------------------------------------------------------------------------------------------- - /** - * Generic lookup function - * @param entity - * @param mbid - * @param inc - */ - public lookupEntity(entity: mb.EntityType, mbid: string, inc: I[] = []): Promise { + * Lookup entity + * @param entity 'area', 'artist', collection', 'instrument', 'label', 'place', 'release', 'release-group', 'recording', 'series', 'work', 'url' or 'event' + * @param mbid Entity MBID + * @param inc Query, like: {: ; + public lookup(entity: 'artist', mbid: string, inc?: ArtistIncludes[]): Promise; + public lookup(entity: 'collection', mbid: string, inc?: CollectionIncludes[]): Promise; + public lookup(entity: 'instrument', mbid: string, inc?: InstrumentIncludes[]): Promise; + public lookup(entity: 'label', mbid: string, inc?: LabelIncludes[]): Promise; + public lookup(entity: 'place', mbid: string, inc?: PlaceIncludes[]): Promise; + public lookup(entity: 'release', mbid: string, inc?: ReleaseIncludes[]): Promise; + public lookup(entity: 'release-group', mbid: string, inc?: ReleaseGroupIncludes[]): Promise; + public lookup(entity: 'recording', mbid: string, inc?: RecordingIncludes[]): Promise; + public lookup(entity: 'series', mbid: string, inc?: SeriesIncludes[]): Promise; + public lookup(entity: 'work', mbid: string, inc?: WorkIncludes[]): Promise; + public lookup(entity: 'url', mbid: string, inc?: UrlIncludes[]): Promise; + public lookup(entity: 'event', mbid: string, inc?: EventIncludes[]): Promise; + public lookup(entity: mb.EntityType, mbid: string, inc: I[] = []): Promise { return this.restGet(`/${entity}/${mbid}`, {inc: inc.join(' ')}); } /** - * Lookup area - * @param areaId Area MBID - * @param inc Sub-queries - */ - public lookupArea(areaId: string, inc: AreaIncludes[] = []): Promise { - return this.lookupEntity('area', areaId, inc); - } - - /** - * Lookup artist - * @param artistId Artist MBID - * @param inc Sub-queries - */ - public lookupArtist(artistId: string, inc: ArtistIncludes[] = []): Promise { - return this.lookupEntity('artist', artistId, inc); - } - - /** - * Lookup collection - * @param collectionId Collection MBID - * @param inc List of additional information to be included about the entity. Any of the entities directly linked to the entity can be included. - */ - public lookupCollection(collectionId: string, inc: ArtistIncludes[] = []): Promise { - return this.lookupEntity('collection', collectionId, inc); - } - - /** - * Lookup instrument - * @param artistId Instrument MBID - * @param inc Sub-queries - */ - public lookupInstrument(instrumentId: string, inc: InstrumentIncludes[] = []): Promise { - return this.lookupEntity('instrument', instrumentId, inc); - } - - /** - * Lookup label - * @param labelId Area MBID - * @param inc Sub-queries - */ - public lookupLabel(labelId: string, inc: LabelIncludes[] = []): Promise { - return this.lookupEntity('label', labelId, inc); - } - - /** - * Lookup place - * @param placeId Area MBID - * @param inc Sub-queries - */ - public lookupPlace(placeId: string, inc: PlaceIncludes[] = []): Promise { - return this.lookupEntity('place', placeId, inc); - } - - /** - * Lookup release - * @param releaseId Release MBID - * @param inc Include: artist-credits, labels, recordings, release-groups, media, discids, isrcs (with recordings) - * ToDo: ['recordings', 'artists', 'artist-credits', 'isrcs', 'url-rels', 'release-groups'] - */ - public lookupRelease(releaseId: string, inc: ReleasesIncludes[] = []): Promise { - return this.lookupEntity('release', releaseId, inc); - } - - /** - * Lookup release-group - * @param releaseGroupId Release-group MBID - * @param inc Include: ToDo - */ - public lookupReleaseGroup(releaseGroupId: string, inc: ReleaseGroupIncludes[] = []): Promise { - return this.lookupEntity('release-group', releaseGroupId, inc); - } - - /** - * Lookup recording - * @param recordingId Label MBID - * @param inc Include: artist-credits, isrcs - */ - public lookupRecording(recordingId: string, inc: RecordingIncludes[] = []): Promise { - return this.lookupEntity('recording', recordingId, inc); - } - - /** - * Lookup series - * @param seriesId Series MBID - */ - public lookupSeries(seriesId: string): Promise { - return this.lookupEntity('series', seriesId); - } - - /** - * Lookup work - * @param workId Work MBID - */ - public lookupWork(workId: string, inc: WorkIncludes[] = []): Promise { - return this.lookupEntity('work', workId, inc); - } - - /** - * Lookup URL - * @param urlId URL MBID - */ - public lookupUrl(urlId: string, inc: UrlIncludes[] = []): Promise { - return this.lookupEntity('url', urlId, inc); - } - - /** - * Lookup Event - * @param eventId Event MBID - * @param eventIncludes List of sub-queries to enable - */ - public lookupEvent(eventId: string, eventIncludes: EventIncludes[] = []): Promise { - return this.lookupEntity('event', eventId, eventIncludes); - } - - // ----------------------------------------------------------------------------------------------------------------- - // Browse functions - // ----------------------------------------------------------------------------------------------------------------- - // https://wiki.musicbrainz.org/MusicBrainz_API#Browse - // https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities - // For example: http://musicbrainz.org/ws/2/release?label=47e718e1-7ee4-460c-b1cc-1192a841c6e5&offset=12&limit=2 - - /** - * Generic browse function + * Browse entity + * https://wiki.musicbrainz.org/MusicBrainz_API#Browse + * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities * https://wiki.musicbrainz.org/Development/JSON_Web_Service#Browse_Requests + * For example: http://musicbrainz.org/ws/2/release?label=47e718e1-7ee4-460c-b1cc-1192a841c6e5&offset=12&limit=2 * @param entity MusicBrainz entity * @param query Query, like: {: (entity: mb.EntityType, query?: { [key: string]: any; }): Promise { + public browse(entity: 'area', query?: mb.IBrowseAreasQuery): Promise; + public browse(entity: 'artist', query?: mb.IBrowseArtistsQuery): Promise; + public browse(entity: 'collection', query?: mb.IBrowseCollectionsQuery): Promise ; + public browse(entity: 'event', query?: mb.IBrowseEventsQuery): Promise; + public browse(entity: 'label', query?: mb.IBrowseLabelsQuery): Promise; + public browse(entity: 'instrument', query?: mb.IBrowseInstrumentsQuery): Promise; + public browse(entity: 'place', query?: mb.IBrowsePlacesQuery): Promise; + public browse(entity: 'recording', query?: mb.IBrowseRecordingsQuery): Promise; + public browse(entity: 'release', query?: mb.IBrowseReleasesQuery): Promise; + public browse(entity: 'release-group', query?: mb.IBrowseReleaseGroupsQuery): Promise; + public browse(entity: 'series', query?: mb.IBrowseSeriesQuery): Promise; + public browse(entity: 'url', query?: mb.IBrowseUrlsQuery): Promise; + public browse(entity: 'work', query?: mb.IBrowseWorksQuery): Promise; + public browse(entity: mb.EntityType, query?: { [key: string]: any; }): Promise { return this.restGet(`/${entity}`, query); } - /** - * Browse areas - * @param query Query, like: {: { - return this.browseEntity('area', query); - } - - /** - * Browse artists - * @param query Query, like: {: { - return this.browseEntity('artist', query); - } - - /** - * Browse collections - * @param query Query, like: {: { - return this.browseEntity('collection', query); - } - - /** - * Browse events - * @param query Query, like: {: { - return this.browseEntity('event', query); - } - - /** - * Browse instruments - * @param query Query, like: {: { - return this.browseEntity('instrument', query); - } - - /** - * Browse labels - * @param query Query, like: {: { - return this.browseEntity('label', query); - } - - /** - * Browse places - * @param query Query, like: {: { - return this.browseEntity('place', query); - } - - /** - * Browse recordings - * @param query Query, like: {: { - return this.browseEntity('recording', query); - } - - /** - * Browse releases - * @param query Query, like: {: { - return this.browseEntity('release', query); - } - - /** - * Browse release-groups - * @param query Query, like: {: { - return this.browseEntity('release-group', query); - } - - /** - * Browse series - * @param query Query, like: {: { - return this.browseEntity('series', query); - } - - /** - * Browse works - * @param query Query, like: {: { - return this.browseEntity('work', query); - } + // ----------------------------------------------------------------------------------------------------------------- + // Query functions + // ----------------------------------------------------------------------------------------------------------------- /** - * Browse URLs - * @param query Query, like: {: { - return this.browseEntity('url', query); + public search(entity:'area', query: mb.ISearchQuery & mb.ILinkedEntitiesArea): Promise; + public search(artist:'artist', query: mb.ISearchQuery & mb.ILinkedEntitiesArea): Promise; + public search(artist:'recording', query: mb.ISearchQuery & mb.ILinkedEntitiesArea): Promise; + public search(artist:'release', query: mb.ISearchQuery & mb.ILinkedEntitiesArea): Promise; + public search(artist:'release-group', query: mb.ISearchQuery & mb.ILinkedEntitiesArea): Promise; + public search(artist:'url', query: mb.ISearchQuery & mb.ILinkedEntitiesArea): Promise; + public search(entity: mb.EntityType, query: mb.ISearchQuery): Promise { + const urlQuery: any = {...query}; + if (typeof query.query === 'object') { + urlQuery.query = makeAndQueryString(query.query); + } + if (Array.isArray(query.inc)) { + urlQuery.inc = urlQuery.inc.join(' '); + } + return this.restGet('/' + entity + '/', urlQuery); } // --------------------------------------------------------------------------- @@ -702,26 +528,6 @@ export class MusicBrainzApi { } } - // ----------------------------------------------------------------------------------------------------------------- - // Query functions - // ----------------------------------------------------------------------------------------------------------------- - - /** - * Search an entity using a search query - * @param query e.g.: '" artist: Madonna, track: Like a virgin"' or object with search terms: {artist: Madonna} - * @param entity e.g. 'recording' - * @param query Arguments - */ - public search(entity: mb.EntityType, query: mb.ISearchQuery): Promise { - const urlQuery: any = {...query}; - if (typeof query.query === 'object') { - urlQuery.query = makeAndQueryString(query.query); - } - if (Array.isArray(query.inc)) { - urlQuery.inc = urlQuery.inc.join(' '); - } - return this.restGet('/' + entity + '/', urlQuery); - } // ----------------------------------------------------------------------------------------------------------------- // Helper functions @@ -744,26 +550,6 @@ export class MusicBrainzApi { }, editNote); } - public searchArea(query: mb.ISearchQuery & mb.ILinkedEntitiesArea): Promise { - return this.search('area', query); - } - - public searchArtist(query: mb.ISearchQuery & mb.ILinkedEntitiesArtist): Promise { - return this.search('artist', query); - } - - public searchRelease(query: mb.ISearchQuery & mb.ILinkedEntitiesRelease): Promise { - return this.search('release', query); - } - - public searchReleaseGroup(query: mb.ISearchQuery & mb.ILinkedEntitiesReleaseGroup): Promise { - return this.search('release-group', query); - } - - public searchUrl(query: mb.ISearchQuery & mb.ILinkedEntitiesUrl): Promise { - return this.search('url', query); - } - private async getSession(): Promise { const response = await got.get('login', { diff --git a/lib/musicbrainz.types.ts b/lib/musicbrainz.types.ts index 07e5b85a..9ab45abd 100644 --- a/lib/musicbrainz.types.ts +++ b/lib/musicbrainz.types.ts @@ -113,6 +113,7 @@ export interface IRelease extends IEntity { relations?: IRelation[]; 'artist-credit'?: IArtistCredit[]; // Include 'artist-credits ' 'release-group'?: IReleaseGroup; // Include: 'release-groups' + collections?: ICollection[] } export interface IReleaseEvent { @@ -175,16 +176,19 @@ export interface IReleaseGroup extends IEntity { releases?: IRelease[]; // include 'releases' } +export interface IAreaMatch extends IArea, IMatch { +} + export interface IArtistMatch extends IArtist, IMatch { } -export interface IReleaseGroupMatch extends IReleaseGroup, IMatch { +export interface IRecordingMatch extends IRecording, IMatch { } -export interface IReleaseMatch extends IRelease, IMatch { +export interface IReleaseGroupMatch extends IReleaseGroup, IMatch { } -export interface IAreaMatch extends IArea, IMatch { +export interface IReleaseMatch extends IRelease, IMatch { } export interface ISearchResult { @@ -206,6 +210,11 @@ export interface IReleaseList extends ISearchResult { 'release-count': number; } +export interface IRecordingList extends ISearchResult { + recordings: IRecordingMatch[]; + 'recordings-count': number; +} + export interface IReleaseGroupList extends ISearchResult { 'release-groups': IReleaseGroupMatch[]; } @@ -348,6 +357,7 @@ export interface ISearchQuery extends IPagination { */ query?: string | IFormData, inc?: I[] + artist?: string; } /** @@ -593,7 +603,7 @@ export interface IBrowseReleasesQuery extends IPagination { /** * Browse release-groups query : */ -export interface IReleaseGroupsQuery extends IPagination { +export interface IBrowseReleaseGroupsQuery extends IPagination { artist?: string; collection?: string; release?: string; @@ -685,13 +695,13 @@ export interface IBrowseReleaseGroupsResult { } export interface IBrowseSeriesResult { - series: IReleaseGroupsQuery[]; + series: IReleaseGroup[]; 'series-count': number; 'series-offset': number; } export interface IBrowseWorksResult { - works: IReleaseGroupsQuery[]; + works: IReleaseGroup[]; 'work-count': number; 'work-offset': number; } diff --git a/test/test-musicbrainz-api.ts b/test/test-musicbrainz-api.ts index 56e84fb0..c18fe118 100644 --- a/test/test-musicbrainz-api.ts +++ b/test/test-musicbrainz-api.ts @@ -1,4 +1,7 @@ import { + CoverArtArchiveApi, + XmlMetadata, + type EventIncludes, type IBrowseArtistsResult, type IBrowseCollectionsResult, type IBrowseEventsResult, @@ -10,12 +13,15 @@ import { type IBrowseReleasesResult, type IBrowseSeriesResult, type IBrowseWorksResult, + type IEvent, + type IRelease, + type IReleaseGroup, + type ReleaseGroupIncludes, + type ReleaseIncludes, LinkType, - MusicBrainzApi -} from '../lib/musicbrainz-api.js'; -import {CoverArtArchiveApi} from '../lib/coverartarchive-api.js'; + MusicBrainzApi, RecordingIncludes, IRecording +} from '../lib/index.js'; import { assert } from 'chai'; -import { XmlMetadata } from '../lib/xml/xml-metadata.js'; import * as mb from '../lib/musicbrainz.types.js'; import { readFile } from 'fs/promises'; @@ -165,31 +171,31 @@ describe('MusicBrainz-api', function () { describe('Lookup', () => { it('area', async () => { - const area = await mbApi.lookupArea(mbid.area.Belgium); + const area = await mbApi.lookup('area', mbid.area.Belgium); assert.strictEqual(area.id, mbid.area.Belgium); assert.strictEqual(area.name, 'Belgium'); }); it('artist', async () => { - const artist = await mbApi.lookupArtist(mbid.artist.Stromae); + const artist = await mbApi.lookup('artist', mbid.artist.Stromae); assert.strictEqual(artist.id, mbid.artist.Stromae); assert.strictEqual(artist.name, 'Stromae'); }); it('collection', async () => { - const collection = await mbApi.lookupCollection(mbid.collection.Ringtone); + const collection = await mbApi.lookup('collection', mbid.collection.Ringtone); assert.strictEqual(collection.id, mbid.collection.Ringtone); assert.strictEqual(collection.name, 'Ringtone'); }); it('instrument', async () => { - const instrument = await mbApi.lookupInstrument(mbid.instrument.spanishAcousticGuitar); + const instrument = await mbApi.lookup('instrument', mbid.instrument.spanishAcousticGuitar); assert.strictEqual(instrument.id, mbid.instrument.spanishAcousticGuitar); assert.strictEqual(instrument.type, 'String instrument'); }); it('label', async () => { - const label = await mbApi.lookupLabel(mbid.label.Mosaert); + const label = await mbApi.lookup('label', mbid.label.Mosaert); assert.strictEqual(label.id, mbid.label.Mosaert); assert.strictEqual(label.name, 'Mosaert'); }); @@ -197,18 +203,18 @@ describe('MusicBrainz-api', function () { describe('release', () => { it('release Formidable', async () => { - const release = await mbApi.lookupRelease(mbid.release.Formidable); + const release = await mbApi.lookup('release', mbid.release.Formidable); assert.strictEqual(release.id, mbid.release.Formidable); assert.strictEqual(release.title, 'Formidable'); }); it('check release Anomalie', async () => { - const release = await mbApi.lookupRelease(mbid.release.Anomalie); + const release = await mbApi.lookup('release', mbid.release.Anomalie); assert.strictEqual(release.id, mbid.release.Anomalie); assert.strictEqual(release.title, 'Anomalie'); }); - [ + const includes: {inc: ReleaseIncludes, key: keyof IRelease}[] = [ {inc: 'artist-credits', key: 'artist-credit'}, {inc: 'artists', key: 'artist-credit'}, {inc: 'collections', key: 'collections'}, @@ -216,13 +222,14 @@ describe('MusicBrainz-api', function () { {inc: 'media', key: 'media'}, // {inc: 'recordings', key: 'recordings'}, {inc: 'release-groups', key: 'release-group'} - ].forEach(inc => { + ]; + includes.forEach(inc => { it(`get release, include: '${inc.inc}'`, async () => { - const release = await mbApi.lookupRelease(mbid.release.Formidable, [inc.inc as any]); + const release = await mbApi.lookup('release', mbid.release.Formidable, [inc.inc]); assert.strictEqual(release.id, mbid.release.Formidable); assert.strictEqual(release.title, 'Formidable'); - assert.isDefined((release as any)[inc.key], `Should include '${inc.key}'`); + assert.isDefined(release[inc.key], `Should include '${inc.key}'`); }); }); @@ -231,27 +238,29 @@ describe('MusicBrainz-api', function () { describe('Release-group', () => { it('release-group', async () => { - const releaseGroup = await mbApi.lookupReleaseGroup(mbid.releaseGroup.Formidable); + const releaseGroup = await mbApi.lookup('release-group', mbid.releaseGroup.Formidable); assert.strictEqual(releaseGroup.id, mbid.releaseGroup.Formidable); assert.strictEqual(releaseGroup.title, 'Formidable'); }); - [ + const includes: {inc: ReleaseGroupIncludes, key: keyof IReleaseGroup}[] = [ {inc: 'artist-credits', key: 'artist-credit'} - ].forEach(inc => { + ]; + + includes.forEach(inc => { it(`get release-group, include: '${inc.inc}'`, async () => { - const group = await mbApi.lookupReleaseGroup(mbid.releaseGroup.Formidable, [inc.inc as any]); + const group = await mbApi.lookup('release-group', mbid.releaseGroup.Formidable, [inc.inc]); assert.strictEqual(group.id, mbid.releaseGroup.Formidable); assert.strictEqual(group.title, 'Formidable'); - assert.isDefined((group as any)[inc.key], `Should include '${inc.key}'`); + assert.isDefined(group[inc.key], `Should include '${inc.key}'`); }); }); }); it('series', async () => { - const series = await mbApi.lookupSeries(mbid.series.DireStraitsRemastered); + const series = await mbApi.lookup('series', mbid.series.DireStraitsRemastered); assert.strictEqual(series.id, mbid.series.DireStraitsRemastered, 'series.id'); assert.strictEqual(series.name, 'Dire Straits Remastered', 'series.name'); assert.strictEqual(series.disambiguation, '', 'series.disambiguation'); @@ -259,7 +268,7 @@ describe('MusicBrainz-api', function () { }); it('work', async () => { - const work = await mbApi.lookupWork(mbid.work.Formidable); + const work = await mbApi.lookup('work', mbid.work.Formidable); assert.strictEqual(work.id, mbid.work.Formidable); assert.strictEqual(work.title, 'Formidable'); }); @@ -267,7 +276,7 @@ describe('MusicBrainz-api', function () { describe('Recording', () => { it('recording', async () => { - const recording = await mbApi.lookupRecording(mbid.recording.Formidable); + const recording = await mbApi.lookup('recording', mbid.recording.Formidable); assert.strictEqual(recording.id, mbid.recording.Formidable); assert.strictEqual(recording.title, 'Formidable'); assert.isUndefined(recording.isrcs); @@ -275,61 +284,62 @@ describe('MusicBrainz-api', function () { assert.isUndefined(recording.releases); }); - [ + const includes:{inc: RecordingIncludes, key: keyof IRecording}[] = [ {inc: 'isrcs', key: 'isrcs'}, {inc: 'artist-credits', key: 'artist-credit'}, {inc: 'artists', key: 'artist-credit'}, {inc: 'releases', key: 'releases'} - ].forEach(inc => { + ]; + + includes.forEach(inc => { it(`recording, include: '${inc.inc}'`, async () => { - const recording = await mbApi.lookupRecording(mbid.recording.Formidable, [inc.inc as any]); + const recording = await mbApi.lookup('recording', mbid.recording.Formidable, [inc.inc]); assert.strictEqual(recording.id, mbid.recording.Formidable); assert.strictEqual(recording.title, 'Formidable'); - assert.isDefined((recording as any)[inc.key], `Should include '${inc.key}'`); + assert.isDefined(recording[inc.key], `Should include '${inc.key}'`); }); }); it('extended recording', async () => { - const recording = await mbApi.lookupRecording(mbid.recording.Formidable, ['isrcs', 'artists', 'releases', 'url-rels']); + const recording = await mbApi.lookup('recording', mbid.recording.Formidable, ['isrcs', 'artists', 'releases', 'url-rels']); assert.strictEqual(recording.id, mbid.recording.Formidable); assert.strictEqual(recording.title, 'Formidable'); assert.isDefined(recording.isrcs); assert.isDefined(recording['artist-credit']); - // assert.isDefined(recording.releases); }); }); describe('release-group', () => { it('release-group', async () => { - const releaseGroup = await mbApi.lookupReleaseGroup(mbid.releaseGroup.Formidable); + const releaseGroup = await mbApi.lookup('release-group', mbid.releaseGroup.Formidable); assert.strictEqual(releaseGroup.id, mbid.releaseGroup.Formidable); assert.strictEqual(releaseGroup.title, 'Formidable'); }); [ - {inc: 'artist-credits', key: 'artist-credit'} + {inc: 'artist-credits' as ReleaseGroupIncludes, key: 'artist-credit' as keyof IReleaseGroup} ].forEach(inc => { it(`get release-group, include: '${inc.inc}'`, async () => { - const group = await mbApi.lookupReleaseGroup(mbid.releaseGroup.Formidable, [inc.inc as any]); + const group = await mbApi.lookup('release-group', mbid.releaseGroup.Formidable, [inc.inc]); assert.strictEqual(group.id, mbid.releaseGroup.Formidable); assert.strictEqual(group.title, 'Formidable'); - assert.isDefined((group as any)[inc.key], `Should include '${inc.key}'`); + assert.isDefined(group[inc.key], `Should include '${inc.key}'`); }); }); }); it('work', async () => { - const work = await mbApi.lookupWork(mbid.work.Formidable); + const work = await mbApi.lookup('work', mbid.work.Formidable); assert.strictEqual(work.id, mbid.work.Formidable); assert.strictEqual(work.title, 'Formidable'); }); it('url', async () => { - const url = await mbApi.lookupUrl(mbid.url.SpotifyLisboaMulata); + const url = await mbApi.lookup('url', mbid.url.SpotifyLisboaMulata); assert.strictEqual(url.id, mbid.url.SpotifyLisboaMulata); assert.strictEqual(url.resource, 'https://open.spotify.com/album/5PCfptvsmuFcxsMt86L6wn'); }); @@ -337,23 +347,23 @@ describe('MusicBrainz-api', function () { describe('event', () => { it('event', async () => { - const event = await mbApi.lookupEvent(mbid.event.DireStraitsAlchemyLoveOverGold); + const event = await mbApi.lookup('event', mbid.event.DireStraitsAlchemyLoveOverGold); assert.strictEqual(event.id, mbid.event.DireStraitsAlchemyLoveOverGold); assert.strictEqual(event.name, "Dire Straits - Love Over Gold"); assert.strictEqual(event.type, "Concert"); }); [ - {inc: 'tags', key: 'tags'}, - {inc: 'artist-rels', key: 'relations'}, - {inc: 'ratings', key: 'rating'} + {inc: 'tags' as EventIncludes, key: 'tags' as keyof IEvent}, + {inc: 'artist-rels' as EventIncludes, key: 'relations' as keyof IEvent}, + {inc: 'ratings' as EventIncludes, key: 'rating' as keyof IEvent} ].forEach(inc => { it(`event, include: '${inc.inc}'`, async () => { - const event = await mbApi.lookupEvent(mbid.event.DireStraitsAlchemyLoveOverGold, [inc.inc as any]); + const event = await mbApi.lookup('event', mbid.event.DireStraitsAlchemyLoveOverGold, [inc.inc]); assert.strictEqual(event.id, mbid.event.DireStraitsAlchemyLoveOverGold); assert.strictEqual(event.name, "Dire Straits - Love Over Gold"); - assert.isDefined((event as any)[inc.key], `Should include '${inc.key}'`); + assert.isDefined(event[inc.key], `Should include '${inc.key}'`); }); }); @@ -376,7 +386,7 @@ describe('MusicBrainz-api', function () { } it('by collection', async () => { - const areas = await mbApi.browseAreas({collection: 'de4fdfc4-53aa-458a-b463-8761cc7f5af8', limit: 3}); + const areas = await mbApi.browse('area', {collection: 'de4fdfc4-53aa-458a-b463-8761cc7f5af8', limit: 3}); areBunchOfAreas(areas); }); @@ -389,29 +399,29 @@ describe('MusicBrainz-api', function () { } it('by area', async () => { - const artists = await mbApi.browseArtists({area: mbid.area.Lisbon, limit: 3}); + const artists = await mbApi.browse('artist', {area: mbid.area.Lisbon, limit: 3}); areBunchOfArtists(artists); }); it('by collection', async () => { - const artists = await mbApi.browseArtists({collection: 'de4fdfc4-53aa-458a-b463-8761cc7f5af8', limit: 3}); + const artists = await mbApi.browse('artist', {collection: 'de4fdfc4-53aa-458a-b463-8761cc7f5af8', limit: 3}); areBunchOfArtists(artists); }); it('by recording', async () => { - const artists = await mbApi.browseArtists({recording: 'a6c9e941-58ab-4f2e-9684-3b1b230f915f', limit: 3}); + const artists = await mbApi.browse('artist', {recording: 'a6c9e941-58ab-4f2e-9684-3b1b230f915f', limit: 3}); areBunchOfArtists(artists); assert.strictEqual(artists.artists[0].name, 'Dead Combo'); }); it('by release', async () => { - const artists = await mbApi.browseArtists({release: 'd9e00093-7a4b-44f1-830d-611e88ec694a', limit: 3}); + const artists = await mbApi.browse('artist', {release: 'd9e00093-7a4b-44f1-830d-611e88ec694a', limit: 3}); areBunchOfArtists(artists); assert.strictEqual(artists.artists[0].name, 'Dead Combo'); }); it('by release-group', async () => { - const artists = await mbApi.browseArtists({ + const artists = await mbApi.browse('artist', { 'release-group': 'f9726e3b-833a-4997-b16a-b1baf22ff87e', limit: 3 }); @@ -420,7 +430,7 @@ describe('MusicBrainz-api', function () { }); it('by work', async () => { - const artists = await mbApi.browseArtists({work: '6d7fbf07-3795-4ee1-8c69-4cc5c08e8f09', limit: 3}); + const artists = await mbApi.browse('artist', {work: '6d7fbf07-3795-4ee1-8c69-4cc5c08e8f09', limit: 3}); areBunchOfArtists(artists); assert.strictEqual(artists.artists[0].name, 'Dead Combo'); }); @@ -434,22 +444,22 @@ describe('MusicBrainz-api', function () { } it('by area', async () => { - const collections = await mbApi.browseCollections({area: mbid.area.Lisbon, limit: 3}); + const collections = await mbApi.browse('collection', {area: mbid.area.Lisbon, limit: 3}); areBunchOfCollections(collections); }); it('by artist', async () => { - const collections = await mbApi.browseCollections({artist: mbid.artist.Stromae, limit: 3}); + const collections = await mbApi.browse('collection', {artist: mbid.artist.Stromae, limit: 3}); areBunchOfCollections(collections); }); it('by editor', async () => { - const collections = await mbApi.browseCollections({editor: 'Borewit', limit: 3}); + const collections = await mbApi.browse('collection', {editor: 'Borewit', limit: 3}); areBunchOfCollections(collections); }); it('by event', async () => { - const collections = await mbApi.browseCollections({ + const collections = await mbApi.browse('collection', { event: mbid.event.DireStraitsAlchemyLoveOverGold, limit: 3 }); @@ -465,22 +475,22 @@ describe('MusicBrainz-api', function () { } it('by area', async () => { - const events = await mbApi.browseEvents({area: mbid.area.Lisbon, limit: 3}); + const events = await mbApi.browse('event', {area: mbid.area.Lisbon, limit: 3}); areBunchOfEvents(events); }); it('by artist', async () => { - const events = await mbApi.browseEvents({artist: mbid.artist.DeadCombo, limit: 3}); + const events = await mbApi.browse('event', {artist: mbid.artist.DeadCombo, limit: 3}); areBunchOfEvents(events); }); it('by collection', async () => { - const events = await mbApi.browseEvents({collection: mbid.collection.Ringtone, limit: 3}); + const events = await mbApi.browse('event', {collection: mbid.collection.Ringtone, limit: 3}); areBunchOfEvents(events); }); it('by place', async () => { - const events = await mbApi.browseEvents({place: mbid.place.Paradiso, limit: 3}); + const events = await mbApi.browse('event', {place: mbid.place.Paradiso, limit: 3}); areBunchOfEvents(events); }); @@ -493,7 +503,7 @@ describe('MusicBrainz-api', function () { } it('by collection', async () => { - const instruments = await mbApi.browseInstruments({collection: mbid.collection.Ringtone, limit: 3}); + const instruments = await mbApi.browse('instrument', {collection: mbid.collection.Ringtone, limit: 3}); areBunchOfInstruments(instruments); }); @@ -506,17 +516,17 @@ describe('MusicBrainz-api', function () { } it('by area', async () => { - const labels = await mbApi.browseLabels({area: mbid.area.Lisbon, limit: 3}); + const labels = await mbApi.browse('label', {area: mbid.area.Lisbon, limit: 3}); areBunchOfLabels(labels); }); it('by collection', async () => { - const labels = await mbApi.browseLabels({collection: mbid.collection.Ringtone, limit: 3}); + const labels = await mbApi.browse('label', {collection: mbid.collection.Ringtone, limit: 3}); areBunchOfLabels(labels); }); it('by release', async () => { - const labels = await mbApi.browseLabels({release: mbid.release.Formidable, limit: 3}); + const labels = await mbApi.browse('label', {release: mbid.release.Formidable, limit: 3}); areBunchOfLabels(labels); }); }); @@ -528,12 +538,12 @@ describe('MusicBrainz-api', function () { } it('by area', async () => { - const places = await mbApi.browsePlaces({area: mbid.area.Lisbon, limit: 3}); + const places = await mbApi.browse('place', {area: mbid.area.Lisbon, limit: 3}); areBunchOfPlaces(places); }); it('by collection', async () => { - const places = await mbApi.browsePlaces({collection: mbid.collection.Ringtone, limit: 3}); + const places = await mbApi.browse('place', {collection: mbid.collection.Ringtone, limit: 3}); areBunchOfPlaces(places); }); @@ -546,22 +556,22 @@ describe('MusicBrainz-api', function () { } it('by artist', async () => { - const recordings = await mbApi.browseRecordings({artist: mbid.artist.DeadCombo, limit: 3}); + const recordings = await mbApi.browse('recording', {artist: mbid.artist.DeadCombo, limit: 3}); areBunchOfRecordings(recordings); }); it('by collection', async () => { - const recordings = await mbApi.browseRecordings({collection: mbid.collection.Ringtone, limit: 3}); + const recordings = await mbApi.browse('recording', {collection: mbid.collection.Ringtone, limit: 3}); areBunchOfRecordings(recordings); }); it('by release', async () => { - const recordings = await mbApi.browseRecordings({release: mbid.release.Formidable, limit: 3}); + const recordings = await mbApi.browse('recording', {release: mbid.release.Formidable, limit: 3}); areBunchOfRecordings(recordings); }); it('by work', async () => { - const recordings = await mbApi.browseRecordings({work: mbid.work.Formidable, limit: 3}); + const recordings = await mbApi.browse('recording', {work: mbid.work.Formidable, limit: 3}); areBunchOfRecordings(recordings); }); @@ -574,27 +584,27 @@ describe('MusicBrainz-api', function () { } it('by area', async () => { - const releases = await mbApi.browseReleases({area: mbid.area.Lisbon, limit: 3}); + const releases = await mbApi.browse('release', {area: mbid.area.Lisbon, limit: 3}); areBunchOfReleases(releases); }); it('by artist', async () => { - const releases = await mbApi.browseReleases({artist: mbid.artist.DeadCombo, limit: 3}); + const releases = await mbApi.browse('release', {artist: mbid.artist.DeadCombo, limit: 3}); areBunchOfReleases(releases); }); it('by labels', async () => { - const releases = await mbApi.browseReleases({label: mbid.label.Mosaert, limit: 3}); + const releases = await mbApi.browse('release', {label: mbid.label.Mosaert, limit: 3}); areBunchOfReleases(releases); }); it('by recording', async () => { - const releases = await mbApi.browseReleases({recording: mbid.recording.Montilla, limit: 3}); + const releases = await mbApi.browse('release', {recording: mbid.recording.Montilla, limit: 3}); areBunchOfReleases(releases); }); it('by release-group', async () => { - const releases = await mbApi.browseReleases({'release-group': mbid.releaseGroup.Formidable, limit: 3}); + const releases = await mbApi.browse('release', {'release-group': mbid.releaseGroup.Formidable, limit: 3}); areBunchOfReleases(releases); }); }); @@ -606,17 +616,17 @@ describe('MusicBrainz-api', function () { } it('by artist', async () => { - const releaseGroups = await mbApi.browseReleaseGroups({artist: mbid.artist.DeadCombo, limit: 3}); + const releaseGroups = await mbApi.browse('release-group', {artist: mbid.artist.DeadCombo, limit: 3}); areBunchOfReleaseGroups(releaseGroups); }); it('by collection', async () => { - const releaseGroups = await mbApi.browseReleaseGroups({collection: mbid.collection.Ringtone, limit: 3}); + const releaseGroups = await mbApi.browse('release-group', {collection: mbid.collection.Ringtone, limit: 3}); areBunchOfReleaseGroups(releaseGroups); }); it('by release', async () => { - const releaseGroups = await mbApi.browseReleaseGroups({release: mbid.release.Formidable, limit: 3}); + const releaseGroups = await mbApi.browse('release-group', {release: mbid.release.Formidable, limit: 3}); areBunchOfReleaseGroups(releaseGroups); }); @@ -629,7 +639,7 @@ describe('MusicBrainz-api', function () { } it('by collection', async () => { - const series = await mbApi.browseSeries({collection: mbid.collection.Ringtone, limit: 3}); + const series = await mbApi.browse('series', {collection: mbid.collection.Ringtone, limit: 3}); areBunchOfSeries(series); }); }); @@ -641,7 +651,7 @@ describe('MusicBrainz-api', function () { } it('by collection', async () => { - const works = await mbApi.browseWorks({collection: mbid.collection.Ringtone, limit: 3}); + const works = await mbApi.browse('work', {collection: mbid.collection.Ringtone, limit: 3}); areBunchOfWorks(works); }); }); @@ -649,7 +659,7 @@ describe('MusicBrainz-api', function () { describe('url', async () => { it('by resources', async () => { - const url = await mbApi.browseUrls({ + const url = await mbApi.browse('url', { resource: 'https://open.spotify.com/album/5PCfptvsmuFcxsMt86L6wn', limit: 3 }); @@ -663,7 +673,7 @@ describe('MusicBrainz-api', function () { it('query: Queen - We Will Rock You', async () => { const query = 'query="We Will Rock You" AND arid:0383dadf-2a4e-4d10-a46a-e9e041da8eb3'; - const result = await mbApi.search('release-group', {query}); + const result = await mbApi.search('release-group', {query}); assert.isAtLeast(result.count, 1); }); @@ -671,19 +681,20 @@ describe('MusicBrainz-api', function () { describe('Search', () => { - describe('generic search', () => { + describe('area', () => { - it('find artist: Stromae', async () => { - const result = await mbApi.search('artist', {query: 'Stromae'}); + it('find area by name', async () => { + const result = await mbApi.search('area', {query: 'Île-de-France'}); assert.isAtLeast(result.count, 1); + assert.isAtLeast(result.areas.length, 1); + assert.strictEqual(result.areas[0].id, mbid.area.IleDeFrance); }); - }); - describe('searchArtist', () => { + describe('artist', () => { it('find artist: Stromae', async () => { - const result = await mbApi.searchArtist({query: 'Stromae'}); + const result = await mbApi.search('artist', {query: 'Stromae'}); assert.isAtLeast(result.count, 1); assert.isAtLeast(result.artists.length, 1); assert.strictEqual(result.artists[0].id, mbid.artist.Stromae); @@ -691,41 +702,35 @@ describe('MusicBrainz-api', function () { }); - describe('searchReleaseGroup', () => { - - it('find release-group: Racine carrée', async () => { - const result = await mbApi.searchReleaseGroup({query: 'Racine carrée'}); - assert.isAtLeast(result.count, 1); - assert.isAtLeast(result['release-groups'].length, 1); - assert.strictEqual(result['release-groups'][0].id, mbid.releaseGroup.RacineCarree); - }); + describe('recording', () => { - it('find release-group: Racine carrée, by artist and group name', async () => { - const result = await mbApi.searchReleaseGroup({query: {release: 'Racine carrée', artist: 'Stromae'}}); - assert.isAtLeast(result.count, 1); - assert.isAtLeast(result['release-groups'].length, 1); - assert.strictEqual(result['release-groups'][0].id, mbid.releaseGroup.RacineCarree); + it('find recording by artist and recoding name', async () => { + const result = await mbApi.search('recording', {query: {name: 'Formidable', artist: 'Stromae'}}); + assert.isAtLeast(result.count, 2); + assert.isAtLeast(result.recordings.length, 2); + assert.includeMembers(result.recordings.map(recording => recording.id), [mbid.recording.Formidable]); }); }); - describe('searchRelease', () => { + + describe('release', () => { it('find release-group: Racine carrée', async () => { - const result = await mbApi.searchRelease({query: {release: 'Racine carrée'}}); + const result = await mbApi.search('release', {query: {release: 'Racine carrée'}}); assert.isAtLeast(result.count, 2); assert.isAtLeast(result.releases.length, 2); assert.includeMembers(result.releases.map(release => release.id), mbid.release.RacineCarree); }); it('find release by barcode', async () => { - const result = await mbApi.searchRelease({query: {barcode: 602537479870}}); + const result = await mbApi.search('release', {query: {barcode: 602537479870}}); assert.isAtLeast(result.count, 1); assert.isAtLeast(result.releases.length, 1); assert.equal(result.releases[0].id, mbid.release.RacineCarree[2]); }); it('find release by barcode', async () => { - const result = await mbApi.searchRelease({query: {barcode: 602537479870}}); + const result = await mbApi.search('release', {query: {barcode: 602537479870}}); assert.isAtLeast(result.count, 1); assert.isAtLeast(result.releases.length, 1); assert.equal(result.releases[0].id, mbid.release.RacineCarree[2]); @@ -733,21 +738,21 @@ describe('MusicBrainz-api', function () { it('find releases by artist use query API', async () => { const artist_mbid = 'eeb41a1e-4326-4d04-8c47-0f564ceecd68'; - const result = await mbApi.searchRelease({query: {arid: artist_mbid}}); + const result = await mbApi.search('release', {query: {arid: artist_mbid}}); assert.isAtLeast(result.count, 1); assert.isAtLeast(result.releases.length, 1); }); it('find releases by artist use browse API', async () => { const artist_mbid = 'eeb41a1e-4326-4d04-8c47-0f564ceecd68'; - const result = await mbApi.searchRelease({artist: artist_mbid}); + const result = await mbApi.search('release', {artist: artist_mbid}); assert.isAtLeast(result['release-count'], 1); assert.isAtLeast(result.releases.length, 1); }); it('find releases with inc', async () => { const artist_mbid = '024a7074-dcef-4851-8f9c-090a9746a75a'; - const result = await mbApi.searchRelease({ + const result = await mbApi.search('release', { query: `arid:${artist_mbid}`, inc: ['release-groups', 'media', 'label-rels'], offset: 0, @@ -758,13 +763,20 @@ describe('MusicBrainz-api', function () { }); - describe('searchArea', () => { + describe('release-group', () => { - it('find area by name', async () => { - const result = await mbApi.searchArea({query: 'Île-de-France'}); + it('find release-group: Racine carrée', async () => { + const result = await mbApi.search('release-group', {query: 'Racine carrée'}); assert.isAtLeast(result.count, 1); - assert.isAtLeast(result.areas.length, 1); - assert.strictEqual(result.areas[0].id, mbid.area.IleDeFrance); + assert.isAtLeast(result['release-groups'].length, 1); + assert.strictEqual(result['release-groups'][0].id, mbid.releaseGroup.RacineCarree); + }); + + it('find release-group: Racine carrée, by artist and group name', async () => { + const result = await mbApi.search('release-group', {query: {release: 'Racine carrée', artist: 'Stromae'}}); + assert.isAtLeast(result.count, 1); + assert.isAtLeast(result['release-groups'].length, 1); + assert.strictEqual(result['release-groups'][0].id, mbid.releaseGroup.RacineCarree); }); }); @@ -773,7 +785,7 @@ describe('MusicBrainz-api', function () { const spotifyUrl = 'https://open.spotify.com/album/' + spotify.album.RacineCarree.id; it('find url by url', async () => { - const result = await mbApi.searchUrl({query: {url: spotifyUrl}}); + const result = await mbApi.search('url', {query: {url: spotifyUrl}}); assert.isAtLeast(result.count, 1); assert.isAtLeast(result.urls.length, 1); assert.strictEqual(result.urls[0].resource, spotifyUrl); @@ -811,7 +823,7 @@ describe('MusicBrainz-api', function () { describe('Recording', () => { it('add link', async () => { - const recording = await mbTestApi.lookupRecording(mbid.recording.Formidable); + const recording = await mbTestApi.lookup('recording', mbid.recording.Formidable); assert.strictEqual(recording.id, mbid.recording.Formidable); assert.strictEqual(recording.title, 'Formidable'); @@ -822,7 +834,7 @@ describe('MusicBrainz-api', function () { }); it('add Spotify-ID', async () => { - const recording = await mbTestApi.lookupRecording(mbid.recording.Formidable); + const recording = await mbTestApi.lookup('recording', mbid.recording.Formidable); const editNote = `Unit-test musicbrainz-api (${appUrl}), test augment recording with Spotify URL & ISRC`; await mbTestApi.addSpotifyIdToRecording(recording, spotify.track.Formidable.id, editNote); @@ -832,7 +844,7 @@ describe('MusicBrainz-api', function () { // https://test.musicbrainz.org/recording/a75b85bf-63dd-4fe1-8008-d15541b93bac const recording_id = 'a75b85bf-63dd-4fe1-8008-d15541b93bac'; - const recording = await mbTestApi.lookupRecording(recording_id); + const recording = await mbTestApi.lookup('recording', recording_id); const editNote = `Unit-test musicbrainz-api (${appUrl}), test augment recording with Spotify URL & ISRC`; await mbTestApi.addSpotifyIdToRecording(recording, '3ZDO5YINwfoifRQ3ElshPM', editNote); }); @@ -842,7 +854,7 @@ describe('MusicBrainz-api', function () { describe('ISRC', () => { it('add ISRC', async () => { - const recording = await mbTestApi.lookupRecording(mbid.recording.Formidable, ['isrcs']); + const recording = await mbTestApi.lookup('recording', mbid.recording.Formidable, ['isrcs']); assert.strictEqual(recording.id, mbid.recording.Formidable); assert.strictEqual(recording.title, 'Formidable');