diff --git a/src/commands/diskList.ts b/src/commands/diskList.ts index 6fd3f0f..fa4aec7 100644 --- a/src/commands/diskList.ts +++ b/src/commands/diskList.ts @@ -3,9 +3,23 @@ import { SlotId } from '../enums' import { NamedMessage, ResponseMessage } from '../message' import { AbstractCommand } from './abstractCommand' +const deserializeRegex = /(?.+) (?\w+) (?\w+) (?[\d:]+)$/i +const framerateRegex = /\d+[ip](?\d+)/i +const timecodeRegex = /(?\d+):(?\d+):(?\d+):(?\d+)/i + export interface Clip { + /** 1, 2, 3, etc */ clipId: string + /** ExampleVideo.mov, etc */ name: string + /** QuickTimeProRes, etc */ + codec: string + /** 1080i50, 720p60, etc */ + format: string + /** hh:mm:ss:ff */ + timecode: string + /** milliseconds */ + duration: number } export interface DiskListCommandResponse { @@ -25,14 +39,33 @@ export class DiskListCommand extends AbstractCommand { deserialize(msg: ResponseMessage): DiskListCommandResponse { const clipIds = Object.keys(msg.params).filter((x) => x !== 'slot id') - const clips = clipIds.map((x) => { - const clip: Clip = { - clipId: x, - name: msg.params[x], - } - - return clip - }) + const clips = clipIds + .map((x) => { + const match = msg.params[x].match(deserializeRegex) + const frameRateMatch = match?.groups?.format.match(framerateRegex) + const timecodeMatch = match?.groups?.timecode.match(timecodeRegex) + if (match?.groups && frameRateMatch?.groups && timecodeMatch?.groups) { + const frameRate = parseInt(frameRateMatch.groups.frameRate, 10) + const msPerFrame = 1000 / frameRate + const hoursMs = parseInt(timecodeMatch.groups.hours, 10) * 60 * 60 * 1000 + const minutesMs = parseInt(timecodeMatch.groups.minutes, 10) * 60 * 1000 + const secondsMs = parseInt(timecodeMatch.groups.seconds, 10) * 1000 + const framesMs = parseInt(timecodeMatch.groups.frames) * msPerFrame + const clip: Clip = { + clipId: x, + name: match.groups.fileName, + codec: match.groups.codec, + format: match.groups.format, + timecode: match.groups.timecode, + duration: hoursMs + minutesMs + secondsMs + framesMs, + } + + return clip + } + + return undefined + }) + .filter((clip): clip is Clip => Boolean(clip)) const res: DiskListCommandResponse = { slotId: parseInt(msg.params['slot id'], 10),