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@1628 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
61d8df3a40
commit
b3fad3f94a
@ -87,6 +87,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new SubViewer20(),
|
||||
new SwiftText(),
|
||||
new Tek(),
|
||||
new TimeXml(),
|
||||
new TimedText10(),
|
||||
new TimedText200604(),
|
||||
new TimedText(),
|
||||
@ -98,8 +99,17 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new TranscriberXml(),
|
||||
new Tmx14(),
|
||||
new TurboTitler(),
|
||||
// new Idx(),
|
||||
new UTSubtitleXml(),
|
||||
new Utx(),
|
||||
new UtxFrames(),
|
||||
new UleadSubtitleFormat(),
|
||||
new WebVTT(),
|
||||
new YouTubeAnnotations(),
|
||||
new YouTubeSbv(),
|
||||
new YouTubeTranscript(),
|
||||
new ZeroG(),
|
||||
|
||||
// new Idx(),
|
||||
new UnknownSubtitle1(),
|
||||
new UnknownSubtitle2(),
|
||||
new UnknownSubtitle3(),
|
||||
@ -147,15 +157,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new UnknownSubtitle45(),
|
||||
new UnknownSubtitle46(),
|
||||
new UnknownSubtitle47(),
|
||||
new UTSubtitleXml(),
|
||||
new Utx(),
|
||||
new UtxFrames(),
|
||||
new WebVTT(),
|
||||
new TimeXml(),
|
||||
new YouTubeAnnotations(),
|
||||
new YouTubeSbv(),
|
||||
new YouTubeTranscript(),
|
||||
new ZeroG(),
|
||||
new UnknownSubtitle48(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
101
src/Logic/SubtitleFormats/UnknownSubtitle48.cs
Normal file
101
src/Logic/SubtitleFormats/UnknownSubtitle48.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
|
||||
//00:01:27.703 00:01:29.514 Okay.
|
||||
//00:01:29.259 00:01:31.514 Okaaayyyy.
|
||||
//00:01:32.534 00:01:34.888 Let's go over this once again.
|
||||
//00:01:35.446 00:01:38.346 Pick up the bread, walk the dog, go to the dry cleaners,
|
||||
//00:01:38.609 00:01:41.471 pick up the bread, walk the dog, go thoughtless,
|
||||
//00:01:42.247 00:01:43.915 pick up the cake
|
||||
|
||||
public class UnknownSubtitle48 : 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 ".txt"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Unknown 48"; }
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
const string paragraphWriteFormat = "{0} {1} {2}";
|
||||
const string timeFormat = "{0:00}:{1:00}:{2:00}.{3:000}";
|
||||
var sb = new StringBuilder();
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
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);
|
||||
sb.Append(string.Format(paragraphWriteFormat, startTime, endTime, Utilities.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, " "))));
|
||||
}
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (RegexTimeCodes.Match(line).Success)
|
||||
{
|
||||
string[] parts = line.Split(" ".ToCharArray(), StringSplitOptions.None);
|
||||
var p = new Paragraph();
|
||||
if (parts.Length > 2 &&
|
||||
GetTimeCode(p.StartTime, parts[0].Trim()) &&
|
||||
GetTimeCode(p.EndTime, parts[1].Trim()))
|
||||
{
|
||||
p.Text = line.Remove(0, 25).Trim();
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount+=10;
|
||||
}
|
||||
}
|
||||
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 = int.Parse(timeParts[3]);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -871,6 +871,7 @@
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle45.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle46.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle47.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle48.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle5.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\OpenDvt.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AbcIViewer.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user