From 5cea80476d109bf65857999a038e2fa05ec601db Mon Sep 17 00:00:00 2001 From: nilaoda Date: Tue, 20 Sep 2022 15:49:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BDKEY=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E9=87=8D=E8=AF=95=E6=AC=A1?= =?UTF-8?q?=E6=95=B0(3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE.Parser/Config/ParserConfig.cs | 5 +++++ .../Processor/HLS/DefaultHLSKeyProcessor.cs | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/N_m3u8DL-RE.Parser/Config/ParserConfig.cs b/src/N_m3u8DL-RE.Parser/Config/ParserConfig.cs index 5bacc9e..e377345 100644 --- a/src/N_m3u8DL-RE.Parser/Config/ParserConfig.cs +++ b/src/N_m3u8DL-RE.Parser/Config/ParserConfig.cs @@ -57,5 +57,10 @@ namespace N_m3u8DL_RE.Parser.Config /// 此参数将会传递给URL Processor中 /// public string? UrlProcessorArgs { get; set; } + + /// + /// KEY重试次数 + /// + public int KeyRetryCount { get; set; } = 3; } } diff --git a/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSKeyProcessor.cs b/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSKeyProcessor.cs index 128b5b8..68d72f8 100644 --- a/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSKeyProcessor.cs +++ b/src/N_m3u8DL-RE.Parser/Processor/HLS/DefaultHLSKeyProcessor.cs @@ -5,6 +5,7 @@ using N_m3u8DL_RE.Common.Resource; using N_m3u8DL_RE.Common.Util; using N_m3u8DL_RE.Parser.Config; using N_m3u8DL_RE.Parser.Util; +using Spectre.Console; using System; using System.Collections.Generic; using System.Linq; @@ -62,9 +63,21 @@ namespace N_m3u8DL_RE.Parser.Processor.HLS } else if (!string.IsNullOrEmpty(uri)) { - var segUrl = PreProcessUrl(ParserUtil.CombineURL(m3u8Url, uri), parserConfig); - var bytes = HTTPUtil.GetBytesAsync(segUrl, parserConfig.Headers).Result; - encryptInfo.Key = bytes; + var retryCount = parserConfig.KeyRetryCount; + getHttpKey: + try + { + var segUrl = PreProcessUrl(ParserUtil.CombineURL(m3u8Url, uri), parserConfig); + var bytes = HTTPUtil.GetBytesAsync(segUrl, parserConfig.Headers).Result; + encryptInfo.Key = bytes; + } + catch (Exception _ex) + { + Logger.WarnMarkUp($"[grey]{_ex.Message.EscapeMarkup()} retryCount: {retryCount}[/]"); + Thread.Sleep(1000); + if (retryCount > 0) goto getHttpKey; + else throw; + } } } catch (Exception ex)