mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Added two new subtitle formats
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@933 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
30e2fd1ee7
commit
0e9ff56f00
@ -83,6 +83,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new UnknownSubtitle9(),
|
||||
new UnknownSubtitle10(),
|
||||
new UnknownSubtitle11(),
|
||||
new UnknownSubtitle12(),
|
||||
new UnknownSubtitle13(),
|
||||
new UTSubtitleXml(),
|
||||
new Utx(),
|
||||
new UtxFrames(),
|
||||
|
107
src/Logic/SubtitleFormats/UnknownSubtitle12.cs
Normal file
107
src/Logic/SubtitleFormats/UnknownSubtitle12.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
/// <summary>
|
||||
///4.01 5.12
|
||||
///Dit is de dag.
|
||||
/// </summary>
|
||||
public class UnknownSubtitle12 : SubtitleFormat
|
||||
{
|
||||
static Regex _regexTimeCode = new Regex(@"^\d+.\d\d\t\t\d+.\d\d\t*$", RegexOptions.Compiled);
|
||||
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".txt"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Unknown 12"; }
|
||||
}
|
||||
|
||||
public override bool HasLineNumber
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private string MakeTimeCode(TimeCode tc)
|
||||
{
|
||||
return string.Format("{0:0.00}", tc.TotalSeconds);
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
sb.Append(MakeTimeCode(p.StartTime));
|
||||
sb.Append("\t\t");
|
||||
sb.Append(MakeTimeCode(p.EndTime));
|
||||
sb.Append("\t\t\n");
|
||||
sb.Append(p.Text.Replace(Environment.NewLine, "\n") + "\n\n");
|
||||
}
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
|
||||
private TimeCode DecodeTimeCode(string timeCode)
|
||||
{
|
||||
return new TimeCode(TimeSpan.FromSeconds(double.Parse(timeCode.Trim())));
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
Paragraph p = null;
|
||||
var text = new StringBuilder();
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string s = line.Trim();
|
||||
if (_regexTimeCode.IsMatch(s))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (p != null)
|
||||
{
|
||||
p.Text = text.ToString().Trim();
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
string[] arr = s.Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
text = new StringBuilder();
|
||||
p = new Paragraph(DecodeTimeCode(arr[0]), DecodeTimeCode(arr[1]), "");
|
||||
}
|
||||
catch
|
||||
{
|
||||
_errorCount++;
|
||||
p = null;
|
||||
}
|
||||
}
|
||||
else if (p != null)
|
||||
{
|
||||
text.AppendLine(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
137
src/Logic/SubtitleFormats/UnknownSubtitle13.cs
Normal file
137
src/Logic/SubtitleFormats/UnknownSubtitle13.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
class UnknownSubtitle13 : SubtitleFormat
|
||||
{
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".xml"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Unknown 13"; }
|
||||
}
|
||||
|
||||
public override bool HasLineNumber
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
Subtitle subtitle = new Subtitle();
|
||||
this.LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > 0;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
string xmlStructure =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine +
|
||||
"<subtitle><config bgAlpha=\"0.5\" bgColor=\"0x000000\" defaultColor=\"0xCCffff\" fontSize=\"16\"/></subtitle>";
|
||||
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.LoadXml(xmlStructure);
|
||||
|
||||
int id = 1;
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
XmlNode paragraph = xml.CreateElement("entry");
|
||||
|
||||
XmlAttribute duration = xml.CreateAttribute("timeOut");
|
||||
duration.InnerText = p.EndTime.ToString();
|
||||
paragraph.Attributes.Append(duration);
|
||||
|
||||
XmlAttribute start = xml.CreateAttribute("timeIn");
|
||||
start.InnerText = p.StartTime.ToString();
|
||||
paragraph.Attributes.Append(start);
|
||||
|
||||
XmlAttribute idAttr = xml.CreateAttribute("id");
|
||||
idAttr.InnerText = id.ToString();
|
||||
paragraph.Attributes.Append(idAttr);
|
||||
|
||||
paragraph.InnerText = "<![CDATA[" + p.Text + "]]";
|
||||
|
||||
xml.DocumentElement.AppendChild(paragraph);
|
||||
id++;
|
||||
}
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8);
|
||||
writer.Formatting = Formatting.Indented;
|
||||
xml.Save(writer);
|
||||
return Encoding.UTF8.GetString(ms.ToArray()).Trim();
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
|
||||
string allText = sb.ToString();
|
||||
if (!allText.Contains("<subtitle>") || !allText.Contains("timeIn="))
|
||||
return;
|
||||
|
||||
XmlDocument xml = new XmlDocument();
|
||||
try
|
||||
{
|
||||
xml.LoadXml(allText);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(exception.Message);
|
||||
_errorCount = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (XmlNode node in xml.DocumentElement.SelectNodes("entry"))
|
||||
{
|
||||
try
|
||||
{
|
||||
string start = node.Attributes["timeIn"].InnerText;
|
||||
string end = node.Attributes["timeOut"].InnerText;
|
||||
string text = node.InnerText;
|
||||
if (text.StartsWith("![CDATA["))
|
||||
text = text.Remove(0, 8);
|
||||
if (text.StartsWith("]]"))
|
||||
text = text.Remove(text.Length-3, 2);
|
||||
|
||||
subtitle.Paragraphs.Add(new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), text));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
private TimeCode DecodeTimeCode(string timeCode)
|
||||
{
|
||||
string[] arr = timeCode.Split(":,.".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
int hours = int.Parse(arr[0]);
|
||||
int minutes = int.Parse(arr[1]);
|
||||
int seconds = int.Parse(arr[2]);
|
||||
int ms = int.Parse(arr[3]);
|
||||
return new TimeCode(hours, minutes, seconds, ms);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -624,6 +624,8 @@
|
||||
<Compile Include="Logic\SubtitleFormats\UleadSubtitleFormat.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle10.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle11.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle12.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle13.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle5.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\OpenDvt.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AbcIViewer.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user