优化URL参数拼接
This commit is contained in:
parent
456f1fe69e
commit
33a40d2f78
|
@ -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")));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue