diff --git a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs index 25f1158..77970d5 100644 --- a/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs +++ b/src/N_m3u8DL-RE.Parser/Extractor/DASHExtractor2.cs @@ -488,9 +488,21 @@ namespace N_m3u8DL_RE.Parser.Extractor public async Task RefreshPlayListAsync(List streamSpecs) { if (streamSpecs.Count == 0) return; - var (rawText, url) = await HTTPUtil.GetWebSourceAndNewUrlAsync(ParserConfig.OriginalUrl, ParserConfig.Headers); + + var (rawText, url) = ("", ParserConfig.Url); + try + { + (rawText, url) = await HTTPUtil.GetWebSourceAndNewUrlAsync(ParserConfig.Url, ParserConfig.Headers); + } + catch (HttpRequestException) when (ParserConfig.Url!= ParserConfig.OriginalUrl) + { + //当URL无法访问时,再请求原始URL + (rawText, url) = await HTTPUtil.GetWebSourceAndNewUrlAsync(ParserConfig.OriginalUrl, ParserConfig.Headers); + } + ParserConfig.Url = url; SetInitUrl(); + var newStreams = await ExtractStreamsAsync(rawText); foreach (var streamSpec in streamSpecs) { diff --git a/src/N_m3u8DL-RE.Parser/Extractor/HLSExtractor.cs b/src/N_m3u8DL-RE.Parser/Extractor/HLSExtractor.cs index 014da4e..b33e1d0 100644 --- a/src/N_m3u8DL-RE.Parser/Extractor/HLSExtractor.cs +++ b/src/N_m3u8DL-RE.Parser/Extractor/HLSExtractor.cs @@ -506,7 +506,15 @@ namespace N_m3u8DL_RE.Parser.Extractor } else if (url.StartsWith("http")) { - (this.M3u8Content, url) = await HTTPUtil.GetWebSourceAndNewUrlAsync(url, ParserConfig.Headers); + try + { + (this.M3u8Content, url) = await HTTPUtil.GetWebSourceAndNewUrlAsync(url, ParserConfig.Headers); + } + catch (HttpRequestException) when (url != ParserConfig.OriginalUrl) + { + //当URL无法访问时,再请求原始URL + (this.M3u8Content, url) = await HTTPUtil.GetWebSourceAndNewUrlAsync(ParserConfig.OriginalUrl, ParserConfig.Headers); + } } this.M3u8Url = url; @@ -516,10 +524,10 @@ namespace N_m3u8DL_RE.Parser.Extractor public async Task FetchPlayListAsync(List lists) { - if (MasterM3u8Flag && !FirstRefreshFlag) + if (MasterM3u8Flag) { //重新加载master m3u8, 刷新选中流的URL - await LoadM3u8FromUrlAsync(ParserConfig.OriginalUrl); + await LoadM3u8FromUrlAsync(ParserConfig.Url); var newStreams = await ParseMasterListAsync(); newStreams = newStreams.DistinctBy(p => p.Url).ToList(); foreach (var l in lists) @@ -532,11 +540,6 @@ namespace N_m3u8DL_RE.Parser.Extractor } } } - else if (!MasterM3u8Flag && lists.Count == 1 && ParserConfig.OriginalUrl != lists[0].Url) - { - //单m3u8, 但是发生了重定向, 则应从原始URL开始解析 - lists[0].Url = ParserConfig.OriginalUrl; - } for (int i = 0; i < lists.Count; i++) { @@ -555,9 +558,6 @@ namespace N_m3u8DL_RE.Parser.Extractor lists[i].Extension = lists[i].Playlist!.MediaInit != null ? "m4s" : "ts"; } } - - //首次刷新已结束,后续重新加载时应该从master开始重新加载 - FirstRefreshFlag = false; } public async Task RefreshPlayListAsync(List streamSpecs)