diff --git a/index.js b/index.js index 76fafbb..38280e7 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +process.env.YTDL_NO_UPDATE = true; + module.exports = { version: require('./package.json').version, Player: require('./src/Player') diff --git a/package.json b/package.json index e2f9bf3..bd4c6cd 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "homepage": "https://github.com/Androz2091/discord-player#readme", "dependencies": { "@types/node": "^14.14.7", + "chalk": "^4.1.0", "discord-ytdl-core": "^5.0.0", "merge-options": "^3.0.4", "moment": "^2.27.0", @@ -38,7 +39,7 @@ "soundcloud-scraper": "^4.0.0", "spotify-url-info": "^2.2.0", "youtube-sr": "^2.0.5", - "ytdl-core": "^4.4.0" + "ytdl-core": "^4.4.2" }, "devDependencies": { "@discordjs/opus": "^0.3.2", diff --git a/src/Player.js b/src/Player.js index 42b5ae2..2db6fa3 100644 --- a/src/Player.js +++ b/src/Player.js @@ -94,6 +94,8 @@ class Player extends EventEmitter { * @type {Util} */ this.util = Util + this.util.checkFFMPEG(); + /** * Discord.js client instance * @type {Discord.Client} @@ -731,6 +733,8 @@ class Player extends EventEmitter { _playYTDLStream (queue, updateFilter) { return new Promise((resolve) => { + const ffmeg = this.util.checkFFMPEG(); + if (!ffmeg) return; const seekTime = updateFilter ? queue.voiceConnection.dispatcher.streamTime + queue.additionalStreamTime : undefined const encoderArgsFilters = [] Object.keys(queue.filters).forEach((filterName) => { diff --git a/src/Util.js b/src/Util.js index 572e39a..64ea250 100644 --- a/src/Util.js +++ b/src/Util.js @@ -1,5 +1,6 @@ const ytsr = require('youtube-sr') const soundcloud = require('soundcloud-scraper') +const chalk = require('chalk') const spotifySongRegex = (/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-){22})/) const spotifyPlaylistRegex = (/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:playlist\/|\?uri=spotify:playlist:)((\w|-){22})/) @@ -10,6 +11,21 @@ module.exports = class Util { throw new Error(`The ${this.constructor.name} class may not be instantiated.`) } + static checkFFMPEG () { + try { + const prism = require('prism-media') + prism.FFmpeg.getInfo() + return true; + } catch (e) { + this.alertFFMPEG(); + return false; + } + } + + static alertFFMPEG () { + console.log(chalk.red('ERROR:'), 'FFMPEG is not installed. Install with "npm install ffmpeg-static" or download it here: https://ffmpeg.org/download.html.'); + } + static isVoiceEmpty (channel) { return channel.members.filter((member) => !member.user.bot).size === 0 }