Added new subtitle format

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1747 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2013-03-19 21:21:10 +00:00
parent e355202811
commit ab18f7361d
3 changed files with 111 additions and 0 deletions

View File

@ -162,6 +162,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
new UnknownSubtitle48(),
new UnknownSubtitle49(),
new UnknownSubtitle50(),
new UnknownSubtitle51(),
};
}
}

View File

@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
public class UnknownSubtitle51 : SubtitleFormat
{
static readonly Regex RegexTimeCodes = new Regex(@"^\d+:\d+:\d+:\d+ , \d+:\d+:\d+:\d+ , .*$", RegexOptions.Compiled);
public override string Extension
{
get { return ".txt"; }
}
public override string Name
{
get { return "Unknown 51"; }
}
public override bool IsTimeBased
{
get { return true; }
}
public override bool IsMine(List<string> lines, string fileName)
{
if (lines.Count > 0 && lines[0] != null && lines[0].StartsWith("{\\rtf1"))
return false;
var subtitle = new Subtitle();
LoadSubtitle(subtitle, lines, fileName);
return subtitle.Paragraphs.Count > _errorCount;
}
public override string ToText(Subtitle subtitle, string title)
{
const string paragraphWriteFormat = "{0} , {1} , {2}\r\n";
const string timeFormat = "{0:00}:{1:00}:{2:00}:{3:00}";
var sb = new StringBuilder();
foreach (Paragraph p in subtitle.Paragraphs)
{
string startTime = string.Format(timeFormat, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, MillisecondsToFramesMaxFrameRate(p.StartTime.Milliseconds));
string endTime = string.Format(timeFormat, p.EndTime.Hours, p.EndTime.Minutes, p.EndTime.Seconds, MillisecondsToFramesMaxFrameRate(p.EndTime.Milliseconds));
sb.Append(string.Format(paragraphWriteFormat, startTime, endTime, Utilities.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, " | "))));
}
return sb.ToString().Trim();
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
int number = 0;
Paragraph p = null;
foreach (string line in lines)
{
if (line.Trim().Length > 0 && line.Trim('-').Trim().Length > 0)
{
if (RegexTimeCodes.Match(line).Success)
{
string[] threePart = line.Split(",".ToCharArray(), StringSplitOptions.None);
p = new Paragraph();
if (threePart.Length > 2 &&
line.Length > 32 &&
GetTimeCode(p.StartTime, threePart[0].Trim()) &&
GetTimeCode(p.EndTime, threePart[1].Trim()))
{
number++;
p.Number = number;
p.Text = line.Remove(0, 31).Trim().Replace(" | ", Environment.NewLine).Replace("|", Environment.NewLine);
subtitle.Paragraphs.Add(p);
}
}
else if (line.StartsWith("//"))
{
// comment
}
else if (p != null && p.Text.Length < 200)
{
p.Text = (p.Text + Environment.NewLine + line.Trim()).Trim();
}
else
{
_errorCount++;
}
}
}
}
private static bool GetTimeCode(TimeCode timeCode, string timeString)
{
try
{
string[] timeParts = timeString.Split(':');
timeCode.Hours = int.Parse(timeParts[0]);
timeCode.Minutes = int.Parse(timeParts[1]);
timeCode.Seconds = int.Parse(timeParts[2]);
timeCode.Milliseconds = FramesToMillisecondsMax999(int.Parse(timeParts[3]));
return true;
}
catch
{
return false;
}
}
}
}

View File

@ -888,6 +888,7 @@
<Compile Include="Logic\SubtitleFormats\OpenDvt.cs" />
<Compile Include="Logic\SubtitleFormats\AbcIViewer.cs" />
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle50.cs" />
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle51.cs" />
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle6.cs" />
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle7.cs" />
<Compile Include="Logic\SubtitleFormats\DigiBeta.cs" />