mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Added new subtitle format
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1943 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
d42e9c58e3
commit
4725382864
@ -2593,7 +2593,28 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
MessageBox.Show(_language.FileIsEmptyOrShort);
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] arr = File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName));
|
||||
var sb = new StringBuilder();
|
||||
foreach (string l in arr)
|
||||
sb.AppendLine(l);
|
||||
string xmlAsString = sb.ToString().Trim();
|
||||
if (xmlAsString.Contains("http://www.w3.org/ns/ttml") && xmlAsString.Contains("<?xml version="))
|
||||
{
|
||||
var xml = new System.Xml.XmlDocument();
|
||||
try
|
||||
{
|
||||
xml.LoadXml(xmlAsString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Timed text is not valid: " + ex.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ShowUnknownSubtitle();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!videoFileLoaded && mediaPlayer.VideoPlayer != null)
|
||||
|
13
src/Forms/UnknownSubtitle.Designer.cs
generated
13
src/Forms/UnknownSubtitle.Designer.cs
generated
@ -38,17 +38,18 @@
|
||||
this.labelTitle.AutoSize = true;
|
||||
this.labelTitle.Location = new System.Drawing.Point(15, 25);
|
||||
this.labelTitle.Name = "labelTitle";
|
||||
this.labelTitle.Size = new System.Drawing.Size(114, 13);
|
||||
this.labelTitle.Size = new System.Drawing.Size(145, 17);
|
||||
this.labelTitle.TabIndex = 0;
|
||||
this.labelTitle.Text = "Unknown subtitle type";
|
||||
//
|
||||
// buttonOK
|
||||
//
|
||||
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
|
||||
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.buttonOK.Location = new System.Drawing.Point(262, 115);
|
||||
this.buttonOK.Location = new System.Drawing.Point(324, 134);
|
||||
this.buttonOK.Name = "buttonOK";
|
||||
this.buttonOK.Size = new System.Drawing.Size(75, 21);
|
||||
this.buttonOK.Size = new System.Drawing.Size(100, 27);
|
||||
this.buttonOK.TabIndex = 8;
|
||||
this.buttonOK.Text = "&OK";
|
||||
this.buttonOK.UseVisualStyleBackColor = true;
|
||||
@ -62,7 +63,7 @@
|
||||
this.richTextBoxMessage.Name = "richTextBoxMessage";
|
||||
this.richTextBoxMessage.ReadOnly = true;
|
||||
this.richTextBoxMessage.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
|
||||
this.richTextBoxMessage.Size = new System.Drawing.Size(319, 47);
|
||||
this.richTextBoxMessage.Size = new System.Drawing.Size(406, 47);
|
||||
this.richTextBoxMessage.TabIndex = 41;
|
||||
this.richTextBoxMessage.TabStop = false;
|
||||
this.richTextBoxMessage.Text = "If you want this fixed please send an email to mailto:niksedk@gmail.com and inclu" +
|
||||
@ -70,9 +71,9 @@
|
||||
//
|
||||
// UnknownSubtitle
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 17F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(349, 148);
|
||||
this.ClientSize = new System.Drawing.Size(436, 173);
|
||||
this.Controls.Add(this.richTextBoxMessage);
|
||||
this.Controls.Add(this.buttonOK);
|
||||
this.Controls.Add(this.labelTitle);
|
||||
|
@ -187,6 +187,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new UnknownSubtitle60(),
|
||||
new UnknownSubtitle61(),
|
||||
new UnknownSubtitle62(),
|
||||
new UnknownSubtitle63(),
|
||||
};
|
||||
|
||||
string path = Configuration.PluginsDirectory;
|
||||
|
140
src/Logic/SubtitleFormats/UnknownSubtitle63.cs
Normal file
140
src/Logic/SubtitleFormats/UnknownSubtitle63.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
public class UnknownSubtitle63 : SubtitleFormat
|
||||
{
|
||||
|
||||
//3: 00:00:09:23 00:00:16:21 06:23
|
||||
//Alustame sellest...
|
||||
//Siin kajab kuidagi harjumatult.
|
||||
static Regex regexTimeCodes = new Regex(@"^\d+:\s+\d\d:\d\d:\d\d\:\d\d \d\d:\d\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 63"; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (string line in lines)
|
||||
sb.AppendLine(line);
|
||||
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
string format = "{0}: {1} {2} {3:00}:{4:00}";
|
||||
var sb = new StringBuilder();
|
||||
int count = 1;
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
sb.AppendLine(string.Format(format, count, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), p.Duration.Seconds, MillisecondsToFramesMaxFrameRate(p.Duration.Milliseconds)));
|
||||
sb.AppendLine(p.Text);
|
||||
sb.AppendLine();
|
||||
count++;
|
||||
}
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
|
||||
private 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;
|
||||
bool expectStartTime = true;
|
||||
var p = new Paragraph();
|
||||
subtitle.Paragraphs.Clear();
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string s = line.Trim().Replace("*", string.Empty);
|
||||
var match = regexTimeCodes.Match(s);
|
||||
if (match.Success)
|
||||
{
|
||||
string[] parts = s.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(p.Text))
|
||||
{
|
||||
subtitle.Paragraphs.Add(p);
|
||||
p = new Paragraph();
|
||||
}
|
||||
p.StartTime = DecodeTimeCode(parts[1]);
|
||||
p.EndTime = DecodeTimeCode(parts[2]);
|
||||
expectStartTime = false;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_errorCount++;
|
||||
System.Diagnostics.Debug.WriteLine(exception.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (line.Trim().Length == 0)
|
||||
{
|
||||
if (p != null)
|
||||
{
|
||||
if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
|
||||
_errorCount++;
|
||||
else
|
||||
subtitle.Paragraphs.Add(p);
|
||||
p = new Paragraph();
|
||||
}
|
||||
}
|
||||
else if (line.Trim().Length > 0 && !expectStartTime)
|
||||
{
|
||||
p.Text = (p.Text + Environment.NewLine + line).Trim();
|
||||
if (p.Text.Length > 500)
|
||||
{
|
||||
_errorCount+=10;
|
||||
return;
|
||||
}
|
||||
while (p.Text.Contains(Environment.NewLine + " "))
|
||||
p.Text = p.Text.Replace(Environment.NewLine + " ", Environment.NewLine);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(p.Text))
|
||||
subtitle.Paragraphs.Add(p);
|
||||
|
||||
subtitle.RemoveEmptyLines();
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
private TimeCode DecodeTimeCode(string part)
|
||||
{
|
||||
string[] parts = part.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
string hour = parts[0];
|
||||
string minutes = parts[1];
|
||||
string seconds = parts[2];
|
||||
string frames = parts[3];
|
||||
|
||||
return new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), FramesToMillisecondsMax999(int.Parse(frames)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -590,8 +590,10 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
|
||||
_libVlcDLL = LoadLibrary(dllFile);
|
||||
LoadLibVlcDynamic();
|
||||
}
|
||||
else
|
||||
else if (!Directory.Exists(videoFileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnVideoLoaded = onVideoLoaded;
|
||||
OnVideoEnded = onVideoEnded;
|
||||
|
@ -815,6 +815,7 @@
|
||||
<Compile Include="Logic\SubtitleFormats\CaraokeXml.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\Cavena890.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\CheetahCaption.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle63.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle62.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle61.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle60.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user