From 2846e13a815547762719bc8139300e6a81152aec Mon Sep 17 00:00:00 2001 From: knight Date: Wed, 5 Nov 2025 01:16:26 -0500 Subject: [PATCH] Fix timestamp parsing for string format timestamps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both primary and secondary transcripts use 'timestamp' field with string format "HH:MM:SS.mmm" instead of numeric seconds. Changes: - Add parseTimestampToSeconds() to handle string timestamps - Parse "HH:MM:SS.mmm" format (e.g., "00:00:39.480") - Also handle "MM:SS" format - Still support numeric timestamps (seconds or milliseconds) - Check 'timestamp' field first (primary format in data) This fixes the NaN issue and displays correct timestamps for both primary and secondary transcripts. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- static/app.js | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/static/app.js b/static/app.js index e362b98..9c564f3 100644 --- a/static/app.js +++ b/static/app.js @@ -353,35 +353,56 @@ return url.toString(); } + function parseTimestampToSeconds(timestamp) { + // Handle string timestamps like "00:00:39.480" or "HH:MM:SS.mmm" + if (typeof timestamp === 'string' && timestamp.includes(':')) { + const parts = timestamp.split(':'); + if (parts.length === 3) { + const hours = parseFloat(parts[0]) || 0; + const minutes = parseFloat(parts[1]) || 0; + const seconds = parseFloat(parts[2]) || 0; + return hours * 3600 + minutes * 60 + seconds; + } else if (parts.length === 2) { + const minutes = parseFloat(parts[0]) || 0; + const seconds = parseFloat(parts[1]) || 0; + return minutes * 60 + seconds; + } + } + // Handle numeric timestamps + const num = parseFloat(timestamp); + if (!isNaN(num)) { + // If timestamp is in milliseconds (> 10000 for timestamps after ~2.7 hours), convert to seconds + return num > 10000 ? num / 1000 : num; + } + return 0; + } + function renderTranscriptSegment(segment, videoUrl) { const segmentDiv = document.createElement('div'); segmentDiv.className = 'transcript-segment'; segmentDiv.dataset.text = (segment.text || '').toLowerCase(); - // Handle multiple possible timestamp field names and formats - // Try each field and ensure it's a valid number + // Try different timestamp field names let startSeconds = 0; const possibleFields = [ + segment.timestamp, // Primary field (string format "HH:MM:SS.mmm") segment.start_seconds, segment.start, segment.offset, segment.time, - segment.timestamp, segment.startTime ]; for (const field of possibleFields) { - if (field != null && !isNaN(parseFloat(field))) { - startSeconds = parseFloat(field); - break; + if (field != null) { + const parsed = parseTimestampToSeconds(field); + if (parsed > 0 || (parsed === 0 && field !== undefined)) { + startSeconds = parsed; + break; + } } } - // If timestamp is in milliseconds (> 10000 for timestamps after ~2.7 hours), convert to seconds - if (startSeconds > 10000) { - startSeconds = startSeconds / 1000; - } - const timestampText = formatTimestamp(startSeconds); const timestampUrl = getYouTubeTimestampUrl(videoUrl, startSeconds);