UNPKG

playdl-music-extractor

Version:

PlayDL Music Extractor is a Extractor/Scrapper and Helps Players to fetch data from play-dl or Custom Extractors , as Per reduces extra work and credentials

71 lines (65 loc) 2.08 kB
/** * @class Album is a Class used for Patching album Info with Ids and attached with Tracks */ class album { constructor(albumMetadata, queue, tracksCount, metadata = undefined) { this.patch({ ...albumMetadata, tracksCount, metadata, queue, }); queue.add(this, 'album'); } /** * @method patch Patching Raw Album/album Data * @param {Object<any>} metadata Metadata Data for Patching * @returns {this} Returns Modified Data */ patch(metadata) { this.id = metadata?.id; this.name = metadata?.name ?? metadata?.title; this.url = metadata?.external_urls?.spotify ?? metadata?.url; this.tracksCount = metadata?.tracksCount ?? 0; this.description = metadata?.description; this.thumbnail = metadata?.images?.[0]?.url ?? metadata?.thumbnail?.url ?? metadata?.thumbnail; this.channel = metadata?.channel || metadata?.owner || metadata?.author ? { name: metadata?.channel?.name ?? metadata?.channel?.title ?? metadata?.owner?.display_name ?? metadata?.author?.name ?? metadata?.author?.username, description: metadata?.channel?.description ?? metadata?.owner?.description, url: metadata?.channel?.url ?? metadata?.owner?.external_urls?.spotify ?? metadata?.author?.profile, thumbnail: metadata?.channel?.icons?.[0]?.url, } : undefined; this.views = metadata?.views; this.metadata = metadata?.metadata; this.queue = metadata?.queue; this.uniqueId = this.#generateId(); return this; } #generateId() { let requestedId = ''; while ( Array.from(this.queue?.playdl?.queues?.values()).find( (album) => album?.id === requestedId?.trim(), ) || requestedId?.trim() === '' ) requestedId = Math.random().toString(36).slice(2, 15); return requestedId; } get tracks() { return this.queue?.tracks; } } module.exports = album;