diff --git a/utils/hls/parseM3U8ForSubtitles.ts b/utils/hls/parseM3U8ForSubtitles.ts index f4d25458..e5d35fcf 100644 --- a/utils/hls/parseM3U8ForSubtitles.ts +++ b/utils/hls/parseM3U8ForSubtitles.ts @@ -44,12 +44,14 @@ export async function parseM3U8ForSubtitles( function parseAttributes(line: string): { [key: string]: string } { const attributes: { [key: string]: string } = {}; - const parts = line.split(","); - parts.forEach((part) => { - const [key, value] = part.split("="); - if (key && value) { - attributes[key.trim()] = value.replace(/"/g, "").trim(); - } - }); + const regex = /([A-Z-]+)=(?:"([^"]*)"|([^,]*))/g; + let match: RegExpExecArray | null; + + while ((match = regex.exec(line)) !== null) { + const key = match[1]; + const value = match[2] ?? match[3]; // quoted or unquoted + attributes[key] = value; + } + return attributes; }