feat: subtitle: support ai segmentation

This commit is contained in:
Gabe
2025-10-09 23:55:06 +08:00
parent 2d0ea09e06
commit 9bafc937d5
12 changed files with 294 additions and 50 deletions

View File

@@ -298,11 +298,9 @@ export const parseJsonObj = (str) => {
* @returns
*/
export const extractJson = (raw) => {
if (!raw) return "{}";
let s = raw.replace(/^\s*```(?:json)?\s*/i, "").replace(/\s*```\s*$/i, "");
const match = s.match(/\{[\s\S]*\}/);
return match ? match[0] : "{}";
const jsonRegex = /({.*}|\[.*\])/s;
const match = raw.match(jsonRegex);
return match ? match[0] : null;
};
/**