diff --git a/Changelog.txt b/Changelog.txt index 01ae6a75a..9811b8e6f 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -45,7 +45,7 @@ * Do not reapeat colors in color picker - thx SDH Marven * Fix cmd line convert issue with ebu stl headerfile - thx Rumczeis * Fix image export missing error for last two lines - th Antoine - * Fix "Merge short lines" in "Batch Conv" to use UI settings - thx maharaj12 + * Fix "Batch Convert" "Merge short lines" UI settings - thx maharaj12 * Fix casing issue in Remove text for HI - thx Petar diff --git a/src/libse/SubtitleFormats/MacCaption10.cs b/src/libse/SubtitleFormats/MacCaption10.cs index 116df798e..98468917a 100644 --- a/src/libse/SubtitleFormats/MacCaption10.cs +++ b/src/libse/SubtitleFormats/MacCaption10.cs @@ -16,7 +16,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats public override string Name => "MacCaption 1.0"; // ANC data bytes may be represented by one ASCII character according to the following schema: - private static Dictionary _ancDictionary = new Dictionary + private static readonly Dictionary AncDictionary = new Dictionary { { 'G', "FA0000" }, { 'H', "FA0000FA0000" }, @@ -240,7 +240,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats var sb = new StringBuilder(); foreach (var ch in input) { - if (_ancDictionary.TryGetValue(ch, out var hexValue)) + if (AncDictionary.TryGetValue(ch, out var hexValue)) { sb.Append(hexValue); } diff --git a/src/libse/SubtitleFormats/TimeCodesOnly3.cs b/src/libse/SubtitleFormats/TimeCodesOnly3.cs new file mode 100644 index 000000000..cf7d4d7b4 --- /dev/null +++ b/src/libse/SubtitleFormats/TimeCodesOnly3.cs @@ -0,0 +1,73 @@ +using Nikse.SubtitleEdit.Core.Common; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; + +namespace Nikse.SubtitleEdit.Core.SubtitleFormats +{ + public class TimeCodesOnly3 : SubtitleFormat + { + // 01:00:00:15 + private static readonly Regex RegexTimeCodes = new Regex(@"^\d+:\d\d:\d\d:\d\d$", RegexOptions.Compiled); + + public override string Extension => ".txt"; + + public const string NameOfFormat = "Time Codes Only 3"; + + public override string Name => NameOfFormat; + + public override string ToText(Subtitle subtitle, string title) + { + var sb = new StringBuilder(); + foreach (var p in subtitle.Paragraphs) + { + sb.AppendLine($"{EncodeTimeCode(p.StartTime)}"); + } + + return sb.ToString(); + } + + private static string EncodeTimeCode(TimeCode time) + { + return $"{time.Hours}:{time.Minutes:00}:{time.Seconds:00}:{MillisecondsToFramesMaxFrameRate(time.Milliseconds):00}"; + } + + public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) + { + Paragraph p = null; + subtitle.Paragraphs.Clear(); + _errorCount = 0; + foreach (var line in lines) + { + if (RegexTimeCodes.IsMatch(line)) + { + var startParts = line.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries); + if (startParts.Length == 4) + { + p = new Paragraph(DecodeTimeCodeFramesFourParts(startParts), DecodeTimeCodeFramesFourParts(startParts), string.Empty); + p.EndTime.TotalMilliseconds += Configuration.Settings.General.NewEmptyDefaultMs; + + subtitle.Paragraphs.Add(p); + + var prev = subtitle.GetParagraphOrDefault(subtitle.GetIndex(p) - 1); + if (prev != null) + { + if (prev.EndTime.TotalMilliseconds > p.StartTime.TotalMilliseconds) + { + prev.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines; + } + } + } + } + else if (p != null) + { + _errorCount++; + } + } + + + subtitle.Renumber(); + } + } +} diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index cc4335fc6..16d715456 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -20946,12 +20946,6 @@ namespace Nikse.SubtitleEdit.Forms private void toolStripMenuItemImportTimeCodes_Click(object sender, EventArgs e) { - if (_subtitle.Paragraphs.Count < 1) - { - DisplaySubtitleNotLoadedMessage(); - return; - } - openFileDialog1.Title = _languageGeneral.OpenSubtitle; openFileDialog1.FileName = string.Empty; openFileDialog1.Filter = UiUtil.SubtitleExtensionFilter.Value; @@ -20987,7 +20981,8 @@ namespace Nikse.SubtitleEdit.Forms var formats = SubtitleFormat.GetBinaryFormats(true).Union(SubtitleFormat.GetTextOtherFormats()).Union(new SubtitleFormat[] { new TimeCodesOnly1(), - new TimeCodesOnly2() + new TimeCodesOnly2(), + new TimeCodesOnly3(), }).ToArray(); format = SubtitleFormat.LoadSubtitleFromFile(formats, openFileDialog1.FileName, timeCodeSubtitle); } @@ -20998,6 +20993,22 @@ namespace Nikse.SubtitleEdit.Forms return; } + if (_subtitle.Paragraphs.Count < 1) + { + foreach (var p in timeCodeSubtitle.Paragraphs) + { + p.Text = string.Empty; + } + + _subtitle.Paragraphs.AddRange(timeCodeSubtitle.Paragraphs); + _converted = true; + _fileName = string.Empty; + _subtitleListViewIndex = -1; + ShowStatus(string.Format(_language.LoadedSubtitleX, openFileDialog1.FileName)); + SubtitleListview1.Fill(_subtitle, _subtitleOriginal); + RestoreSubtitleListviewIndices(); + } + if (timeCodeSubtitle.Paragraphs.Count != _subtitle.Paragraphs.Count) { var text = string.Format(_language.ImportTimeCodesDifferentNumberOfLinesWarning, timeCodeSubtitle.Paragraphs.Count, _subtitle.Paragraphs.Count);