mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Added subtitle formats (Scenarist + Adobe Encore with tabs)
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@244 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
2bf05580cf
commit
23b7f890bc
119
src/Logic/SubtitleFormats/AdobeEncoreTabs.cs
Normal file
119
src/Logic/SubtitleFormats/AdobeEncoreTabs.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||||
|
{
|
||||||
|
class AdobeEncoreTab : SubtitleFormat
|
||||||
|
{
|
||||||
|
public override string Extension
|
||||||
|
{
|
||||||
|
get { return ".txt"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name
|
||||||
|
{
|
||||||
|
get { return "Adobe Encore (tabs)"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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:00:54:08 00:00:58:06 - Saucers... - ... a dry lake bed. (newline is \r)
|
||||||
|
sb.AppendLine(string.Format("{0}\t{1}\t{2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), Utilities.RemoveHtmlTags(p.Text).Replace(Environment.NewLine, "\r")));
|
||||||
|
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\t\d\d:\d\d:\d\d:\d\d\t", 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();
|
||||||
|
if (!text.Contains(Environment.NewLine))
|
||||||
|
text = text.Replace("\r", Environment.NewLine);
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
_errorCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
118
src/Logic/SubtitleFormats/Scenarist.cs
Normal file
118
src/Logic/SubtitleFormats/Scenarist.cs
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||||
|
{
|
||||||
|
class Scenarist : SubtitleFormat
|
||||||
|
{
|
||||||
|
public override string Extension
|
||||||
|
{
|
||||||
|
get { return ".txt"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name
|
||||||
|
{
|
||||||
|
get { return "Scenarist"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HasLineNumber
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
//0003 00:00:28:16 00:00:31:04 Jeg vil lære jer frygten for HERREN." (newline is \t)
|
||||||
|
sb.AppendLine(string.Format("{0:0000}\t{1}\t{2}\t{3}", index + 1, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), Utilities.RemoveHtmlTags(p.Text).Replace(Environment.NewLine, "\t")));
|
||||||
|
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\t\d\d:\d\d:\d\d:\d\d\t\d\d:\d\d:\d\d:\d\d\t", RegexOptions.Compiled);
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
if (regexTimeCodes.IsMatch(line))
|
||||||
|
{
|
||||||
|
string temp = line.Substring(0, regexTimeCodes.Match(line).Length);
|
||||||
|
string start = temp.Substring(5, 11);
|
||||||
|
string end = temp.Substring(12+5, 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();
|
||||||
|
if (!text.Contains(Environment.NewLine))
|
||||||
|
text = text.Replace("\t", Environment.NewLine);
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
_errorCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
{
|
{
|
||||||
new SubRip(),
|
new SubRip(),
|
||||||
new AdobeEncore(),
|
new AdobeEncore(),
|
||||||
|
new AdobeEncoreTab(),
|
||||||
new DvdStudioPro(),
|
new DvdStudioPro(),
|
||||||
new DvdSubtitle(),
|
new DvdSubtitle(),
|
||||||
// new Ebu(),
|
// new Ebu(),
|
||||||
@ -25,6 +26,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
new PinnacleImpression(),
|
new PinnacleImpression(),
|
||||||
new QuickTimeText(),
|
new QuickTimeText(),
|
||||||
new RealTime(),
|
new RealTime(),
|
||||||
|
new Scenarist(),
|
||||||
new SonyDVDArchitect(),
|
new SonyDVDArchitect(),
|
||||||
new SonyDVDArchitectWithLineNumbers(),
|
new SonyDVDArchitectWithLineNumbers(),
|
||||||
new SubStationAlpha(),
|
new SubStationAlpha(),
|
||||||
|
@ -504,9 +504,11 @@
|
|||||||
<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\AdobeEncore.cs" />
|
||||||
|
<Compile Include="Logic\SubtitleFormats\AdobeEncoreTabs.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\PinnacleImpression.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\RealTime.cs" />
|
||||||
|
<Compile Include="Logic\SubtitleFormats\Scenarist.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