mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 06:52:35 +01:00
[Subviewer2.0] - Several fixes/Updates.
This commit is contained in:
parent
c86aa86419
commit
fc719ca5ab
@ -13,6 +13,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
Text
|
Text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly Regex RegexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d.\d+,\d\d:\d\d:\d\d.\d+$", RegexOptions.Compiled);
|
||||||
|
|
||||||
public override string Extension
|
public override string Extension
|
||||||
{
|
{
|
||||||
get { return ".sub"; }
|
get { return ".sub"; }
|
||||||
@ -31,7 +33,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
public override bool IsMine(List<string> lines, string fileName)
|
public override bool IsMine(List<string> lines, string fileName)
|
||||||
{
|
{
|
||||||
var sbv = new YouTubeSbv();
|
var sbv = new YouTubeSbv();
|
||||||
if (sbv.IsMine(lines, fileName) && !String.Join(String.Empty, lines.ToArray()).Contains("[br]"))
|
if (sbv.IsMine(lines, fileName) && !string.Join(string.Empty, lines.ToArray()).Contains("[br]"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var subtitle = new Subtitle();
|
var subtitle = new Subtitle();
|
||||||
@ -64,13 +66,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
string text = p.Text.Replace(Environment.NewLine, "[br]");
|
string text = p.Text.Replace(Environment.NewLine, "[br]");
|
||||||
text = text.Replace("<i>", "{\\i1}");
|
text = text.Replace("<i>", "{\\i1}");
|
||||||
text = text.Replace("</i>", "{\\i0}");
|
text = text.Replace("</i>", "{\\i0}");
|
||||||
text = text.Replace("</i>", "{\\i}");
|
|
||||||
text = text.Replace("<b>", "{\\b1}");
|
text = text.Replace("<b>", "{\\b1}");
|
||||||
text = text.Replace("</b>", "{\\b0}");
|
text = text.Replace("</b>", "{\\b0}");
|
||||||
text = text.Replace("</b>", "{\\b}");
|
|
||||||
text = text.Replace("<u>", "{\\u1}");
|
text = text.Replace("<u>", "{\\u1}");
|
||||||
text = text.Replace("</u>", "{\\u0}");
|
text = text.Replace("</u>", "{\\u0}");
|
||||||
text = text.Replace("</u>", "{\\u}");
|
|
||||||
|
|
||||||
sb.AppendLine(string.Format(paragraphWriteFormat,
|
sb.AppendLine(string.Format(paragraphWriteFormat,
|
||||||
p.StartTime.Hours,
|
p.StartTime.Hours,
|
||||||
@ -90,72 +89,65 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
|
|
||||||
private static int RoundTo2Cifres(int milliseconds)
|
private static int RoundTo2Cifres(int milliseconds)
|
||||||
{
|
{
|
||||||
int rounded = (int)Math.Round((double)milliseconds / 10);
|
return (int)Math.Round(milliseconds / 10.0);
|
||||||
return rounded;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||||
{
|
{
|
||||||
var regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d.\d+,\d\d:\d\d:\d\d.\d+$", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
var paragraph = new Paragraph();
|
var paragraph = new Paragraph();
|
||||||
ExpectingLine expecting = ExpectingLine.TimeCodes;
|
var expecting = ExpectingLine.TimeCodes;
|
||||||
_errorCount = 0;
|
_errorCount = 0;
|
||||||
char[] splitChars = { ':', ',', '.' };
|
char[] splitChars = { ':', ',', '.' };
|
||||||
subtitle.Paragraphs.Clear();
|
subtitle.Paragraphs.Clear();
|
||||||
foreach (string line in lines)
|
foreach (string line in lines)
|
||||||
{
|
{
|
||||||
if (regexTimeCodes.IsMatch(line))
|
if (expecting == ExpectingLine.TimeCodes && line.Length > 20 && RegexTimeCodes.IsMatch(line))
|
||||||
{
|
{
|
||||||
string[] parts = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
|
string[] parts = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (parts.Length == 8)
|
if (parts.Length == 8)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int startHours = int.Parse(parts[0]);
|
paragraph.StartTime = DecodeTimeCode(parts, 0);
|
||||||
int startMinutes = int.Parse(parts[1]);
|
paragraph.EndTime = DecodeTimeCode(parts, 4);
|
||||||
int startSeconds = int.Parse(parts[2]);
|
|
||||||
int startMilliseconds = int.Parse(parts[3]);
|
|
||||||
int endHours = int.Parse(parts[4]);
|
|
||||||
int endMinutes = int.Parse(parts[5]);
|
|
||||||
int endSeconds = int.Parse(parts[6]);
|
|
||||||
int endMilliseconds = int.Parse(parts[7]);
|
|
||||||
paragraph.StartTime = new TimeCode(startHours, startMinutes, startSeconds, startMilliseconds);
|
|
||||||
paragraph.EndTime = new TimeCode(endHours, endMinutes, endSeconds, endMilliseconds);
|
|
||||||
expecting = ExpectingLine.Text;
|
expecting = ExpectingLine.Text;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
_errorCount++;
|
||||||
expecting = ExpectingLine.TimeCodes;
|
expecting = ExpectingLine.TimeCodes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (expecting == ExpectingLine.Text && line.Length > 0)
|
||||||
{
|
{
|
||||||
if (expecting == ExpectingLine.Text)
|
string text = line.Replace("[br]", Environment.NewLine);
|
||||||
{
|
text = text.Replace("{\\i1}", "<i>");
|
||||||
if (line.Length > 0)
|
text = text.Replace("{\\i0}", "</i>");
|
||||||
{
|
text = text.Replace("{\\i}", "</i>");
|
||||||
string text = line.Replace("[br]", Environment.NewLine);
|
text = text.Replace("{\\b1}", "<b>");
|
||||||
text = text.Replace("{\\i1}", "<i>");
|
text = text.Replace("{\\b0}", "</b>");
|
||||||
text = text.Replace("{\\i0}", "</i>");
|
text = text.Replace("{\\b}", "</b>");
|
||||||
text = text.Replace("{\\i}", "</i>");
|
text = text.Replace("{\\u1}", "<u>");
|
||||||
text = text.Replace("{\\b1}", "<b>");
|
text = text.Replace("{\\u0}", "</u>");
|
||||||
text = text.Replace("{\\b0}", "</b>");
|
text = text.Replace("{\\u}", "</u>");
|
||||||
text = text.Replace("{\\b}", "</b>");
|
|
||||||
text = text.Replace("{\\u1}", "<u>");
|
|
||||||
text = text.Replace("{\\u0}", "</u>");
|
|
||||||
text = text.Replace("{\\u}", "</u>");
|
|
||||||
|
|
||||||
paragraph.Text = text;
|
paragraph.Text = text;
|
||||||
subtitle.Paragraphs.Add(paragraph);
|
subtitle.Paragraphs.Add(paragraph);
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
expecting = ExpectingLine.TimeCodes;
|
expecting = ExpectingLine.TimeCodes;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subtitle.Renumber();
|
subtitle.Renumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TimeCode DecodeTimeCode(string[] encodedTimeCode, int index)
|
||||||
|
{
|
||||||
|
// Hours, Minutes, Seconds, Milliseconds / 10.
|
||||||
|
return new TimeCode(int.Parse(encodedTimeCode[index]),
|
||||||
|
int.Parse(encodedTimeCode[index + 1]),
|
||||||
|
int.Parse(encodedTimeCode[index + 2]),
|
||||||
|
int.Parse(encodedTimeCode[index + 3]) * 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user