UNPKG

player-engine

Version:

Play your Musics in Your Discord Music Bot | Discord.js V13 Only

128 lines (127 loc) 5.38 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const PlayerError_1 = __importDefault(require("../utils/PlayerError")); const music_engines_1 = require("music-engines"); const prism_media_1 = require("prism-media"); const Enums_1 = require("../utils/Enums"); const stream = __importStar(require("node:stream")); const http_1 = require("http"); const voice_1 = require("@discordjs/voice"); const { youtube, soundcloud, spotify, deezer } = music_engines_1.wrappers; const { YouTubeTrack } = youtube; const { SoundCloudTrack } = soundcloud; const { SpotifyTrack } = spotify; const { DeezerTrack } = deezer; class PlayerTrack { constructor(data) { this.metadata = {}; this.raw = data; if (data instanceof YouTubeTrack) { this.title = data.title; this.url = data.url; this.picture = data.picture; this.platform = data.platform; this.stream = data.stream(); this.duration = data.duration; this.streamType = voice_1.StreamType.Opus; } else if (data instanceof SoundCloudTrack) { this.title = data.title; this.url = data.url; this.picture = data.picture; this.platform = data.platform; this.tempStream = data.stream(); this.duration = data.duration; } else if (data instanceof SpotifyTrack) { this.title = data.title; this.url = data.url; this.picture = data.picture; this.platform = data.platform; this.tempStream = data.stream(); this.duration = data.duration; } else if (data instanceof DeezerTrack) { this.title = data.title; this.url = data.url; this.picture = data.picture; this.platform = data.platform; this.tempStream = data.stream(); this.duration = data.duration; } else throw new PlayerError_1.default(Enums_1.Errors.NOT_SUPPORTED, `Recived Track data is not by supported Engines`); } init() { return __awaiter(this, void 0, void 0, function* () { try { if (this.tempStream instanceof Promise) this.tempStream = yield this.tempStream; if (this.tempStream instanceof prism_media_1.opus.Encoder || this.tempStream instanceof prism_media_1.FFmpeg || this.tempStream instanceof http_1.IncomingMessage || this.tempStream instanceof stream.Readable || this.tempStream instanceof Buffer) { this.stream = this.tempStream; //this.createResource(); } } catch (error) { throw error; } }); } createResource(inlineVolume = true) { this.audioResource = (0, voice_1.createAudioResource)(this.stream, { metadata: { title: this.title, picture: this.picture, url: this.url, platform: this.platform, duraation: this.duration.format, }, //inputType: this.streamType ?? StreamType.Raw, inlineVolume, }); return this.audioResource; } addMetadata(data) { this.metadata = Object.assign(Object.assign({}, data), this.metadata); } } exports.default = PlayerTrack;