UNPKG

ytmusic_api_unofficial

Version:

A simple API to get music from YouTube Music

56 lines 3.17 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _Album_musics; 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; _Album_musics.set(this, void 0); __classPrivateFieldSet(this, _Album_musics, (data === null || data === void 0 ? void 0 : data.musics) || [], "f"); 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.description = data.description; 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) => { if (__classPrivateFieldGet(this, _Album_musics, "f").length) return resolve(__classPrivateFieldGet(this, _Album_musics, "f")); (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); }); } } _Album_musics = new WeakMap(); exports.default = Album; //# sourceMappingURL=Album.js.map