Skip to content

Commit 04132b6

Browse files
committed
EACDemuxer.cs: error checking and compatibility improvements
* add error checking for eac3to * manually specify the location of eac3to logs to ensure compatibility with the log generation behavior of eac3to versions >= v3.49 * now the eac3to logs will still be placed in the temporary working directory, sharing the same name as the input file and ending with the .eac3to.log suffix
1 parent 47bff60 commit 04132b6

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

OKEGui/OKEGui/JobProcessor/Demuxer/EACDemuxer.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,33 @@ public EACDemuxer(string eacPath, string fileName, TaskProfile jobProfile)
104104
Logger.Debug($"SkipAllAudioTracks: {jobProfile.SkipAllAudioTracks}, SkipAllSubtitleTracks: {jobProfile.SkipAllSubtitleTracks}");
105105
}
106106

107-
private void StartEac(string arguments, bool asyncRead)
107+
private void StartEac(string arguments, string logPath, bool asyncRead)
108108
{
109+
// Since eac3to does not support log paths containing spaces, we first calculate a short hash
110+
// from the intended log path to serve as the log filename. We then launch eac3to in the
111+
// working directory to generate the log, and finally rename the log file back to its full name.
112+
var workingPathDir = Path.GetDirectoryName(WorkingPathPrefix);
113+
var logPathFull = Path.Combine(workingPathDir, logPath);
114+
byte[] buffer = Encoding.UTF8.GetBytes(logPathFull);
115+
var crc = CRC32.Compute(buffer);
116+
var logHashPath = crc.ToString("X8") + ".eac3to.log";
117+
118+
Logger.Trace($"workingPathDir: {workingPathDir}");
119+
Logger.Trace($"eac3to logPathFull: {logPathFull}");
120+
Logger.Trace($"eac3to logHashPath: {logHashPath}");
121+
109122
var startInfo = new ProcessStartInfo
110123
{
111124
FileName = _eacPath,
112-
Arguments = arguments + " -progressnumbers",
125+
Arguments = arguments + $" -log=\"{logHashPath}\"" + " -progressnumbers",
113126
RedirectStandardOutput = true,
114127
RedirectStandardError = true,
115128
StandardOutputEncoding = Encoding.UTF8,
116129
StandardErrorEncoding = Encoding.UTF8,
117130
UseShellExecute = false,
118131
WindowStyle = ProcessWindowStyle.Hidden,
119132
CreateNoWindow = true,
133+
WorkingDirectory = workingPathDir,
120134
};
121135
Logger.Info(startInfo.FileName + " " + startInfo.Arguments);
122136

@@ -135,6 +149,24 @@ private void StartEac(string arguments, bool asyncRead)
135149
readStream(proc.StandardOutput);
136150
proc.WaitForExit();
137151
}
152+
153+
FileInfo logFile = new FileInfo(Path.Combine(workingPathDir, logHashPath));
154+
if (logFile.Exists)
155+
{
156+
FileInfo logFileFinal = new FileInfo(logPathFull);
157+
if (logFileFinal.Exists)
158+
{
159+
logFileFinal.Delete();
160+
}
161+
logFile.MoveTo(logPathFull);
162+
}
163+
164+
if (proc.ExitCode != 0)
165+
{
166+
OKETaskException ex = new OKETaskException(Constants.eac3toErrorSmr);
167+
ex.Data["EXIT_CODE"] = proc.ExitCode;
168+
throw ex;
169+
}
138170
}
139171
catch (Exception e) { throw e; }
140172
}
@@ -295,10 +327,14 @@ public MediaFile Extract(Action<double, EACProgressType> progressCallback)
295327
{
296328
return null;
297329
}
330+
331+
var baseName = Path.GetFileNameWithoutExtension(sourceFile);
332+
string logPath = $"{baseName}.eac3to.log";
333+
298334
_progressCallback = progressCallback;
299335

300336
state = ProcessState.FetchStream;
301-
StartEac($"\"{sourceFile}\"", false);
337+
StartEac($"\"{sourceFile}\"", logPath, false);
302338

303339
if (SkipAllAudioTracks)
304340
{
@@ -390,7 +426,7 @@ public MediaFile Extract(Action<double, EACProgressType> progressCallback)
390426
JobSub.RemoveAll(info => info.MuxOption == MuxOption.Skip);
391427

392428
state = ProcessState.ExtractStream;
393-
StartEac($"\"{sourceFile}\" {string.Join(" ", args)}", true);
429+
StartEac($"\"{sourceFile}\" {string.Join(" ", args)}", logPath, true);
394430

395431
foreach (TrackInfo track in extractResult)
396432
{

OKEGui/OKEGui/JobProcessor/ExceptionParser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public static ExceptionMsg Parse(OKETaskException ex, TaskDetail task)
6969
}
7070
switch (ex.summary)
7171
{
72+
case Constants.eac3toErrorSmr:
73+
msg.errorMsg = string.Format(Constants.eac3toErrorMsg, ex.Data["EXIT_CODE"], task.InputFile);
74+
break;
75+
7276
case Constants.audioNumMismatchSmr:
7377
msg.errorMsg = string.Format(Constants.audioNumMismatchMsg, ex.Data["SRC_TRACK"], ex.Data["DST_REQ_TRACK"], ex.Data["DST_OPT_TRACK"], task.InputFile);
7478
break;

OKEGui/OKEGui/Utils/Cleaner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Cleaner
1414
private const string TIME_FMT = "ddHHmm";
1515

1616
public Cleaner() : this(
17-
new List<string> { "flac", "alac", "aac", "ac3", "dts", "eac3", "sup", "Log.txt", "vpy", "qpf", "lwi", "rpc", "pyc" },
17+
new List<string> { "flac", "alac", "aac", "ac3", "dts", "eac3", "sup", "Log.txt", "eac3to.log", "vpy", "qpf", "lwi", "rpc", "pyc" },
1818
new List<string> { "hevc", "mkv", "mp4", "mka", "h264" })
1919
{
2020
}

OKEGui/OKEGui/Utils/Constants.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public static class Constants
3939
public const string language = "jpn";
4040

4141
//Error messages and summaries
42-
42+
public const string eac3toErrorMsg = "eac3to出错: 退出代码{0},请查看日志并手动运行eac3to获取更多信息。该文件{1}将跳过处理。请转告技术总监复查。";
43+
public const string eac3toErrorSmr = "eac3to出错";
44+
4345
public const string audioNumMismatchMsg = "当前的视频含有轨道数{0},与json中指定的数量{1}必须+{2}可选不符合。该文件{3}将跳过处理。请转告技术总监复查。";
4446
public const string audioNumMismatchSmr = "音轨数不一致";
4547

0 commit comments

Comments
 (0)