mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-23 11:42:36 +01:00
Added subtitle format ""Swift Interchange File V2"
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1630 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
c0d509831d
commit
39ac6d350f
@ -13,11 +13,14 @@
|
|||||||
* Network mode more stable (auto-restart)
|
* Network mode more stable (auto-restart)
|
||||||
* Updated Czech language file - thx Trottel
|
* Updated Czech language file - thx Trottel
|
||||||
* Updated German language file - thx Christoph Kitsche
|
* Updated German language file - thx Christoph Kitsche
|
||||||
|
* Remembers size of controls in main window better - thx George/Leszek
|
||||||
|
* Format Sami: html-decodes text + reads class attributtes better
|
||||||
* FIXED:
|
* FIXED:
|
||||||
* VobSub (sub/idx) files created by SE now have better compability
|
* VobSub (sub/idx) files created by SE now have better compability
|
||||||
* Possible crash+bug in 'Fix common errors' on selected lines - thx Dan
|
* Possible crash+bug in 'Fix common errors' on selected lines - thx Dan
|
||||||
* Drag'n'drop of large bluray sup files - thx AT
|
* Drag'n'drop of large bluray sup files - thx AT
|
||||||
* Minor fix in 'Fix common errors -> Fix invalid italic tags' - thx azu
|
* Minor fix in 'Fix common errors -> Fix invalid italic tags' - thx azu
|
||||||
|
* List view height in "Set sync point" with large font - thx fox
|
||||||
|
|
||||||
|
|
||||||
3.3.1 (3rd February 2013)
|
3.3.1 (3rd February 2013)
|
||||||
|
@ -85,6 +85,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
new SubtitleEditorProject(),
|
new SubtitleEditorProject(),
|
||||||
new SubViewer10(),
|
new SubViewer10(),
|
||||||
new SubViewer20(),
|
new SubViewer20(),
|
||||||
|
new SwiftInterchange2(),
|
||||||
new SwiftText(),
|
new SwiftText(),
|
||||||
new Tek(),
|
new Tek(),
|
||||||
new TimeXml(),
|
new TimeXml(),
|
||||||
|
162
src/Logic/SubtitleFormats/SwiftInterchange2.cs
Normal file
162
src/Logic/SubtitleFormats/SwiftInterchange2.cs
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||||
|
{
|
||||||
|
public class SwiftInterchange2 : SubtitleFormat
|
||||||
|
{
|
||||||
|
static readonly Regex RegexTimeCodes = new Regex(@"^\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 ".sif"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name
|
||||||
|
{
|
||||||
|
get { return "Swift Interchange File V2"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsTimeBased
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsMine(List<string> lines, string fileName)
|
||||||
|
{
|
||||||
|
if (lines.Count > 0 && lines[0] != null && lines[0].StartsWith("{\\rtf1"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var subtitle = new Subtitle();
|
||||||
|
LoadSubtitle(subtitle, lines, fileName);
|
||||||
|
return subtitle.Paragraphs.Count > _errorCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToText(Subtitle subtitle, string title)
|
||||||
|
{
|
||||||
|
string date = string.Format("{0:00}/{1:00}/{2}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year);
|
||||||
|
const string header = @"# SWIFT INTERCHANGE FILE V2
|
||||||
|
# DO NOT EDIT LINES BEGINNING WITH '#' SIGN
|
||||||
|
# Originating Swift: Line21 30 DROP English (USA)
|
||||||
|
# VIDEO CLIP : [VIDEO_FILE]
|
||||||
|
# BROADCAST DATE : [DATE]
|
||||||
|
# REVISION DATE : [DATE]
|
||||||
|
# CREATION DATE : [DATE]
|
||||||
|
# COUNTRY OF ORIGIN : ENG
|
||||||
|
# EPISODE NUMBER : 0
|
||||||
|
# DEADLINE DATE : [DATE]
|
||||||
|
# AUTO TX : false
|
||||||
|
# CURRENT STYLE : None
|
||||||
|
# STYLE DATE : None
|
||||||
|
# STYLE Time : None
|
||||||
|
# SUBTITLE [1] RU3
|
||||||
|
# TIMEIN 01:00:00:06
|
||||||
|
# DURATION 03:21 AUTO
|
||||||
|
# TIMEOUT --:--:--:--
|
||||||
|
# START ROW BOTTOM
|
||||||
|
# ALIGN CENTRE JUSTIFY LEFT
|
||||||
|
# ROW 0";
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.AppendLine(header.Replace("[DATE]", date).Replace("[VIDEO_FILE]", title + ".mpg"));
|
||||||
|
sb.AppendLine();
|
||||||
|
sb.AppendLine();
|
||||||
|
const string paragraphWriteFormat = @"# SUBTITLE [{3}] RU3
|
||||||
|
# TIMEIN {0}
|
||||||
|
# DURATION {1} AUTO
|
||||||
|
# TIMEOUT --:--:--:--
|
||||||
|
# START ROW BOTTOM
|
||||||
|
# ALIGN CENTRE JUSTIFY LEFT
|
||||||
|
# ROW 0
|
||||||
|
{2}";
|
||||||
|
int count = 2;
|
||||||
|
foreach (Paragraph p in subtitle.Paragraphs)
|
||||||
|
{
|
||||||
|
string startTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, MillisecondsToFramesMaxFrameRate(p.StartTime.Milliseconds));
|
||||||
|
string duration = string.Format("{0:00}:{1:00}", p.Duration.Seconds, MillisecondsToFramesMaxFrameRate(p.Duration.Milliseconds));
|
||||||
|
sb.AppendLine(string.Format(paragraphWriteFormat, startTime, duration, Utilities.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, " ")), count));
|
||||||
|
sb.AppendLine();
|
||||||
|
sb.AppendLine();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return sb.ToString().Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||||
|
{
|
||||||
|
_errorCount = 0;
|
||||||
|
Paragraph p = null;
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
if (line.StartsWith("# SUBTITLE"))
|
||||||
|
{
|
||||||
|
if (p != null)
|
||||||
|
subtitle.Paragraphs.Add(p);
|
||||||
|
p = new Paragraph();
|
||||||
|
}
|
||||||
|
else if (p != null && line.StartsWith("# TIMEIN"))
|
||||||
|
{
|
||||||
|
string timeCode = line.Remove(0, 8).Trim();
|
||||||
|
if (timeCode != "--:--:--:--" && !GetTimeCode(p.StartTime, timeCode))
|
||||||
|
_errorCount++;
|
||||||
|
}
|
||||||
|
else if (p != null && line.StartsWith("# DURATION"))
|
||||||
|
{
|
||||||
|
// # DURATION 01:17 AUTO
|
||||||
|
string timecode = line.Remove(0, 10).Replace("AUTO", string.Empty).Trim();
|
||||||
|
if (timecode != "--:--")
|
||||||
|
{
|
||||||
|
var arr = timecode.Split(": ".ToCharArray());
|
||||||
|
if (arr.Length > 1)
|
||||||
|
{
|
||||||
|
int sec;
|
||||||
|
int frame;
|
||||||
|
if (int.TryParse(arr[0], out sec) && int.TryParse(arr[1], out frame))
|
||||||
|
{
|
||||||
|
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + FramesToMillisecondsMax999(frame);
|
||||||
|
p.EndTime.TotalSeconds += sec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (p != null && line.StartsWith("# TIMEOUT"))
|
||||||
|
{
|
||||||
|
string timeCode = line.Remove(0, 9).Trim();
|
||||||
|
if (timeCode != "--:--:--:--" && !GetTimeCode(p.EndTime, timeCode))
|
||||||
|
_errorCount++;
|
||||||
|
}
|
||||||
|
else if (p != null && !line.StartsWith("#"))
|
||||||
|
{
|
||||||
|
if (p.Text.Length > 500)
|
||||||
|
{
|
||||||
|
_errorCount += 10;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
p.Text = (p.Text + Environment.NewLine + line).Trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p != null)
|
||||||
|
subtitle.Paragraphs.Add(p);
|
||||||
|
subtitle.RemoveEmptyLines();
|
||||||
|
subtitle.Renumber(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool GetTimeCode(TimeCode timeCode, string timeString)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string[] timeParts = timeString.Split(":.".ToCharArray());
|
||||||
|
timeCode.Hours = int.Parse(timeParts[0]);
|
||||||
|
timeCode.Minutes = int.Parse(timeParts[1]);
|
||||||
|
timeCode.Seconds = int.Parse(timeParts[2]);
|
||||||
|
timeCode.Milliseconds = FramesToMillisecondsMax999(int.Parse(timeParts[3]));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -51,7 +51,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
{
|
{
|
||||||
string startTime = string.Format(timeFormat, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, p.StartTime.Milliseconds);
|
string startTime = string.Format(timeFormat, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, p.StartTime.Milliseconds);
|
||||||
string endTime = string.Format(timeFormat, p.EndTime.Hours, p.EndTime.Minutes, p.EndTime.Seconds, p.EndTime.Milliseconds);
|
string endTime = string.Format(timeFormat, p.EndTime.Hours, p.EndTime.Minutes, p.EndTime.Seconds, p.EndTime.Milliseconds);
|
||||||
sb.Append(string.Format(paragraphWriteFormat, startTime, endTime, Utilities.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, " "))));
|
sb.AppendLine(string.Format(paragraphWriteFormat, startTime, endTime, Utilities.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, " "))));
|
||||||
}
|
}
|
||||||
return sb.ToString().Trim();
|
return sb.ToString().Trim();
|
||||||
}
|
}
|
||||||
|
@ -819,6 +819,7 @@
|
|||||||
<Compile Include="Logic\SubtitleFormats\Spt.cs" />
|
<Compile Include="Logic\SubtitleFormats\Spt.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\StructuredTitles.cs" />
|
<Compile Include="Logic\SubtitleFormats\StructuredTitles.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\SubtitleEditorProject.cs" />
|
<Compile Include="Logic\SubtitleFormats\SubtitleEditorProject.cs" />
|
||||||
|
<Compile Include="Logic\SubtitleFormats\SwiftInterchange2.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\SwiftText .cs" />
|
<Compile Include="Logic\SubtitleFormats\SwiftText .cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\Tek.cs" />
|
<Compile Include="Logic\SubtitleFormats\Tek.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\TimedText10.cs" />
|
<Compile Include="Logic\SubtitleFormats\TimedText10.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user