UNPKG

spotify-ts-wrapper

Version:

Spotify TypeScript wrapper.

97 lines (96 loc) 6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.albumParser = albumParser; const getSpotifyId_1 = require("../Utils/getSpotifyId"); function albumParser(body) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; const { data } = body; const album = data === null || data === void 0 ? void 0 : data.albumUnion; const type = album === null || album === void 0 ? void 0 : album.__typename; const title = album === null || album === void 0 ? void 0 : album.name; const label = album === null || album === void 0 ? void 0 : album.label; const artists = (_b = (_a = album === null || album === void 0 ? void 0 : album.artists) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.map((artist) => { var _a, _b, _c, _d; const item = artist; const name = (_a = item === null || item === void 0 ? void 0 : item.profile) === null || _a === void 0 ? void 0 : _a.name; const id = item === null || item === void 0 ? void 0 : item.id; const image = (_d = (_c = (_b = item === null || item === void 0 ? void 0 : item.visuals) === null || _b === void 0 ? void 0 : _b.avatarImage) === null || _c === void 0 ? void 0 : _c.sources[0]) === null || _d === void 0 ? void 0 : _d.url; return { name, id, image, }; }); const copyright = (_d = (_c = album === null || album === void 0 ? void 0 : album.copyright) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d.map((item) => item); const date = (_e = album === null || album === void 0 ? void 0 : album.date) === null || _e === void 0 ? void 0 : _e.isoString; const id = (0, getSpotifyId_1.extractSpotifyID)(album === null || album === void 0 ? void 0 : album.uri); const artwork = (_h = (_g = (_f = album === null || album === void 0 ? void 0 : album.coverArt) === null || _f === void 0 ? void 0 : _f.sources) === null || _g === void 0 ? void 0 : _g.at(-1)) === null || _h === void 0 ? void 0 : _h.url; const artworkColor = (_j = album === null || album === void 0 ? void 0 : album.coverArt) === null || _j === void 0 ? void 0 : _j.extractedColors; const colors = { dark: (_k = artworkColor.colorDark) === null || _k === void 0 ? void 0 : _k.hex, light: (_l = artworkColor.colorLight) === null || _l === void 0 ? void 0 : _l.hex, raw: (_m = artworkColor === null || artworkColor === void 0 ? void 0 : artworkColor.colorRaw) === null || _m === void 0 ? void 0 : _m.hex, }; const items = (_p = (_o = album === null || album === void 0 ? void 0 : album.tracksV2) === null || _o === void 0 ? void 0 : _o.items) === null || _p === void 0 ? void 0 : _p.map((item) => { var _a, _b, _c; const track = item === null || item === void 0 ? void 0 : item.track; const title = track === null || track === void 0 ? void 0 : track.name; const artists = (_b = (_a = track === null || track === void 0 ? void 0 : track.artists) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.map((a) => { var _a; return ({ name: (_a = a === null || a === void 0 ? void 0 : a.profile) === null || _a === void 0 ? void 0 : _a.name, id: (0, getSpotifyId_1.extractSpotifyID)(a === null || a === void 0 ? void 0 : a.uri), }); }); const disc = track === null || track === void 0 ? void 0 : track.discNumber; const playcount = track === null || track === void 0 ? void 0 : track.playcount; const id = (0, getSpotifyId_1.extractSpotifyID)(track === null || track === void 0 ? void 0 : track.uri); const duration = (_c = track === null || track === void 0 ? void 0 : track.duration) === null || _c === void 0 ? void 0 : _c.totalMilliseconds; const trackNumber = track === null || track === void 0 ? void 0 : track.trackNumber; return { title, artists, disc, playcount, id, duration, trackNumber, }; }); const disc = (_q = album === null || album === void 0 ? void 0 : album.discs) === null || _q === void 0 ? void 0 : _q.items.map((disc) => { var _a; return ({ number: disc === null || disc === void 0 ? void 0 : disc.number, totalTracks: (_a = disc === null || disc === void 0 ? void 0 : disc.tracks) === null || _a === void 0 ? void 0 : _a.totalCount, }); }); const more = (_v = (_u = (_t = (_s = (_r = album === null || album === void 0 ? void 0 : album.moreAlbumsByArtist) === null || _r === void 0 ? void 0 : _r.items[0]) === null || _s === void 0 ? void 0 : _s.discography) === null || _t === void 0 ? void 0 : _t.popularReleasesAlbums) === null || _u === void 0 ? void 0 : _u.items) === null || _v === void 0 ? void 0 : _v.map((item) => { var _a, _b, _c, _d; const type = item === null || item === void 0 ? void 0 : item.type; const artwork = (_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.coverArt) === null || _a === void 0 ? void 0 : _a.sources) === null || _b === void 0 ? void 0 : _b.at(-1)) === null || _c === void 0 ? void 0 : _c.url; const date = (_d = item === null || item === void 0 ? void 0 : item.date) === null || _d === void 0 ? void 0 : _d.year; const title = item === null || item === void 0 ? void 0 : item.name; const id = (0, getSpotifyId_1.extractSpotifyID)(item === null || item === void 0 ? void 0 : item.uri); return { type, title, date, artwork, id, }; }); return { type, label, title, copyright, date, id, artwork, colors, items, disc, artists, more, }; }