Fixed and switched to ytdl-core-discord

- removed volume commands
- removed volume functions and properties from MusicPlayer
- fixed missing space on 'Next n Songs' on dashboard
- removed ytdl-core from package.json
pull/70/head
Trivernis 6 years ago
parent b8a0d124fe
commit d65616eadc

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- all hard coded sql statements to generic sql generation
- MusicPlayer to extend the default EventEmitter
- MessageHandler to accept instances of Response and redirect events to it
- switched to `ytdl-core-discord` for youtube audio playback
### Added
- Utility classes for generic SQL Statements
@ -33,6 +34,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ExtendedEventEmitter class in lib/utils/extended-events.js
- Response object that allows the registration of events for messages
### Removed
- `~volume` command because volume can't be controlled anymore
- volume functions and properties from the MusicPlayer
## [0.11.0-beta] - 2019-03-03
### Changed
- template Files to name `template.yaml`

@ -322,6 +322,7 @@ class MusicCommandModule extends cmdLib.CommandModule {
})
);
/* TODO: Delete completely on release
let volume = new cmdLib.Command(
this.template.volume,
new cmdLib.Answer(async (m, k) => {
@ -335,7 +336,7 @@ class MusicCommandModule extends cmdLib.CommandModule {
return this.template.volume.response.invalid;
}
})
);
);*/
let quality = new cmdLib.Command(
this.template.quality,
@ -369,7 +370,6 @@ class MusicCommandModule extends cmdLib.CommandModule {
.registerCommand(saveMedia)
.registerCommand(deleteMedia)
.registerCommand(savedMedia)
.registerCommand(volume)
.registerCommand(quality);
}
}

@ -156,7 +156,6 @@ class GuildHandler {
*/
async applySettings() {
this.settings = await this.db.getSettings();
this.musicPlayer.setVolume(Number(this.settings.musicPlayerVolume) || 0.5);
this.musicPlayer.quality = this.settings.musicPlayerQuality || 'lowest';
}

@ -1,4 +1,4 @@
const ytdl = require("ytdl-core"),
const ytdl = require("ytdl-core-discord"),
ypi = require('youtube-playlist-info'),
yttl = require('get-youtube-title'),
config = require('../../config.json'),
@ -11,7 +11,7 @@ const ytdl = require("ytdl-core"),
* The Music Player class is used to handle music playing tasks on Discord Servers (Guilds).
* @type {MusicPlayer}
*/
class MusicPlayer extends xevents.ExtendedEventEmitter{
class MusicPlayer extends xevents.ExtendedEventEmitter {
/**
* Constructor
* @param [voiceChannel] {Discord.VoiceChannel}
@ -24,13 +24,12 @@ class MusicPlayer extends xevents.ExtendedEventEmitter{
this.playing = false;
this.current = null;
this.repeat = false;
this.volume = 0.5;
this.voiceChannel = voiceChannel;
this.exitTimeout = null;
this._logger = new logging.Logger(this);
this._logger.silly('Initialized Music Player');
config.music? this.quality = config.music.quality || 'lowest' : this.quality = 'lowest';
config.music? this.liveBuffer = config.music.liveBuffer || 10000 : 10000;
config.music ? this.quality = config.music.quality || 'lowest' : this.quality = 'lowest';
config.music ? this.liveBuffer = config.music.liveBuffer || 10000 : 10000;
}
/**
@ -132,7 +131,7 @@ class MusicPlayer extends xevents.ExtendedEventEmitter{
* If the url is a playlist, the videos of the playlist are fetched and put
* in the queue. For each song the title is saved in the queue too.
* @param url {String}
* @param playnext {Boolean}
* @param [playnext] {Boolean}
*/
async playYouTube(url, playnext) {
let plist = utils.YouTube.getPlaylistIdFromUrl(url);
@ -143,7 +142,7 @@ class MusicPlayer extends xevents.ExtendedEventEmitter{
let firstSongTitle = null;
try {
firstSongTitle = await this.getVideoName(firstSong);
} catch(err) {
} catch (err) {
if (err.message !== 'Not found') {
this._logger.warn(err.message);
this._logger.debug(err.stack);
@ -172,32 +171,37 @@ class MusicPlayer extends xevents.ExtendedEventEmitter{
this.current = ({'url': url, 'title': await this.getVideoName(url)});
if (this.repeat)
this.queue.push(this.current);
let toggleNext = () => {
if (this.queue.length > 0) {
this.current = this.queue.shift();
this.emit('next', this.current);
this.playYouTube(this.current.url).catch((err) => this._logger.warn(err.message));
} else {
this.stop();
}
};
try {
this.disp = this.conn.playStream(ytdl(url,
{filter: 'audioonly', quality: this.quality, liveBuffer: this.liveBuffer}),
{volume: this.volume});
this.disp.on('error', (err) => {
this._logger.error(err.message);
this._logger.debug(err.stack);
});
this.disp = this.conn.playOpusStream(await ytdl(url,
{filter: 'audioonly', quality: this.quality, liveBuffer: this.liveBuffer}));
this.disp.on('error', (err) => {
this._logger.error(err.message);
this._logger.debug(err.stack);
});
this.disp.on('end', (reason) => { // end event triggers the next song to play when the reason is not stop
if (reason !== 'stop') {
this.playing = false;
this.current = null;
if (this.queue.length > 0) {
this.current = this.queue.shift();
if (this.repeat) // listen on repeat
this.queue.push(this.current);
this.emit('next', this.current);
this.playYouTube(this.current.url).catch((err) => this._logger.warn(err.message));
} else {
this.stop();
this.disp.on('end', (reason) => { // end event triggers the next song to play when the reason is not stop
if (reason !== 'stop') {
this.playing = false;
this.current = null;
toggleNext();
}
}
});
this.playing = true;
});
this.playing = true;
} catch (err) {
this._logger.verbose(err.message);
this._logger.silly(err.stack);
toggleNext();
}
} else {
this._logger.debug(`Added ${url} to the queue`);
if (playnext)
@ -226,17 +230,6 @@ 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
*/
@ -244,7 +237,7 @@ class MusicPlayer extends xevents.ExtendedEventEmitter{
this._logger.verbose("Pausing music...");
if (this.disp !== null)
this.disp.pause();
else
else
this._logger.warn("No dispatcher found");
}
@ -256,7 +249,7 @@ class MusicPlayer extends xevents.ExtendedEventEmitter{
this._logger.verbose("Resuming music...");
if (this.disp !== null)
this.disp.resume();
else
else
this._logger.warn("No dispatcher found");
}

@ -19,6 +19,7 @@
"express-session": "1.15.6",
"ffmpeg-binaries": "4.0.0",
"fs-extra": "7.0.1",
"get-youtube-title": "^1.0.0",
"graphql": "14.1.1",
"js-md5": "0.7.3",
"js-sha512": "0.8.0",
@ -33,8 +34,7 @@
"winston": "3.2.1",
"winston-daily-rotate-file": "3.8.0",
"youtube-playlist-info": "1.1.2",
"ytdl-core": "0.29.1",
"get-youtube-title": "latest"
"ytdl-core-discord": "^1.0.3"
},
"devDependencies": {
"assert": "1.4.1",

@ -71,7 +71,7 @@ head
span#mp-queueCount
| Songs in Queue
span.cell
| Next
| Next
span#mp-queueDisplayCount 0
| Songs:
#mp-songQueue

@ -2,8 +2,8 @@ $cPrimary: #fff
$cPrimaryVariant: #4c10a5
$cSecondary: #c889f5
$cSecondaryVariant: #740bce
$cBackground: #77f
$cBackgroundVariant: #55b
$cBackground: #1f1f2f
$cBackgroundVariant: #3f3f55
$cSurface: #fff
$cSurfaceVariant: #000
$cError: #f59289
@ -28,4 +28,4 @@ $cInfo: #890
$cWarn: #a60
$cError: #a00
$fNormal: Ubuntu, sans-serif
$fNormal: Ubuntu, sans-serif

Loading…
Cancel
Save