diff --git a/src/Logic/SubtitleFormats/SubtitleFormat.cs b/src/Logic/SubtitleFormats/SubtitleFormat.cs index d9b786b31..07a249e6f 100644 --- a/src/Logic/SubtitleFormats/SubtitleFormat.cs +++ b/src/Logic/SubtitleFormats/SubtitleFormat.cs @@ -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(), }; } } diff --git a/src/Logic/SubtitleFormats/UnknownSubtitle48.cs b/src/Logic/SubtitleFormats/UnknownSubtitle48.cs new file mode 100644 index 000000000..1c0e64086 --- /dev/null +++ b/src/Logic/SubtitleFormats/UnknownSubtitle48.cs @@ -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 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 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; + } + } + } +} diff --git a/src/SubtitleEdit.csproj b/src/SubtitleEdit.csproj index eacaeed56..25cf84f89 100644 --- a/src/SubtitleEdit.csproj +++ b/src/SubtitleEdit.csproj @@ -871,6 +871,7 @@ +