Allow some malformed WebVTT - thx manuelrn :)

Fix #5334
This commit is contained in:
niksedk 2021-09-11 00:55:00 +02:00
parent f37a701e6e
commit 78387fd5ed
4 changed files with 52 additions and 12 deletions

View File

@ -2484,6 +2484,9 @@ Continue?</RestoreDefaultSettingsMsg>
<MinFrameGap>Min. gap in frames</MinFrameGap>
<XFramesAtYFrameRateGivesZMs>{0} frames at a frame rate of {1} gives {2} milliseconds.</XFramesAtYFrameRateGivesZMs>
<UseXAsNewGap>Use "{0}" milliseconds as new minimum gap?</UseXAsNewGap>
<BDOpensIn>BD sup/bdn-xml opens in</BDOpensIn>
<BDOpensInOcr>OCR</BDOpensInOcr>
<BDOpensInEdit>Edit</BDOpensInEdit>
</Settings>
<SettingsMpv>
<DownloadMpv>Download mpv lib</DownloadMpv>

View File

@ -134,7 +134,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
positionInfo = Configuration.Settings.SubtitleSettings.WebVttCueAn2;
}
return (" " + positionInfo).TrimEnd();
return (" " + positionInfo).TrimEnd();
}
internal static string FormatText(Paragraph p)
@ -329,6 +329,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
paragraph.Text = ColorWebVttToHtml(paragraph.Text);
paragraph.Text = EscapeDecodeText(paragraph.Text);
paragraph.Text = RemoveWeirdReatingHeader(paragraph.Text);
paragraph.StartTime.TotalMilliseconds += addSeconds * 1000;
paragraph.EndTime.TotalMilliseconds += addSeconds * 1000;
}
@ -342,6 +343,33 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
}
private string RemoveWeirdReatingHeader(string input)
{
var text = input.Trim();
text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
if (text.Contains(Environment.NewLine + "WEBVTT"))
{
if (text.EndsWith('}') && text.Contains("STYLE"))
{
text = text.Remove(text.IndexOf(Environment.NewLine + "WEBVTT"));
}
}
else if (text.EndsWith(Environment.NewLine + "WEBVTT", StringComparison.Ordinal))
{
text = text.Remove(text.LastIndexOf(Environment.NewLine + "WEBVTT"));
}
else if (text.Contains(Environment.NewLine + "STYLE" + Environment.NewLine))
{
if (text.TrimEnd().EndsWith("}"))
{
text = text.Remove(text.IndexOf(Environment.NewLine + "STYLE" + Environment.NewLine));
}
}
return text;
}
private static double GetXTimeStampSeconds(string input)
{
if (!Configuration.Settings.SubtitleSettings.WebVttUseXTimestampMap)

View File

@ -538,16 +538,16 @@
<data name="toolStripButtonAssaDraw.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIvSURBVFhH1ZbPShtRFMYH6aaCXZR2E5NadSdu/AOi79DH
aDbFxqbNY7iQJGYSsnEhRG3c9CFcKFhwY11qLNguWuiqhDD9zsk98To5JnNnVOoPfszcmdz7fXMThniP
Dt/3g2q16qSZmpxarRbE4c5K0EJMdiG6IFEB2cZiscgyWtBtglgFek87CC0wLHAuYId7OO3TNzcJLdQW
OBWgX7mghlv20IJF4FSg0+nwJC1Qk7m60MNJELmAbD1tsRamuslT9HASuBcIhwyR0cJJELuA4JWur2ky
WjgJYhXYPuPT4Mu3dT6GQ20ZLZwEsQoQ/uHboHqU5fPzP/3BIqOFkyBygXq9zhMEChcJLXxim28NJHIB
otlsdidZ4VKACBcgGo0Gh9ymWXo4lUrlV3fJ/gJSIhxOYOd+myWSUS6XeUEtnBQKB+YE2E/4efp1cJlf
Y82l6NBCxNZxXg0XhVKpROEnZjpjF7j6lHcrYdZVQ223jj92Pxf6bvcRTgX2pibcd0GeXgvUJNrt9o0A
Cid30umnUqCVyxXM7cFIAVfMdG93Mr0hBWjcyr//GmsXXMT/w59mau/p96Yyp+aS51wgCfbTC60POfff
QhwknM2k/to+fIGQUuDeSmihtruTrx6mgBmqSIEfBccX0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xpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2
CAAAAk1TRnQBSQFMAgEBAgEAAcQBKwHEASsBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAAcwBKwHMASsBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

View File

@ -6820,6 +6820,15 @@ namespace Nikse.SubtitleEdit.Logic
case "Settings/UseXAsNewGap":
language.Settings.UseXAsNewGap = reader.Value;
break;
case "Settings/BDOpensIn":
language.Settings.BDOpensIn = reader.Value;
break;
case "Settings/BDOpensInOcr":
language.Settings.BDOpensInOcr = reader.Value;
break;
case "Settings/BDOpensInEdit":
language.Settings.BDOpensInEdit = reader.Value;
break;
case "SettingsMpv/DownloadMpv":
language.SettingsMpv.DownloadMpv = reader.Value;
break;