From f2468d16d71b9e535e9489d32bf8233fe1fe96e4 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Thu, 6 Apr 2023 15:40:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8E=BB=E9=99=A4VTT=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 例如: ``` [bell tolls] [bell tolls] Is it open now, dough boy? ``` --- src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs b/src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs index 9bcbfe9..3bff876 100644 --- a/src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs +++ b/src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs @@ -15,6 +15,8 @@ namespace N_m3u8DL_RE.Common.Entity private static partial Regex TSValueRegex(); [GeneratedRegex("\\s")] private static partial Regex SplitRegex(); + [GeneratedRegex("([\\s\\S]*?)<\\/c>")] + private static partial Regex VttClassRegex(); public List Cues { get; set; } = new List(); public long MpegtsTimestamp { get; set; } = 0L; @@ -88,7 +90,7 @@ namespace N_m3u8DL_RE.Common.Entity { StartTime = startTime, EndTime = endTime, - Payload = string.Join("", payload.Where(c => c != 8203)), //Remove Zero Width Space! + Payload = RemoveClassTag(string.Join("", payload.Where(c => c != 8203))), //Remove Zero Width Space! Settings = style }); payloads.Clear(); @@ -120,6 +122,15 @@ namespace N_m3u8DL_RE.Common.Entity return webSub; } + private static string RemoveClassTag(string text) + { + if (VttClassRegex().IsMatch(text)) + { + return VttClassRegex().Match(text).Groups[1].Value; + } + else return text; + } + /// /// 从另一个字幕中获取所有Cue,并加载此字幕中,且自动修正偏移 ///