MCPcopy
hub / github.com/watsonbox/exportify / data

Method data

src/components/data/TracksArtistsData.ts:21–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19 }
20
21 async data() {
22 const artistIds = Array.from(new Set(this.tracks.flatMap((track: any) => {
23 return track
24 .artists
25 .filter((a: any) => a.type === "artist")
26 .map((a: any) => a.id)
27 .filter((i: string) => i)
28 })))
29
30 let requests = []
31
32 for (var offset = 0; offset < artistIds.length; offset = offset + this.ARTIST_LIMIT) {
33 requests.push(`https://api.spotify.com/v1/artists?ids=${artistIds.slice(offset, offset + this.ARTIST_LIMIT)}`)
34 }
35
36 const artistPromises = requests.map(request => { return apiCall(request, this.accessToken) })
37 const artistResponses = await Promise.all(artistPromises)
38
39 const artistsById = new Map(artistResponses.flatMap((response) => response.data.artists).map((artist: any) => [artist.id, artist]))
40
41 return new Map<string, string[]>(this.tracks.map((track: any) => {
42 return [
43 track.uri,
44 [
45 track.artists.map((a: any) => {
46 return artistsById.has(a.id) ? artistsById.get(a.id)!.genres.filter((g: string) => g).join(',') : ""
47 }).filter((g: string) => g).join(",")
48 ]
49 ]
50 }))
51 }
52}
53
54export default TracksArtistsData

Callers

nothing calls this directly

Calls 2

sliceMethod · 0.80
allMethod · 0.80

Tested by

no test coverage detected