UNPKG

spotify-ts-wrapper

Version:

Spotify TypeScript wrapper.

79 lines (78 loc) 6.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.playlistParser = playlistParser; const getSpotifyId_1 = require("../Utils/getSpotifyId"); const fetchAttributes_1 = require("../Helpers/fetchAttributes"); function playlistParser(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 playlistV2 = data === null || data === void 0 ? void 0 : data.playlistV2; const type = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.__typename; const description = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.description; const permission = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.basePermission; const followers = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.followers; const image = (_d = (_c = (_b = (_a = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.images) === null || _a === void 0 ? void 0 : _a.items[0]) === null || _b === void 0 ? void 0 : _b.sources) === null || _c === void 0 ? void 0 : _c.at(-1)) === null || _d === void 0 ? void 0 : _d.url; const owner = { name: (_f = (_e = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.ownerV2) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.name, id: (0, getSpotifyId_1.extractSpotifyID)((_h = (_g = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.ownerV2) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.uri), username: (_k = (_j = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.ownerV2) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.username, type: (_m = (_l = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.ownerV2) === null || _l === void 0 ? void 0 : _l.data) === null || _m === void 0 ? void 0 : _m.__typename, image: (_s = (_r = (_q = (_p = (_o = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.ownerV2) === null || _o === void 0 ? void 0 : _o.data) === null || _p === void 0 ? void 0 : _p.avatar) === null || _q === void 0 ? void 0 : _q.sources) === null || _r === void 0 ? void 0 : _r.at(-1)) === null || _s === void 0 ? void 0 : _s.url, }; const format = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.format; const title = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.name; const id = (0, getSpotifyId_1.extractSpotifyID)(playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.uri); const headerImage = (_t = (0, fetchAttributes_1.fetchPlaylistAttributes)(playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.attributes)) !== null && _t !== void 0 ? _t : ""; const items = (_v = (_u = playlistV2 === null || playlistV2 === void 0 ? void 0 : playlistV2.content) === null || _u === void 0 ? void 0 : _u.items) === null || _v === void 0 ? void 0 : _v.map((item) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; const content = (_a = item === null || item === void 0 ? void 0 : item.itemV2) === null || _a === void 0 ? void 0 : _a.data; if (!(content === null || content === void 0 ? void 0 : content.uri)) return; const addedAt = (_b = item === null || item === void 0 ? void 0 : item.addedAt) === null || _b === void 0 ? void 0 : _b.isoString; const title = content === null || content === void 0 ? void 0 : content.name; const type = content === null || content === void 0 ? void 0 : content.__typename; const artists = (_d = (_c = content === null || content === void 0 ? void 0 : content.artists) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d.map((a) => { var _a; return ({ name: (_a = 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 duration = (_e = content === null || content === void 0 ? void 0 : content.trackDuration) === null || _e === void 0 ? void 0 : _e.totalMilliseconds; const id = (0, getSpotifyId_1.extractSpotifyID)(content === null || content === void 0 ? void 0 : content.uri); const album = { name: (_f = content === null || content === void 0 ? void 0 : content.albumOfTrack) === null || _f === void 0 ? void 0 : _f.name, id: (0, getSpotifyId_1.extractSpotifyID)((_g = content === null || content === void 0 ? void 0 : content.albumOfTrack) === null || _g === void 0 ? void 0 : _g.uri), artwork: (_l = (_k = (_j = (_h = content === null || content === void 0 ? void 0 : content.albumOfTrack) === null || _h === void 0 ? void 0 : _h.coverArt) === null || _j === void 0 ? void 0 : _j.sources) === null || _k === void 0 ? void 0 : _k.at(-1)) === null || _l === void 0 ? void 0 : _l.url, artists: (_p = (_o = (_m = content === null || content === void 0 ? void 0 : content.albumOfTrack) === null || _m === void 0 ? void 0 : _m.artists) === null || _o === void 0 ? void 0 : _o.items) === null || _p === void 0 ? void 0 : _p.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), }); }), }; return { addedAt, title, type, artists, album, id, duration, }; }); return { title, id, type, format, followers, owner, permission, image, description, items, headerImage, }; }