From ea1c62b5b6cedacf618a75319ee81d4f32ab713d Mon Sep 17 00:00:00 2001 From: moosecrab Date: Thu, 9 Jun 2022 16:42:35 -0700 Subject: [PATCH] Added support for seeking when playing youtube videos. --- bot.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bot.js b/bot.js index 7eb8845..f62a04c 100644 --- a/bot.js +++ b/bot.js @@ -7,6 +7,8 @@ const fs = require('fs'); const ytdl = require('ytdl-core-discord'); // Include our local auth key, so that we don't leak keys const auth = require('./auth.json'); +// Volume for playback (fraction) +var volume = 0.6; // **** PROGRAM START **** // This program is 2 lines of code, the rest is callback function definition, wherein the bot magic happens @@ -151,7 +153,7 @@ client.on('message', async message => { const ytmatch = message.content.match(/(?<=!play (https?:\/\/)(www\.)?youtu((be\.com\/watch\?v=)|(\.be\/)))[\w-]{11}/); if (ytmatch && message.member.voice.channel) { const timematch = message.content.match(/t=(\d{1,2}h)?(\d{1,2}m)?\d{1,4}s?(?=$)/); - var timestamp = ''; + var timestamp = '0'; if (timematch) { timestamp = timematch[0]; } @@ -163,7 +165,7 @@ client.on('message', async message => { // Play the video as requested try { //TODO: process the timestamp with ffmpeg or whatever - const dispatcher = connection.play(await ytdl(yturl), { type: 'opus', volume: 0.60 }); + const dispatcher = connection.play(await ytdl(yturl), { type: 'opus', volume: 0.60, begin: timestamp}); dispatcher.on('start', () => { console.log(`Playing ${yturl}`); }); dispatcher.on('finish', () => { console.log(`Finished ${yturl}`); }); dispatcher.on('error', console.error);