From 4b0ddce190e4be0a4f7db4498290a21f8be7e633 Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Tue, 12 Dec 2023 15:33:20 +0800
Subject: [PATCH 01/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A?=
=?UTF-8?q?=E4=B9=89Console,=E5=8F=AF=E5=BC=BA=E5=88=B6=E4=BB=A5ansi?=
=?UTF-8?q?=E6=A8=A1=E5=BC=8F=E8=BE=93=E5=87=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Log/CustomAnsiConsole.cs | 49 +++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
new file mode 100644
index 0000000..88e508a
--- /dev/null
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -0,0 +1,49 @@
+using Spectre.Console;
+
+namespace N_m3u8DL_RE.Common.Log;
+
+///
+/// A console capable of writing ANSI escape sequences.
+///
+public static class CustomAnsiConsole
+{
+ // var ansiConsoleSettings = new AnsiConsoleSettings();
+ // ansiConsoleSettings.Ansi = AnsiSupport.Yes;
+ public static IAnsiConsole Console { get; set; }
+
+ public static void InitConsole(bool forceAnsi)
+ {
+ if (forceAnsi)
+
+ {
+ var ansiConsoleSettings = new AnsiConsoleSettings();
+ ansiConsoleSettings.Interactive = InteractionSupport.Yes;
+ ansiConsoleSettings.Ansi = AnsiSupport.Yes;
+ // ansiConsoleSettings.Ansi = AnsiSupport.Yes;
+ Console = AnsiConsole.Create(ansiConsoleSettings);
+ }
+ else
+ {
+ Console = AnsiConsole.Console;
+ }
+ }
+
+ ///
+ /// Writes the specified markup to the console.
+ ///
+ /// The value to write.
+ public static void Markup(string value)
+ {
+ Console.Markup(value);
+ }
+
+ ///
+ /// Writes the specified markup, followed by the current line terminator, to the console.
+ ///
+ /// The value to write.
+ public static void MarkupLine(string value)
+ {
+ Console.MarkupLine(value);
+ }
+
+}
\ No newline at end of file
From 32806247e8e2d88ab2527bcc6283201a57ed132c Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Tue, 12 Dec 2023 15:34:51 +0800
Subject: [PATCH 02/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20`--force-ansi-consol?=
=?UTF-8?q?e`=20=E4=BB=A5=E5=9C=A8=E9=9D=9Eansi=E7=8E=AF=E5=A2=83=E6=98=BE?=
=?UTF-8?q?=E7=A4=BA=E8=BF=9B=E5=BA=A6=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/N_m3u8DL-RE.Common/Log/Logger.cs | 22 +++++++++++++------
src/N_m3u8DL-RE.Common/Resource/ResString.cs | 1 +
src/N_m3u8DL-RE.Common/Resource/StaticText.cs | 6 +++++
src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 4 +++-
src/N_m3u8DL-RE/CommandLine/MyOption.cs | 4 ++++
.../DownloadManager/HTTPLiveRecordManager.cs | 2 +-
.../DownloadManager/SimpleDownloadManager.cs | 4 ++--
.../SimpleLiveRecordManager2.cs | 2 +-
src/N_m3u8DL-RE/Program.cs | 1 +
src/N_m3u8DL-RE/Util/FilterUtil.cs | 2 +-
10 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/Logger.cs b/src/N_m3u8DL-RE.Common/Log/Logger.cs
index 897f086..4ea9016 100644
--- a/src/N_m3u8DL-RE.Common/Log/Logger.cs
+++ b/src/N_m3u8DL-RE.Common/Log/Logger.cs
@@ -40,7 +40,11 @@ public static void InitLogFile()
try
{
var logDir = Path.GetDirectoryName(Environment.ProcessPath) + "/Logs";
- if (!Directory.Exists(logDir)) { Directory.CreateDirectory(logDir); }
+ if (!Directory.Exists(logDir))
+ {
+ Directory.CreateDirectory(logDir);
+ }
+
LogFilePath = Path.Combine(logDir, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff") + ".log");
//若文件存在则加序号
int index = 1;
@@ -49,11 +53,12 @@ public static void InitLogFile()
{
LogFilePath = Path.Combine(Path.GetDirectoryName(LogFilePath)!, $"{fileName}-{index++}.log");
}
+
string now = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
string init = "LOG " + DateTime.Now.ToString("yyyy/MM/dd") + Environment.NewLine
- + "Save Path: " + Path.GetDirectoryName(LogFilePath) + Environment.NewLine
- + "Task Start: " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + Environment.NewLine
- + "Task CommandLine: " + Environment.CommandLine;
+ + "Save Path: " + Path.GetDirectoryName(LogFilePath) + Environment.NewLine
+ + "Task Start: " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + Environment.NewLine
+ + "Task CommandLine: " + Environment.CommandLine;
init += $"{Environment.NewLine}{Environment.NewLine}";
File.WriteAllText(LogFilePath, init, Encoding.UTF8);
}
@@ -74,13 +79,14 @@ private static void HandleLog(string write, string subWrite = "")
{
if (subWrite == "")
{
- AnsiConsole.MarkupLine(write);
+ CustomAnsiConsole.MarkupLine(write);
}
else
{
- AnsiConsole.Markup(write);
+ CustomAnsiConsole.Markup(write);
Console.WriteLine(subWrite);
}
+
if (IsWriteFile && File.Exists(LogFilePath))
{
var plain = write.RemoveMarkup() + subWrite.RemoveMarkup();
@@ -112,6 +118,7 @@ private static string ReplaceVars(string data, params object[] ps)
{
data = VarsRepRegex().Replace(data, $"{ps[i]}", 1);
}
+
return data;
}
@@ -202,6 +209,7 @@ public static void ErrorMarkUp(Exception exception)
{
data = exception.ToString().EscapeMarkup();
}
+
ErrorMarkUp(data);
}
@@ -233,4 +241,4 @@ public static void Extra(string data, params object[] ps)
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/N_m3u8DL-RE.Common/Resource/ResString.cs b/src/N_m3u8DL-RE.Common/Resource/ResString.cs
index dd50078..afc099b 100644
--- a/src/N_m3u8DL-RE.Common/Resource/ResString.cs
+++ b/src/N_m3u8DL-RE.Common/Resource/ResString.cs
@@ -55,6 +55,7 @@ public class ResString
public static string cmd_customHLSKey { get => GetText("cmd_customHLSKey"); }
public static string cmd_customHLSIv { get => GetText("cmd_customHLSIv"); }
public static string cmd_Input { get => GetText("cmd_Input"); }
+ public static string cmd_force_ansi_console { get => GetText("cmd_force_ansi_console"); }
public static string cmd_keys { get => GetText("cmd_keys"); }
public static string cmd_keyText { get => GetText("cmd_keyText"); }
public static string cmd_loadKeyFailed { get => GetText("cmd_loadKeyFailed"); }
diff --git a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
index df1732f..730b914 100644
--- a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
+++ b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
@@ -22,6 +22,12 @@ internal class StaticText
zhTW: "即時解密已被強制關閉",
enUS: "Real-time decryption has been disabled"
),
+ ["force_ansi_console"] = new TextContainer
+ (
+ zhCN: "强制认定终端为支持Ansi且可交互的终端",
+ zhTW: "強制認定終端為支援Ansi且可交往的終端",
+ enUS: "Force assuming the terminal is ANSI-compatible and interactive"
+ ),
["customRangeWarn"] = new TextContainer
(
zhCN: "请注意,自定义下载范围有时会导致音画不同步",
diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
index 2237d02..1a68ac3 100644
--- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
+++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
@@ -53,6 +53,7 @@ internal partial class CommandInvoker
private readonly static Option AppendUrlParams = new(new string[] { "--append-url-params" }, description: ResString.cmd_appendUrlParams, getDefaultValue: () => false);
private readonly static Option MP4RealTimeDecryption = new (new string[] { "--mp4-real-time-decryption" }, description: ResString.cmd_MP4RealTimeDecryption, getDefaultValue: () => false);
private readonly static Option UseShakaPackager = new (new string[] { "--use-shaka-packager" }, description: ResString.cmd_useShakaPackager, getDefaultValue: () => false);
+ private readonly static Option ForceAnsiConsole = new(new string[] { "--force-ansi-console" }, description: ResString.cmd_force_ansi_console);
private readonly static Option DecryptionBinaryPath = new(new string[] { "--decryption-binary-path" }, description: ResString.cmd_decryptionBinaryPath) { ArgumentHelpName = "PATH" };
private readonly static Option FFmpegBinaryPath = new(new string[] { "--ffmpeg-binary-path" }, description: ResString.cmd_ffmpegBinaryPath) { ArgumentHelpName = "PATH" };
private readonly static Option BaseUrl = new(new string[] { "--base-url" }, description: ResString.cmd_baseUrl);
@@ -484,6 +485,7 @@ protected override MyOption GetBoundValue(BindingContext bindingContext)
var option = new MyOption
{
Input = bindingContext.ParseResult.GetValueForArgument(Input),
+ ForceAnsiConsole = bindingContext.ParseResult.GetValueForOption(ForceAnsiConsole),
LogLevel = bindingContext.ParseResult.GetValueForOption(LogLevel),
AutoSelect = bindingContext.ParseResult.GetValueForOption(AutoSelect),
SkipMerge = bindingContext.ParseResult.GetValueForOption(SkipMerge),
@@ -594,7 +596,7 @@ public static async Task InvokeArgs(string[] args, Func act
var rootCommand = new RootCommand(VERSION_INFO)
{
- Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
+ Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, ForceAnsiConsole,AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
BinaryMerge, UseFFmpegConcatDemuxer, DelAfterDone, NoDateInfo, NoLog, WriteMetaJson, AppendUrlParams, ConcurrentDownload, Headers, /**SavePattern,**/ SubOnly, SubtitleFormat, AutoSubtitleFix,
FFmpegBinaryPath,
LogLevel, UILanguage, UrlProcessorArgs, Keys, KeyTextFile, DecryptionBinaryPath, UseShakaPackager, MP4RealTimeDecryption,
diff --git a/src/N_m3u8DL-RE/CommandLine/MyOption.cs b/src/N_m3u8DL-RE/CommandLine/MyOption.cs
index 1bb4478..7d748fc 100644
--- a/src/N_m3u8DL-RE/CommandLine/MyOption.cs
+++ b/src/N_m3u8DL-RE/CommandLine/MyOption.cs
@@ -85,6 +85,10 @@ internal class MyOption
///
public bool BinaryMerge { get; set; }
///
+ /// See: .
+ ///
+ public bool ForceAnsiConsole { get; set; }
+ ///
/// See: .
///
public bool UseFFmpegConcatDemuxer { get; set; }
diff --git a/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs b/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs
index 8bcab13..da7d137 100644
--- a/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs
+++ b/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs
@@ -197,7 +197,7 @@ public async Task StartRecordAsync()
ConcurrentDictionary SpeedContainerDic = new(); //速度计算
ConcurrentDictionary Results = new();
- var progress = AnsiConsole.Progress().AutoClear(true);
+ var progress = CustomAnsiConsole.Console.Progress().AutoClear(true);
progress.AutoRefresh = DownloaderConfig.MyOptions.LogLevel != LogLevel.OFF;
//进度条的列定义
diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
index 21951fa..e07fc1f 100644
--- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
+++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
@@ -616,8 +616,8 @@ public async Task StartDownloadAsync()
{
ConcurrentDictionary SpeedContainerDic = new(); //速度计算
ConcurrentDictionary Results = new();
-
- var progress = AnsiConsole.Progress().AutoClear(true);
+
+ var progress = CustomAnsiConsole.Console.Progress().AutoClear(true);
progress.AutoRefresh = DownloaderConfig.MyOptions.LogLevel != LogLevel.OFF;
//进度条的列定义
diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
index 2458923..2d393e7 100644
--- a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
+++ b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
@@ -801,7 +801,7 @@ public async Task StartRecordAsync()
await StreamingUtil.WriteMasterListAsync(SelectedSteams, saveName, saveDir);
}*/
- var progress = AnsiConsole.Progress().AutoClear(true);
+ var progress = CustomAnsiConsole.Console.Progress().AutoClear(true);
progress.AutoRefresh = DownloaderConfig.MyOptions.LogLevel != LogLevel.OFF;
//进度条的列定义
diff --git a/src/N_m3u8DL-RE/Program.cs b/src/N_m3u8DL-RE/Program.cs
index b522fb5..853ddf3 100644
--- a/src/N_m3u8DL-RE/Program.cs
+++ b/src/N_m3u8DL-RE/Program.cs
@@ -70,6 +70,7 @@ static int GetOrder(StreamSpec streamSpec)
static async Task DoWorkAsync(MyOption option)
{
+ CustomAnsiConsole.InitConsole(option.ForceAnsiConsole);
//检测更新
CheckUpdateAsync();
diff --git a/src/N_m3u8DL-RE/Util/FilterUtil.cs b/src/N_m3u8DL-RE/Util/FilterUtil.cs
index f89a595..80a1a6b 100644
--- a/src/N_m3u8DL-RE/Util/FilterUtil.cs
+++ b/src/N_m3u8DL-RE/Util/FilterUtil.cs
@@ -135,7 +135,7 @@ public static List SelectStreams(IEnumerable lists)
prompt.Select(basicStreams.Concat(audios).Concat(subs).First());
//多选
- var selectedStreams = AnsiConsole.Prompt(prompt);
+ var selectedStreams = CustomAnsiConsole.Console.Prompt(prompt);
return selectedStreams;
}
From 9a047dee727498268b0ba0259d200062de12016a Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Tue, 12 Dec 2023 15:54:53 +0800
Subject: [PATCH 03/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E4=BA=8E?=
=?UTF-8?q?=E7=A7=BB=E9=99=A4ANSI=E9=A2=9C=E8=89=B2=E7=9A=84=20`--noansi`?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Log/CustomAnsiConsole.cs | 44 ++++++++++++++++---
src/N_m3u8DL-RE.Common/Resource/ResString.cs | 1 +
src/N_m3u8DL-RE.Common/Resource/StaticText.cs | 8 +++-
src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 4 +-
src/N_m3u8DL-RE/CommandLine/MyOption.cs | 4 ++
src/N_m3u8DL-RE/Program.cs | 2 +-
6 files changed, 55 insertions(+), 8 deletions(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index 88e508a..d280bd7 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -1,7 +1,33 @@
-using Spectre.Console;
+using System.Text;
+using System.Text.RegularExpressions;
+using Spectre.Console;
namespace N_m3u8DL_RE.Common.Log;
+public class NonAnsiWriter : TextWriter
+{
+ public override Encoding Encoding => Encoding.UTF8;
+
+ public override void Write(char value)
+ {
+ Console.Write(value);
+ }
+
+ public override void Write(string value)
+ {
+ RemoveAnsiEscapeSequences(value);
+ }
+
+ private void RemoveAnsiEscapeSequences(string input)
+ {
+ // Use regular expression to remove ANSI escape sequences
+ string output = Regex.Replace(input, @"\x1B\[[0-?]*[ -/]*[@-~]", "");
+
+ // Implement your custom write logic here, e.g., write to console
+ Console.Write(output);
+ }
+}
+
///
/// A console capable of writing ANSI escape sequences.
///
@@ -11,12 +37,16 @@ public static class CustomAnsiConsole
// ansiConsoleSettings.Ansi = AnsiSupport.Yes;
public static IAnsiConsole Console { get; set; }
- public static void InitConsole(bool forceAnsi)
+ public static void InitConsole(bool forceAnsi, bool noansi)
{
if (forceAnsi)
-
{
var ansiConsoleSettings = new AnsiConsoleSettings();
+ if (noansi)
+ {
+ ansiConsoleSettings.Out = new AnsiConsoleOutput(new NonAnsiWriter());
+ }
+
ansiConsoleSettings.Interactive = InteractionSupport.Yes;
ansiConsoleSettings.Ansi = AnsiSupport.Yes;
// ansiConsoleSettings.Ansi = AnsiSupport.Yes;
@@ -24,7 +54,12 @@ public static void InitConsole(bool forceAnsi)
}
else
{
- Console = AnsiConsole.Console;
+ var ansiConsoleSettings = new AnsiConsoleSettings();
+ if (noansi)
+ {
+ ansiConsoleSettings.Out = new AnsiConsoleOutput(new NonAnsiWriter());
+ }
+ Console = AnsiConsole.Create(ansiConsoleSettings);
}
}
@@ -45,5 +80,4 @@ public static void MarkupLine(string value)
{
Console.MarkupLine(value);
}
-
}
\ No newline at end of file
diff --git a/src/N_m3u8DL-RE.Common/Resource/ResString.cs b/src/N_m3u8DL-RE.Common/Resource/ResString.cs
index afc099b..fa546d2 100644
--- a/src/N_m3u8DL-RE.Common/Resource/ResString.cs
+++ b/src/N_m3u8DL-RE.Common/Resource/ResString.cs
@@ -56,6 +56,7 @@ public class ResString
public static string cmd_customHLSIv { get => GetText("cmd_customHLSIv"); }
public static string cmd_Input { get => GetText("cmd_Input"); }
public static string cmd_force_ansi_console { get => GetText("cmd_force_ansi_console"); }
+ public static string cmd_noansi { get => GetText("cmd_noansi"); }
public static string cmd_keys { get => GetText("cmd_keys"); }
public static string cmd_keyText { get => GetText("cmd_keyText"); }
public static string cmd_loadKeyFailed { get => GetText("cmd_loadKeyFailed"); }
diff --git a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
index 730b914..31e412f 100644
--- a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
+++ b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
@@ -22,12 +22,18 @@ internal class StaticText
zhTW: "即時解密已被強制關閉",
enUS: "Real-time decryption has been disabled"
),
- ["force_ansi_console"] = new TextContainer
+ ["cmd_force_ansi_console"] = new TextContainer
(
zhCN: "强制认定终端为支持Ansi且可交互的终端",
zhTW: "強制認定終端為支援Ansi且可交往的終端",
enUS: "Force assuming the terminal is ANSI-compatible and interactive"
),
+ ["cmd_noansi"] = new TextContainer
+ (
+ zhCN: "去除ansi颜色",
+ zhTW: "關閉ansi顏色",
+ enUS: "Remove ANSI colors"
+ ),
["customRangeWarn"] = new TextContainer
(
zhCN: "请注意,自定义下载范围有时会导致音画不同步",
diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
index 1a68ac3..7fee8cb 100644
--- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
+++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
@@ -54,6 +54,7 @@ internal partial class CommandInvoker
private readonly static Option MP4RealTimeDecryption = new (new string[] { "--mp4-real-time-decryption" }, description: ResString.cmd_MP4RealTimeDecryption, getDefaultValue: () => false);
private readonly static Option UseShakaPackager = new (new string[] { "--use-shaka-packager" }, description: ResString.cmd_useShakaPackager, getDefaultValue: () => false);
private readonly static Option ForceAnsiConsole = new(new string[] { "--force-ansi-console" }, description: ResString.cmd_force_ansi_console);
+ private readonly static Option Noansi = new(new string[] { "--noansi" }, description: ResString.cmd_noansi);
private readonly static Option DecryptionBinaryPath = new(new string[] { "--decryption-binary-path" }, description: ResString.cmd_decryptionBinaryPath) { ArgumentHelpName = "PATH" };
private readonly static Option FFmpegBinaryPath = new(new string[] { "--ffmpeg-binary-path" }, description: ResString.cmd_ffmpegBinaryPath) { ArgumentHelpName = "PATH" };
private readonly static Option BaseUrl = new(new string[] { "--base-url" }, description: ResString.cmd_baseUrl);
@@ -486,6 +487,7 @@ protected override MyOption GetBoundValue(BindingContext bindingContext)
{
Input = bindingContext.ParseResult.GetValueForArgument(Input),
ForceAnsiConsole = bindingContext.ParseResult.GetValueForOption(ForceAnsiConsole),
+ Noansi = bindingContext.ParseResult.GetValueForOption(Noansi),
LogLevel = bindingContext.ParseResult.GetValueForOption(LogLevel),
AutoSelect = bindingContext.ParseResult.GetValueForOption(AutoSelect),
SkipMerge = bindingContext.ParseResult.GetValueForOption(SkipMerge),
@@ -596,7 +598,7 @@ public static async Task InvokeArgs(string[] args, Func act
var rootCommand = new RootCommand(VERSION_INFO)
{
- Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, ForceAnsiConsole,AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
+ Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, ForceAnsiConsole,Noansi,AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
BinaryMerge, UseFFmpegConcatDemuxer, DelAfterDone, NoDateInfo, NoLog, WriteMetaJson, AppendUrlParams, ConcurrentDownload, Headers, /**SavePattern,**/ SubOnly, SubtitleFormat, AutoSubtitleFix,
FFmpegBinaryPath,
LogLevel, UILanguage, UrlProcessorArgs, Keys, KeyTextFile, DecryptionBinaryPath, UseShakaPackager, MP4RealTimeDecryption,
diff --git a/src/N_m3u8DL-RE/CommandLine/MyOption.cs b/src/N_m3u8DL-RE/CommandLine/MyOption.cs
index 7d748fc..ab5e90f 100644
--- a/src/N_m3u8DL-RE/CommandLine/MyOption.cs
+++ b/src/N_m3u8DL-RE/CommandLine/MyOption.cs
@@ -89,6 +89,10 @@ internal class MyOption
///
public bool ForceAnsiConsole { get; set; }
///
+ /// See: .
+ ///
+ public bool Noansi { get; set; }
+ ///
/// See: .
///
public bool UseFFmpegConcatDemuxer { get; set; }
diff --git a/src/N_m3u8DL-RE/Program.cs b/src/N_m3u8DL-RE/Program.cs
index 853ddf3..a1b2fc8 100644
--- a/src/N_m3u8DL-RE/Program.cs
+++ b/src/N_m3u8DL-RE/Program.cs
@@ -70,7 +70,7 @@ static int GetOrder(StreamSpec streamSpec)
static async Task DoWorkAsync(MyOption option)
{
- CustomAnsiConsole.InitConsole(option.ForceAnsiConsole);
+ CustomAnsiConsole.InitConsole(option.ForceAnsiConsole,option.Noansi);
//检测更新
CheckUpdateAsync();
From b5cfaf7ba7bdb82ff64df7bfc982ff3d28cb1b6d Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Tue, 12 Dec 2023 17:03:59 +0800
Subject: [PATCH 04/16] =?UTF-8?q?=E5=8F=AA=E5=8E=BB=E9=99=A4=E9=A2=9C?=
=?UTF-8?q?=E8=89=B2=E5=92=8C=E6=8C=87=E9=92=88=E7=A7=BB=E5=8A=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index d280bd7..0dba82f 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -21,7 +21,8 @@ public override void Write(string value)
private void RemoveAnsiEscapeSequences(string input)
{
// Use regular expression to remove ANSI escape sequences
- string output = Regex.Replace(input, @"\x1B\[[0-?]*[ -/]*[@-~]", "");
+ string output = Regex.Replace(input, @"\x1B\[([\d]+;?)+m", "");
+ output = Regex.Replace(input, @"\[\d+[AK]", "");
// Implement your custom write logic here, e.g., write to console
Console.Write(output);
From 8bd0bbc8d5a3a0fb5546dccd5a9071a4d7465727 Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Tue, 12 Dec 2023 19:46:10 +0800
Subject: [PATCH 05/16] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=B3=BB=E7=BB=9F?=
=?UTF-8?q?=E9=BB=98=E8=AE=A4=E8=BE=93=E5=87=BA=E7=BC=96=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index 0dba82f..ba8c88c 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -6,7 +6,9 @@ namespace N_m3u8DL_RE.Common.Log;
public class NonAnsiWriter : TextWriter
{
- public override Encoding Encoding => Encoding.UTF8;
+ public override Encoding Encoding => Console.OutputEncoding;
+
+
public override void Write(char value)
{
From e02a4396b5f84dcb6390c78149d3d28fd447b94d Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Tue, 12 Dec 2023 20:05:27 +0800
Subject: [PATCH 06/16] =?UTF-8?q?=E4=B8=8D=E9=87=8D=E5=A4=8D=E8=BE=93?=
=?UTF-8?q?=E5=87=BA=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF=E7=9A=84?=
=?UTF-8?q?=E6=AD=A3=E5=88=99=E6=9B=BF=E6=8D=A2=EF=BC=8C=E8=A1=A5=E5=85=85?=
=?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=BF=87=E6=BB=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Log/CustomAnsiConsole.cs | 26 +++++++++++++++----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index ba8c88c..68fc1a6 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -7,8 +7,9 @@ namespace N_m3u8DL_RE.Common.Log;
public class NonAnsiWriter : TextWriter
{
public override Encoding Encoding => Console.OutputEncoding;
-
-
+
+ private string lastOut = "";
+ private int dupCount = 0;
public override void Write(char value)
{
@@ -17,15 +18,30 @@ public override void Write(char value)
public override void Write(string value)
{
+ if (lastOut == value)
+ {
+ dupCount++;
+ return;
+ }
+
+ if (dupCount!=0)
+ {
+ Console.Write($"Suppress {dupCount} duplicate out");
+ dupCount = 0;
+ }
+ lastOut = value;
RemoveAnsiEscapeSequences(value);
}
private void RemoveAnsiEscapeSequences(string input)
{
// Use regular expression to remove ANSI escape sequences
- string output = Regex.Replace(input, @"\x1B\[([\d]+;?)+m", "");
- output = Regex.Replace(input, @"\[\d+[AK]", "");
-
+ string output = Regex.Replace(input, @"\x1B\[(\d+;?)+m", "");
+ output = Regex.Replace(output, @"\[\??\d+[AKl]", "");
+ if (string.IsNullOrWhiteSpace(output))
+ {
+ return;
+ }
// Implement your custom write logic here, e.g., write to console
Console.Write(output);
}
From 60109b9b2b8c3c719c1ddfd873d061428a5c7e05 Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Tue, 12 Dec 2023 21:07:24 +0800
Subject: [PATCH 07/16] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=9C=A8NoAnsi?=
=?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=E7=9A=84=E6=97=A0=E7=94=A8=E8=BE=93?=
=?UTF-8?q?=E5=87=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs | 9 +--------
.../DownloadManager/SimpleLiveRecordManager2.cs | 11 ++++++++---
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index 68fc1a6..a6dbfeb 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -9,7 +9,6 @@ public class NonAnsiWriter : TextWriter
public override Encoding Encoding => Console.OutputEncoding;
private string lastOut = "";
- private int dupCount = 0;
public override void Write(char value)
{
@@ -20,15 +19,8 @@ public override void Write(string value)
{
if (lastOut == value)
{
- dupCount++;
return;
}
-
- if (dupCount!=0)
- {
- Console.Write($"Suppress {dupCount} duplicate out");
- dupCount = 0;
- }
lastOut = value;
RemoveAnsiEscapeSequences(value);
}
@@ -38,6 +30,7 @@ private void RemoveAnsiEscapeSequences(string input)
// Use regular expression to remove ANSI escape sequences
string output = Regex.Replace(input, @"\x1B\[(\d+;?)+m", "");
output = Regex.Replace(output, @"\[\??\d+[AKl]", "");
+ output = Regex.Replace(output,"[\r\n] +","");
if (string.IsNullOrWhiteSpace(output))
{
return;
diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
index 2d393e7..f2e3c16 100644
--- a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
+++ b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
@@ -803,9 +803,9 @@ public async Task StartRecordAsync()
var progress = CustomAnsiConsole.Console.Progress().AutoClear(true);
progress.AutoRefresh = DownloaderConfig.MyOptions.LogLevel != LogLevel.OFF;
-
+
//进度条的列定义
- progress.Columns(new ProgressColumn[]
+ var progressColumns = new ProgressColumn[]
{
new TaskDescriptionColumn() { Alignment = Justify.Left },
new RecordingDurationColumn(RecordedDurDic, RefreshedDurDic), //时长显示
@@ -813,7 +813,12 @@ public async Task StartRecordAsync()
new PercentageColumn(),
new DownloadSpeedColumn(SpeedContainerDic), //速度计算
new SpinnerColumn(),
- });
+ };
+ if (DownloaderConfig.MyOptions.Noansi)
+ {
+ progressColumns = progressColumns.SkipLast(1).ToArray();
+ }
+ progress.Columns(progressColumns);
await progress.StartAsync(async ctx =>
{
From af3f1ee22ca77344f9399fa090ba86f930643f70 Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Fri, 15 Dec 2023 12:47:35 +0800
Subject: [PATCH 08/16] force console width to max
---
src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index a6dbfeb..cd47599 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -63,6 +63,7 @@ public static void InitConsole(bool forceAnsi, bool noansi)
ansiConsoleSettings.Ansi = AnsiSupport.Yes;
// ansiConsoleSettings.Ansi = AnsiSupport.Yes;
Console = AnsiConsole.Create(ansiConsoleSettings);
+ Console.Profile.Width = int.MaxValue;
}
else
{
From 9cfdcfd07958a75ff5308d5d0dad4919767b9f19 Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Fri, 15 Dec 2023 12:49:08 +0800
Subject: [PATCH 09/16] add escape sequence `\e[?25h`
---
src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index cd47599..8d6e142 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -29,7 +29,7 @@ private void RemoveAnsiEscapeSequences(string input)
{
// Use regular expression to remove ANSI escape sequences
string output = Regex.Replace(input, @"\x1B\[(\d+;?)+m", "");
- output = Regex.Replace(output, @"\[\??\d+[AKl]", "");
+ output = Regex.Replace(output, @"\[\??\d+[AKlh]", "");
output = Regex.Replace(output,"[\r\n] +","");
if (string.IsNullOrWhiteSpace(output))
{
From d17c583b155dec7c9767cf43a2bf40fb703ee712 Mon Sep 17 00:00:00 2001
From: RikaCelery <94585272+RikaCelery@users.noreply.github.com>
Date: Fri, 15 Dec 2023 12:53:06 +0800
Subject: [PATCH 10/16] remove spinner for HTTPLiveRecordManager.cs and
SimpleDownloadManager.cs when `--noansi`
---
src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs | 9 +++++++--
src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs | 9 +++++++--
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs b/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs
index da7d137..d59ba69 100644
--- a/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs
+++ b/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs
@@ -201,7 +201,7 @@ public async Task StartRecordAsync()
progress.AutoRefresh = DownloaderConfig.MyOptions.LogLevel != LogLevel.OFF;
//进度条的列定义
- progress.Columns(new ProgressColumn[]
+ var progressColumns = new ProgressColumn[]
{
new TaskDescriptionColumn() { Alignment = Justify.Left },
new RecordingDurationColumn(RecordingDurDic), //时长显示
@@ -209,7 +209,12 @@ public async Task StartRecordAsync()
new RecordingStatusColumn(),
new DownloadSpeedColumn(SpeedContainerDic), //速度计算
new SpinnerColumn(),
- });
+ };
+ if (DownloaderConfig.MyOptions.Noansi)
+ {
+ progressColumns = progressColumns.SkipLast(1).ToArray();
+ }
+ progress.Columns(progressColumns);
await progress.StartAsync(async ctx =>
{
diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
index e07fc1f..dbe3adc 100644
--- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
+++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
@@ -621,7 +621,7 @@ public async Task StartDownloadAsync()
progress.AutoRefresh = DownloaderConfig.MyOptions.LogLevel != LogLevel.OFF;
//进度条的列定义
- progress.Columns(new ProgressColumn[]
+ var progressColumns = new ProgressColumn[]
{
new TaskDescriptionColumn() { Alignment = Justify.Left },
new ProgressBarColumn(){ Width = 30 },
@@ -630,7 +630,12 @@ public async Task StartDownloadAsync()
new DownloadSpeedColumn(SpeedContainerDic), //速度计算
new RemainingTimeColumn(),
new SpinnerColumn(),
- });
+ };
+ if (DownloaderConfig.MyOptions.Noansi)
+ {
+ progressColumns = progressColumns.SkipLast(1).ToArray();
+ }
+ progress.Columns(progressColumns);
if (DownloaderConfig.MyOptions.MP4RealTimeDecryption && !DownloaderConfig.MyOptions.UseShakaPackager
&& DownloaderConfig.MyOptions.Keys != null && DownloaderConfig.MyOptions.Keys.Length > 0)
From 99109f0d69dcff254eb155146f0daf7c5f6b3f9a Mon Sep 17 00:00:00 2001
From: RikaCelery
Date: Sat, 22 Jun 2024 20:24:29 +0800
Subject: [PATCH 11/16] camelCase
---
src/N_m3u8DL-RE.Common/Resource/ResString.cs | 4 ++--
src/N_m3u8DL-RE.Common/Resource/StaticText.cs | 4 ++--
src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/N_m3u8DL-RE.Common/Resource/ResString.cs b/src/N_m3u8DL-RE.Common/Resource/ResString.cs
index fa546d2..a0b15e3 100644
--- a/src/N_m3u8DL-RE.Common/Resource/ResString.cs
+++ b/src/N_m3u8DL-RE.Common/Resource/ResString.cs
@@ -55,8 +55,8 @@ public class ResString
public static string cmd_customHLSKey { get => GetText("cmd_customHLSKey"); }
public static string cmd_customHLSIv { get => GetText("cmd_customHLSIv"); }
public static string cmd_Input { get => GetText("cmd_Input"); }
- public static string cmd_force_ansi_console { get => GetText("cmd_force_ansi_console"); }
- public static string cmd_noansi { get => GetText("cmd_noansi"); }
+ public static string cmd_forceAnsiConsole { get => GetText("cmd_forceAnsiConsole"); }
+ public static string cmd_noAnsiColor { get => GetText("cmd_noAnsiColor"); }
public static string cmd_keys { get => GetText("cmd_keys"); }
public static string cmd_keyText { get => GetText("cmd_keyText"); }
public static string cmd_loadKeyFailed { get => GetText("cmd_loadKeyFailed"); }
diff --git a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
index 31e412f..4b78ce4 100644
--- a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
+++ b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
@@ -22,13 +22,13 @@ internal class StaticText
zhTW: "即時解密已被強制關閉",
enUS: "Real-time decryption has been disabled"
),
- ["cmd_force_ansi_console"] = new TextContainer
+ ["cmd_forceAnsiConsole"] = new TextContainer
(
zhCN: "强制认定终端为支持Ansi且可交互的终端",
zhTW: "強制認定終端為支援Ansi且可交往的終端",
enUS: "Force assuming the terminal is ANSI-compatible and interactive"
),
- ["cmd_noansi"] = new TextContainer
+ ["cmd_noAnsiColor"] = new TextContainer
(
zhCN: "去除ansi颜色",
zhTW: "關閉ansi顏色",
diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
index 7fee8cb..2faef07 100644
--- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
+++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
@@ -53,8 +53,8 @@ internal partial class CommandInvoker
private readonly static Option AppendUrlParams = new(new string[] { "--append-url-params" }, description: ResString.cmd_appendUrlParams, getDefaultValue: () => false);
private readonly static Option MP4RealTimeDecryption = new (new string[] { "--mp4-real-time-decryption" }, description: ResString.cmd_MP4RealTimeDecryption, getDefaultValue: () => false);
private readonly static Option UseShakaPackager = new (new string[] { "--use-shaka-packager" }, description: ResString.cmd_useShakaPackager, getDefaultValue: () => false);
- private readonly static Option ForceAnsiConsole = new(new string[] { "--force-ansi-console" }, description: ResString.cmd_force_ansi_console);
- private readonly static Option Noansi = new(new string[] { "--noansi" }, description: ResString.cmd_noansi);
+ private readonly static Option ForceAnsiConsole = new(new string[] { "--force-ansi-console" }, description: ResString.cmd_forceAnsiConsole);
+ private readonly static Option Noansi = new(new string[] { "--noansi" }, description: ResString.cmd_noAnsiColor);
private readonly static Option DecryptionBinaryPath = new(new string[] { "--decryption-binary-path" }, description: ResString.cmd_decryptionBinaryPath) { ArgumentHelpName = "PATH" };
private readonly static Option FFmpegBinaryPath = new(new string[] { "--ffmpeg-binary-path" }, description: ResString.cmd_ffmpegBinaryPath) { ArgumentHelpName = "PATH" };
private readonly static Option BaseUrl = new(new string[] { "--base-url" }, description: ResString.cmd_baseUrl);
From c1a890ce444ca30a07c8d6b841ef44d8c2024c9b Mon Sep 17 00:00:00 2001
From: RikaCelery
Date: Sat, 22 Jun 2024 20:38:08 +0800
Subject: [PATCH 12/16] rename variable
---
src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs | 6 +++---
src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 6 +++---
src/N_m3u8DL-RE/CommandLine/MyOption.cs | 4 ++--
src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs | 2 +-
src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs | 2 +-
src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs | 2 +-
6 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index 8d6e142..a2ce02e 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -49,12 +49,12 @@ public static class CustomAnsiConsole
// ansiConsoleSettings.Ansi = AnsiSupport.Yes;
public static IAnsiConsole Console { get; set; }
- public static void InitConsole(bool forceAnsi, bool noansi)
+ public static void InitConsole(bool forceAnsi, bool noAnsiColor)
{
if (forceAnsi)
{
var ansiConsoleSettings = new AnsiConsoleSettings();
- if (noansi)
+ if (noAnsiColor)
{
ansiConsoleSettings.Out = new AnsiConsoleOutput(new NonAnsiWriter());
}
@@ -68,7 +68,7 @@ public static void InitConsole(bool forceAnsi, bool noansi)
else
{
var ansiConsoleSettings = new AnsiConsoleSettings();
- if (noansi)
+ if (noAnsiColor)
{
ansiConsoleSettings.Out = new AnsiConsoleOutput(new NonAnsiWriter());
}
diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
index 2faef07..af2e546 100644
--- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
+++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
@@ -54,7 +54,7 @@ internal partial class CommandInvoker
private readonly static Option MP4RealTimeDecryption = new (new string[] { "--mp4-real-time-decryption" }, description: ResString.cmd_MP4RealTimeDecryption, getDefaultValue: () => false);
private readonly static Option UseShakaPackager = new (new string[] { "--use-shaka-packager" }, description: ResString.cmd_useShakaPackager, getDefaultValue: () => false);
private readonly static Option ForceAnsiConsole = new(new string[] { "--force-ansi-console" }, description: ResString.cmd_forceAnsiConsole);
- private readonly static Option Noansi = new(new string[] { "--noansi" }, description: ResString.cmd_noAnsiColor);
+ private readonly static Option NoAnsiColor = new(new string[] { "--no-ansi-color" }, description: ResString.cmd_noAnsiColor);
private readonly static Option DecryptionBinaryPath = new(new string[] { "--decryption-binary-path" }, description: ResString.cmd_decryptionBinaryPath) { ArgumentHelpName = "PATH" };
private readonly static Option FFmpegBinaryPath = new(new string[] { "--ffmpeg-binary-path" }, description: ResString.cmd_ffmpegBinaryPath) { ArgumentHelpName = "PATH" };
private readonly static Option BaseUrl = new(new string[] { "--base-url" }, description: ResString.cmd_baseUrl);
@@ -487,7 +487,7 @@ protected override MyOption GetBoundValue(BindingContext bindingContext)
{
Input = bindingContext.ParseResult.GetValueForArgument(Input),
ForceAnsiConsole = bindingContext.ParseResult.GetValueForOption(ForceAnsiConsole),
- Noansi = bindingContext.ParseResult.GetValueForOption(Noansi),
+ NoAnsiColor = bindingContext.ParseResult.GetValueForOption(NoAnsiColor),
LogLevel = bindingContext.ParseResult.GetValueForOption(LogLevel),
AutoSelect = bindingContext.ParseResult.GetValueForOption(AutoSelect),
SkipMerge = bindingContext.ParseResult.GetValueForOption(SkipMerge),
@@ -598,7 +598,7 @@ public static async Task InvokeArgs(string[] args, Func act
var rootCommand = new RootCommand(VERSION_INFO)
{
- Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, ForceAnsiConsole,Noansi,AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
+ Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, ForceAnsiConsole,NoAnsiColor,AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
BinaryMerge, UseFFmpegConcatDemuxer, DelAfterDone, NoDateInfo, NoLog, WriteMetaJson, AppendUrlParams, ConcurrentDownload, Headers, /**SavePattern,**/ SubOnly, SubtitleFormat, AutoSubtitleFix,
FFmpegBinaryPath,
LogLevel, UILanguage, UrlProcessorArgs, Keys, KeyTextFile, DecryptionBinaryPath, UseShakaPackager, MP4RealTimeDecryption,
diff --git a/src/N_m3u8DL-RE/CommandLine/MyOption.cs b/src/N_m3u8DL-RE/CommandLine/MyOption.cs
index ab5e90f..9b926ce 100644
--- a/src/N_m3u8DL-RE/CommandLine/MyOption.cs
+++ b/src/N_m3u8DL-RE/CommandLine/MyOption.cs
@@ -89,9 +89,9 @@ internal class MyOption
///
public bool ForceAnsiConsole { get; set; }
///
- /// See: .
+ /// See: .
///
- public bool Noansi { get; set; }
+ public bool NoAnsiColor { get; set; }
///
/// See: .
///
diff --git a/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs b/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs
index d59ba69..be6c39d 100644
--- a/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs
+++ b/src/N_m3u8DL-RE/DownloadManager/HTTPLiveRecordManager.cs
@@ -210,7 +210,7 @@ public async Task StartRecordAsync()
new DownloadSpeedColumn(SpeedContainerDic), //速度计算
new SpinnerColumn(),
};
- if (DownloaderConfig.MyOptions.Noansi)
+ if (DownloaderConfig.MyOptions.NoAnsiColor)
{
progressColumns = progressColumns.SkipLast(1).ToArray();
}
diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
index dbe3adc..536fc21 100644
--- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
+++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs
@@ -631,7 +631,7 @@ public async Task StartDownloadAsync()
new RemainingTimeColumn(),
new SpinnerColumn(),
};
- if (DownloaderConfig.MyOptions.Noansi)
+ if (DownloaderConfig.MyOptions.NoAnsiColor)
{
progressColumns = progressColumns.SkipLast(1).ToArray();
}
diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
index f2e3c16..4ab0b66 100644
--- a/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
+++ b/src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
@@ -814,7 +814,7 @@ public async Task StartRecordAsync()
new DownloadSpeedColumn(SpeedContainerDic), //速度计算
new SpinnerColumn(),
};
- if (DownloaderConfig.MyOptions.Noansi)
+ if (DownloaderConfig.MyOptions.NoAnsiColor)
{
progressColumns = progressColumns.SkipLast(1).ToArray();
}
From 0279765c5a592bcffdd9bc811d627f4b73d23232 Mon Sep 17 00:00:00 2001
From: RikaCelery
Date: Sat, 22 Jun 2024 20:45:16 +0800
Subject: [PATCH 13/16] auto enable `--no-ansi` and `--force-ansi-console` when
out/err redirected
---
src/N_m3u8DL-RE.Common/Resource/ResString.cs | 1 +
src/N_m3u8DL-RE.Common/Resource/StaticText.cs | 6 ++++++
src/N_m3u8DL-RE/Program.cs | 10 +++++++++-
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/N_m3u8DL-RE.Common/Resource/ResString.cs b/src/N_m3u8DL-RE.Common/Resource/ResString.cs
index a0b15e3..a97f0d4 100644
--- a/src/N_m3u8DL-RE.Common/Resource/ResString.cs
+++ b/src/N_m3u8DL-RE.Common/Resource/ResString.cs
@@ -16,6 +16,7 @@ public class ResString
public static string customRangeFound { get => GetText("customRangeFound"); }
public static string customAdKeywordsFound { get => GetText("customAdKeywordsFound"); }
public static string customRangeInvalid { get => GetText("customRangeInvalid"); }
+ public static string consoleRedirected { get => GetText("consoleRedirected"); }
public static string autoBinaryMerge { get => GetText("autoBinaryMerge"); }
public static string autoBinaryMerge2 { get => GetText("autoBinaryMerge2"); }
public static string autoBinaryMerge3 { get => GetText("autoBinaryMerge3"); }
diff --git a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
index 4b78ce4..1d14323 100644
--- a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
+++ b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
@@ -58,6 +58,12 @@ internal class StaticText
zhTW: "用戶自定義下載範圍:",
enUS: "User customed range: "
),
+ ["consoleRedirected"] = new TextContainer
+ (
+ zhCN: "输出被重定向, 将清除Ansi颜色",
+ zhTW: "輸出被重定向, 將清除Ansi顏色",
+ enUS: "Output is redirected, Ansi colors are cleared."
+ ),
["processImageSub"] = new TextContainer
(
zhCN: "正在处理图形字幕",
diff --git a/src/N_m3u8DL-RE/Program.cs b/src/N_m3u8DL-RE/Program.cs
index a1b2fc8..8e9dc87 100644
--- a/src/N_m3u8DL-RE/Program.cs
+++ b/src/N_m3u8DL-RE/Program.cs
@@ -25,6 +25,7 @@ static async Task Main(string[] args)
Console.CancelKeyPress += Console_CancelKeyPress;
ServicePointManager.DefaultConnectionLimit = 1024;
try { Console.CursorVisible = true; } catch { }
+
string loc = "en-US";
string currLoc = Thread.CurrentThread.CurrentUICulture.Name;
if (currLoc == "zh-CN" || currLoc == "zh-SG") loc = "zh-CN";
@@ -70,7 +71,14 @@ static int GetOrder(StreamSpec streamSpec)
static async Task DoWorkAsync(MyOption option)
{
- CustomAnsiConsole.InitConsole(option.ForceAnsiConsole,option.Noansi);
+
+ if (Console.IsOutputRedirected||Console.IsErrorRedirected)
+ {
+ option.ForceAnsiConsole = true;
+ option.NoAnsiColor = true;
+ Logger.Info(ResString.consoleRedirected);
+ }
+ CustomAnsiConsole.InitConsole(option.ForceAnsiConsole,option.NoAnsiColor);
//检测更新
CheckUpdateAsync();
From f604a4c94155aa32c3b0b074ba4792e436f8c8dd Mon Sep 17 00:00:00 2001
From: RikaCelery
Date: Sat, 22 Jun 2024 20:53:26 +0800
Subject: [PATCH 14/16] avoid null reference
---
src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index a2ce02e..5feaeda 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -47,7 +47,7 @@ public static class CustomAnsiConsole
{
// var ansiConsoleSettings = new AnsiConsoleSettings();
// ansiConsoleSettings.Ansi = AnsiSupport.Yes;
- public static IAnsiConsole Console { get; set; }
+ public static IAnsiConsole Console { get; set; } = AnsiConsole.Console;
public static void InitConsole(bool forceAnsi, bool noAnsiColor)
{
From a4c2181f1891f8a1c98f97791b4b773da7bd2b97 Mon Sep 17 00:00:00 2001
From: RikaCelery
Date: Sat, 22 Jun 2024 20:53:26 +0800
Subject: [PATCH 15/16] format code and clean up
---
src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs | 4 ----
src/N_m3u8DL-RE.Common/Log/Logger.cs | 4 ++--
src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 2 +-
src/N_m3u8DL-RE/Program.cs | 4 ++--
4 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
index 5feaeda..417bcf8 100644
--- a/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
+++ b/src/N_m3u8DL-RE.Common/Log/CustomAnsiConsole.cs
@@ -35,7 +35,6 @@ private void RemoveAnsiEscapeSequences(string input)
{
return;
}
- // Implement your custom write logic here, e.g., write to console
Console.Write(output);
}
}
@@ -45,8 +44,6 @@ private void RemoveAnsiEscapeSequences(string input)
///
public static class CustomAnsiConsole
{
- // var ansiConsoleSettings = new AnsiConsoleSettings();
- // ansiConsoleSettings.Ansi = AnsiSupport.Yes;
public static IAnsiConsole Console { get; set; } = AnsiConsole.Console;
public static void InitConsole(bool forceAnsi, bool noAnsiColor)
@@ -61,7 +58,6 @@ public static void InitConsole(bool forceAnsi, bool noAnsiColor)
ansiConsoleSettings.Interactive = InteractionSupport.Yes;
ansiConsoleSettings.Ansi = AnsiSupport.Yes;
- // ansiConsoleSettings.Ansi = AnsiSupport.Yes;
Console = AnsiConsole.Create(ansiConsoleSettings);
Console.Profile.Width = int.MaxValue;
}
diff --git a/src/N_m3u8DL-RE.Common/Log/Logger.cs b/src/N_m3u8DL-RE.Common/Log/Logger.cs
index 4ea9016..eafbdc4 100644
--- a/src/N_m3u8DL-RE.Common/Log/Logger.cs
+++ b/src/N_m3u8DL-RE.Common/Log/Logger.cs
@@ -79,11 +79,11 @@ private static void HandleLog(string write, string subWrite = "")
{
if (subWrite == "")
{
- CustomAnsiConsole.MarkupLine(write);
+ CustomAnsiConsole.MarkupLine(write);
}
else
{
- CustomAnsiConsole.Markup(write);
+ CustomAnsiConsole.Markup(write);
Console.WriteLine(subWrite);
}
diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
index af2e546..83e8a33 100644
--- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
+++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs
@@ -598,7 +598,7 @@ public static async Task InvokeArgs(string[] args, Func act
var rootCommand = new RootCommand(VERSION_INFO)
{
- Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, ForceAnsiConsole,NoAnsiColor,AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
+ Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, ForceAnsiConsole, NoAnsiColor,AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount,
BinaryMerge, UseFFmpegConcatDemuxer, DelAfterDone, NoDateInfo, NoLog, WriteMetaJson, AppendUrlParams, ConcurrentDownload, Headers, /**SavePattern,**/ SubOnly, SubtitleFormat, AutoSubtitleFix,
FFmpegBinaryPath,
LogLevel, UILanguage, UrlProcessorArgs, Keys, KeyTextFile, DecryptionBinaryPath, UseShakaPackager, MP4RealTimeDecryption,
diff --git a/src/N_m3u8DL-RE/Program.cs b/src/N_m3u8DL-RE/Program.cs
index 8e9dc87..b0dac1e 100644
--- a/src/N_m3u8DL-RE/Program.cs
+++ b/src/N_m3u8DL-RE/Program.cs
@@ -72,13 +72,13 @@ static int GetOrder(StreamSpec streamSpec)
static async Task DoWorkAsync(MyOption option)
{
- if (Console.IsOutputRedirected||Console.IsErrorRedirected)
+ if (Console.IsOutputRedirected || Console.IsErrorRedirected)
{
option.ForceAnsiConsole = true;
option.NoAnsiColor = true;
Logger.Info(ResString.consoleRedirected);
}
- CustomAnsiConsole.InitConsole(option.ForceAnsiConsole,option.NoAnsiColor);
+ CustomAnsiConsole.InitConsole(option.ForceAnsiConsole, option.NoAnsiColor);
//检测更新
CheckUpdateAsync();
From 89300f1b79f50bcd96f66dfa0d14dfadb336eb8c Mon Sep 17 00:00:00 2001
From: RikaCelery
Date: Sun, 23 Jun 2024 01:25:45 +0800
Subject: [PATCH 16/16] capitalize word `ANSI`
---
src/N_m3u8DL-RE.Common/Resource/StaticText.cs | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
index 1d14323..5a8e3a8 100644
--- a/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
+++ b/src/N_m3u8DL-RE.Common/Resource/StaticText.cs
@@ -24,14 +24,14 @@ internal class StaticText
),
["cmd_forceAnsiConsole"] = new TextContainer
(
- zhCN: "强制认定终端为支持Ansi且可交互的终端",
- zhTW: "強制認定終端為支援Ansi且可交往的終端",
+ zhCN: "强制认定终端为支持ANSI且可交互的终端",
+ zhTW: "強制認定終端為支援ANSI且可交往的終端",
enUS: "Force assuming the terminal is ANSI-compatible and interactive"
),
["cmd_noAnsiColor"] = new TextContainer
(
- zhCN: "去除ansi颜色",
- zhTW: "關閉ansi顏色",
+ zhCN: "去除ANSI颜色",
+ zhTW: "關閉ANSI顏色",
enUS: "Remove ANSI colors"
),
["customRangeWarn"] = new TextContainer
@@ -60,9 +60,9 @@ internal class StaticText
),
["consoleRedirected"] = new TextContainer
(
- zhCN: "输出被重定向, 将清除Ansi颜色",
- zhTW: "輸出被重定向, 將清除Ansi顏色",
- enUS: "Output is redirected, Ansi colors are cleared."
+ zhCN: "输出被重定向, 将清除ANSI颜色",
+ zhTW: "輸出被重定向, 將清除ANSI顏色",
+ enUS: "Output is redirected, ANSI colors are cleared."
),
["processImageSub"] = new TextContainer
(