mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 23:47:33 +00:00
fix: parse scripted volume probes with html parser
This commit is contained in:
@@ -21,6 +21,10 @@ describe("hasScriptedAudioVolumeAutomation", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("parses script tags with whitespace before the closing bracket", () => {
|
||||
expect(hasScriptedAudioVolumeAutomation(`<script>audio.volume = 0.5;</script >`, 1)).toBe(true);
|
||||
});
|
||||
|
||||
it("requires audio metadata", () => {
|
||||
expect(
|
||||
hasScriptedAudioVolumeAutomation(`<script>gsap.to(audio, { volume: 1 });</script>`, 0),
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
import { join } from "node:path";
|
||||
import { parseHTML } from "linkedom";
|
||||
import {
|
||||
type CaptureOptions,
|
||||
type CaptureSession,
|
||||
@@ -91,8 +92,9 @@ export interface ProbeStageResult {
|
||||
export function hasScriptedAudioVolumeAutomation(html: string, audioCount: number): boolean {
|
||||
if (audioCount <= 0) return false;
|
||||
|
||||
const scriptBodies = [...html.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)]
|
||||
.map((match) => match[1] ?? "")
|
||||
const { document } = parseHTML(html);
|
||||
const scriptBodies = [...document.querySelectorAll("script")]
|
||||
.map((script) => script.textContent ?? "")
|
||||
.join("\n");
|
||||
if (!scriptBodies) return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user