解决mp4decrypt解密中文文件名失败问题 (#524)
This commit is contained in:
parent
3081701a32
commit
8702d36276
|
@ -1,6 +1,6 @@
|
||||||
namespace N_m3u8DL_RE.Common.Resource;
|
namespace N_m3u8DL_RE.Common.Resource;
|
||||||
|
|
||||||
public class ResString
|
public static class ResString
|
||||||
{
|
{
|
||||||
public static string CurrentLoc = "en-US";
|
public static string CurrentLoc = "en-US";
|
||||||
|
|
||||||
|
@ -125,6 +125,7 @@ public class ResString
|
||||||
public static string promptTitle => GetText("promptTitle");
|
public static string promptTitle => GetText("promptTitle");
|
||||||
public static string readingInfo => GetText("readingInfo");
|
public static string readingInfo => GetText("readingInfo");
|
||||||
public static string searchKey => GetText("searchKey");
|
public static string searchKey => GetText("searchKey");
|
||||||
|
public static string decryptionFailed => GetText("decryptionFailed");
|
||||||
public static string segmentCountCheckNotPass => GetText("segmentCountCheckNotPass");
|
public static string segmentCountCheckNotPass => GetText("segmentCountCheckNotPass");
|
||||||
public static string selectedStream => GetText("selectedStream");
|
public static string selectedStream => GetText("selectedStream");
|
||||||
public static string startDownloading => GetText("startDownloading");
|
public static string startDownloading => GetText("startDownloading");
|
||||||
|
|
|
@ -910,6 +910,12 @@ internal class StaticText
|
||||||
zhTW: "正在嘗試從文本文件搜尋KEY...",
|
zhTW: "正在嘗試從文本文件搜尋KEY...",
|
||||||
enUS: "Trying to search for KEY from text file..."
|
enUS: "Trying to search for KEY from text file..."
|
||||||
),
|
),
|
||||||
|
["decryptionFailed"] = new TextContainer
|
||||||
|
(
|
||||||
|
zhCN: "解密失败",
|
||||||
|
zhTW: "解密失敗",
|
||||||
|
enUS: "Decryption failed"
|
||||||
|
),
|
||||||
["segmentCountCheckNotPass"] = new TextContainer
|
["segmentCountCheckNotPass"] = new TextContainer
|
||||||
(
|
(
|
||||||
zhCN: "分片数量校验不通过, 共{}个,已下载{}.",
|
zhCN: "分片数量校验不通过, 共{}个,已下载{}.",
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace N_m3u8DL_RE.CommandLine;
|
||||||
|
|
||||||
internal partial class CommandInvoker
|
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)")]
|
[GeneratedRegex("((best|worst)\\d*|all)")]
|
||||||
private static partial Regex ForStrRegex();
|
private static partial Regex ForStrRegex();
|
||||||
|
|
|
@ -17,6 +17,9 @@ internal static class MP4DecryptUtil
|
||||||
var keyPairs = keys.ToList();
|
var keyPairs = keys.ToList();
|
||||||
string? keyPair = null;
|
string? keyPair = null;
|
||||||
string? trackId = null;
|
string? trackId = null;
|
||||||
|
string? tmpEncFile = null;
|
||||||
|
string? tmpDecFile = null;
|
||||||
|
string? workDir = null;
|
||||||
|
|
||||||
if (isMultiDRM)
|
if (isMultiDRM)
|
||||||
{
|
{
|
||||||
|
@ -75,11 +78,17 @@ internal static class MP4DecryptUtil
|
||||||
{
|
{
|
||||||
cmd = string.Join(" ", keyPairs.Select(k => $"--key {trackId}:{k.Split(':')[1]}"));
|
cmd = string.Join(" ", keyPairs.Select(k => $"--key {trackId}:{k.Split(':')[1]}"));
|
||||||
}
|
}
|
||||||
|
// 解决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);
|
||||||
if (init != "")
|
if (init != "")
|
||||||
{
|
{
|
||||||
cmd += $" --fragments-info \"{init}\" ";
|
var infoFile = Path.GetDirectoryName(init) == workDir ? Path.GetFileName(init) : init;
|
||||||
|
cmd += $" --fragments-info \"{infoFile}\" ";
|
||||||
}
|
}
|
||||||
cmd += $" \"{source}\" \"{dest}\"";
|
cmd += $" \"{Path.GetFileName(tmpEncFile)}\" \"{Path.GetFileName(tmpDecFile)}\"";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -95,30 +104,41 @@ internal static class MP4DecryptUtil
|
||||||
cmd = $"-loglevel error -nostdin -decryption_key {keyPair.Split(':')[1]} -i \"{enc}\" -c copy \"{dest}\"";
|
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);
|
||||||
|
|
||||||
if (File.Exists(dest) && new FileInfo(dest).Length > 0)
|
// mp4decrypt 还原文件改名操作
|
||||||
|
if (workDir is not null)
|
||||||
|
{
|
||||||
|
if (File.Exists(tmpEncFile)) File.Move(tmpEncFile, source);
|
||||||
|
if (File.Exists(tmpDecFile)) File.Move(tmpDecFile, dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSuccess)
|
||||||
{
|
{
|
||||||
if (tmpFile != "" && File.Exists(tmpFile)) File.Delete(tmpFile);
|
if (tmpFile != "" && File.Exists(tmpFile)) File.Delete(tmpFile);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.Error(ResString.decryptionFailed);
|
||||||
return false;
|
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($"FileName: {name}");
|
||||||
Logger.DebugMarkUp($"Arguments: {arg}");
|
Logger.DebugMarkUp($"Arguments: {arg}");
|
||||||
await Process.Start(new ProcessStartInfo()
|
var process = Process.Start(new ProcessStartInfo()
|
||||||
{
|
{
|
||||||
FileName = name,
|
FileName = name,
|
||||||
Arguments = arg,
|
Arguments = arg,
|
||||||
// RedirectStandardOutput = true,
|
// RedirectStandardOutput = true,
|
||||||
// RedirectStandardError = true,
|
// RedirectStandardError = true,
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
UseShellExecute = false
|
UseShellExecute = false,
|
||||||
})!.WaitForExitAsync();
|
WorkingDirectory = workDir
|
||||||
|
});
|
||||||
|
await process!.WaitForExitAsync();
|
||||||
|
return process.ExitCode == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue