下载KEY时,增加默认重试次数(3)

This commit is contained in:
nilaoda 2022-09-20 15:49:18 +08:00
parent c935ca624e
commit 5cea80476d
2 changed files with 21 additions and 3 deletions

View File

@ -57,5 +57,10 @@ namespace N_m3u8DL_RE.Parser.Config
/// 此参数将会传递给URL Processor中 /// 此参数将会传递给URL Processor中
/// </summary> /// </summary>
public string? UrlProcessorArgs { get; set; } public string? UrlProcessorArgs { get; set; }
/// <summary>
/// KEY重试次数
/// </summary>
public int KeyRetryCount { get; set; } = 3;
} }
} }

View File

@ -5,6 +5,7 @@ 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;
using Spectre.Console;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -62,9 +63,21 @@ namespace N_m3u8DL_RE.Parser.Processor.HLS
} }
else if (!string.IsNullOrEmpty(uri)) else if (!string.IsNullOrEmpty(uri))
{ {
var segUrl = PreProcessUrl(ParserUtil.CombineURL(m3u8Url, uri), parserConfig); var retryCount = parserConfig.KeyRetryCount;
var bytes = HTTPUtil.GetBytesAsync(segUrl, parserConfig.Headers).Result; getHttpKey:
encryptInfo.Key = bytes; 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) catch (Exception ex)