From 8a25815c1fe53f29feb7e37bbcdf171f67220082 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Sat, 2 Nov 2024 20:44:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8F=AA=E8=BE=93=E5=85=A5KE?= =?UTF-8?q?Y=E6=9C=AA=E8=BE=93=E5=85=A5KID=E5=9C=BA=E6=99=AF=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=A1=A5=E5=85=A8=20(#476)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src/N_m3u8DL-RE.Common/Resource/StaticText.cs | 6 +++--- src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 08f7f6e..37d7f88 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Options: --urlprocessor-args 此字符串将直接传递给URL Processor --key 设置解密密钥, 程序调用mp4decrpyt/shaka-packager进行解密. 格式: --key KID1:KEY1 --key KID2:KEY2 + 对于KEY相同的情况可以直接输入 --key KEY --key-text-file 设置密钥文件,程序将从文件中按KID搜寻KEY以解密.(不建议使用特大文件) --decryption-binary-path MP4解密所用工具的全路径, 例如 C:\Tools\mp4decrypt.exe --use-shaka-packager 解密时使用shaka-packager替代mp4decrypt [default: False] diff --git a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs index a1bf517..23f84f3 100644 --- a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs +++ b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs @@ -252,9 +252,9 @@ namespace N_m3u8DL_RE.Common.Resource ), ["cmd_keys"] = new TextContainer ( - zhCN: "设置解密密钥, 程序调用mp4decrpyt/shaka-packager进行解密. 格式:\r\n--key KID1:KEY1 --key KID2:KEY2", - zhTW: "設置解密密鑰, 程序調用mp4decrpyt/shaka-packager進行解密. 格式:\r\n--key KID1:KEY1 --key KID2:KEY2", - enUS: "Pass decryption key(s) to mp4decrypt/shaka-packager. format:\r\n--key KID1:KEY1 --key KID2:KEY2" + zhCN: "设置解密密钥, 程序调用mp4decrpyt/shaka-packager进行解密. 格式:\r\n--key KID1:KEY1 --key KID2:KEY2\r\n对于KEY相同的情况可以直接输入 --key KEY", + zhTW: "設置解密密鑰, 程序調用mp4decrpyt/shaka-packager進行解密. 格式:\r\n--key KID1:KEY1 --key KID2:KEY2\r\n對於KEY相同的情況可以直接輸入 --key KEY", + enUS: "Set decryption key(s) to mp4decrypt/shaka-packager. format:\r\n--key KID1:KEY1 --key KID2:KEY2\r\nor use --key KEY if all tracks share the same key." ), ["cmd_keyText"] = new TextContainer ( diff --git a/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs b/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs index a04291e..d8b38a8 100644 --- a/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs +++ b/src/N_m3u8DL-RE/Util/MP4DecryptUtil.cs @@ -14,6 +14,7 @@ namespace N_m3u8DL_RE.Util { if (keys == null || keys.Length == 0) return false; + var keyPairs = keys.ToList(); string? keyPair = null; string? trackId = null; @@ -24,17 +25,24 @@ namespace N_m3u8DL_RE.Util if (!string.IsNullOrEmpty(kid)) { - var test = keys.Where(k => k.StartsWith(kid)); + var test = keyPairs.Where(k => k.StartsWith(kid)); if (test.Any()) keyPair = test.First(); } - //Apple + // Apple if (kid == ZeroKid) { - keyPair = keys.First(); + keyPair = keyPairs.First(); trackId = "1"; } + // user only input key, append kid + if (keyPair == null && keyPairs.Count == 1 && !keyPairs.First().Contains(':')) + { + keyPairs = keyPairs.Select(x => $"{kid}:{x}").ToList(); + keyPair = keyPairs.First(); + } + if (keyPair == null) return false; //shakaPackager 无法单独解密init文件 @@ -61,11 +69,11 @@ namespace N_m3u8DL_RE.Util { if (trackId == null) { - cmd = string.Join(" ", keys.Select(k => $"--key {k}")); + cmd = string.Join(" ", keyPairs.Select(k => $"--key {k}")); } else { - cmd = string.Join(" ", keys.Select(k => $"--key {trackId}:{k.Split(':')[1]}")); + cmd = string.Join(" ", keyPairs.Select(k => $"--key {trackId}:{k.Split(':')[1]}")); } if (init != "") {