Skip to content
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

解决mp4decrypt对中文文件名支持不佳问题 #524

Merged
merged 1 commit into from
Nov 29, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/N_m3u8DL-RE.Common/Resource/ResString.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace N_m3u8DL_RE.Common.Resource;

public class ResString
public static class ResString
{
public static string CurrentLoc = "en-US";

Expand Down Expand Up @@ -125,6 +125,7 @@ public class ResString
public static string promptTitle => GetText("promptTitle");
public static string readingInfo => GetText("readingInfo");
public static string searchKey => GetText("searchKey");
public static string decryptionFailed => GetText("decryptionFailed");
public static string segmentCountCheckNotPass => GetText("segmentCountCheckNotPass");
public static string selectedStream => GetText("selectedStream");
public static string startDownloading => GetText("startDownloading");
Expand Down
6 changes: 6 additions & 0 deletions src/N_m3u8DL-RE.Common/Resource/StaticText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@ internal class StaticText
zhTW: "正在嘗試從文本文件搜尋KEY...",
enUS: "Trying to search for KEY from text file..."
),
["decryptionFailed"] = new TextContainer
(
zhCN: "解密失败",
zhTW: "解密失敗",
enUS: "Decryption failed"
),
["segmentCountCheckNotPass"] = new TextContainer
(
zhCN: "分片数量校验不通过, 共{}个,已下载{}.",
Expand Down
2 changes: 1 addition & 1 deletion src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace N_m3u8DL_RE.CommandLine;

internal partial class CommandInvoker
{
public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20241129";
public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20241130";

[GeneratedRegex("((best|worst)\\d*|all)")]
private static partial Regex ForStrRegex();
Expand Down
35 changes: 27 additions & 8 deletions src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public static async Task<bool> DecryptAsync(DecryptEngine decryptEngine, string
var keyPairs = keys.ToList();
string? keyPair = null;
string? trackId = null;
string? tmpEncFile = null;
string? tmpDecFile = null;
string? workDir = null;

if (isMultiDRM)
{
Expand Down Expand Up @@ -79,7 +82,12 @@ public static async Task<bool> DecryptAsync(DecryptEngine decryptEngine, string
{
cmd += $" --fragments-info \"{init}\" ";
}
cmd += $" \"{source}\" \"{dest}\"";
// 解决mp4decrypt中文问题 切换到源文件所在目录并改名再解密
workDir = Path.GetDirectoryName(source)!;
tmpEncFile = Path.Combine(workDir, $"{Guid.NewGuid()}{Path.GetExtension(source)}");
tmpDecFile = Path.Combine(workDir, $"{Path.GetFileNameWithoutExtension(tmpEncFile)}_dec{Path.GetExtension(tmpEncFile)}");
File.Move(source, tmpEncFile);
cmd += $" \"{Path.GetFileName(tmpEncFile)}\" \"{Path.GetFileName(tmpDecFile)}\"";
}
else
{
Expand All @@ -95,30 +103,41 @@ public static async Task<bool> DecryptAsync(DecryptEngine decryptEngine, string
cmd = $"-loglevel error -nostdin -decryption_key {keyPair.Split(':')[1]} -i \"{enc}\" -c copy \"{dest}\"";
}

await RunCommandAsync(bin, cmd);
var isSuccess = await RunCommandAsync(bin, cmd, workDir);

// mp4decrypt 还原文件改名操作
if (workDir is not null)
{
File.Move(tmpEncFile!, source);
File.Move(tmpDecFile!, dest);
}

if (File.Exists(dest) && new FileInfo(dest).Length > 0)
if (isSuccess)
{
if (tmpFile != "" && File.Exists(tmpFile)) File.Delete(tmpFile);
return true;
}


Logger.Error(ResString.decryptionFailed);
return false;
}

private static async Task RunCommandAsync(string name, string arg)
private static async Task<bool> RunCommandAsync(string name, string arg, string? workDir = null)
{
Logger.DebugMarkUp($"FileName: {name}");
Logger.DebugMarkUp($"Arguments: {arg}");
await Process.Start(new ProcessStartInfo()
var process = Process.Start(new ProcessStartInfo()
{
FileName = name,
Arguments = arg,
// RedirectStandardOutput = true,
// RedirectStandardError = true,
CreateNoWindow = true,
UseShellExecute = false
})!.WaitForExitAsync();
UseShellExecute = false,
WorkingDirectory = workDir
});
await process!.WaitForExitAsync();
return process.ExitCode == 0;
}

/// <summary>
Expand Down