优化KEY-URI读取,不抛出异常

This commit is contained in:
nilaoda 2022-07-26 23:43:11 +08:00
parent 3126216d9f
commit 3e71a2286f
1 changed files with 25 additions and 10 deletions

View File

@ -1,5 +1,7 @@
using N_m3u8DL_RE.Common.Entity; using N_m3u8DL_RE.Common.Entity;
using N_m3u8DL_RE.Common.Enum; using N_m3u8DL_RE.Common.Enum;
using N_m3u8DL_RE.Common.Log;
using N_m3u8DL_RE.Common.Resource;
using N_m3u8DL_RE.Common.Util; using N_m3u8DL_RE.Common.Util;
using N_m3u8DL_RE.Parser.Config; using N_m3u8DL_RE.Parser.Config;
using N_m3u8DL_RE.Parser.Util; using N_m3u8DL_RE.Parser.Util;
@ -22,6 +24,8 @@ namespace N_m3u8DL_RE.Parser.Processor.HLS
var method = ParserUtil.GetAttribute(keyLine, "METHOD"); var method = ParserUtil.GetAttribute(keyLine, "METHOD");
var uri = ParserUtil.GetAttribute(keyLine, "URI"); var uri = ParserUtil.GetAttribute(keyLine, "URI");
Logger.Debug("METHOD:{},URI:{},IV:{}", method, uri, iv);
var encryptInfo = new EncryptInfo(method); var encryptInfo = new EncryptInfo(method);
//IV //IV
if (!string.IsNullOrEmpty(iv)) if (!string.IsNullOrEmpty(iv))
@ -30,10 +34,16 @@ namespace N_m3u8DL_RE.Parser.Processor.HLS
} }
//KEY //KEY
try
{
if (uri.ToLower().StartsWith("base64:")) if (uri.ToLower().StartsWith("base64:"))
{ {
encryptInfo.Key = Convert.FromBase64String(uri[7..]); encryptInfo.Key = Convert.FromBase64String(uri[7..]);
} }
else if (uri.ToLower().StartsWith("data:;base64,"))
{
encryptInfo.Key = Convert.FromBase64String(uri[13..]);
}
else if (uri.ToLower().StartsWith("data:text/plain;base64,")) else if (uri.ToLower().StartsWith("data:text/plain;base64,"))
{ {
encryptInfo.Key = Convert.FromBase64String(uri[23..]); encryptInfo.Key = Convert.FromBase64String(uri[23..]);
@ -44,6 +54,11 @@ namespace N_m3u8DL_RE.Parser.Processor.HLS
var bytes = HTTPUtil.GetBytesAsync(segUrl, parserConfig.Headers).Result; var bytes = HTTPUtil.GetBytesAsync(segUrl, parserConfig.Headers).Result;
encryptInfo.Key = bytes; encryptInfo.Key = bytes;
} }
}
catch (Exception ex)
{
Logger.Error(ResString.cmd_loadKeyFailed + ": " + ex.ToString());
}
return encryptInfo; return encryptInfo;
} }