Minor subtitle formats refact

This commit is contained in:
Nikolaj Olsson 2016-06-07 06:31:03 +02:00
parent d1409ede4a
commit 988b14c075
40 changed files with 60 additions and 87 deletions

View File

@ -154,7 +154,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
int frames = MillisecondsToFrames(time.TotalMilliseconds);
int footage = frames / 16;
int rest = (int)((frames % 16) / 16.0 * 24.0);
int rest = (int)(frames % 16 / 16.0 * 24.0);
return string.Format("{0:00},{1:00}", footage, rest).PadLeft(8);
}

View File

@ -118,7 +118,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
catch
{
_errorCount = 1;
return;
}
}

View File

@ -90,8 +90,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
if (line.StartsWith('[') && RegexTimeCodes.Match(line).Success)
{
string s = line;
s = line.Substring(1, 8);
string s = line.Substring(1, 8);
string[] parts = s.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 3)
{

View File

@ -125,7 +125,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (text == "942c 942c" || text == "942c")
{
p.EndTime = new TimeCode(startTime.TotalMilliseconds);
if (p != null)
p.EndTime = new TimeCode(startTime.TotalMilliseconds);
}
else
{
@ -139,7 +140,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
p = subtitle.GetParagraphOrDefault(i);
Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
if (p != null && next != null && p.EndTime.TotalMilliseconds == p.StartTime.TotalMilliseconds)
if (p != null && next != null && Math.Abs(p.EndTime.TotalMilliseconds - p.StartTime.TotalMilliseconds) < 0.001)
p.EndTime = new TimeCode(next.StartTime.TotalMilliseconds);
if (next != null && string.IsNullOrEmpty(next.Text))
subtitle.Paragraphs.Remove(next);
@ -171,6 +172,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
catch
{
// ignored
}
}
string res = sb.ToString().Replace("<i></i>", string.Empty).Replace("</i><i>", string.Empty);

View File

@ -74,11 +74,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlStructure);
XmlNode div = xml.DocumentElement.SelectSingleNode("array");
int no = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
XmlNode paragraph = xml.CreateElement("dict");
string text = HtmlUtil.RemoveHtmlTags(p.Text);
XmlNode keyNode = xml.CreateElement("key");
keyNode.InnerText = "in";
@ -113,7 +111,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
paragraph.AppendChild(valueNode);
}
div.AppendChild(paragraph);
no++;
}
return ToUtf8XmlString(xml).Replace("<plist>", "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" + Environment.NewLine +

View File

@ -44,13 +44,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
sb.AppendLine(@"-------------------------------------------------
#INPOINT OUTPOINT PATH
-------------------------------------------------");
int index = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
//00:03:15:22 00:03:23:10 This is line one.
//This is line two.
sb.AppendLine(string.Format("{0} {1} {2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), HtmlUtil.RemoveHtmlTags(p.Text)));
index++;
}
sb.AppendLine(@"-------------------------------------------------");

View File

@ -102,7 +102,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
else if (string.IsNullOrWhiteSpace(line))
{
if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
if (Math.Abs(p.StartTime.TotalMilliseconds) < 0.001 && Math.Abs(p.EndTime.TotalMilliseconds) < 0.001)
_errorCount++;
else
subtitle.Paragraphs.Add(p);
@ -125,7 +125,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
bool allNullEndTime = true;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
if (subtitle.Paragraphs[i].EndTime.TotalMilliseconds != 0)
if (Math.Abs(subtitle.Paragraphs[i].EndTime.TotalMilliseconds) > 0.001)
allNullEndTime = false;
}
if (allNullEndTime)

View File

@ -36,15 +36,14 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override string ToText(Subtitle subtitle, string title)
{
const string Header = @"{QTtext} {font:Tahoma}
const string header = @"{QTtext} {font:Tahoma}
{plain} {size:20}
{timeScale:30}
{width:160} {height:32}
{timestamps:absolute} {language:0}";
var sb = new StringBuilder();
sb.AppendLine(Header);
int index = 0;
sb.AppendLine(header);
foreach (Paragraph p in subtitle.Paragraphs)
{
//[00:00:07.12]
@ -55,7 +54,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
//tout le temps,
//[00:00:35.08]
sb.AppendLine(string.Format("{0}{1}{2}", EncodeTimeCode(p.StartTime) + Environment.NewLine, HtmlUtil.RemoveHtmlTags(p.Text) + Environment.NewLine, EncodeTimeCode(p.EndTime) + Environment.NewLine));
index++;
}
return sb.ToString();
}

View File

@ -6,9 +6,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public class ScenaristClosedCaptionsDropFrame : ScenaristClosedCaptions
{
//00:01:00:29 9420 9420 94ae 94ae 94d0 94d0 4920 f761 7320 ... semi colon (instead of colon) before frame number is used to indicate drop frame
private const string _timeCodeRegEx = @"^\d+:\d\d:\d\d[;,]\d\d\t";
private static readonly Regex _regex = new Regex(_timeCodeRegEx, RegexOptions.Compiled);
protected override Regex RegexTimeCodes { get { return _regex; } }
private const string TimeCodeRegEx = @"^\d+:\d\d:\d\d[;,]\d\d\t";
private static readonly Regex Regex = new Regex(TimeCodeRegEx, RegexOptions.Compiled);
protected override Regex RegexTimeCodes { get { return Regex; } }
public ScenaristClosedCaptionsDropFrame()
{

View File

@ -48,7 +48,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
if (line.Contains(".png") && RegexTimeCodes.IsMatch(line))
{
int idx = line.IndexOf("<div");
int idx = line.IndexOf("<div", StringComparison.Ordinal);
if (idx > 0)
{
try
@ -59,9 +59,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var p = new Paragraph();
p.StartTime = DecodeTimeCode(arr[0]);
p.EndTime = DecodeTimeCode(arr[1]);
int start = line.IndexOf("<img src=") + 9;
int end = line.IndexOf(".png") + 4;
p.Text = line.Substring(start, end - start).Trim(new[] { '"', '\'' });
int start = line.IndexOf("<img src=", StringComparison.Ordinal) + 9;
int end = line.IndexOf(".png", StringComparison.Ordinal) + 4;
p.Text = line.Substring(start, end - start).Trim('"', '\'');
subtitle.Paragraphs.Add(p);
}

View File

@ -57,7 +57,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var lines = text.SplitToLines();
int count = 0;
lineSb.Clear();
string tempLine = string.Empty;
bool nextLineInItalics = false;
foreach (string line in lines)
{
@ -65,7 +64,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (count > 0)
lineSb.Append(Environment.NewLine);
tempLine = line;
var tempLine = line;
// This line should be in italics (it was detected in previous line)
if (nextLineInItalics)
@ -179,13 +178,12 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var subtitleLines = text.SplitToLines();
int count = 0;
lineSb.Clear();
string tempLine = string.Empty;
foreach (string subtitleLine in subtitleLines)
{
// Append line break in every line except the first one
if (count > 0)
lineSb.Append(Environment.NewLine);
tempLine = subtitleLine;
var tempLine = subtitleLine;
// Close italics in every line (if next line is in italics, SoftNI will use "[" at the beginning)
if (Utilities.CountTagInText(tempLine, "<i>") > Utilities.CountTagInText(tempLine, "</i>"))
tempLine = tempLine + "</i>";

View File

@ -58,7 +58,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var lines = text.SplitToLines();
int count = 0;
lineSb.Clear();
string tempLine = string.Empty;
bool nextLineInItalics = false;
foreach (string line in lines)
{
@ -66,7 +65,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (count > 0)
lineSb.Append(Environment.NewLine);
tempLine = line;
var tempLine = line;
// This line should be in italics (it was detected in previous line)
if (nextLineInItalics)
@ -180,13 +179,12 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var subtitleLines = text.SplitToLines();
int count = 0;
lineSb.Clear();
string tempLine = string.Empty;
foreach (string subtitleLine in subtitleLines)
{
// Append line break in every line except the first one
if (count > 0)
lineSb.Append(Environment.NewLine);
tempLine = subtitleLine;
var tempLine = subtitleLine;
// Close italics in every line (if next line is in italics, SoftNI will use "[" at the beginning)
if (Utilities.CountTagInText(tempLine, "<i>") > Utilities.CountTagInText(tempLine, "</i>"))
tempLine = tempLine + "</i>";

View File

@ -7,7 +7,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class SonyDVDArchitectExplicitDuration : SubtitleFormat
{
private static readonly Regex regex = new Regex(@"^\d\d:\d\d:\d\d\.\d\d\d[ \t]+\d\d:\d\d:\d\d\.\d\d\d[ \t]+\d\d:\d\d:\d\d\.\d\d\d[ \t]+", RegexOptions.Compiled);
private static readonly Regex Regex = new Regex(@"^\d\d:\d\d:\d\d\.\d\d\d[ \t]+\d\d:\d\d:\d\d\.\d\d\d[ \t]+\d\d:\d\d:\d\d\.\d\d\d[ \t]+", RegexOptions.Compiled);
public override string Extension
{
@ -67,7 +67,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (s.Length > 26 && s.IndexOf(':') == 2)
{
var match = regex.Match(s);
var match = Regex.Match(s);
if (match.Success)
{
isTimeCode = true;

View File

@ -38,7 +38,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override string ToText(Subtitle subtitle, string title)
{
const string Header = @"//Font select and font size
const string header = @"//Font select and font size
$FontName = Arial
$FontSize = 30
@ -76,7 +76,7 @@ $ColorIndex4 = 3
//Subtitles";
var sb = new StringBuilder();
sb.AppendLine(Header);
sb.AppendLine(header);
foreach (Paragraph p in subtitle.Paragraphs)
{
sb.AppendLine(string.Format("{0},{1},{2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), EncodeText(p.Text)));
@ -177,18 +177,18 @@ $ColorIndex4 = 3
return text;
}
private static string DecoderTextExtension(string text, string SpruceTag, string htmlOpenTag)
private static string DecoderTextExtension(string text, string spruceTag, string htmlOpenTag)
{
var htmlCloseTag = htmlOpenTag.Insert(1, "/");
var idx = text.IndexOf(SpruceTag, StringComparison.Ordinal);
var c = Utilities.CountTagInText(text, SpruceTag);
var idx = text.IndexOf(spruceTag, StringComparison.Ordinal);
var c = Utilities.CountTagInText(text, spruceTag);
if (c == 1)
{
var l = idx + SpruceTag.Length;
var l = idx + spruceTag.Length;
if (l < text.Length)
{
text = text.Replace(SpruceTag, htmlOpenTag) + htmlCloseTag;
text = text.Replace(spruceTag, htmlOpenTag) + htmlCloseTag;
}
else if (l == text.Length) // Brillstein^I
{
@ -201,9 +201,9 @@ $ColorIndex4 = 3
while (idx >= 0)
{
var htmlTag = isOpen ? htmlOpenTag : htmlCloseTag;
text = text.Remove(idx, SpruceTag.Length).Insert(idx, htmlTag);
text = text.Remove(idx, spruceTag.Length).Insert(idx, htmlTag);
isOpen = !isOpen;
idx = text.IndexOf(SpruceTag, idx + htmlTag.Length);
idx = text.IndexOf(spruceTag, idx + htmlTag.Length, StringComparison.Ordinal);
}
}
return text;

View File

@ -34,7 +34,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override string ToText(Subtitle subtitle, string title)
{
const string Header = @"$FontName = Arial
const string header = @"$FontName = Arial
$FontSize = 34
$HorzAlign = Left
$VertAlign = Bottom
@ -62,7 +62,7 @@ $TapeOffset = FALSE
\\Colour 7 = White
";
StringBuilder sb = new StringBuilder();
sb.AppendLine(Header);
sb.AppendLine(header);
foreach (Paragraph p in subtitle.Paragraphs)
{
sb.AppendLine(string.Format("$HorzAlign = Center\r\n{0}, {1}, {2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), EncodeText(p.Text)));

View File

@ -35,11 +35,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
fs.WriteByte(0x60);
// paragraphs
int number = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
WriteParagraph(p);
number++;
}
// footer

View File

@ -207,6 +207,7 @@ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
}
catch
{
// ignored
}
}

View File

@ -262,6 +262,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
catch
{
// ignored
}
}
}

View File

@ -24,7 +24,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
var subtitle = new Subtitle();
LoadSubtitle(subtitle, lines, fileName);
return subtitle.Paragraphs.Count > this._errorCount;
return subtitle.Paragraphs.Count > _errorCount;
}
public override string ToText(Subtitle subtitle, string title)

View File

@ -58,13 +58,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
ý
ý Kraj info blocka.");
sb.AppendLine();
int count = 0;
if (!subtitle.WasLoadedWithFrameNumbers)
subtitle.CalculateFrameNumbersFromTimeCodes(Configuration.Settings.General.CurrentFrameRate);
foreach (Paragraph p in subtitle.Paragraphs)
{
count++;
var text = HtmlUtil.RemoveOpenCloseTags(p.Text, HtmlUtil.TagFont);
sb.AppendLine(string.Format(paragraphWriteFormat, p.StartFrame, p.EndFrame, text));
}

View File

@ -230,7 +230,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
int length = buffer[i + 1];
p.StartTime = DecodeTimestamp(buffer, i + 3);
if (last != null && last.EndTime.TotalMilliseconds == 0)
if (last != null && Math.Abs(last.EndTime.TotalMilliseconds) < 0.001)
last.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds - 1;
if (length > 22)
@ -448,7 +448,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
if (last != null)
{
if (last.EndTime.TotalMilliseconds == 0)
if (Math.Abs(last.EndTime.TotalMilliseconds) < 0.001)
last.EndTime.TotalMilliseconds = last.StartTime.TotalMilliseconds + 2500;
if (last.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
last.EndTime.TotalMilliseconds = last.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(last.Text);

View File

@ -68,13 +68,13 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Paragraphs.Clear();
var sb = new StringBuilder();
char[] splitChars = { '', ' ' };
Match match = null;
foreach (string line in lines)
{
Match match;
if (line.Length > 11 && (match = RegexTimeCodes.Match(line)).Success)
{
if (p != null)
p.Text = (p.Text + Environment.NewLine + sb.ToString()).Trim();
p.Text = (p.Text + Environment.NewLine + sb).Trim();
var parts = line.Substring(0, match.Length).Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
try
{
@ -101,7 +101,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return;
}
if (p != null)
p.Text = (p.Text + Environment.NewLine + sb.ToString()).Trim();
p.Text = (p.Text + Environment.NewLine + sb).Trim();
subtitle.Renumber();
}

View File

@ -7,7 +7,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class UnknownSubtitle27 : SubtitleFormat
{
private static readonly Regex regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d: ", RegexOptions.Compiled);
private static readonly Regex RegexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d: ", RegexOptions.Compiled);
public override string Extension
{
@ -39,10 +39,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override string ToText(Subtitle subtitle, string title)
{
var sb = new StringBuilder();
int index = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
index++;
//00:18:02: (斉藤)失礼な大人って! (悠子)何言ってんのあんた?
string text = HtmlUtil.RemoveHtmlTags(p.Text);
text = text.Replace(Environment.NewLine, " ");
@ -70,7 +68,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
foreach (string line in lines)
{
string s = line.Trim();
if (regexTimeCodes.IsMatch(s))
if (RegexTimeCodes.IsMatch(s))
{
var temp = s.Substring(0, 8);

View File

@ -74,7 +74,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
_errorCount = 0;
int number = 1;
char[] splitChar = { ',' };
Match match = null;
foreach (string line in lines)
{
if (string.IsNullOrWhiteSpace(line) || string.IsNullOrWhiteSpace(line.Trim('-')))
@ -82,6 +81,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
continue;
}
Match match;
if (line.Length > 57 && (match = RegexTimeCodes.Match(line)).Success)
{
try

View File

@ -35,11 +35,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override string ToText(Subtitle subtitle, string title)
{
var sb = new StringBuilder();
int index = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
sb.AppendLine(string.Format("{0} {1}{2}{3}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), Environment.NewLine, HtmlUtil.RemoveHtmlTags(p.Text)));
index++;
}
return sb.ToString();
}

View File

@ -8,8 +8,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public class UnknownSubtitle46 : SubtitleFormat
{
//7:00:01:27AM
private static readonly Regex regexTimeCodesAM = new Regex(@"^\d\:\d\d\:\d\d\:\d\dAM", RegexOptions.Compiled);
private static readonly Regex regexTimeCodesPM = new Regex(@"^\d\:\d\d\:\d\d\:\d\dPM", RegexOptions.Compiled);
private static readonly Regex RegexTimeCodesAm = new Regex(@"^\d\:\d\d\:\d\d\:\d\dAM", RegexOptions.Compiled);
private static readonly Regex RegexTimeCodesPm = new Regex(@"^\d\:\d\d\:\d\d\:\d\dPM", RegexOptions.Compiled);
public override string Extension
{
@ -60,7 +60,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
string s = line.Trim();
string[] arr = line.Split();
var timeCode = arr[arr.Length - 1];
if (regexTimeCodesAM.Match(timeCode).Success || regexTimeCodesPM.Match(timeCode).Success)
if (RegexTimeCodesAm.Match(timeCode).Success || RegexTimeCodesPm.Match(timeCode).Success)
{
try
{

View File

@ -90,9 +90,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
ExpectingLine expecting = ExpectingLine.TimeCodes;
Paragraph p = new Paragraph();
expecting = ExpectingLine.TimeCodes;
var expecting = ExpectingLine.TimeCodes;
_errorCount = 0;
subtitle.Paragraphs.Clear();

View File

@ -102,7 +102,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
else if (string.IsNullOrWhiteSpace(line))
{
if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
if (Math.Abs(p.StartTime.TotalMilliseconds) < 0.001 && Math.Abs(p.EndTime.TotalMilliseconds) < 0.001)
_errorCount++;
else
subtitle.Paragraphs.Add(p);
@ -125,7 +125,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
bool allNullEndTime = true;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
if (subtitle.Paragraphs[i].EndTime.TotalMilliseconds != 0)
if (Math.Abs(subtitle.Paragraphs[i].EndTime.TotalMilliseconds) > 0.001)
allNullEndTime = false;
}
if (allNullEndTime)

View File

@ -104,7 +104,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
else if (string.IsNullOrWhiteSpace(line))
{
if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
if (Math.Abs(p.StartTime.TotalMilliseconds) < 0.001 && Math.Abs(p.EndTime.TotalMilliseconds) < 0.001)
_errorCount++;
else
subtitle.Paragraphs.Add(p);

View File

@ -41,13 +41,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
var sb = new StringBuilder();
const string format = "{0:0000}\t{1}\t{2}";
int count = 1;
foreach (Paragraph p in subtitle.Paragraphs)
{
sb.AppendLine(string.Format(format, 1, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime)));
sb.AppendLine(HtmlUtil.RemoveHtmlTags(p.Text));
sb.AppendLine();
count++;
}
return sb.ToString();
}

View File

@ -39,12 +39,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override string ToText(Subtitle subtitle, string title)
{
var sb = new StringBuilder();
int index = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
//00:00:54.08 00:00:58.06 - Saucers... - ... a dry lake bed. (newline is //)
sb.AppendLine(string.Format("{0} {1} {2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), HtmlUtil.RemoveHtmlTags(p.Text).Replace(Environment.NewLine, "//")));
index++;
}
return sb.ToString();
}

View File

@ -93,7 +93,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
else if (string.IsNullOrWhiteSpace(line))
{
if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
if (Math.Abs(p.StartTime.TotalMilliseconds) < 0.001 && Math.Abs(p.EndTime.TotalMilliseconds) < 0.001)
_errorCount++;
else
subtitle.Paragraphs.Add(p);

View File

@ -102,7 +102,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
else if (string.IsNullOrWhiteSpace(line))
{
if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
if (Math.Abs(p.StartTime.TotalMilliseconds) < 0.001 && Math.Abs(p.EndTime.TotalMilliseconds) < 0.001)
_errorCount++;
else
subtitle.Paragraphs.Add(p);

View File

@ -106,7 +106,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
else if (string.IsNullOrWhiteSpace(line))
{
if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
if (Math.Abs(p.StartTime.TotalMilliseconds) < 0.001 && Math.Abs(p.EndTime.TotalMilliseconds) < 0.001)
_errorCount++;
else
subtitle.Paragraphs.Add(p);

View File

@ -119,7 +119,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
try
{
TimeCode start = DecodeTimeCodeFrames(timeParts[0].Substring(0, 11), splitChars);
if (p != null && p.EndTime.TotalMilliseconds == 0)
if (p != null && Math.Abs(p.EndTime.TotalMilliseconds) < 0.001)
p.EndTime.TotalMilliseconds = start.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
TimeCode end = new TimeCode(0, 0, 0, 0);
p = MakeTextParagraph(text, p, start, end);
@ -136,7 +136,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
try
{
TimeCode start = DecodeTimeCodeFrames(timeParts[0].Substring(0, 11), splitChars);
if (p != null && p.EndTime.TotalMilliseconds == 0)
if (p != null && Math.Abs(p.EndTime.TotalMilliseconds) < 0.001)
p.EndTime.TotalMilliseconds = start.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
TimeCode end = DecodeTimeCodeFrames(timeParts[1].Substring(0, 11), splitChars);
p = MakeTextParagraph(text, p, start, end);

View File

@ -48,7 +48,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
var paragraph = new Paragraph();
_errorCount = 0;
subtitle.Paragraphs.Clear();
for (int i = 0; i < lines.Count; i++)
@ -60,7 +59,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (line.Contains(':') && !next.Contains(':') && RegexTimeCodes.IsMatch(line) && !RegexTimeCodes.IsMatch(next))
{
paragraph = new Paragraph();
var paragraph = new Paragraph();
if (TryReadTimeCodesLine(line, paragraph))
{
paragraph.Text = next;

View File

@ -46,7 +46,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var sb = new StringBuilder();
foreach (Paragraph p in subtitle.Paragraphs)
{
string text = p.Text;
sb.AppendLine(string.Format(paragraphWriteFormat, p.Text, Environment.NewLine, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime)));
}
return sb.ToString().Trim();

View File

@ -82,7 +82,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var endTime = time.Substring(8);
string[] startTimeParts = { starTime.Substring(0, 2), starTime.Substring(2, 2), starTime.Substring(4, 2), starTime.Substring(6, 2) };
string[] endTimeParts = { starTime.Substring(0, 2), starTime.Substring(2, 2), starTime.Substring(4, 2), starTime.Substring(6, 2) };
string[] endTimeParts = { endTime.Substring(0, 2), endTime.Substring(2, 2), endTime.Substring(4, 2), endTime.Substring(6, 2) };
p = new Paragraph(DecodeTimeCodeFramesFourParts(startTimeParts), DecodeTimeCodeFramesFourParts(endTimeParts), text);
subtitle.Paragraphs.Add(p);

View File

@ -89,7 +89,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
ReadLine(subtitle, line, next);
}
if (!string.IsNullOrWhiteSpace(_paragraph.Text))
if (_paragraph != null && !string.IsNullOrWhiteSpace(_paragraph.Text))
subtitle.Paragraphs.Add(_paragraph);
foreach (Paragraph p in subtitle.Paragraphs)

View File

@ -39,11 +39,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override string ToText(Subtitle subtitle, string title)
{
var sb = new StringBuilder();
int index = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
sb.AppendLine(string.Format("{0}" + Environment.NewLine + "{1}", EncodeTimeCode(p.StartTime), HtmlUtil.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, " "))));
index++;
}
return sb.ToString();
}