From 9a2fca09eb349ef90a0e9eec98a9b5248b3449b2 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sat, 12 Jul 2014 09:14:19 +0200 Subject: [PATCH] Added new subtitle format --- src/Forms/Main.cs | 24 ++++++ src/Logic/SubtitleFormats/SatBoxPng.cs | 102 +++++++++++++++++++++++++ src/SubtitleEdit.csproj | 1 + 3 files changed, 127 insertions(+) create mode 100644 src/Logic/SubtitleFormats/SatBoxPng.cs diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index a441e3e2f..a10b8ce32 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -2642,6 +2642,30 @@ namespace Nikse.SubtitleEdit.Forms } } + if (format == null) + { + try + { + var satBoxPng = new SatBoxPng(); + string[] arr = File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)); + var list = new List(); + foreach (string l in arr) + list.Add(l); + if (satBoxPng.IsMine(list, fileName)) + { + var subtitle = new Subtitle(); + satBoxPng.LoadSubtitle(subtitle, list, fileName); + if (ContinueNewOrExit()) + ImportAndOcrSrt(fileName, subtitle); + return; + } + } + catch + { + format = null; + } + } + if (format == null || format.Name == new Scenarist().Name) { try diff --git a/src/Logic/SubtitleFormats/SatBoxPng.cs b/src/Logic/SubtitleFormats/SatBoxPng.cs new file mode 100644 index 000000000..197292caa --- /dev/null +++ b/src/Logic/SubtitleFormats/SatBoxPng.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; + +namespace Nikse.SubtitleEdit.Logic.SubtitleFormats +{ + /// + /// http://forum.videohelp.com/threads/365786-Converting-Subtitles-%28XML-PNG%29-to-idx-sub + /// + public class SatBoxPng : SubtitleFormat + { + + public override string Extension + { + get { return ".txt"; } + } + + public override string Name + { + get { return "SatBox png"; } + } + + public override bool IsTimeBased + { + get { return true; } + } + + public override bool IsMine(List lines, string fileName) + { + var subtitle = new Subtitle(); + LoadSubtitle(subtitle, lines, fileName); + return subtitle.Paragraphs.Count > _errorCount; + } + + public override string ToText(Subtitle subtitle, string title) + { + return "Not implemented"; + } + + public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) + { + // + Paragraph p = null; + subtitle.Paragraphs.Clear(); + _errorCount = 0; + if (string.IsNullOrEmpty(fileName)) + return; + string path = System.IO.Path.GetDirectoryName(fileName); + foreach (string line in lines) + { + string s = line; + if (line.Contains(" s=\"") && line.Contains(" e=\"") && line.Contains(" i=\"") && line.Contains(".png") && (line.Contains(" 0 && p != null) + { + _errorCount++; + } + } + subtitle.Renumber(1); + } + + private string GetTagValue(string tag, string line) + { + int start = line.IndexOf(tag + "=\""); + if (start > 0 && line.Length > start + 4) + { + int end = line.IndexOf("\"", start + 3); + if (end > 0 && line.Length > end + 3) + { + string value = line.Substring(start + 3, end - start - 3); + return value; + } + + } + return string.Empty; + } + + private TimeCode DecodeTimeCode(string s) + { + return TimeCode.FromSeconds(double.Parse(s, CultureInfo.InvariantCulture)); + } + + } +} + diff --git a/src/SubtitleEdit.csproj b/src/SubtitleEdit.csproj index 6efc9db7f..88364c311 100644 --- a/src/SubtitleEdit.csproj +++ b/src/SubtitleEdit.csproj @@ -875,6 +875,7 @@ +