diff --git a/Changelog.txt b/Changelog.txt index 22c4a8f10..370325d0a 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -12,6 +12,7 @@ * Add "Toggle custom surround text with" shortcut - thx HadiSparrow * Add "Go to next/previous time code from video position" shortcuts - thx faon-92 * Add option to change search engine in "Spell check" - thx Keddyan + * Add reading of TTML images from ISMT - thx azrie * IMPROVED: * Update French translation - thx Pierre * Update Hungarian translation - thx Zityi diff --git a/src/libse/Common/Subtitle.cs b/src/libse/Common/Subtitle.cs index 0de51151d..c248fcf05 100644 --- a/src/libse/Common/Subtitle.cs +++ b/src/libse/Common/Subtitle.cs @@ -21,7 +21,7 @@ namespace Nikse.SubtitleEdit.Core.Common public static int MaximumHistoryItems => 100; - public SubtitleFormat OriginalFormat { get; private set; } + public SubtitleFormat OriginalFormat { get; set; } public Encoding OriginalEncoding { get; private set; } public List HistoryItems { get; } @@ -101,17 +101,39 @@ namespace Nikse.SubtitleEdit.Core.Common return Paragraphs.Find(p => p.Id == id); } - public SubtitleFormat ReloadLoadSubtitle(List lines, string fileName, SubtitleFormat format) + public SubtitleFormat ReloadLoadSubtitle(List lines, string fileName, SubtitleFormat format, SubtitleFormat format2 = null, SubtitleFormat format3 = null) { Paragraphs.Clear(); + if (format != null && format.IsMine(lines, fileName)) { format.LoadSubtitle(this, lines, fileName); OriginalFormat = format; return format; } + + if (format2 != null && format2.IsMine(lines, fileName)) + { + format2.LoadSubtitle(this, lines, fileName); + OriginalFormat = format2; + return format2; + } + + if (format3 != null && format3.IsMine(lines, fileName)) + { + format3.LoadSubtitle(this, lines, fileName); + OriginalFormat = format3; + return format3; + } + foreach (var subtitleFormat in SubtitleFormat.AllSubtitleFormats) { + var name = subtitleFormat.Name; + if (format?.Name == name || format2?.Name == name || format3?.Name == name) + { + continue; + } + if (subtitleFormat.IsMine(lines, fileName)) { subtitleFormat.LoadSubtitle(this, lines, fileName); @@ -119,6 +141,7 @@ namespace Nikse.SubtitleEdit.Core.Common return subtitleFormat; } } + return null; } diff --git a/src/libse/SubtitleFormats/IsmtDfxp.cs b/src/libse/SubtitleFormats/IsmtDfxp.cs index f0689e6aa..a1d3c5cbe 100644 --- a/src/libse/SubtitleFormats/IsmtDfxp.cs +++ b/src/libse/SubtitleFormats/IsmtDfxp.cs @@ -28,7 +28,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } var buffer = new byte[12]; - int l = fs.Read(buffer, 0, buffer.Length); + var l = fs.Read(buffer, 0, buffer.Length); if (l != buffer.Length) { return false; @@ -54,6 +54,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats var mp4Parser = new MP4Parser(fileName); var dfxpStrings = mp4Parser.GetMdatsAsStrings(); SubtitleFormat format = new TimedText10(); + SubtitleFormat format2 = new TimedTextBase64Image(); + SubtitleFormat format3 = new TimedTextImage(); foreach (var xmlAsString in dfxpStrings) { try @@ -71,7 +73,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats var sub = new Subtitle(); var mdatLines = xmlAsString.SplitToLines(25_000); - format = sub.ReloadLoadSubtitle(mdatLines, null, format); + format = sub.ReloadLoadSubtitle(mdatLines, null, format, format2, format3); if (sub.Paragraphs.Count == 0) { continue; @@ -93,6 +95,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { _errorCount++; } + + subtitle.OriginalFormat = format; } var merged = MergeLinesSameTextUtils.MergeLinesWithSameTextInSubtitle(subtitle, false, 250); diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index 0fef3b393..cae3bdaca 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -2960,6 +2960,19 @@ namespace Nikse.SubtitleEdit.Forms if (f.IsMine(null, fileName)) { f.LoadSubtitle(_subtitle, null, fileName); + + if (_subtitle.OriginalFormat?.Name == new TimedTextBase64Image().Name) + { + ImportAndInlineBase64(_subtitle, _loading, fileName); + return; + } + + if (_subtitle.OriginalFormat?.Name == new TimedTextImage().Name) + { + ImportAndOcrDost(fileName, _subtitle); + return; + } + SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat); SetEncoding(Configuration.Settings.General.DefaultEncoding); encoding = GetCurrentEncoding(); @@ -4324,6 +4337,35 @@ namespace Nikse.SubtitleEdit.Forms } } + private void ImportAndOcrDost(string fileName, Subtitle sub) + { + using (var formSubOcr = new VobSubOcr()) + { + formSubOcr.Initialize(sub, Configuration.Settings.VobSubOcr, false); + if (formSubOcr.ShowDialog(this) == DialogResult.OK) + { + MakeHistoryForUndo(_language.BeforeImportingBdnXml); + FileNew(); + _subtitle.Paragraphs.Clear(); + SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat); + foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs) + { + _subtitle.Paragraphs.Add(p); + } + + UpdateSourceView(); + SubtitleListview1.Fill(_subtitle, _subtitleOriginal); + _subtitleListViewIndex = -1; + SubtitleListview1.FirstVisibleIndex = -1; + SubtitleListview1.SelectIndexAndEnsureVisible(0, true); + + _fileName = Path.ChangeExtension(formSubOcr.FileName, GetCurrentSubtitleFormat().Extension); + SetTitle(); + _converted = true; + } + } + } + private void ImportAndOcrSst(string fileName, SonicScenaristBitmaps format, List list) { using (var formSubOcr = new VobSubOcr())