Skip to content

Commit

Permalink
修改字幕生成算法
Browse files Browse the repository at this point in the history
  • Loading branch information
luvletter2333 committed Jun 10, 2019
1 parent 5dad62f commit bf1dc16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
41 changes: 6 additions & 35 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void Form1_Load(object sender, EventArgs e)
else
Font_Size = 50;
}
catch(Exception ex)
catch (Exception ex)
{
Console.WriteLine("Reading Config File Failed");
Console.WriteLine(ex.ToString());
Expand Down Expand Up @@ -114,42 +114,13 @@ private List<SubTitle> GenerateSubTitles(string filePath)
Console.WriteLine(e.ToString());
return new List<SubTitle>();
}
for (int i = 0; i < lines.Count - 1; i++)
if (string.IsNullOrWhiteSpace(lines[i]) && string.IsNullOrWhiteSpace(lines[i + 1]))
{
lines.RemoveAt(i);
i--;
}
while (string.IsNullOrWhiteSpace(lines[lines.Count - 1]))
lines.RemoveAt(lines.Count - 1);
// Clean Blank Lines in the bottom of txt

var lst = new List<SubTitle>();
lst.Add(new SubTitle(0, "", ""));
int counter = 1;
int file_counter = 1;
while (true)
{
if (counter > lines.Count)
break;
string sub1 = lines[counter - 1];
string sub2 = "";
if (counter == lines.Count)
sub2 = "";
else
sub2 = lines[counter];
if (sub2.Trim() == "")
counter -= 1;
if (sub1.Trim() == "")
{
counter -= 1;
sub1 = "";
sub2 = "";
}
lst.Add(new SubTitle(file_counter, sub1, sub2));
file_counter++;
counter += 2;
}
if (lines.Count % 2 == 1)
lines.Add("\r\n");
for (int i = 0; i < lines.Count - 1; i += 2)
lst.Add(new SubTitle(i / 2 + 1, lines[i], lines[i + 1]));
lst.Add(new SubTitle(lines.Count / 2 + 1, "", ""));
return lst;
}

Expand Down
2 changes: 1 addition & 1 deletion SubTitle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override string ToString()
public string ToString(bool double_line = false)
{
if (double_line)
return $"{First_Sub} \n {Second_Sub}";
return $"{First_Sub}\n{Second_Sub}";
return $"{id.ToString()} {First_Sub} {Second_Sub}";
}

Expand Down

0 comments on commit bf1dc16

Please sign in to comment.