mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Added new subtitle format - thx emmanuel :)
This commit is contained in:
parent
8bcc5f1cbb
commit
f54edc89e3
@ -364,6 +364,7 @@
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle21.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle22.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle23.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle83.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle24.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle25.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle26.cs" />
|
||||
|
@ -242,6 +242,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
new UnknownSubtitle80(),
|
||||
new UnknownSubtitle81(),
|
||||
new UnknownSubtitle82(),
|
||||
new UnknownSubtitle83(),
|
||||
};
|
||||
|
||||
string path = Configuration.PluginsDirectory;
|
||||
|
99
libse/SubtitleFormats/UnknownSubtitle83.cs
Normal file
99
libse/SubtitleFormats/UnknownSubtitle83.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
public class UnknownSubtitle83 : SubtitleFormat
|
||||
{
|
||||
|
||||
private static readonly Regex RegexTimeCodes = new Regex(@"^\d+\)\s+\d+:\d+:\d+:\d+\s+\d+:\d+:\d+:\d+\s+Durée\s+\d+:\d+\s+Lis\s+:\s+\d+\s+Nbc\s+:\s+\d+$", RegexOptions.Compiled);
|
||||
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".rtf"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Unknown 83"; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
var subtitle = new Subtitle();
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
string format = "{0}) {1} {2} Durée {3} Lis : {4} Nbc : {5}" + Environment.NewLine + "{6}" + Environment.NewLine;
|
||||
var sb = new StringBuilder();
|
||||
for (int index = 0; index < subtitle.Paragraphs.Count;)
|
||||
{
|
||||
var p = subtitle.Paragraphs[index++];
|
||||
var lis = (int)Math.Round(MillisecondsToFrames(p.Duration.TotalMilliseconds) / 2.0);
|
||||
sb.AppendLine(string.Format(format, index, p.StartTime.ToHHMMSSFF(), p.EndTime.ToHHMMSSFF(), p.Duration.ToSSFF(), lis, p.Text.Length, p.Text));
|
||||
}
|
||||
return sb.ToString().ToRtf();
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
var sb = new StringBuilder();
|
||||
foreach (string line in lines)
|
||||
sb.AppendLine(line);
|
||||
|
||||
string rtf = sb.ToString().Trim();
|
||||
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
|
||||
return;
|
||||
|
||||
lines = rtf.FromRtf().SplitToLines().ToList();
|
||||
Paragraph p = null;
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (RegexTimeCodes.IsMatch(line)) // 1) 00:00:08:02 00:00:10:10 Durée 02:08 Lis : 28 Nbc : 19
|
||||
{
|
||||
if (p != null)
|
||||
{
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
try
|
||||
{
|
||||
var timeCodes = line.Substring(line.IndexOf(")", StringComparison.Ordinal) + 1, line.IndexOf("Durée", StringComparison.Ordinal) - 2).Trim().Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
p = new Paragraph(string.Empty, TimeCode.ParseHHMMSSFFToMilliseconds(timeCodes[0]), TimeCode.ParseHHMMSSFFToMilliseconds(timeCodes[1]));
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
else if (p != null && p.Text.Length < 1000)
|
||||
{
|
||||
p.Text = (p.Text + Environment.NewLine + line).Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
if (_errorCount > 50)
|
||||
return;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -226,6 +226,15 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", ts.Hours, ts.Minutes, ts.Seconds + 1, 0);
|
||||
return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", ts.Hours, ts.Minutes, ts.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(ts.Milliseconds));
|
||||
}
|
||||
|
||||
public string ToSSFF()
|
||||
{
|
||||
var ts = TimeSpan;
|
||||
var frames = Math.Round(ts.Milliseconds / (BaseUnit / Configuration.Settings.General.CurrentFrameRate));
|
||||
if (frames >= Configuration.Settings.General.CurrentFrameRate - 0.001)
|
||||
return string.Format("{0:00}:{1:00}", ts.Seconds + 1, 0);
|
||||
return string.Format("{0:00}:{1:00}", ts.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(ts.Milliseconds));
|
||||
}
|
||||
|
||||
public string ToHHMMSSPeriodFF()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user