Fix dialog line when it's a number & Fix new line

Fix dialog line when the dialog is just a number | Fix new line in dialog that happens on the same line
This commit is contained in:
Fábio Nogueira
2025-10-16 18:51:28 +01:00
parent 28f9e4f8f9
commit b3f9bfb074
+24 -28
View File
@@ -228,15 +228,12 @@ namespace ConvertSRTto3DASS
var timestamp_start = ""; var timestamp_start = "";
var timestamp_end = ""; var timestamp_end = "";
var subtitiles = ""; var subtitles = "";
string srt = ReadTextSmart(file); string srt = ReadTextSmart(file);
//Which dialog we are on (sanity check)
int i = 1;
//Whether to extract the time stamp or not
int j = 0; //TODO: Change to a bool
int dialogNumber = 1; // Which dialog we are on
int dialogLine = 0; // Which line of the dialog block we are on
int linecounter = 0; //Where we are in the .srt, meant for debugging int linecounter = 0; //Where we are in the .srt, meant for debugging
foreach (string line in srt.Split('\n')) foreach (string line in srt.Split('\n'))
@@ -245,46 +242,45 @@ namespace ConvertSRTto3DASS
//Empty line assumes that the next line with event number thus previous dialog is finished and can be saved //Empty line assumes that the next line with event number thus previous dialog is finished and can be saved
if (line == "" | line == "\r") if (line == "" | line == "\r")
{ {
j = 0; dialogLine = 0;
converted.Add(new Tuple<string, string, string, string>(timestamp_start, timestamp_end, ChangeFormatting(subtitiles), "")); converted.Add(new Tuple<string, string, string, string>(timestamp_start, timestamp_end, ChangeFormatting(subtitles), ""));
subtitiles = ""; subtitles = "";
continue; continue;
} }
//Try to parse the event/dialog number
if (int.TryParse(line, out int k)) //Handle the first line
if (dialogLine == 0)
{ {
//Event number doesn't match counted event number. Mismatch means something probably went wrong //Check that the line is an actual number
if (k != i && j == 1) if (int.TryParse(line, out int k) && k == dialogNumber)
{ {
Console.Error.WriteLine("Something went wrong"); dialogNumber++;
Console.Error.WriteLine("Something wrong on line:" + linecounter); dialogLine++;
System.Environment.Exit(-1);
}
else
{
i++;
j++;
continue; continue;
} }
Console.Error.WriteLine("Something went wrong");
Console.Error.WriteLine("Something wrong on line:" + linecounter);
System.Environment.Exit(-1);
} }
//If it a timestamp is expected, extract it //Timestamp extraction
if (j == 1) if (dialogLine == 1)
{ {
timestamp_start = line.Substring(0, 12); timestamp_start = line.Substring(0, 12);
timestamp_end = line.Substring(17, 12); timestamp_end = line.Substring(17, 12);
j++; dialogLine++;
} }
else else
{ {
if (subtitiles == "") if (subtitles == "")
{ {
subtitiles = line; subtitles = line;
subtitiles = subtitiles.Replace("\\.r", ""); subtitles = subtitles.Replace("\\.r", "");
} }
else else
{ {
subtitiles = subtitiles + "\\n" + line; subtitles = subtitles + "\\N" + line;
} }
} }
} }