From 76e15b4b7642657ef79c05c2affe19e4bf60958f Mon Sep 17 00:00:00 2001 From: Zac Gaetano Date: Tue, 7 Apr 2026 21:58:20 -0400 Subject: [PATCH] add services/worker/src/edl/parser.js --- services/worker/src/edl/parser.js | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 services/worker/src/edl/parser.js diff --git a/services/worker/src/edl/parser.js b/services/worker/src/edl/parser.js new file mode 100644 index 0000000..3056e89 --- /dev/null +++ b/services/worker/src/edl/parser.js @@ -0,0 +1,71 @@ +/** + * Parse CMX3600 EDL format + * Standard edit line format: + * EDIT# REEL TRACK_TYPE TRANS_TYPE SOURCE_IN SOURCE_OUT RECORD_IN RECORD_OUT + * + * Example: + * 001 REEL001 V C 01:00:00:00 01:00:05:00 01:00:00:00 01:00:05:00 + */ +export const parseEDL = (edlContent) => { + const lines = edlContent + .split('\n') + .map(line => line.trim()) + .filter(line => line && !line.startsWith('TITLE:')); + + const edits = []; + + for (const line of lines) { + // Skip empty lines and non-edit lines + if (!line || line.startsWith('*') || line.startsWith('TITLE')) { + continue; + } + + const parts = line.split(/\s+/); + + if (parts.length < 8) { + continue; + } + + const edit = { + editNumber: parts[0], + reelName: parts[1], + trackType: parts[2], + transitionType: parts[3], + sourceIn: parts[4], + sourceOut: parts[5], + recordIn: parts[6], + recordOut: parts[7], + }; + + edits.push(edit); + } + + return edits; +}; + +/** + * Convert timecode string (HH:MM:SS:FF) to seconds + */ +export const timecodeToSeconds = (timecode) => { + const [hours, minutes, seconds, frames] = timecode + .split(':') + .map(Number); + + // Assuming 30fps (adjust if needed for 24fps or 25fps) + const fps = 30; + const frameSeconds = frames / fps; + + return hours * 3600 + minutes * 60 + seconds + frameSeconds; +}; + +/** + * Convert seconds to timecode string (HH:MM:SS:FF) + */ +export const secondsToTimecode = (totalSeconds, fps = 30) => { + const hours = Math.floor(totalSeconds / 3600); + const minutes = Math.floor((totalSeconds % 3600) / 60); + const seconds = Math.floor(totalSeconds % 60); + const frames = Math.round((totalSeconds % 1) * fps); + + return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}:${String(frames).padStart(2, '0')}`; +};