diff --git a/server.js b/server.js index d1a11f7..7794805 100644 --- a/server.js +++ b/server.js @@ -120,6 +120,29 @@ const probeFile = (filePath) => { }); }; +const parseTimemarkToSeconds = (timemark) => { + if (typeof timemark !== 'string' || !timemark.trim()) { + return 0; + } + + const parts = timemark.trim().split(':'); + if (parts.length !== 3) { + const numericValue = parseFloat(timemark); + return Number.isFinite(numericValue) ? numericValue : 0; + } + + const [hoursPart, minutesPart, secondsPart] = parts; + const hours = parseInt(hoursPart, 10); + const minutes = parseInt(minutesPart, 10); + const seconds = parseFloat(secondsPart); + + if (![hours, minutes, seconds].every(Number.isFinite)) { + return 0; + } + + return (hours * 3600) + (minutes * 60) + seconds; +}; + const stopActiveTranscode = (progressKey) => { const activeCommand = transcodeProcesses.get(progressKey); if (!activeCommand) { @@ -448,7 +471,7 @@ app.get('/api/stream', async (req, res) => { ffmpegCommand .on('progress', (progress) => { const effectiveDuration = Math.max(0, (progressMap[progressKey]?.duration || 0) - startSeconds); - const timemarkSeconds = ffmpeg.timemarkToSeconds(progress.timemark || '0'); + const timemarkSeconds = parseTimemarkToSeconds(progress.timemark || '0'); const absoluteSeconds = startSeconds + (isFinite(timemarkSeconds) ? timemarkSeconds : 0); const percent = effectiveDuration > 0 ? Math.min(Math.max(Math.round((absoluteSeconds / (progressMap[progressKey]?.duration || effectiveDuration)) * 100), 0), 100)