Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
ajout du temps des vidéos et compatibilité sur Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaruike committed Oct 28, 2017
1 parent 10b372f commit 9c47a5d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
37 changes: 25 additions & 12 deletions music.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const config = require('./config.json');
const tool = require('./tool.js');
const ytdl = require('ytdl-core');

const ySearch = require("youtube-search");
const Song = require('./obj/Song.js');
const MusicPlayer = require('./obj/MusicPlayer.js');

Expand Down Expand Up @@ -76,20 +76,31 @@ function processInput(msg, guild) {
}

function processSearch(msg, guild, searchQuery) {
searchQuery = 'ytsearch1:' + searchQuery;
youtubeDL.getInfo(searchQuery, ['--extract-audio'], (err, song) => {
const opts = {
maxResults: 3,
key: config.youtube_api_key
};
ySearch(searchQuery, opts, function (err, results) {
if (err) {
msg.channel.send(`Sorry, I couldn't find matching song.`);
msg.channel.send(`Désolé, je ne trouve pas ta musique.`);
return console.log(err);
}
guild.queueSong(new Song(song.title, song.url, 'search'));

msg.channel.send(
`Enqueued ${tool.wrap(song.title.trim())} requested by ${tool.wrap(msg.author.username + '#' + msg.author.discriminator)} ${tool.inaHappy}`
for (var y = 0; results[y].kind === 'youtube#channel'; y++);
ytdl.getInfo(results[y].link, function (err, song) {
if (err) {
msg.channel.send(`Désolé, je ne trouve pas ta musique.`);
return console.log(err);
}
const author = msg.author.username + '#' + msg.author.discriminator;
guild.queueSong(new Song(song.title, song.video_url, 'youtube', author, song.length_seconds));
msg.channel.send(
`Enqueued ${tool.wrap(song.title.trim())} (\`${song.length_seconds}\`) requested by ${tool.wrap(author)}`
);

if (guild.status != 'playing')
guild.playSong(msg, guild);

});
});
}

Expand All @@ -101,17 +112,18 @@ const processYoutube = {
Processes a Youtube song, pushing it to the queue.
@param {String} url The URL of the new song.
*/
song(msg, guild, url) {
song(msg, guild, url, time) {
ytdl.getInfo(url, (err, song) => {
if (err) {
console.log(err);
msg.channel.send(`Sorry I couldn't queue your song.`);
return;
}

guild.queueSong(new Song(song.title, url, 'youtube'));
console.log(guild.queueSong(new Song(song.title, url, 'youtube', '0:00')));
guild.queueSong(new Song(song.title, url, 'youtube', '0:00'));
msg.channel.send(
`Enqueued ${tool.wrap(song.title.trim())} requested by ${tool.wrap(msg.author.username + '#' + msg.author.discriminator)} ${tool.inaHappy}`
`Enqueued ${tool.wrap(song.title.trim())} requested by ${tool.wrap(msg.author.username + '#' + msg.author.discriminator)}`
);
if (guild.status != 'playing') {
guild.playSong(msg);
Expand Down Expand Up @@ -180,7 +192,7 @@ const processYoutube = {
}

msg.channel.send(
`Enqueued ${tool.wrap(playlistItems.length)} songs from ${tool.wrap(playlistTitle)} requested by ${tool.wrap(msg.author.username + '#' + msg.author.discriminator)} ${tool.inaHappy}`
`Enqueued ${tool.wrap(playlistItems.length)} songs from ${tool.wrap(playlistTitle)} requested by ${tool.wrap(msg.author.username + '#' + msg.author.discriminator)}`
);

if (guild.status != 'playing') {
Expand Down Expand Up @@ -211,3 +223,4 @@ function timer() {
setInterval(timer, 10000);



6 changes: 3 additions & 3 deletions obj/MusicPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class MusicPlayer {
resolveVoiceChannel.call(this).then(() => {
let song = this.queue[0];
let stream = song.getStream();

this.musicChannel.send(`:notes: Now playing ${tool.wrap(song.title)}`);
this.musicChannel.send(`:notes: Now playing ${tool.wrap(song.title)} (\`${song.time}\`) requested by ${tool.wrap(song.author)}`);
this.changeStatus('playing');
this.dispatch = this.voiceConnection.playStream(stream, {
passes: 2,
Expand Down Expand Up @@ -134,7 +133,7 @@ class MusicPlayer {
try {
let queueString = '';
for (let i = 0; i < this.queue.length && i < 15; i++)
queueString += `${i + 1}. ${this.queue[i].title}\n`;
queueString += `${i + 1}. ${this.queue[i].title} (\`${this.queue[i].time}\`) requested by ${this.queue[i].author}\n`;
if (this.queue.length > 15)
queueString += `\nand ${this.queue.length - 15} more.`;
msg.channel.send(queueString, {
Expand Down Expand Up @@ -241,3 +240,4 @@ class MusicPlayer {

module.exports = MusicPlayer;


4 changes: 3 additions & 1 deletion obj/Song.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const ytdl = require('ytdl-core');
An object representing a song.
*/
class Song {
constructor(title, url, type) {
constructor(title, url, type, authorname, time) {
this.title = title;
this.url = url;
this.type = type; //youtube, soundcloud, search
this.author = authorname;
this.time = time;
}

getStream() {
Expand Down

0 comments on commit 9c47a5d

Please sign in to comment.