From 3e71a2286fad22f18e7e06bef4fec2ce4db21ef1 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Tue, 26 Jul 2022 23:43:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96KEY-URI=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Processor/HLS/DefaultHLSKeyProcessor.cs | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSKeyProcessor.cs b/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSKeyProcessor.cs index efcd560..6828acb 100644 --- a/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSKeyProcessor.cs +++ b/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSKeyProcessor.cs @@ -1,5 +1,7 @@ using N_m3u8DL_RE.Common.Entity; 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.Parser.Config; using N_m3u8DL_RE.Parser.Util; @@ -22,6 +24,8 @@ namespace N_m3u8DL_RE.Parser.Processor.HLS var method = ParserUtil.GetAttribute(keyLine, "METHOD"); var uri = ParserUtil.GetAttribute(keyLine, "URI"); + Logger.Debug("METHOD:{},URI:{},IV:{}", method, uri, iv); + var encryptInfo = new EncryptInfo(method); //IV if (!string.IsNullOrEmpty(iv)) @@ -30,19 +34,30 @@ namespace N_m3u8DL_RE.Parser.Processor.HLS } //KEY - if (uri.ToLower().StartsWith("base64:")) + try { - encryptInfo.Key = Convert.FromBase64String(uri[7..]); + if (uri.ToLower().StartsWith("base64:")) + { + 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,")) + { + encryptInfo.Key = Convert.FromBase64String(uri[23..]); + } + else if (!string.IsNullOrEmpty(uri)) + { + var segUrl = PreProcessUrl(ParserUtil.CombineURL(m3u8Url, uri), parserConfig); + var bytes = HTTPUtil.GetBytesAsync(segUrl, parserConfig.Headers).Result; + encryptInfo.Key = bytes; + } } - else if (uri.ToLower().StartsWith("data:text/plain;base64,")) + catch (Exception ex) { - encryptInfo.Key = Convert.FromBase64String(uri[23..]); - } - else if (!string.IsNullOrEmpty(uri)) - { - var segUrl = PreProcessUrl(ParserUtil.CombineURL(m3u8Url, uri), parserConfig); - var bytes = HTTPUtil.GetBytesAsync(segUrl, parserConfig.Headers).Result; - encryptInfo.Key = bytes; + Logger.Error(ResString.cmd_loadKeyFailed + ": " + ex.ToString()); } return encryptInfo;