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); } }