1+ import { shareValues } from "$lib/util/array" ;
12import { COVERARCH , type CAARelease , type CAAReleaseImage } from "./coveArtArchive" ;
2- import { type MBArtistSearchResult , type MBArtistSearch , MUSICBRAINZ , type MBArtist , type MBRecordingSearchResult , type MBRecordingSearch , type MBRelease } from "./musicBrainz" ;
3+ import { type MBArtistSearchResult , type MBArtistSearch , MUSICBRAINZ , type MBArtist , type MBRecordingSearchResult , type MBRecordingSearch , type MBRelease , type MBArtistCredit } from "./musicBrainz" ;
34
45export type APIArtist = {
56 name : string ,
67 id : string ,
7- logo ?: string
8+ logo ?: string ,
89}
910
1011export type APISong = {
1112 title : string ,
1213 id : string ,
14+ artistIds : string [ ] ,
1315 coverArt ?: string
1416}
1517
@@ -173,12 +175,12 @@ export class SongAPI {
173175 }
174176
175177 let url = `${ MUSICBRAINZ } /recording/?query=${ encodeURI ( searchString ) } &limit=5` ;
176-
178+ console . log ( url )
177179 const search : MBRecordingSearch | undefined = await this . get ( url ) ;
178180
179181 if ( ! search || ! search . recordings )
180182 return ;
181-
183+
182184 return search . recordings [ 0 ] ;
183185 }
184186
@@ -190,13 +192,13 @@ export class SongAPI {
190192 }
191193
192194 private async querySongCoverArt ( song : MBRecordingSearchResult ) : Promise < string | undefined > {
193- let release : MBRelease | null = null ;
194-
195- for ( const rel of song . releases ) {
196- if ( rel [ "artist-credit-id" ] == song [ "artist-credit-id" ] ) {
195+ let release : MBRelease | undefined = song . releases [ 0 ] ;
196+
197+ /* for(const rel of song.releases) {
198+ if(rel.status == "Official" ) {
197199 release = rel;
198200 }
199- }
201+ }*/
200202
201203 if ( ! release )
202204 return ;
@@ -217,6 +219,7 @@ export class SongAPI {
217219 return {
218220 title : searchRes . title ,
219221 id : searchRes . id ,
222+ artistIds : this . getArtistIdsFromCredits ( searchRes [ "artist-credit" ] ) ,
220223 coverArt : await this . querySongCoverArt ( searchRes )
221224 } ;
222225 }
@@ -245,6 +248,9 @@ export class SongAPI {
245248 // TODO: Search in other sources. There are barely any artist images in MusicBrainz
246249 // this function is 'async' to prepare it for making requests in the future
247250
251+ if ( ! artist . relations )
252+ return ;
253+
248254 for ( const rel of artist . relations ) {
249255 if ( rel . type == "image" ) {
250256 return rel . url . resource ;
@@ -262,4 +268,25 @@ export class SongAPI {
262268 // the logo logic is highly flawed (URL contains the image page instead of the actual file, barely any artists have an image). Disabled for now
263269 } ;
264270 }
271+
272+ private getArtistIdsFromCredits ( credits : MBArtistCredit [ ] | undefined ) : string [ ] {
273+ const res : string [ ] = [ ] ;
274+
275+ if ( ! credits ) {
276+ return [ ] ;
277+ }
278+
279+ for ( const artist of credits ) {
280+ res . push ( artist . artist . id ) ;
281+ }
282+
283+ return res ;
284+ }
285+
286+ private shareCredits ( a : MBArtistCredit [ ] , b : MBArtistCredit [ ] ) {
287+ const aIds = this . getArtistIdsFromCredits ( a ) ;
288+ const bIds = this . getArtistIdsFromCredits ( b ) ;
289+
290+ return shareValues ( a , b ) ;
291+ }
265292}
0 commit comments