SubtitleEdit/libse/SubtitleFormats/Tek.cs

114 lines
3.8 KiB
C#
Raw Normal View History

2016-02-08 21:11:03 +01:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class Tek : SubtitleFormat
{
private static readonly Regex RegexTimeCode = new Regex(@"^\d+ \d+ \d \d \d$", RegexOptions.Compiled);
2017-08-03 12:43:52 +02:00
public override string Extension => ".tek";
2016-02-08 21:11:03 +01:00
2017-08-03 12:43:52 +02:00
public override string Name => "TEK";
2016-02-08 21:11:03 +01:00
2017-08-03 12:43:52 +02:00
public override bool IsTimeBased => false;
2016-02-08 21:11:03 +01:00
public override string ToText(Subtitle subtitle, string title)
{
//1.
//8.03
//10.06
//- Labai aèiû.
//- Jûs rimtai?
//2.
//16.00
//19.06
//Kaip reikalai ðunø grobimo versle?
const string paragraphWriteFormat = "{0} {1} 1 1 0\r\n{2}";
var sb = new StringBuilder();
sb.AppendLine(@"ý Smart Titl Editor / Smart Titler (A)(C)1992-2001. Dragutin Nikolic
ý Serial No: XXXXXXXXXXXXXX
ý Korisnik: Prava i Prevodi - prevodioci
ý
ý KONFIGURACIONI PODACI
ý Dozvoljeno slova u redu: 30
ý Vremenska korekcija: 1.0000000000E+00
ý Radjeno vremenskih korekcija: TRUE
ý Slovni raspored ASCIR
ý
ý Kraj info blocka.");
sb.AppendLine();
if (!subtitle.WasLoadedWithFrameNumbers)
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
subtitle.CalculateFrameNumbersFromTimeCodes(Configuration.Settings.General.CurrentFrameRate);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
foreach (Paragraph p in subtitle.Paragraphs)
{
var text = HtmlUtil.RemoveOpenCloseTags(p.Text, HtmlUtil.TagFont);
sb.AppendLine(string.Format(paragraphWriteFormat, p.StartFrame, p.EndFrame, text));
}
return sb.ToString().Trim();
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
Paragraph paragraph = null;
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
string s = line.Trim();
if (RegexTimeCode.IsMatch(s))
{
if (paragraph != null)
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
subtitle.Paragraphs.Add(paragraph);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
paragraph = new Paragraph();
string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 5)
{
try
{
paragraph.StartFrame = int.Parse(parts[0]);
paragraph.EndFrame = int.Parse(parts[1]);
paragraph.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
}
catch
{
_errorCount++;
}
}
}
else if (paragraph != null && s.Length > 0)
{
paragraph.Text = (paragraph.Text + Environment.NewLine + s).Trim();
if (paragraph.Text.Length > 2000)
{
_errorCount += 100;
return;
}
}
else if (s.Length > 0 && !s.StartsWith('ý'))
{
_errorCount++;
}
}
if (paragraph != null)
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
subtitle.Paragraphs.Add(paragraph);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
subtitle.Renumber();
}
}
}