支持只输入KEY未输入KID场景自动补全 (#476)

This commit is contained in:
nilaoda 2024-11-02 20:44:00 +08:00 committed by GitHub
parent dd30bd99f9
commit 8a25815c1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 8 deletions

View File

@ -65,6 +65,7 @@ Options:
--urlprocessor-args <urlprocessor-args> 此字符串将直接传递给URL Processor --urlprocessor-args <urlprocessor-args> 此字符串将直接传递给URL Processor
--key <key> 设置解密密钥, 程序调用mp4decrpyt/shaka-packager进行解密. 格式: --key <key> 设置解密密钥, 程序调用mp4decrpyt/shaka-packager进行解密. 格式:
--key KID1:KEY1 --key KID2:KEY2 --key KID1:KEY1 --key KID2:KEY2
对于KEY相同的情况可以直接输入 --key KEY
--key-text-file <key-text-file> 设置密钥文件,程序将从文件中按KID搜寻KEY以解密.(不建议使用特大文件) --key-text-file <key-text-file> 设置密钥文件,程序将从文件中按KID搜寻KEY以解密.(不建议使用特大文件)
--decryption-binary-path <PATH> MP4解密所用工具的全路径, 例如 C:\Tools\mp4decrypt.exe --decryption-binary-path <PATH> MP4解密所用工具的全路径, 例如 C:\Tools\mp4decrypt.exe
--use-shaka-packager 解密时使用shaka-packager替代mp4decrypt [default: False] --use-shaka-packager 解密时使用shaka-packager替代mp4decrypt [default: False]

View File

@ -252,9 +252,9 @@ namespace N_m3u8DL_RE.Common.Resource
), ),
["cmd_keys"] = new TextContainer ["cmd_keys"] = new TextContainer
( (
zhCN: "设置解密密钥, 程序调用mp4decrpyt/shaka-packager进行解密. 格式:\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", zhTW: "設置解密密鑰, 程序調用mp4decrpyt/shaka-packager進行解密. 格式:\r\n--key KID1:KEY1 --key KID2:KEY2\r\n對於KEY相同的情況可以直接輸入 --key KEY",
enUS: "Pass decryption key(s) to mp4decrypt/shaka-packager. format:\r\n--key KID1:KEY1 --key KID2:KEY2" 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 ["cmd_keyText"] = new TextContainer
( (

View File

@ -14,6 +14,7 @@ namespace N_m3u8DL_RE.Util
{ {
if (keys == null || keys.Length == 0) return false; if (keys == null || keys.Length == 0) return false;
var keyPairs = keys.ToList();
string? keyPair = null; string? keyPair = null;
string? trackId = null; string? trackId = null;
@ -24,17 +25,24 @@ namespace N_m3u8DL_RE.Util
if (!string.IsNullOrEmpty(kid)) 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(); if (test.Any()) keyPair = test.First();
} }
// Apple // Apple
if (kid == ZeroKid) if (kid == ZeroKid)
{ {
keyPair = keys.First(); keyPair = keyPairs.First();
trackId = "1"; 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; if (keyPair == null) return false;
//shakaPackager 无法单独解密init文件 //shakaPackager 无法单独解密init文件
@ -61,11 +69,11 @@ namespace N_m3u8DL_RE.Util
{ {
if (trackId == null) if (trackId == null)
{ {
cmd = string.Join(" ", keys.Select(k => $"--key {k}")); cmd = string.Join(" ", keyPairs.Select(k => $"--key {k}"));
} }
else 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 != "") if (init != "")
{ {