(html: string)
| 228 | * Used by callers to validate declared durations against actual source durations. |
| 229 | */ |
| 230 | export 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. |
no test coverage detected