From 01de8a53adaf75c247823325f26d3afebeeb43b2 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Sun, 21 Aug 2022 15:52:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=89=B9=E6=AE=8Attml?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE.Parser/Mp4/MP4TtmlUtil.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/N_m3u8DL-RE.Parser/Mp4/MP4TtmlUtil.cs b/src/N_m3u8DL-RE.Parser/Mp4/MP4TtmlUtil.cs index 42c87e7..1696fcd 100644 --- a/src/N_m3u8DL-RE.Parser/Mp4/MP4TtmlUtil.cs +++ b/src/N_m3u8DL-RE.Parser/Mp4/MP4TtmlUtil.cs @@ -32,6 +32,8 @@ namespace Mp4SubtitleParser { [RegexGenerator("(.+?)<\\/p>")] private static partial Regex LabelFixRegex(); + [RegexGenerator("\\")] + private static partial Regex MultiElementsFixRegex(); public static bool CheckInit(byte[] data) { @@ -110,6 +112,12 @@ namespace Mp4SubtitleParser return sb.ToString(); } + public static List SplitMultipleRootElements(string xml) + { + if (!MultiElementsFixRegex().IsMatch(xml)) return new List(); + return MultiElementsFixRegex().Matches(xml).Select(m => m.Value).ToList(); + } + public static WebVttSub ExtractFromMp4s(IEnumerable items, long segTimeMs) { //read ttmls @@ -129,11 +137,19 @@ namespace Mp4SubtitleParser // mdats. if (segTimeMs != 0) { - xmls.Add(ShiftTime(Encoding.UTF8.GetString(data), segTimeMs, segIndex)); + var datas = SplitMultipleRootElements(Encoding.UTF8.GetString(data)); + foreach (var item in datas) + { + xmls.Add(ShiftTime(item, segTimeMs, segIndex)); + } } else { - xmls.Add(Encoding.UTF8.GetString(data)); + var datas = SplitMultipleRootElements(Encoding.UTF8.GetString(data)); + foreach (var item in datas) + { + xmls.Add(item); + } } })) .Parse(dataSeg,/* partialOkay= */ false);