MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / extractResolvedMedia

Function extractResolvedMedia

packages/core/src/compiler/timingCompiler.ts:230–260  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

228 * Used by callers to validate declared durations against actual source durations.
229 */
230export function extractResolvedMedia(html: string): ResolvedMediaElement[] {
231 const resolved: ResolvedMediaElement[] = [];
232
233 const mediaRegex = /<(?:video|audio)[^>]*>/gi;
234 let match: RegExpExecArray | null;
235 while ((match = mediaRegex.exec(html)) !== null) {
236 const tag = match[0];
237 const id = getAttr(tag, "id");
238 const durationStr = getAttr(tag, "data-duration");
239 if (!id || durationStr === null) continue;
240
241 const duration = parseFloat(durationStr);
242 if (!Number.isFinite(duration) || duration <= 0) continue;
243
244 const isVideo = /^<video/i.test(tag);
245 const startStr = getAttr(tag, "data-start");
246 const mediaStartStr = getAttr(tag, "data-media-start");
247
248 resolved.push({
249 id,
250 tagName: isVideo ? "video" : "audio",
251 src: getAttr(tag, "src") ?? undefined,
252 start: startStr !== null ? parseFloat(startStr) : 0,
253 duration,
254 mediaStart: mediaStartStr ? parseFloat(mediaStartStr) : 0,
255 loop: hasAttr(tag, "loop"),
256 });
257 }
258
259 return resolved;
260}
261
262/**
263 * Clamp existing data-duration and data-end on media elements.

Callers 3

compileHtmlFileFunction · 0.90
compileHtmlFunction · 0.90

Calls 2

getAttrFunction · 0.85
hasAttrFunction · 0.85

Tested by

no test coverage detected