From 723160beb351f429211dcda17463ad89632c00f6 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Thu, 14 Mar 2024 12:55:46 +0100 Subject: [PATCH] Add format "Timed Text IMSC 1.1" --- SubtitleEdit.sln.DotSettings | 1 + .../SubtitleFormats/NetflixImsc11Japanese.cs | 2 +- src/libse/SubtitleFormats/SubtitleFormat.cs | 1 + src/libse/SubtitleFormats/TimedText10.cs | 13 +- .../SubtitleFormats/TimedText200604Ooyala.cs | 2 +- src/libse/SubtitleFormats/TimedTextImsc11.cs | 546 ++++++++++++++++++ src/ui/Forms/Main.cs | 18 +- 7 files changed, 571 insertions(+), 12 deletions(-) create mode 100644 src/libse/SubtitleFormats/TimedTextImsc11.cs diff --git a/SubtitleEdit.sln.DotSettings b/SubtitleEdit.sln.DotSettings index 9d0156b2c..d33014b13 100644 --- a/SubtitleEdit.sln.DotSettings +++ b/SubtitleEdit.sln.DotSettings @@ -42,6 +42,7 @@ True True True + True True True True diff --git a/src/libse/SubtitleFormats/NetflixImsc11Japanese.cs b/src/libse/SubtitleFormats/NetflixImsc11Japanese.cs index 3e1f485fe..1f1194f82 100644 --- a/src/libse/SubtitleFormats/NetflixImsc11Japanese.cs +++ b/src/libse/SubtitleFormats/NetflixImsc11Japanese.cs @@ -8,7 +8,7 @@ using System.Xml; namespace Nikse.SubtitleEdit.Core.SubtitleFormats { /// - /// IMSC 1.1 Viewer: http://sandflow.com/imsc1_1/ + /// IMSC 1.1 Viewer: https://www.sandflow.com/imsc1_1/ /// More about bouten/furigana: https://www.japanesewithanime.com/2018/03/furigana-dots-bouten.html /// Netflix blog entry: https://medium.com/netflix-techblog/implementing-japanese-subtitles-on-netflix-c165fbe61989 /// diff --git a/src/libse/SubtitleFormats/SubtitleFormat.cs b/src/libse/SubtitleFormats/SubtitleFormat.cs index 8ef4bb055..77119252e 100644 --- a/src/libse/SubtitleFormats/SubtitleFormat.cs +++ b/src/libse/SubtitleFormats/SubtitleFormat.cs @@ -223,6 +223,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats new TimedText200604CData(), new TimedText200604Ooyala(), new TimedText(), + new TimedTextImsc11(), new TitleExchangePro(), new Titra(), new TmpegEncText(), diff --git a/src/libse/SubtitleFormats/TimedText10.cs b/src/libse/SubtitleFormats/TimedText10.cs index eec9bcdb6..9f71fd677 100644 --- a/src/libse/SubtitleFormats/TimedText10.cs +++ b/src/libse/SubtitleFormats/TimedText10.cs @@ -31,7 +31,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); - string xmlAsString = sb.ToString().Trim(); + var xmlAsString = sb.ToString().Trim(); if (xmlAsString.Contains("xmlns:tts=\"http://www.w3.org/2006/04")) { @@ -41,6 +41,16 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats if (xmlAsString.Contains("http://www.w3.org/ns/ttml")) { xmlAsString = xmlAsString.RemoveControlCharactersButWhiteSpace(); + + if (xmlAsString.Contains("profile/imsc1")) + { + var f = new TimedTextImsc11(); + if (f.IsMine(lines, fileName)) + { + return false; + } + } + var xml = new XmlDocument { XmlResolver = null }; try { @@ -79,6 +89,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } } } + return false; } diff --git a/src/libse/SubtitleFormats/TimedText200604Ooyala.cs b/src/libse/SubtitleFormats/TimedText200604Ooyala.cs index 46a57a0a3..a0ac3a735 100644 --- a/src/libse/SubtitleFormats/TimedText200604Ooyala.cs +++ b/src/libse/SubtitleFormats/TimedText200604Ooyala.cs @@ -19,7 +19,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); - string xmlAsString = sb.ToString().Replace("http://www.w3.org/2006/04/ttaf1#styling\"xml:lang", "http://www.w3.org/2006/04/ttaf1#styling\" xml:lang").Trim(); + var xmlAsString = sb.ToString().Replace("http://www.w3.org/2006/04/ttaf1#styling\"xml:lang", "http://www.w3.org/2006/04/ttaf1#styling\" xml:lang").Trim(); if (xmlAsString.Contains("http://www.w3.org/2006/10")) { diff --git a/src/libse/SubtitleFormats/TimedTextImsc11.cs b/src/libse/SubtitleFormats/TimedTextImsc11.cs new file mode 100644 index 000000000..8dfb69475 --- /dev/null +++ b/src/libse/SubtitleFormats/TimedTextImsc11.cs @@ -0,0 +1,546 @@ +using Nikse.SubtitleEdit.Core.Common; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; + +namespace Nikse.SubtitleEdit.Core.SubtitleFormats +{ + /// + /// IMSC 1.1 Viewer: https://www.sandflow.com/imsc1_1/ + /// + public class TimedTextImsc11 : SubtitleFormat + { + public override string Extension => ".xml"; + public override string Name => "Timed Text IMSC 1.1"; + + private static string GetXmlStructure() + { + return @" + + + +