|
|
@ -1,4 +1,4 @@
|
|
|
|
const ytdl = require("ytdl-core-discord"),
|
|
|
|
const ytdl = require("ytdl-core"),
|
|
|
|
ypi = require('youtube-playlist-info'),
|
|
|
|
ypi = require('youtube-playlist-info'),
|
|
|
|
yttl = require('get-youtube-title'),
|
|
|
|
yttl = require('get-youtube-title'),
|
|
|
|
config = require('../../config.json'),
|
|
|
|
config = require('../../config.json'),
|
|
|
@ -24,6 +24,7 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
|
|
|
|
this.playing = false;
|
|
|
|
this.playing = false;
|
|
|
|
this.current = null;
|
|
|
|
this.current = null;
|
|
|
|
this.repeat = false;
|
|
|
|
this.repeat = false;
|
|
|
|
|
|
|
|
this.volume = 0.5;
|
|
|
|
this.voiceChannel = voiceChannel;
|
|
|
|
this.voiceChannel = voiceChannel;
|
|
|
|
this.exitTimeout = null;
|
|
|
|
this.exitTimeout = null;
|
|
|
|
this._logger = new logging.Logger(this);
|
|
|
|
this._logger = new logging.Logger(this);
|
|
|
@ -178,6 +179,7 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
|
|
|
|
this.queue.push(this.current);
|
|
|
|
this.queue.push(this.current);
|
|
|
|
let toggleNext = () => {
|
|
|
|
let toggleNext = () => {
|
|
|
|
if (this.queue.length > 0) {
|
|
|
|
if (this.queue.length > 0) {
|
|
|
|
|
|
|
|
this.disp = null;
|
|
|
|
this.current = this.queue.shift();
|
|
|
|
this.current = this.queue.shift();
|
|
|
|
this.emit('next', this.current);
|
|
|
|
this.emit('next', this.current);
|
|
|
|
this.playYouTube(this.current.url).catch((err) => this._logger.warn(err.message));
|
|
|
|
this.playYouTube(this.current.url).catch((err) => this._logger.warn(err.message));
|
|
|
@ -188,8 +190,8 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.disp = this.conn.playOpusStream(await ytdl(url,
|
|
|
|
this.disp = this.conn.playStream(await ytdl(url,
|
|
|
|
{filter: 'audioonly', quality: this.quality, liveBuffer: this.liveBuffer}));
|
|
|
|
{filter: 'audioonly', quality: this.quality, liveBuffer: this.liveBuffer}, {volume: this.volume}));
|
|
|
|
this.disp.on('error', (err) => {
|
|
|
|
this.disp.on('error', (err) => {
|
|
|
|
this._logger.error(err.message);
|
|
|
|
this._logger.error(err.message);
|
|
|
|
this._logger.debug(err.stack);
|
|
|
|
this._logger.debug(err.stack);
|
|
|
@ -232,6 +234,17 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Sets the volume of the dispatcher to the given value
|
|
|
|
|
|
|
|
* @param percentage {Number}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
setVolume(percentage) {
|
|
|
|
|
|
|
|
this._logger.verbose(`Setting volume to ${percentage}`);
|
|
|
|
|
|
|
|
this.volume = percentage;
|
|
|
|
|
|
|
|
if (this.disp !== null)
|
|
|
|
|
|
|
|
this.disp.setVolume(percentage);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Pauses if a dispatcher exists
|
|
|
|
* Pauses if a dispatcher exists
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -295,7 +308,9 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
|
|
|
|
skip() {
|
|
|
|
skip() {
|
|
|
|
this._logger.debug("Skipping song");
|
|
|
|
this._logger.debug("Skipping song");
|
|
|
|
if (this.disp !== null) {
|
|
|
|
if (this.disp !== null) {
|
|
|
|
this.disp.end();
|
|
|
|
let disp = this.disp;
|
|
|
|
|
|
|
|
this.disp = null;
|
|
|
|
|
|
|
|
disp.end();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.playing = false;
|
|
|
|
this.playing = false;
|
|
|
|
if (this.queue.length > 0) {
|
|
|
|
if (this.queue.length > 0) {
|
|
|
|