ytmusic_api_unofficial
Version:
A simple API to get music from YouTube Music
38 lines • 1.68 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Thumbnail_1 = require("./Thumbnail");
const Artist_1 = __importDefault(require("./Artist"));
const index_1 = require("../index");
const error_1 = require("../utils/error");
class Album {
constructor(data) {
var _a, _b;
this.resultType = data.resultType;
this.thumbnails = (_a = data === null || data === void 0 ? void 0 : data.thumbnails) === null || _a === void 0 ? void 0 : _a.map((thumbnail) => new Thumbnail_1.Thumbnail(thumbnail));
this.id = data.id;
this.name = data.title || data.name;
this.artists = (_b = data === null || data === void 0 ? void 0 : data.artists) === null || _b === void 0 ? void 0 : _b.map((artist) => new Artist_1.default(artist));
this.year = data.year;
this.isExplicit = !!data.isExplicit;
}
/**
* Get the Album's songs
* @return Music[]
*/
getSongs() {
return new Promise((resolve, reject) => {
(0, index_1.get)(this.id).then((res) => {
var _a;
console.log(res.musics);
if ((_a = res === null || res === void 0 ? void 0 : res.musics) === null || _a === void 0 ? void 0 : _a.length)
return resolve(res === null || res === void 0 ? void 0 : res.musics);
reject((0, error_1.error)(1008, { artist: this.name, type: 'song' }));
}).catch(reject);
});
}
}
exports.default = Album;
//# sourceMappingURL=Album.js.map