diff --git a/libse/LibSE.csproj b/libse/LibSE.csproj index e6e372d31..4c31fdb09 100644 --- a/libse/LibSE.csproj +++ b/libse/LibSE.csproj @@ -196,7 +196,7 @@ - + diff --git a/libse/SubtitleFormats/PowerkaraokeText.cs b/libse/SubtitleFormats/KaraokeCdgCreatorText.cs similarity index 67% rename from libse/SubtitleFormats/PowerkaraokeText.cs rename to libse/SubtitleFormats/KaraokeCdgCreatorText.cs index 0c9db3fee..5526b8e85 100644 --- a/libse/SubtitleFormats/PowerkaraokeText.cs +++ b/libse/SubtitleFormats/KaraokeCdgCreatorText.cs @@ -4,13 +4,13 @@ using System.Text.RegularExpressions; namespace Nikse.SubtitleEdit.Core.SubtitleFormats { - public class PowerkaraokeText : SubtitleFormat + public class KaraokeCdgCreatorText : SubtitleFormat { private static readonly Regex RegexTimeCodes = new Regex(@"^\d+(:\d+){0,1}\.\d+ : \d+(:\d+){0,1}\.\d+ : .+", RegexOptions.Compiled); public override string Extension => ".txt"; - public override string Name => "Powerkaraoke text"; + public override string Name => "Karaoke CDG Creator text"; public override string ToText(Subtitle subtitle, string title) { @@ -34,11 +34,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats char[] splitChars = { ':', '.', ',' }; string[] startParts = start.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); - if ((startParts.Length >= 2 && startParts.Length <= 4) && (endParts.Length >= 2 && endParts.Length <= 4)) + if (startParts.Length >= 2 && startParts.Length <= 4 && (endParts.Length >= 2 && endParts.Length <= 4)) { try { - string text = line.Remove(0, temp[0].Length + temp[1].Length).Trim().TrimStart(':'); + string text = line.Remove(0, temp[0].Length + temp[1].Length + 6).Trim().TrimStart('\0'); text = text.Replace("\\n", Environment.NewLine); p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text); subtitle.Paragraphs.Add(p); @@ -59,6 +59,32 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats _errorCount++; } } + + // merge lines + int i = 0; + while (i < subtitle.Paragraphs.Count - 1) + { + p = subtitle.Paragraphs[i]; + var next = subtitle.Paragraphs[i + 1]; + if (next.StartTime.TotalMilliseconds - 1000 < p.EndTime.TotalMilliseconds && + !(next.Text.StartsWith(Environment.NewLine, StringComparison.Ordinal) || p.Text.EndsWith(Environment.NewLine, StringComparison.Ordinal))) + { + p.Text += " " + next.Text; + p.EndTime.TotalMilliseconds = next.EndTime.TotalMilliseconds; + subtitle.Paragraphs.RemoveAt(i + 1); + } + else + { + i++; + } + } + + // remove "*" (syllable separator) and trim + foreach (var paragraph in subtitle.Paragraphs) + { + paragraph.Text = paragraph.Text.Replace("* ", string.Empty).RemoveChar('*').Trim(); + } + subtitle.Renumber(); } diff --git a/libse/SubtitleFormats/SubtitleFormat.cs b/libse/SubtitleFormats/SubtitleFormat.cs index cae6ab6b2..be6703377 100644 --- a/libse/SubtitleFormats/SubtitleFormat.cs +++ b/libse/SubtitleFormats/SubtitleFormat.cs @@ -520,7 +520,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { new DlDd(), new Ted20(), new Captionate(), new TimeLineAscii(), new TimeLineFootageAscii(), new TimedTextImage(), new FinalCutProImage(), new SpuImage(), new Dost(), new SeImageHtmlIndex(), new BdnXml(), new Wsb(), - new JsonTypeOnlyLoad1(), new TranscriptiveJson(), new PowerkaraokeText() + new JsonTypeOnlyLoad1(), new TranscriptiveJson(), new KaraokeCdgCreatorText() }; } }