UNPKG

@terron/djs-music

Version:

New simple voice player with yt-dlp supporting, filters & events for discord.js v14.

39 lines (34 loc) 1.24 kB
const { Readable } = require('stream'); const YTDlpWrap = require('yt-dlp-wrap').default; const ytDlpWrap = new YTDlpWrap( __dirname + '/yt-dlp/' + (require('os').platform() == 'win32' ? 'win.exe' : 'linux') ); module.exports.Resolvable = class Resolvable { static from(value) { return String(value?.id || value); } } module.exports.shuffleArray = function shuffleArray(array) { for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array; } module.exports.getFullStream = async function(url, options = []) { return new Promise((resolve, reject) => { const dataChunks = []; const ytStream = ytDlpWrap.execStream([url, ...options]) .on('data', (chunk) => { dataChunks.push(chunk); }) .on('error', (error) => { reject(error); }) .on('close', () => { const fullBuffer = Buffer.concat(dataChunks); const fullStream = Readable.from(fullBuffer); resolve(fullStream); }); }); }