mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Added new subtitle format
This commit is contained in:
parent
a7c3935eb4
commit
0d9f510ee8
@ -994,6 +994,9 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
|
||||
|
||||
public static string CheckForErrors(string header)
|
||||
{
|
||||
if (string.IsNullOrEmpty(header))
|
||||
return string.Empty;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
int styleCount = -1;
|
||||
|
@ -214,6 +214,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new UnknownSubtitle69(),
|
||||
new UnknownSubtitle70(),
|
||||
new UnknownSubtitle71(),
|
||||
new UnknownSubtitle72(),
|
||||
};
|
||||
|
||||
string path = Configuration.PluginsDirectory;
|
||||
|
131
src/Logic/SubtitleFormats/UnknownSubtitle72.cs
Normal file
131
src/Logic/SubtitleFormats/UnknownSubtitle72.cs
Normal file
@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
public class UnknownSubtitle72 : SubtitleFormat
|
||||
{
|
||||
//00:00:02.000
|
||||
//Junior Semifinal, part 1
|
||||
//Aidiba Talamunuer, Berezan
|
||||
//Bogdan Voloshin, Yaroslavl
|
||||
//Alexandr Doronin, Almaty
|
||||
|
||||
//00:04:41.480
|
||||
//G. Zhubanova
|
||||
//«Kui»
|
||||
//Aidiba Talamunuer, Berezan
|
||||
|
||||
//00:05:55.000
|
||||
//N. Mendigaliev
|
||||
//«Steppe»
|
||||
//Bogdan Voloshin, Yaroslavl
|
||||
|
||||
static readonly Regex RegexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d.\d\d\d$", RegexOptions.Compiled);
|
||||
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".txt"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Unknown 72"; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
const string paragraphWriteFormat = "{0}\r\n{1}\r\n";
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
sb.AppendLine(string.Format(paragraphWriteFormat, p.StartTime.ToString().Replace(",","."), p.Text));
|
||||
}
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
Paragraph paragraph = null;
|
||||
_errorCount = 0;
|
||||
subtitle.Paragraphs.Clear();
|
||||
for (int i = 0; i < lines.Count; i++)
|
||||
{
|
||||
string line = lines[i].TrimEnd();
|
||||
|
||||
if (line.Contains(":") && RegexTimeCodes.IsMatch(line))
|
||||
{
|
||||
if (paragraph != null && string.IsNullOrEmpty(paragraph.Text))
|
||||
_errorCount++;
|
||||
|
||||
paragraph = new Paragraph();
|
||||
if (TryReadTimeCodesLine(line, paragraph))
|
||||
{
|
||||
subtitle.Paragraphs.Add(paragraph);
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
else if (paragraph != null && paragraph.Text.Length < 1000)
|
||||
{
|
||||
paragraph.Text = (paragraph.Text + Environment.NewLine + line).Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
index++;
|
||||
p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
|
||||
Paragraph nextParagraph = subtitle.GetParagraphOrDefault(index);
|
||||
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(p.Text) + 100;
|
||||
if (nextParagraph != null && p.EndTime.TotalMilliseconds >= nextParagraph.StartTime.TotalMilliseconds)
|
||||
{
|
||||
p.EndTime.TotalMilliseconds = nextParagraph.StartTime.TotalMilliseconds - 1;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
private bool TryReadTimeCodesLine(string line, Paragraph paragraph)
|
||||
{
|
||||
string[] parts = line.Split(':', '.');
|
||||
try
|
||||
{
|
||||
int startHours = int.Parse(parts[0]);
|
||||
int startMinutes = int.Parse(parts[1]);
|
||||
int startSeconds = int.Parse(parts[2]);
|
||||
int startMilliseconds = int.Parse(parts[3]);
|
||||
paragraph.StartTime = new TimeCode(startHours, startMinutes, startSeconds, startMilliseconds);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,10 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
|
@ -913,6 +913,7 @@
|
||||
<Compile Include="Logic\SubtitleFormats\SwiftTextLineNumber .cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\Titra.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle69.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle72.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\WebVTTFileWithLineNumber.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\FinalCutProXmlGap.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle66.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user