Try to fix incorecct time remaining
This commit is contained in:
parent
0641ccfb0d
commit
2660275306
|
@ -1,11 +1,12 @@
|
||||||
const { getCurrentTrack, getPlayer } = require('../utils/queueManager');
|
const { getCurrentTrack, getPlayer } = require('../utils/queueManager');
|
||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'np',
|
name: 'np',
|
||||||
description: 'Show the currently playing track and time left',
|
description: 'Show the currently playing track and time left',
|
||||||
execute(message) {
|
async execute(message) {
|
||||||
const currentTrack = getCurrentTrack(message.guild.id);
|
const currentTrack = getCurrentTrack(message.guild.id);
|
||||||
|
|
||||||
if (!currentTrack) {
|
if (!currentTrack) {
|
||||||
|
@ -18,7 +19,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentTime = player.state?.resource?.playbackDuration || 0;
|
const currentTime = player.state?.resource?.playbackDuration || 0;
|
||||||
const totalDuration = getTrackDuration(currentTrack.filePath);
|
const totalDuration = await getTrackDuration(currentTrack.filePath);
|
||||||
const timeLeft = msToTime(totalDuration - currentTime);
|
const timeLeft = msToTime(totalDuration - currentTime);
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
|
@ -47,7 +48,12 @@ function msToTime(duration) {
|
||||||
return hours + ":" + minutes + ":" + seconds;
|
return hours + ":" + minutes + ":" + seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTrackDuration(filePath) {
|
async function getTrackDuration(filePath) {
|
||||||
const stats = fs.statSync(filePath);
|
try {
|
||||||
return stats.size / 32000 * 1000;
|
const output = execSync(`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${filePath}"`).toString().trim();
|
||||||
|
return parseFloat(output) * 1000;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error getting track duration:', error);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue