SubtitleEdit/libse/SubtitleFormats/UnknownSubtitle36.cs

98 lines
4.3 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
{
//00:00:31:17 , 00:00:35:12 , Signori e Signorine come state?|Va tutto bene?
//00:00:35:24 , 00:00:40:17 ,Oggi riceveremo un |grande artista che viene dallAfrica.
//00:00:40:20 , 00:00:44:12 ,Indovinate come si chiama?|Indovinate come si chiama?
//00:00:44:15 , 00:00:48:24 ,Si chiama Bella Balde.
//00:00:49:04 , 00:00:50:16 ,Grazie Signore e Signori.
//00:00:50:18 , 00:00:52:24 ,per ricevere questo grande artista| che viene dallAfrica.
//00:00:53:00 , 00:00:55:08 ,Grazie di nuovo,|grazie ancora.
//---------------------------------------------------
//00:02:13:14 , 00:02:18:21 ,Stiamo preparando un festival|nel centro scolastico.
//00:02:20:16 , 00:02:24:00 ,Gente di questo quartiere |Un gran festival!
public class UnknownSubtitle36 : SubtitleFormat
{
private static readonly Regex RegexTimeCodes = new Regex(@"^\d+:\d+:\d+:\d+ , \d+:\d+:\d+:\d+ ,", RegexOptions.Compiled);
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 36";
2016-02-08 21:11:03 +01:00
public override bool IsMine(List<string> lines, string fileName)
{
if (lines.Count > 0 && lines[0] != null && lines[0].StartsWith("{\\rtf1", StringComparison.Ordinal))
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
return false;
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
2017-08-03 12:43:52 +02:00
return base.IsMine(lines, fileName);
2016-02-08 21:11:03 +01:00
}
public override string ToText(Subtitle subtitle, string title)
{
string paragraphWriteFormat = "{0} , {1} ,{2}" + Environment.NewLine;
2016-02-08 21:11:03 +01:00
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.AppendFormat(paragraphWriteFormat, startTime, endTime, HtmlUtil.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 = 1;
char[] splitChar = { ',' };
2016-02-08 21:11:03 +01:00
foreach (string line in lines)
{
if (string.IsNullOrWhiteSpace(line) || string.IsNullOrWhiteSpace(line.Trim('-')))
{
continue;
}
2016-06-07 06:31:03 +02:00
Match match;
if (line.Length > 57 && (match = RegexTimeCodes.Match(line)).Success)
2016-02-08 21:11:03 +01:00
{
try
2016-02-08 21:11:03 +01:00
{
string[] timeParts = line.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
TimeCode startTime = DecodeTimeCodeFrames(timeParts[0].Trim(), SplitCharColon);
TimeCode endTime = DecodeTimeCodeFrames(timeParts[1].Trim(), SplitCharColon);
var p = new Paragraph { Number = number++, StartTime = startTime, EndTime = endTime };
p.Text = line.Substring(match.Length).Replace(" | ", Environment.NewLine).Replace("|", Environment.NewLine);
2016-02-08 21:11:03 +01:00
subtitle.Paragraphs.Add(p);
}
catch
{
_errorCount++;
}
2016-02-08 21:11:03 +01:00
}
else
{
_errorCount++;
}
}
}
}
}