mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
[refact] - more refact for sub formats
This commit is contained in:
parent
27e112ca5a
commit
1aadb82267
@ -136,17 +136,5 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
subtitle.Renumber();
|
||||
}
|
||||
|
||||
private static TimeCode DecodeTimeCode(string[] parts)
|
||||
{
|
||||
//00:00:07:12
|
||||
string hour = parts[0];
|
||||
string minutes = parts[1];
|
||||
string seconds = parts[2];
|
||||
string frames = parts[3];
|
||||
|
||||
TimeCode tc = new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), FramesToMillisecondsMax999(int.Parse(frames)));
|
||||
return tc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ ST 0 EB 3.10
|
||||
sb.AppendLine(line);
|
||||
|
||||
string rtf = sb.ToString().Trim();
|
||||
if (!rtf.StartsWith("{\\rtf"))
|
||||
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
|
||||
return;
|
||||
|
||||
string[] arr = rtf.FromRtf().SplitToLines();
|
||||
@ -93,7 +93,7 @@ ST 0 EB 3.10
|
||||
string[] endParts = end.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 2 && endParts.Length == 2)
|
||||
{
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty); //00119.12
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
}
|
||||
@ -115,14 +115,5 @@ ST 0 EB 3.10
|
||||
subtitle.Renumber();
|
||||
}
|
||||
|
||||
private static TimeCode DecodeTimeCode(string[] parts)
|
||||
{
|
||||
//00119.12
|
||||
string seconds = parts[0];
|
||||
string frames = parts[1];
|
||||
TimeCode tc = new TimeCode(0, 0, int.Parse(seconds), FramesToMillisecondsMax999(int.Parse(frames)));
|
||||
return tc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -67,12 +67,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
arr = timeCode.Substring(0, 10).Split(':');
|
||||
if (arr.Length == 4)
|
||||
{
|
||||
int hours = int.Parse(arr[0]);
|
||||
int minutes = int.Parse(arr[1]);
|
||||
int seconds = int.Parse(arr[2]);
|
||||
int frames = int.Parse(arr[3]);
|
||||
p = new Paragraph();
|
||||
p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
|
||||
p.StartTime = DecodeTimeCode(arr);
|
||||
p.Text = s.Substring(0, s.IndexOf(timeCode, StringComparison.Ordinal)).Trim();
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
|
@ -60,12 +60,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
var arr = s.Substring(0, 10).Split(':');
|
||||
if (arr.Length == 4)
|
||||
{
|
||||
int hours = int.Parse(arr[0]);
|
||||
int minutes = int.Parse(arr[1]);
|
||||
int seconds = int.Parse(arr[2]);
|
||||
int frames = int.Parse(arr[3]);
|
||||
var p = new Paragraph();
|
||||
p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
|
||||
p.StartTime = DecodeTimeCode(arr);
|
||||
p.Text = s.Remove(0, 10).Trim();
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
XmlNode paragraph = xml.CreateElement("text");
|
||||
|
||||
XmlAttribute start = xml.CreateAttribute("start");
|
||||
start.InnerText = string.Format("{0}", p.StartTime.TotalMilliseconds / 1000).Replace(",", ".");
|
||||
start.InnerText = string.Format("{0}", p.StartTime.TotalMilliseconds / 1000).Replace(',', '.');
|
||||
paragraph.Attributes.Append(start);
|
||||
|
||||
XmlAttribute duration = xml.CreateAttribute("dur");
|
||||
duration.InnerText = string.Format("{0}", p.Duration.TotalMilliseconds / 1000).Replace(",", ".");
|
||||
duration.InnerText = string.Format("{0}", p.Duration.TotalMilliseconds / 1000).Replace(',', '.');
|
||||
paragraph.Attributes.Append(duration);
|
||||
|
||||
paragraph.InnerText = p.Text;
|
||||
@ -87,10 +87,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
string start = node.Attributes["start"].InnerText;
|
||||
if (!string.IsNullOrEmpty(start))
|
||||
start = start.Replace(",", ".");
|
||||
start = start.Replace(',', '.');
|
||||
string end = node.Attributes["dur"].InnerText;
|
||||
if (!string.IsNullOrEmpty(end))
|
||||
end = end.Replace(",", ".");
|
||||
end = end.Replace(',', '.');
|
||||
string text = node.InnerText;
|
||||
|
||||
subtitle.Paragraphs.Add(new Paragraph(text, Convert.ToDouble(start, System.Globalization.CultureInfo.InvariantCulture) * TimeCode.BaseUnit, TimeCode.BaseUnit * (Convert.ToDouble(start, System.Globalization.CultureInfo.InvariantCulture) + Convert.ToDouble(end, System.Globalization.CultureInfo.InvariantCulture))));
|
||||
|
@ -139,7 +139,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else
|
||||
{
|
||||
if (line.StartsWith("||"))
|
||||
if (line.StartsWith("||", StringComparison.Ordinal))
|
||||
line = "<i>" + line.Replace("||", string.Empty) + "</i>";
|
||||
p.Text = (p.Text + Environment.NewLine + line).Trim();
|
||||
expecting = ExpectingLine.TimeCodes;
|
||||
|
@ -75,7 +75,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
}
|
||||
else if (line.StartsWith("//"))
|
||||
else if (line.StartsWith("//", StringComparison.Ordinal))
|
||||
{
|
||||
// comment
|
||||
}
|
||||
|
@ -71,12 +71,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string[] arr = s.Substring(0, 11).Split(':');
|
||||
if (arr.Length == 4)
|
||||
{
|
||||
int hours = int.Parse(arr[0]);
|
||||
int minutes = int.Parse(arr[1]);
|
||||
int seconds = int.Parse(arr[2]);
|
||||
int frames = int.Parse(arr[3]);
|
||||
p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
|
||||
string text = s.Remove(0, 11).Trim();
|
||||
p.StartTime = DecodeTimeCode(arr);
|
||||
string text = s.Substring(11).Trim();
|
||||
p.Text = text;
|
||||
if (text.Length > 1 && Utilities.IsInteger(text.Substring(0, 2)))
|
||||
_errorCount++;
|
||||
|
@ -63,6 +63,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
bool expectStartTime = true;
|
||||
var p = new Paragraph();
|
||||
subtitle.Paragraphs.Clear();
|
||||
char[] splitChars = { '.', ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string s = line.Trim();
|
||||
@ -79,8 +80,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
subtitle.Paragraphs.Add(p);
|
||||
p = new Paragraph();
|
||||
}
|
||||
p.StartTime = DecodeTimeCode(parts[1]);
|
||||
p.EndTime = DecodeTimeCode(parts[2]);
|
||||
p.StartTime = DecodeTimeCode(parts[1], splitChars);
|
||||
p.EndTime = DecodeTimeCode(parts[2], splitChars);
|
||||
expectStartTime = false;
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -120,18 +121,5 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
subtitle.Renumber();
|
||||
}
|
||||
|
||||
private static TimeCode DecodeTimeCode(string part)
|
||||
{
|
||||
string[] parts = part.Split(new[] { '.', ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
//00:00:07:12
|
||||
string hour = parts[0];
|
||||
string minutes = parts[1];
|
||||
string seconds = parts[2];
|
||||
string frames = parts[3];
|
||||
|
||||
return new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), FramesToMillisecondsMax999(int.Parse(frames)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -61,22 +61,19 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
_errorCount = 0;
|
||||
Paragraph p = null;
|
||||
subtitle.Paragraphs.Clear();
|
||||
char[] splitChars = { ':', '.' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (RegexTimeCodes.IsMatch(line))
|
||||
var match = RegexTimeCodes.Match(line);
|
||||
if (match.Success)
|
||||
{
|
||||
string temp = line.Substring(0, RegexTimeCodes.Match(line).Length);
|
||||
string start = temp.Substring(0, 11);
|
||||
string end = temp.Substring(12, 11);
|
||||
|
||||
string[] startParts = start.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4 && line.Length >= 23)
|
||||
string temp = line.Substring(0, match.Length);
|
||||
if (line.Length >= 23)
|
||||
{
|
||||
string text = line.Remove(0, 23).Trim();
|
||||
if (!text.Contains(Environment.NewLine))
|
||||
text = text.Replace("//", Environment.NewLine);
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text);
|
||||
p = new Paragraph(DecodeTimeCode(temp.Substring(0, 11), splitChars), DecodeTimeCode(temp.Substring(12, 11), splitChars), text);
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
sb.AppendLine(line);
|
||||
|
||||
string rtf = sb.ToString().Trim();
|
||||
if (!rtf.StartsWith("{\\rtf"))
|
||||
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
|
||||
return;
|
||||
|
||||
string[] arr = rtf.FromRtf().SplitToLines();
|
||||
|
Loading…
Reference in New Issue
Block a user