mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Added new subtitle format
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1949 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
94ff37dca4
commit
e918d05a46
139
src/Logic/SubtitleFormats/Oresme.cs
Normal file
139
src/Logic/SubtitleFormats/Oresme.cs
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||||
|
{
|
||||||
|
public class Oresme : SubtitleFormat
|
||||||
|
{
|
||||||
|
//00:00:00:00{BC}{W2710}
|
||||||
|
//10:00:00:15{Bottom}{Open Caption}{Center}{White}{Font Arial GVP Bold}
|
||||||
|
//10:00:17:06{Bottom}{Open Caption}{Center}{White}{Font Arial GVP Bold}We view
|
||||||
|
//10:00:19:06{Bottom}{Open Caption}{Center}{White}{Font Arial GVP Bold}Lufa Farms as{N}an agrotechnology business
|
||||||
|
static Regex regexTimeCodes1 = 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 "Oresme"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsTimeBased
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsMine(List<string> lines, string fileName)
|
||||||
|
{
|
||||||
|
var subtitle = new Subtitle();
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
foreach (string line in lines)
|
||||||
|
sb.AppendLine(line);
|
||||||
|
|
||||||
|
LoadSubtitle(subtitle, lines, fileName);
|
||||||
|
return subtitle.Paragraphs.Count > _errorCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToText(Subtitle subtitle, string title)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
string format = "{0}{1}{2}";
|
||||||
|
sb.AppendLine("00:00:00:00{BC}{W2710}");
|
||||||
|
foreach (Paragraph p in subtitle.Paragraphs)
|
||||||
|
{
|
||||||
|
string tags = "{Bottom}{Open Caption}{Center}{White}{Font Arial GVP Bold}";
|
||||||
|
string text = Utilities.RemoveHtmlTags(p.Text, true);
|
||||||
|
text = text.Replace(Environment.NewLine, "{N}");
|
||||||
|
sb.AppendLine(string.Format(format, EncodeTimeCode(p.StartTime), tags, text));
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string EncodeTimeCode(TimeCode time)
|
||||||
|
{
|
||||||
|
return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", time.Hours, time.Minutes, time.Seconds, MillisecondsToFramesMaxFrameRate(time.Milliseconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||||
|
{
|
||||||
|
_errorCount = 0;
|
||||||
|
|
||||||
|
subtitle.Paragraphs.Clear();
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
string s = line.Trim();
|
||||||
|
var match = regexTimeCodes1.Match(s);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
var p = new Paragraph();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
p.StartTime = DecodeTimeCode(s.Substring(0,11));
|
||||||
|
p.Text = GetText(line.Remove(0, 11));
|
||||||
|
subtitle.Paragraphs.Add(p);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
_errorCount++;
|
||||||
|
System.Diagnostics.Debug.WriteLine(exception.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_errorCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < subtitle.Paragraphs.Count-1; i++)
|
||||||
|
{
|
||||||
|
var p2 = subtitle.Paragraphs[i];
|
||||||
|
var next = subtitle.Paragraphs[i+1];
|
||||||
|
p2.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MininumMillisecondsBetweenLines;
|
||||||
|
}
|
||||||
|
if (subtitle.Paragraphs.Count > 0)
|
||||||
|
subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].EndTime.TotalMilliseconds = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].StartTime.TotalMilliseconds +
|
||||||
|
Utilities.GetOptimalDisplayMilliseconds(subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].Text);
|
||||||
|
|
||||||
|
}
|
||||||
|
subtitle.RemoveEmptyLines();
|
||||||
|
subtitle.Renumber(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetText(string s)
|
||||||
|
{
|
||||||
|
s = s.Replace("{N}", Environment.NewLine);
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
bool tagOn = false;
|
||||||
|
for (int i=0; i<s.Length; i++)
|
||||||
|
{
|
||||||
|
if (s[i] == '{')
|
||||||
|
tagOn = true;
|
||||||
|
else if (s[i] == '}')
|
||||||
|
tagOn = false;
|
||||||
|
else if (!tagOn)
|
||||||
|
sb.Append(s[i].ToString());
|
||||||
|
}
|
||||||
|
return sb.ToString().Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private TimeCode DecodeTimeCode(string part)
|
||||||
|
{
|
||||||
|
string[] parts = part.Split(".:".ToCharArray(), 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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -72,6 +72,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
new MidwayInscriberCGX(),
|
new MidwayInscriberCGX(),
|
||||||
new MPlayer2(),
|
new MPlayer2(),
|
||||||
new OpenDvt(),
|
new OpenDvt(),
|
||||||
|
new Oresme(),
|
||||||
new PE2(),
|
new PE2(),
|
||||||
new PinnacleImpression(),
|
new PinnacleImpression(),
|
||||||
new PListCaption(),
|
new PListCaption(),
|
||||||
|
@ -821,6 +821,7 @@
|
|||||||
<Compile Include="Logic\SubtitleFormats\CaraokeXml.cs" />
|
<Compile Include="Logic\SubtitleFormats\CaraokeXml.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\Cavena890.cs" />
|
<Compile Include="Logic\SubtitleFormats\Cavena890.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\CheetahCaption.cs" />
|
<Compile Include="Logic\SubtitleFormats\CheetahCaption.cs" />
|
||||||
|
<Compile Include="Logic\SubtitleFormats\Oresme.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle63.cs" />
|
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle63.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle62.cs" />
|
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle62.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle61.cs" />
|
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle61.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user