mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
Added new subtitle format
This commit is contained in:
parent
eac25f4c1f
commit
4a7832e9bc
@ -6,6 +6,8 @@
|
||||
* New Netflix quality checker - thx askolesov/pavel-belenko
|
||||
* Added optional list view column "Actor" for ASS/SSA - thx william
|
||||
* Added new subtitle format - thx Merwyn
|
||||
* Added new subtitle format - thx Philippe
|
||||
* Added new subtitle fomrat - thx Eddy
|
||||
* IMPROVED:
|
||||
* Updated Chinese translation - thx Leon
|
||||
* Updated French translation - thx JM GBT
|
||||
|
@ -216,6 +216,7 @@
|
||||
<Compile Include="Subtitle.cs" />
|
||||
<Compile Include="SubtitleFormats\AribB36.cs" />
|
||||
<Compile Include="SubtitleFormats\AribB24Decoder.cs" />
|
||||
<Compile Include="SubtitleFormats\Csv5.cs" />
|
||||
<Compile Include="SubtitleFormats\JsonType11.cs" />
|
||||
<Compile Include="SubtitleFormats\SmpteTt2052.cs" />
|
||||
<Compile Include="SubtitleFormats\Ted20.cs" />
|
||||
|
105
libse/SubtitleFormats/Csv5.cs
Normal file
105
libse/SubtitleFormats/Csv5.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
public class Csv5 : SubtitleFormat
|
||||
{
|
||||
private const string Separator = ",";
|
||||
private static readonly Regex TimeCodeRegex = new Regex(@"^\d\d:\d\d:\d\d\.\d\d$", RegexOptions.Compiled);
|
||||
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".csv"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Csv5"; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(fileName) && !fileName.EndsWith(".csv", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var subtitle = new Subtitle();
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > 0;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
const string format = "{1}{0}{2}{0}{3}";
|
||||
var sb = new StringBuilder();
|
||||
foreach (var p in subtitle.Paragraphs)
|
||||
{
|
||||
string text = p.Text.Replace(Environment.NewLine, "///").Replace("\"", string.Empty);
|
||||
if (text.Contains(','))
|
||||
{
|
||||
text = "\"" + text + "\"";
|
||||
}
|
||||
sb.AppendLine(string.Format(format, Separator, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), text));
|
||||
}
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
|
||||
private static 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;
|
||||
foreach (string line in lines)
|
||||
{
|
||||
var parts = line.Split(',');
|
||||
if (parts.Length >= 3)
|
||||
{
|
||||
var start = parts[0].Replace(" ", string.Empty).Replace("-", string.Empty);
|
||||
var end = parts[1].Replace(" ", string.Empty).Replace("-", string.Empty);
|
||||
string text = line.Remove(0, parts[0].Length + 1 + parts[1].Length).Replace("///", Environment.NewLine).Replace("\"", string.Empty).Trim();
|
||||
if (text.StartsWith(",", StringComparison.Ordinal))
|
||||
{
|
||||
text = text.Remove(0, 1);
|
||||
if (TimeCodeRegex.IsMatch(start) && TimeCodeRegex.IsMatch(end))
|
||||
{
|
||||
try
|
||||
{
|
||||
subtitle.Paragraphs.Add(new Paragraph(DecodeTimeCodeFrames(start, SplitCharColon), DecodeTimeCodeFrames(end, SplitCharColon), text));
|
||||
}
|
||||
catch
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
_errorCount++;
|
||||
if (line.StartsWith("$", StringComparison.Ordinal))
|
||||
{
|
||||
_errorCount += 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
subtitle.Renumber();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -46,6 +46,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
new Csv2(),
|
||||
new Csv3(),
|
||||
new Csv4(),
|
||||
new Csv5(),
|
||||
new DCSubtitle(),
|
||||
new DCinemaSmpte2010(),
|
||||
new DCinemaSmpte2007(),
|
||||
|
@ -5954,7 +5954,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
||||
{
|
||||
if (File.Exists(outputFileName))
|
||||
{
|
||||
result = File.ReadAllText(outputFileName);
|
||||
result = File.ReadAllText(outputFileName, Encoding.UTF8);
|
||||
result = ParseHocr(result);
|
||||
File.Delete(outputFileName);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user