Skip to content

Commit c9f29b3

Browse files
committed
fix #3
1 parent 0295fd1 commit c9f29b3

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

Mp4SubtitleParser/Mp4SubtitleParser.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
6-
<Version>1.5.0</Version>
6+
<Version>1.5.1</Version>
77
</PropertyGroup>
88

99
</Project>

Mp4SubtitleParser/TTMLAction.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,26 @@ public static void DoWork(IEnumerable<string> items, string outName, long segTim
149149
var finalSubs = new List<SubEntity>();
150150
XmlNode headNode = null;
151151
XmlNamespaceManager nsMgr = null;
152-
var regex = new Regex(">(.+?)<\\/p>");
152+
var regex = new Regex("<p.*?>(.+?)<\\/p>");
153153
foreach (var item in xmls)
154154
{
155155
var xmlContent = item;
156156
if (!xmlContent.Contains("<tt")) continue;
157157

158158
//fix non-standard xml
159159
var xmlContentFix = xmlContent;
160-
if(regex.IsMatch(xmlContent))
160+
if (regex.IsMatch(xmlContent))
161161
{
162162
foreach (Match m in regex.Matches(xmlContentFix))
163163
{
164-
if(!m.Groups[1].Value.StartsWith("<span"))
164+
try
165+
{
166+
new XmlDocument().LoadXml($"<p>{m.Groups[1].Value}</p>");
167+
}
168+
catch (Exception)
169+
{
165170
xmlContentFix = xmlContentFix.Replace(m.Groups[1].Value, System.Web.HttpUtility.HtmlEncode(m.Groups[1].Value));
171+
}
166172
}
167173
}
168174
xmlDoc.LoadXml(xmlContentFix);

0 commit comments

Comments
 (0)