优化URL参数追加处理逻辑

This commit is contained in:
nilaoda 2022-11-13 00:06:33 +08:00
parent 0e9d84f529
commit 004575c152
1 changed files with 5 additions and 4 deletions

View File

@ -19,12 +19,13 @@ namespace N_m3u8DL_RE.Parser.Processor
if (paserConfig.AppendUrlParams) if (paserConfig.AppendUrlParams)
{ {
var uriFromConfig = new Uri(paserConfig.Url); var uriFromConfig = new Uri(paserConfig.Url);
var newUri = new Uri(oriUrl); var oldUri = new Uri(oriUrl);
var newQuery = (newUri.Query.TrimStart('?') + "&" + uriFromConfig.Query.TrimStart('?')).Trim('&'); var newQuery = (oldUri.Query.TrimStart('?') + "&" + uriFromConfig.Query.TrimStart('?')).Trim('&');
if (!oriUrl.Contains(uriFromConfig.Query)) var sameLeft = oldUri.GetLeftPart(UriPartial.Path) == uriFromConfig.GetLeftPart(UriPartial.Path);
if (sameLeft && !oriUrl.Contains(uriFromConfig.Query))
{ {
Logger.Debug("Before: " + oriUrl); Logger.Debug("Before: " + oriUrl);
oriUrl = (newUri.GetLeftPart(UriPartial.Path) + "?" + newQuery).TrimEnd('?'); oriUrl = (oldUri.GetLeftPart(UriPartial.Path) + "?" + newQuery).TrimEnd('?');
Logger.Debug("After: " + oriUrl); Logger.Debug("After: " + oriUrl);
} }
} }