Skip to content

Commit

Permalink
自动去除VTT class
Browse files Browse the repository at this point in the history
例如:
```
<c.background-color_transparent.font-family_monospace.font-style_normal.font-weight_normal>[bell tolls]</c>
<c.background-color_transparent.font-family_monospace.font-style_normal.font-weight_normal><b>[bell tolls]</b></c>
<c.background-color_transparent.font-family_monospace.font-style_normal.font-weight_normal>Is it open now,
dough boy?</c>
```
  • Loading branch information
nilaoda committed Apr 6, 2023
1 parent 2ac1868 commit f2468d1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/N_m3u8DL-RE.Common/Entity/WebVttSub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public partial class WebVttSub
private static partial Regex TSValueRegex();
[GeneratedRegex("\\s")]
private static partial Regex SplitRegex();
[GeneratedRegex("<c\\..*?>([\\s\\S]*?)<\\/c>")]
private static partial Regex VttClassRegex();

public List<SubCue> Cues { get; set; } = new List<SubCue>();
public long MpegtsTimestamp { get; set; } = 0L;
Expand Down Expand Up @@ -88,7 +90,7 @@ public static WebVttSub Parse(string text, long BaseTimestamp = 0L)
{
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();
Expand Down Expand Up @@ -120,6 +122,15 @@ public static WebVttSub Parse(string text, long BaseTimestamp = 0L)
return webSub;
}

private static string RemoveClassTag(string text)
{
if (VttClassRegex().IsMatch(text))
{
return VttClassRegex().Match(text).Groups[1].Value;
}
else return text;
}

/// <summary>
/// 从另一个字幕中获取所有Cue,并加载此字幕中,且自动修正偏移
/// </summary>
Expand Down

0 comments on commit f2468d1

Please sign in to comment.