mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
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:
parent
ebc2053282
commit
8eab0f8f18
@ -963,8 +963,8 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
_oldSubtitleFormat = ebu;
|
_oldSubtitleFormat = ebu;
|
||||||
SetFormatToSubRip();
|
SetFormatToSubRip();
|
||||||
justConverted = true;
|
justConverted = true;
|
||||||
|
format = GetCurrentSubtitleFormat();
|
||||||
}
|
}
|
||||||
format = GetCurrentSubtitleFormat();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_fileDateTime = File.GetLastWriteTime(fileName);
|
_fileDateTime = File.GetLastWriteTime(fileName);
|
||||||
|
123
src/Logic/SubtitleFormats/AdobeEncore.cs
Normal file
123
src/Logic/SubtitleFormats/AdobeEncore.cs
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
128
src/Logic/SubtitleFormats/PinnacleImpression.cs
Normal file
128
src/Logic/SubtitleFormats/PinnacleImpression.cs
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
123
src/Logic/SubtitleFormats/RealTime.cs
Normal file
123
src/Logic/SubtitleFormats/RealTime.cs
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,13 +15,16 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
return new List<SubtitleFormat>
|
return new List<SubtitleFormat>
|
||||||
{
|
{
|
||||||
new SubRip(),
|
new SubRip(),
|
||||||
|
new AdobeEncore(),
|
||||||
new DvdStudioPro(),
|
new DvdStudioPro(),
|
||||||
new DvdSubtitle(),
|
new DvdSubtitle(),
|
||||||
// new Ebu(),
|
// new Ebu(),
|
||||||
new MicroDvd(),
|
new MicroDvd(),
|
||||||
new MPlayer2(),
|
new MPlayer2(),
|
||||||
new OpenDvt(),
|
new OpenDvt(),
|
||||||
|
new PinnacleImpression(),
|
||||||
new QuickTimeText(),
|
new QuickTimeText(),
|
||||||
|
new RealTime(),
|
||||||
new SonyDVDArchitect(),
|
new SonyDVDArchitect(),
|
||||||
new SonyDVDArchitectWithLineNumbers(),
|
new SonyDVDArchitectWithLineNumbers(),
|
||||||
new SubStationAlpha(),
|
new SubStationAlpha(),
|
||||||
|
@ -32,6 +32,21 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
{
|
{
|
||||||
var subtitle = new Subtitle();
|
var subtitle = new Subtitle();
|
||||||
LoadSubtitle(subtitle, lines, fileName);
|
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;
|
return subtitle.Paragraphs.Count > _errorCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,7 +501,10 @@
|
|||||||
<Compile Include="Logic\FindReplaceDialogHelper.cs" />
|
<Compile Include="Logic\FindReplaceDialogHelper.cs" />
|
||||||
<Compile Include="Logic\HistoryItem.cs" />
|
<Compile Include="Logic\HistoryItem.cs" />
|
||||||
<Compile Include="Logic\StripableText.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\QuickTimeText.cs" />
|
||||||
|
<Compile Include="Logic\SubtitleFormats\RealTime.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\SonyDVDArchitectWithLineNumbers.cs" />
|
<Compile Include="Logic\SubtitleFormats\SonyDVDArchitectWithLineNumbers.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\Ebu.cs" />
|
<Compile Include="Logic\SubtitleFormats\Ebu.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\SonyDVDArchitect.cs" />
|
<Compile Include="Logic\SubtitleFormats\SonyDVDArchitect.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user