✨ Add ffmpeg check
This commit is contained in:
parent
15e223a50e
commit
a2df82d70d
4 changed files with 24 additions and 1 deletions
2
index.js
2
index.js
|
@ -1,3 +1,5 @@
|
|||
process.env.YTDL_NO_UPDATE = true;
|
||||
|
||||
module.exports = {
|
||||
version: require('./package.json').version,
|
||||
Player: require('./src/Player')
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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) => {
|
||||
|
|
16
src/Util.js
16
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue