Skip to content

Skip empty SRT files #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/FileTypes/ASS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public bool IsAss()
return _srt.ToLower().EndsWith(".ass") && (File.ReadLines(_srt).First() == "[Script Info]"); // Lazy checkup
}

public void ParseSrt()
public bool ParseSrt()
{
string subsLines = File.ReadAllText(_srt); // No worries about the encoding, this is smart enough
string[] splitLines = subsLines.ReplaceLineEndings().Split(Environment.NewLine);
Expand Down Expand Up @@ -66,6 +66,12 @@ public void ParseSrt()
_dialogLines.Add(dialogLine);
i += 1;
}
if (_dialogLines.Count == 0)
{
Console.WriteLine($"{_srt} file is empty or incorrect");
return false;
}
return true;
}

public string ConvertToAss(string outputPath)
Expand Down
16 changes: 13 additions & 3 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,25 @@ private static void MergeFiles(string outputPath, string basename, string engine
string res = Array.Find(search, name => ASS.SubsExtensions.Contains(Path.GetExtension(name))) ?? throw new FileNotFoundException(
$"No valid file could be found for the subs {subName} while the files corresponding to the name is {search.Length}"); ;
Console.WriteLine($"Using subs file {Path.GetFileName(res)}");
bool skipSubs = false;
ASS sub = new(res, lang);
string subFile = search[0];
if (!sub.IsAss())
{
sub.ParseSrt();
subFile = sub.ConvertToAss(outputPath);
if (sub.ParseSrt())
{
subFile = sub.ConvertToAss(outputPath);
}
else
{
skipSubs = true;
}
}

merger.AddSubtitlesTrack(subFile, lang);
if (!skipSubs)
{
merger.AddSubtitlesTrack(subFile, lang);
}
break;
default:
throw new Exception($"Too many results ({search.Length}), please report this case");
Expand Down