SubtitleEdit/libse/SubtitleFormats/UnknownSubtitle3.cs

76 lines
2.7 KiB
C#
Raw Normal View History

2016-02-08 21:11:03 +01:00
using System;
using System.Collections.Generic;
using System.Text;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
//Subtitle number: 1
//Start time (or frames): 00:00:48,862:0000001222
//End time (or frames): 00:00:50,786:0000001270
//Subtitle text: In preajma lacului Razel,
public class UnknownSubtitle3 : SubtitleFormat
{
private static readonly char[] SplitChar = { '|' };
2016-02-08 21:11:03 +01:00
2017-08-03 12:43:52 +02:00
public override string Extension => ".txt";
2016-02-08 21:11:03 +01:00
2017-08-03 12:43:52 +02:00
public override string Name => "Unknown 3";
2016-02-08 21:11:03 +01:00
public override string ToText(Subtitle subtitle, string title)
{
//150583||3968723||Rythme standard quatre-par-quatre.\~- Sûr... Accord d'entrée, D majeur?||
//155822||160350||Rob n'y connait rien en claviers. Il\~commence chaque chanson en D majeur||
const string paragraphWriteFormat = "{0}||{1}||{2}||";
var sb = new StringBuilder();
foreach (Paragraph p in subtitle.Paragraphs)
{
if (!subtitle.WasLoadedWithFrameNumbers)
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
p.CalculateFrameNumbersFromTimeCodes(Configuration.Settings.General.CurrentFrameRate);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
sb.AppendLine(string.Format(paragraphWriteFormat, p.StartFrame, p.EndFrame, p.Text.Replace(Environment.NewLine, "\\~")));
}
return sb.ToString().Trim();
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
foreach (string line in lines)
{
ReadLine(subtitle, line);
}
subtitle.Renumber();
}
private void ReadLine(Subtitle subtitle, string line)
{
// 150583||3968723||Rythme standard quatre-par-quatre.\~- Sûr... Accord d'entrée, D majeur?||
// 155822||160350||Rob n'y connait rien en claviers. Il\~commence chaque chanson en D majeur||
string[] parts = line.Split(SplitChar, StringSplitOptions.RemoveEmptyEntries);
2016-02-08 21:11:03 +01:00
if (parts.Length == 3)
{
int start;
int end;
if (int.TryParse(parts[0], out start) && int.TryParse(parts[1], out end))
{
var p = new Paragraph(parts[2].Replace("\\~", Environment.NewLine), start, end);
2016-02-08 21:11:03 +01:00
subtitle.Paragraphs.Add(p);
}
else
{
_errorCount++;
}
}
else
{
_errorCount++;
}
}
}
}