Show duration

This commit is contained in:
Wizzard 2024-08-17 20:55:49 -04:00
parent ecb5a75de1
commit b1bc4306eb
1 changed files with 35 additions and 8 deletions

View File

@ -3,7 +3,7 @@ const { v4: uuidv4 } = require('uuid');
const path = require('path');
const { EmbedBuilder } = require('discord.js');
const fs = require('fs');
const { exec, spawn } = require('child_process');
const { exec, spawn, execSync } = require('child_process');
module.exports = {
name: 'play',
@ -26,6 +26,19 @@ module.exports = {
let loadingMessage;
try {
const getDuration = (filePath) => {
try {
const output = execSync(`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${filePath}"`).toString().trim();
const durationSeconds = parseFloat(output);
const minutes = Math.floor(durationSeconds / 60);
const seconds = Math.floor(durationSeconds % 60);
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
} catch (error) {
console.error('Error getting track duration:', error);
return 'Unknown';
}
};
if (message.attachments.size > 0) {
const attachment = message.attachments.first();
const attachmentName = attachment.name.toLowerCase();
@ -43,10 +56,12 @@ module.exports = {
console.log(`Downloaded and saved: ${tempFilePath}`);
const duration = getDuration(tempFilePath);
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Added To Queue')
.setDescription(`**${title}**`)
.setDescription(`**${title}** (${duration})`)
.setFooter({ text: `Requested by ${message.author.username}`, iconURL: message.author.displayAvatarURL() })
.setTimestamp();
@ -81,10 +96,12 @@ module.exports = {
console.log(`Converted and saved: ${tempFilePath}`);
fs.unlinkSync(tempVideoPath);
const duration = getDuration(tempFilePath);
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Added To Queue')
.setDescription(`**${title}**`)
.setDescription(`**${title}** (${duration})`)
.setFooter({ text: `Requested by ${message.author.username}`, iconURL: message.author.displayAvatarURL() })
.setTimestamp();
@ -122,10 +139,12 @@ module.exports = {
console.log(`Downloaded and saved: ${tempFilePath}`);
const duration = getDuration(tempFilePath);
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Added To Queue')
.setDescription(`**${title}**`)
.setDescription(`**${title}** (${duration})`)
.setFooter({ text: `Requested by ${message.author.username}`, iconURL: message.author.displayAvatarURL() })
.setTimestamp();
@ -165,10 +184,12 @@ module.exports = {
console.log(`Converted and saved: ${tempFilePath}`);
fs.unlinkSync(tempVideoPath);
const duration = getDuration(tempFilePath);
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Added To Queue')
.setDescription(`**${title}**`)
.setDescription(`**${title}** (${duration})`)
.setFooter({ text: `Requested by ${message.author.username}`, iconURL: message.author.displayAvatarURL() })
.setTimestamp();
@ -188,10 +209,12 @@ module.exports = {
fs.writeFileSync(tempFilePath, buffer);
console.log(`Downloaded and saved: ${tempFilePath}`);
const duration = getDuration(tempFilePath);
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Added To Queue')
.setDescription(`**${title}**`)
.setDescription(`**${title}** (${duration})`)
.setFooter({ text: `Requested by ${message.author.username}`, iconURL: message.author.displayAvatarURL() })
.setTimestamp();
@ -233,6 +256,8 @@ module.exports = {
console.log(`Downloaded and saved: ${tempFilePath}`);
const duration = getDuration(tempFilePath);
if (loadingMessage) {
await loadingMessage.delete();
}
@ -240,7 +265,7 @@ module.exports = {
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Added To Queue')
.setDescription(`**${title}**`)
.setDescription(`**${title}** (${duration})`)
.setThumbnail(thumbnailUrl)
.setFooter({ text: `Requested by ${message.author.username}`, iconURL: message.author.displayAvatarURL() })
.setTimestamp();
@ -281,6 +306,8 @@ module.exports = {
console.log(`Downloaded and saved: ${tempFilePath}`);
const duration = getDuration(tempFilePath);
if (loadingMessage) {
await loadingMessage.delete();
}
@ -288,7 +315,7 @@ module.exports = {
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Added To Queue')
.setDescription(`**${title}**`)
.setDescription(`**${title}** (${duration})`)
.setThumbnail(thumbnailUrl)
.setFooter({ text: `Requested by ${message.author.username}`, iconURL: message.author.displayAvatarURL() })
.setTimestamp();