Skip to content

Commit 848545a

Browse files
authored
当环境变量RE_KEEP_IMAGE_SEGMENTS=1时, 跳过字幕转换为PNG后删除原始文件的逻辑 (#625)
1 parent 30499f5 commit 848545a

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace N_m3u8DL_RE.CommandLine;
1717

1818
internal static partial class CommandInvoker
1919
{
20-
public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20241216";
20+
public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20250311";
2121

2222
[GeneratedRegex("((best|worst)\\d*|all)")]
2323
private static partial Regex ForStrRegex();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace N_m3u8DL_RE.Config;
2+
3+
/// <summary>
4+
/// 通过配置环境变量来实现更细节地控制某些逻辑
5+
/// </summary>
6+
public static class EnvConfigKey
7+
{
8+
/// <summary>
9+
/// 当此值为1时, 在图形字幕处理逻辑中PNG生成后不再删除m4s文件
10+
/// </summary>
11+
public const string ReKeepImageSegments = "RE_KEEP_IMAGE_SEGMENTS";
12+
13+
/// <summary>
14+
/// 控制启用PipeMux时, 具体ffmpeg命令行
15+
/// </summary>
16+
public const string ReLivePipeOptions = "RE_LIVE_PIPE_OPTIONS";
17+
18+
/// <summary>
19+
/// 控制启用PipeMux时, 非Windows环境下命名管道文件的生成目录
20+
/// </summary>
21+
public const string ReLivePipeTmpDir = "RE_LIVE_PIPE_TMP_DIR";
22+
}

src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ await Parallel.ForEachAsync(segments, options, async (seg, _) =>
454454
// 处理图形字幕
455455
await SubtitleUtil.TryWriteImagePngsAsync(finalVtt, tmpDir);
456456

457-
foreach (var item in files) File.Delete(item);
457+
var keepSegments = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReKeepImageSegments);
458+
if (keepSegments != "1")
459+
foreach (var item in files) File.Delete(item);
458460
FileDic.Clear();
459461
var index = 0;
460462
var path = Path.Combine(tmpDir, index.ToString(pad) + ".fix.vtt");
@@ -506,7 +508,9 @@ await Parallel.ForEachAsync(segments, options, async (seg, _) =>
506508
// 处理图形字幕
507509
await SubtitleUtil.TryWriteImagePngsAsync(finalVtt, tmpDir);
508510

509-
foreach (var item in files) File.Delete(item);
511+
var keepSegments = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReKeepImageSegments);
512+
if (keepSegments != "1")
513+
foreach (var item in files) File.Delete(item);
510514
FileDic.Clear();
511515
var index = 0;
512516
var path = Path.Combine(tmpDir, index.ToString(pad) + ".fix.vtt");

src/N_m3u8DL-RE/Util/PipeUtil.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.IO.Pipes;
55
using System.Text;
6+
using N_m3u8DL_RE.Config;
67

78
namespace N_m3u8DL_RE.Util;
89

@@ -43,11 +44,11 @@ public static async Task<bool> StartPipeMuxAsync(string binary, string[] pipeNam
4344

4445
public static bool StartPipeMux(string binary, string[] pipeNames, string outputPath)
4546
{
46-
string dateString = DateTime.Now.ToString("o");
47-
StringBuilder command = new StringBuilder("-y -fflags +genpts -loglevel quiet ");
47+
var dateString = DateTime.Now.ToString("o");
48+
var command = new StringBuilder("-y -fflags +genpts -loglevel quiet ");
4849

49-
string customDest = OtherUtil.GetEnvironmentVariable("RE_LIVE_PIPE_OPTIONS");
50-
string pipeDir = OtherUtil.GetEnvironmentVariable("RE_LIVE_PIPE_TMP_DIR", Path.GetTempPath());
50+
var customDest = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReLivePipeOptions);
51+
var pipeDir = OtherUtil.GetEnvironmentVariable(EnvConfigKey.ReLivePipeTmpDir, Path.GetTempPath());
5152

5253
if (!string.IsNullOrEmpty(customDest))
5354
{
@@ -63,7 +64,7 @@ public static bool StartPipeMux(string binary, string[] pipeNames, string output
6364
command.Append($" -i \"{Path.Combine(pipeDir, item)}\" ");
6465
}
6566

66-
for (int i = 0; i < pipeNames.Length; i++)
67+
for (var i = 0; i < pipeNames.Length; i++)
6768
{
6869
command.Append($" -map {i} ");
6970
}

0 commit comments

Comments
 (0)