Now shows "Unknown subtitle dialog" again if subtitle file is not recognized + a few new formats

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@227 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2011-01-07 17:24:34 +00:00
parent ebc2053282
commit 8eab0f8f18
7 changed files with 396 additions and 1 deletions

View File

@ -963,9 +963,9 @@ namespace Nikse.SubtitleEdit.Forms
_oldSubtitleFormat = ebu;
SetFormatToSubRip();
justConverted = true;
}
format = GetCurrentSubtitleFormat();
}
}
_fileDateTime = File.GetLastWriteTime(fileName);

View File

@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
class AdobeEncore : SubtitleFormat
{
public override string Extension
{
get { return ".txt"; }
}
public override string Name
{
get { return "Adobe Encore"; }
}
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();
StringBuilder sb = new StringBuilder();
foreach (string line in lines)
sb.AppendLine(line);
if (sb.ToString().Contains("#INPOINT OUTPOINT PATH"))
return false; // Pinnacle Impression
LoadSubtitle(subtitle, lines, fileName);
return subtitle.Paragraphs.Count > _errorCount;
}
public override string ToText(Subtitle subtitle, string title)
{
StringBuilder sb = new StringBuilder();
int index = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
//00:03:15:22 00:03:23:10 This is line one.
//This is line two.
sb.AppendLine(string.Format("{0} {1} {2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), Utilities.RemoveHtmlTags(p.Text)));
index++;
}
return sb.ToString();
}
private string EncodeTimeCode(TimeCode time)
{
//00:03:15:22 (last is frame)
int frames = time.Milliseconds / (1000 / 30);
return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", time.Hours, time.Minutes, time.Seconds, frames);
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
//00:03:15:22 00:03:23:10 This is line one.
//This is line two.
Paragraph p = null;
subtitle.Paragraphs.Clear();
var regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d \d\d:\d\d:\d\d:\d\d ", RegexOptions.Compiled);
foreach (string line in lines)
{
if (regexTimeCodes.IsMatch(line))
{
string temp = line.Substring(0, regexTimeCodes.Match(line).Length);
string start = temp.Substring(0, 11);
string end = temp.Substring(12, 11);
string[] startParts = start.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] endParts = end.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (startParts.Length == 4 && endParts.Length == 4)
{
string text = line.Remove(0, regexTimeCodes.Match(line).Length-1).Trim();
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text);
subtitle.Paragraphs.Add(p);
}
}
else if (line.Trim().Length == 0)
{
// skip these lines
}
else if (line.Trim().Length > 0 && p != null)
{
if (string.IsNullOrEmpty(p.Text))
p.Text = line;
else
p.Text = p.Text + Environment.NewLine + line;
}
}
subtitle.Renumber(1);
}
private TimeCode DecodeTimeCode(string[] parts)
{
//00:00:07:12
string hour = parts[0];
string minutes = parts[1];
string seconds = parts[2];
string frames = parts[3];
int milliseconds = (int)((1000 / 30.0) * int.Parse(frames));
if (milliseconds > 999)
milliseconds = 999;
TimeCode tc = new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), milliseconds);
return tc;
}
}
}

View File

@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
class PinnacleImpression : SubtitleFormat
{
public override string Extension
{
get { return ".txt"; }
}
public override string Name
{
get { return "Pinnacle Impression"; }
}
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();
StringBuilder sb = new StringBuilder();
foreach (string line in lines)
sb.AppendLine(line);
if (sb.ToString().Contains("#INPOINT OUTPOINT PATH"))
{
LoadSubtitle(subtitle, lines, fileName);
return subtitle.Paragraphs.Count > _errorCount;
}
return false;
}
public override string ToText(Subtitle subtitle, string title)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(@"-------------------------------------------------
#INPOINT OUTPOINT PATH
-------------------------------------------------");
int index = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
//00:03:15:22 00:03:23:10 This is line one.
//This is line two.
sb.AppendLine(string.Format("{0} {1} {2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), Utilities.RemoveHtmlTags(p.Text)));
index++;
}
sb.AppendLine(@"-------------------------------------------------");
return sb.ToString();
}
private string EncodeTimeCode(TimeCode time)
{
//00:03:15:22 (last is frame)
int frames = time.Milliseconds / (1000 / 30);
return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", time.Hours, time.Minutes, time.Seconds, frames);
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
//00:03:15:22 00:03:23:10 This is line one.
//This is line two.
Paragraph p = null;
subtitle.Paragraphs.Clear();
var regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d \d\d:\d\d:\d\d:\d\d ", RegexOptions.Compiled);
foreach (string line in lines)
{
if (regexTimeCodes.IsMatch(line))
{
string temp = line.Substring(0, regexTimeCodes.Match(line).Length);
string start = temp.Substring(0, 11);
string end = temp.Substring(12, 11);
string[] startParts = start.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] endParts = end.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (startParts.Length == 4 && endParts.Length == 4)
{
string text = line.Remove(0, regexTimeCodes.Match(line).Length-1).Trim();
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text);
subtitle.Paragraphs.Add(p);
}
}
else if (line.Trim().Length == 0)
{
// skip these lines
}
else if (line.Trim().Length > 0 && p != null)
{
if (string.IsNullOrEmpty(p.Text))
p.Text = line;
else
p.Text = p.Text + Environment.NewLine + line;
}
}
subtitle.Renumber(1);
}
private TimeCode DecodeTimeCode(string[] parts)
{
//00:00:07:12
string hour = parts[0];
string minutes = parts[1];
string seconds = parts[2];
string frames = parts[3];
int milliseconds = (int)((1000 / 30.0) * int.Parse(frames));
if (milliseconds > 999)
milliseconds = 999;
TimeCode tc = new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), milliseconds);
return tc;
}
}
}

View File

@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
public class RealTime : SubtitleFormat
{
public override string Extension
{
get { return ".rt"; }
}
public override string Name
{
get { return "RealTime"; }
}
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;
}
public override string ToText(Subtitle subtitle, string title)
{
StringBuilder sb = new StringBuilder();
int index = 0;
sb.AppendLine("<Window" + Environment.NewLine +
" Width = \"640\"" + Environment.NewLine +
" Height = \"480\"" + Environment.NewLine +
" WordWrap = \"true\"" + Environment.NewLine +
" Loop = \"true\"" + Environment.NewLine +
" bgcolor = \"black\"" + Environment.NewLine +
">" + Environment.NewLine +
"<Font" + Environment.NewLine +
" Color = \"white\"" + Environment.NewLine +
" Face = \"Arial\"" + Environment.NewLine +
" Size = \"+2\"" + Environment.NewLine +
">" + Environment.NewLine +
"<center>" + Environment.NewLine +
"<b>" + Environment.NewLine);
foreach (Paragraph p in subtitle.Paragraphs)
{
//<Time begin="0:03:24.8" end="0:03:29.4" /><clear/>Man stjæler ikke fra Chavo, nej.
sb.AppendLine(string.Format("<Time begin=\"{0}\" end=\"{1}\" /><clear/>{2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), p.Text.Replace(Environment.NewLine, " ")));
index++;
}
sb.AppendLine("</b>");
sb.AppendLine("</center>");
return sb.ToString();
}
private string EncodeTimeCode(TimeCode time)
{
//0:03:24.8
return string.Format("{0:0}:{1:00}:{2:00}.{3:0}", time.Hours, time.Minutes, time.Seconds, time.Milliseconds / 100);
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
//<Time begin="0:03:24.8" end="0:03:29.4" /><clear/>Man stjæler ikke fra Chavo, nej.
Paragraph p = null;
subtitle.Paragraphs.Clear();
var regexTimeCodes = new Regex(@"^[\d\d:\d\d:\d\d\.\d\d]", RegexOptions.Compiled);
foreach (string line in lines)
{
try
{
if (line.Contains("<Time ") && line.Contains(" begin=") && line.Contains("end="))
{
int indexOfBegin = line.IndexOf(" begin=");
int indexOfEnd = line.IndexOf(" end=");
string begin = line.Substring(indexOfBegin + 7, 11);
string end = line.Substring(indexOfEnd + 5, 11);
string[] startParts = begin.Split(":.\"".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] endParts = end.Split(":.\"".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (startParts.Length == 4 && endParts.Length == 4)
{
string text = line.Substring(line.LastIndexOf("/>") + 2);
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text);
subtitle.Paragraphs.Add(p);
}
}
}
catch
{
_errorCount++;
}
}
subtitle.Renumber(1);
}
private TimeCode DecodeTimeCode(string[] parts)
{
//[00:06:51.48]
string hour = parts[0];
string minutes = parts[1];
string seconds = parts[2];
string millisesonds = parts[3];
TimeCode tc = new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), int.Parse(millisesonds) * 10);
return tc;
}
}
}

View File

@ -15,13 +15,16 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
return new List<SubtitleFormat>
{
new SubRip(),
new AdobeEncore(),
new DvdStudioPro(),
new DvdSubtitle(),
// new Ebu(),
new MicroDvd(),
new MPlayer2(),
new OpenDvt(),
new PinnacleImpression(),
new QuickTimeText(),
new RealTime(),
new SonyDVDArchitect(),
new SonyDVDArchitectWithLineNumbers(),
new SubStationAlpha(),

View File

@ -32,6 +32,21 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
var subtitle = new Subtitle();
LoadSubtitle(subtitle, lines, fileName);
if (subtitle.Paragraphs.Count > 4)
{
bool allStartWithNumber = true;
foreach (Paragraph p in subtitle.Paragraphs)
{
if (p.Text.Length > 1 && !Utilities.IsInteger(p.Text.Substring(0, 2)))
{
allStartWithNumber = false;
break;
}
}
if (allStartWithNumber)
return false;
}
return subtitle.Paragraphs.Count > _errorCount;
}

View File

@ -501,7 +501,10 @@
<Compile Include="Logic\FindReplaceDialogHelper.cs" />
<Compile Include="Logic\HistoryItem.cs" />
<Compile Include="Logic\StripableText.cs" />
<Compile Include="Logic\SubtitleFormats\AdobeEncore.cs" />
<Compile Include="Logic\SubtitleFormats\PinnacleImpression.cs" />
<Compile Include="Logic\SubtitleFormats\QuickTimeText.cs" />
<Compile Include="Logic\SubtitleFormats\RealTime.cs" />
<Compile Include="Logic\SubtitleFormats\SonyDVDArchitectWithLineNumbers.cs" />
<Compile Include="Logic\SubtitleFormats\Ebu.cs" />
<Compile Include="Logic\SubtitleFormats\SonyDVDArchitect.cs" />