Fix new import format

related to 0637332727
This commit is contained in:
niksedk 2019-03-23 09:17:52 +01:00
parent 2bcb8265b6
commit c41eec4ec3
3 changed files with 32 additions and 6 deletions

View File

@ -196,7 +196,7 @@
<Compile Include="PlainTextImporter.cs" />
<Compile Include="SeLogger.cs" />
<Compile Include="RulesProfile.cs" />
<Compile Include="SubtitleFormats\PowerkaraokeText.cs" />
<Compile Include="SubtitleFormats\KaraokeCdgCreatorText.cs" />
<Compile Include="SubtitleFormats\GooglePlayJson.cs" />
<Compile Include="SubtitleFormats\OgmChapters.cs" />
<Compile Include="SubtitleFormats\JsonType14.cs" />

View File

@ -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();
}

View File

@ -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()
};
}
}