From 2310d0472a2e250efd0d371c90cd12cefee6e96c Mon Sep 17 00:00:00 2001 From: nilaoda Date: Fri, 26 Aug 2022 23:34:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Headers=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 12 +----------- src/N_m3u8DL-RE/CommandLine/MyOption.cs | 2 +- src/N_m3u8DL-RE/Program.cs | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs index 079525c..5aa3ff5 100644 --- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs +++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs @@ -56,18 +56,8 @@ namespace N_m3u8DL_RE.CommandLine /// private static Dictionary ParseHeaders(ArgumentResult result) { - //默认的Headers - var headers = new Dictionary() - { - ["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" - }; var array = result.Tokens.Select(t => t.Value).ToArray(); - var otherHeaders = ConvertUtil.SplitHeaderArrayToDic(array); - foreach (var h in otherHeaders) - { - headers[h.Key] = h.Value; - } - return headers; + return ConvertUtil.SplitHeaderArrayToDic(array); } /// diff --git a/src/N_m3u8DL-RE/CommandLine/MyOption.cs b/src/N_m3u8DL-RE/CommandLine/MyOption.cs index 1403f3b..1672f23 100644 --- a/src/N_m3u8DL-RE/CommandLine/MyOption.cs +++ b/src/N_m3u8DL-RE/CommandLine/MyOption.cs @@ -13,7 +13,7 @@ namespace N_m3u8DL_RE.CommandLine /// /// See: . /// - public Dictionary Headers { get; set; } = new Dictionary(); + public Dictionary Headers { get; set; } = new Dictionary(); /// /// See: . /// diff --git a/src/N_m3u8DL-RE/Program.cs b/src/N_m3u8DL-RE/Program.cs index 75ce3d7..b7403ad 100644 --- a/src/N_m3u8DL-RE/Program.cs +++ b/src/N_m3u8DL-RE/Program.cs @@ -13,7 +13,6 @@ using N_m3u8DL_RE.Config; using N_m3u8DL_RE.Util; using N_m3u8DL_RE.DownloadManager; using N_m3u8DL_RE.CommandLine; -using N_m3u8DL_RE.Entity; namespace N_m3u8DL_RE { @@ -103,12 +102,23 @@ namespace N_m3u8DL_RE } } + //默认的headers + var headers = new Dictionary() + { + ["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" + }; + //添加或替换用户输入的headers + foreach (var item in option.Headers) + { + headers[item.Key] = item.Value; + } + var parserConfig = new ParserConfig() { AppendUrlParams = option.AppendUrlParams, UrlProcessorArgs = option.UrlProcessorArgs, BaseUrl = option.BaseUrl!, - Headers = option.Headers + Headers = headers }; //demo1