ytmusic_api_unofficial
Version:
A simple API to get music from YouTube Music
60 lines • 2.86 kB
JavaScript
;
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;
}
/**
* Get the artist's songs
* @return Music[]
*/
getSongs() {
return new Promise((resolve, reject) => {
(0, index_1.search)(this.name, 'artist_song').then((res) => {
var _a;
if ((_a = res === null || res === void 0 ? void 0 : res.content) === null || _a === void 0 ? void 0 : _a.length)
return resolve(res.content);
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) => {
(0, index_1.search)(this.name, 'artist_album').then((res) => {
var _a;
if ((_a = res === null || res === void 0 ? void 0 : res.content) === null || _a === void 0 ? void 0 : _a.length)
return resolve(res.content);
reject((0, error_1.error)(1008, { artist: this.name, type: 'album' }));
}).catch(reject);
});
}
/**
* Get the artist's videos
* @returns Music[]
*/
getVideos() {
return new Promise((resolve, reject) => {
(0, index_1.search)(this.name, 'artist_video').then((res) => {
var _a;
if ((_a = res === null || res === void 0 ? void 0 : res.content) === null || _a === void 0 ? void 0 : _a.length)
return resolve(res.content);
reject((0, error_1.error)(1008, { artist: this.name, type: 'video' }));
}).catch(reject);
});
}
}
exports.default = Artist;
//# sourceMappingURL=Artist.js.map