UNPKG

ytmusic_api_unofficial

Version:

A simple API to get music from YouTube Music

53 lines 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Thumbnail_1 = require("./Thumbnail"); const utils_1 = require("../utils/utils"); const index_1 = require("../index"); const error_1 = require("../utils/error"); class Artist { constructor(artist) { var _a, _b, _c, _d; this.thumbnails = (0, utils_1.thumbnail_defaults_size)((_c = (_a = artist === null || artist === void 0 ? void 0 : artist.thumbnails) === null || _a === void 0 ? void 0 : _a[((_b = artist === null || artist === void 0 ? void 0 : artist.thumbnails) === null || _b === void 0 ? void 0 : _b.length) - 1]) === null || _c === void 0 ? void 0 : _c.url, (_d = artist === null || artist === void 0 ? void 0 : artist.thumbnails) === null || _d === void 0 ? void 0 : _d.map((thumbnail) => new Thumbnail_1.Thumbnail(thumbnail))) || []; this.name = artist.name; this.id = artist === null || artist === void 0 ? void 0 : artist.id; this.followers = artist === null || artist === void 0 ? void 0 : artist.followers; this.description = artist === null || artist === void 0 ? void 0 : artist.description; this.browseIds = (artist === null || artist === void 0 ? void 0 : artist.browseIds) || []; } /** * Get the artist's songs * @returns Playlist */ getSongs() { return new Promise((resolve, reject) => { const typeOfBrowse = this.browseIds.find(id => id.type === 'MUSIC_PAGE_TYPE_PLAYLIST'); (0, index_1.get)(typeOfBrowse.id, typeOfBrowse.param).then((res) => { var _a; res.artists = [this]; if ((_a = res === null || res === void 0 ? void 0 : res.musics) === null || _a === void 0 ? void 0 : _a.length) return resolve(res); reject((0, error_1.error)(1008, { artist: this.name, type: 'song' })); }).catch(reject); }); } /** * Get the artist's albums * @returns Album[] */ getAlbums() { return new Promise((resolve, reject) => { var _a; const typeOfBrowse = (_a = this.browseIds) === null || _a === void 0 ? void 0 : _a.find(id => id.type === 'MUSIC_PAGE_TYPE_ARTIST_DISCOGRAPHY'); (0, index_1.get)(typeOfBrowse.id, typeOfBrowse.param).then((res) => { for (const alb of res) { alb.artists = [this]; } if (res === null || res === void 0 ? void 0 : res.length) return resolve(res); reject((0, error_1.error)(1008, { artist: this.name, type: 'album' })); }).catch(reject); }); } } exports.default = Artist; //# sourceMappingURL=Artist.js.map