From 33a40d2f78f5768a30abd88ac2898f5b1f63ba26 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Wed, 30 Nov 2022 22:45:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96URL=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=8B=BC=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extractor/HLSExtractor.cs | 2 +- .../Processor/DefaultUrlProcessor.cs | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/N_m3u8DL-RE.Parser/Extractor/HLSExtractor.cs b/src/N_m3u8DL-RE.Parser/Extractor/HLSExtractor.cs index 46429e8..546f8e5 100644 --- a/src/N_m3u8DL-RE.Parser/Extractor/HLSExtractor.cs +++ b/src/N_m3u8DL-RE.Parser/Extractor/HLSExtractor.cs @@ -546,7 +546,7 @@ namespace N_m3u8DL_RE.Parser.Extractor { //重新加载m3u8 await LoadM3u8FromUrlAsync(lists[i].Url!); - lists[i].Playlist = await ParseListAsync(); + lists[i].Playlist!.MediaParts = (await ParseListAsync()).MediaParts; //不更新init if (lists[i].MediaType == MediaType.SUBTITLES) { var a = lists[i].Playlist!.MediaParts.Any(p => p.MediaSegments.Any(m => m.Url.Contains(".ttml"))); diff --git a/src/N_m3u8DL-RE.Parser/Processor/DefaultUrlProcessor.cs b/src/N_m3u8DL-RE.Parser/Processor/DefaultUrlProcessor.cs index dc3dd37..ee518f3 100644 --- a/src/N_m3u8DL-RE.Parser/Processor/DefaultUrlProcessor.cs +++ b/src/N_m3u8DL-RE.Parser/Processor/DefaultUrlProcessor.cs @@ -7,25 +7,35 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using System.Web; namespace N_m3u8DL_RE.Parser.Processor { public class DefaultUrlProcessor : UrlProcessor { - public override bool CanProcess(ExtractorType extractorType, string oriUrl, ParserConfig paserConfig) => true; + public override bool CanProcess(ExtractorType extractorType, string oriUrl, ParserConfig paserConfig) => paserConfig.AppendUrlParams; public override string Process(string oriUrl, ParserConfig paserConfig) { - if (paserConfig.AppendUrlParams && oriUrl.StartsWith("http")) + if (oriUrl.StartsWith("http")) { var uriFromConfig = new Uri(paserConfig.Url); + var uriFromConfigQuery = HttpUtility.ParseQueryString(uriFromConfig.Query); + var oldUri = new Uri(oriUrl); - var newQuery = (oldUri.Query.TrimStart('?') + "&" + uriFromConfig.Query.TrimStart('?')).Trim('&'); - var sameLeft = oldUri.GetLeftPart(UriPartial.Path) == uriFromConfig.GetLeftPart(UriPartial.Path); - if (sameLeft && !oriUrl.Contains(uriFromConfig.Query)) + var newQuery = HttpUtility.ParseQueryString(oldUri.Query); + foreach (var item in uriFromConfigQuery.AllKeys) + { + if (newQuery.AllKeys.Contains(item)) + newQuery.Set(item, uriFromConfigQuery.Get(item)); + else + newQuery.Add(item, uriFromConfigQuery.Get(item)); + } + + if (!string.IsNullOrEmpty(newQuery.ToString())) { Logger.Debug("Before: " + oriUrl); - oriUrl = (oldUri.GetLeftPart(UriPartial.Path) + "?" + newQuery).TrimEnd('?'); + oriUrl = (oldUri.GetLeftPart(UriPartial.Path) + "?" + newQuery.ToString()).TrimEnd('?'); Logger.Debug("After: " + oriUrl); } }