Skip to content

Commit

Permalink
优化直播录制逻辑; 优化已录制时长显示
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaoda committed Jun 28, 2023
1 parent e55dd5a commit d58168a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/N_m3u8DL-RE.Parser/StreamExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public async Task RefreshPlayListAsync(List<StreamSpec> streamSpecs)
try
{
await semaphore.WaitAsync();
int retryCount = 3; //增加重试
int retryCount = 5; //增加重试
reGet:
try
{
Expand All @@ -145,7 +145,7 @@ public async Task RefreshPlayListAsync(List<StreamSpec> streamSpecs)
if (retryCount-- > 0)
{
Logger.WarnMarkUp($"[grey]Refresh Exception: {ex.Message.EscapeMarkup()} retryCount: {retryCount}[/]");
await Task.Delay(300);
await Task.Delay(1000);
goto reGet;
}
else throw;
Expand Down
16 changes: 14 additions & 2 deletions src/N_m3u8DL-RE/Column/RecordingDurationColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ internal class RecordingDurationColumn : ProgressColumn
{
protected override bool NoWrap => true;
private ConcurrentDictionary<int, int> _recodingDurDic;
public Style MyStyle { get; set; } = new Style(foreground: Color.Grey);
private ConcurrentDictionary<int, int>? _refreshedDurDic;
public Style GreyStyle { get; set; } = new Style(foreground: Color.Grey);
public Style MyStyle { get; set; } = new Style(foreground: Color.DarkGreen);
public RecordingDurationColumn(ConcurrentDictionary<int, int> recodingDurDic)
{
_recodingDurDic = recodingDurDic;
}
public RecordingDurationColumn(ConcurrentDictionary<int, int> recodingDurDic, ConcurrentDictionary<int, int> refreshedDurDic)
{
_recodingDurDic = recodingDurDic;
_refreshedDurDic = refreshedDurDic;
}
public override IRenderable Render(RenderContext context, ProgressTask task, TimeSpan deltaTime)
{
return new Text(GlobalUtil.FormatTime(_recodingDurDic[task.Id]), MyStyle).LeftAligned();
if (_refreshedDurDic == null)
return new Text($"{GlobalUtil.FormatTime(_recodingDurDic[task.Id])}", MyStyle).LeftAligned();
else
{
return new Text($"{GlobalUtil.FormatTime(_recodingDurDic[task.Id])}/{GlobalUtil.FormatTime(_refreshedDurDic[task.Id])}", GreyStyle);
}
}
}
}
14 changes: 7 additions & 7 deletions src/N_m3u8DL-RE/DownloadManager/SimpleLiveRecordManager2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ await Parallel.ForEachAsync(segments, options, async (seg, _) =>
}
}

if (STOP_FLAG)
if (STOP_FLAG && source.Count == 0)
break;
}

Expand Down Expand Up @@ -720,11 +720,6 @@ await Parallel.ForEachAsync(dic, async (dic, _) =>
Logger.WarnMarkUp($"[darkorange3_1]{ResString.liveLimitReached}[/]");
STOP_FLAG = true;
CancellationTokenSource.Cancel();

foreach (var target in BlockDic.Values)
{
target.Complete();
}
}
});

Expand All @@ -743,6 +738,11 @@ await Parallel.ForEachAsync(dic, async (dic, _) =>
{
Logger.ErrorMarkUp(e);
STOP_FLAG = true;
//停止所有Block
foreach (var target in BlockDic.Values)
{
target.Complete();
}
}
}
}
Expand Down Expand Up @@ -825,7 +825,7 @@ public async Task<bool> StartRecordAsync()
progress.Columns(new ProgressColumn[]
{
new TaskDescriptionColumn() { Alignment = Justify.Left },
new RecordingDurationColumn(RecordedDurDic), //时长显示
new RecordingDurationColumn(RecordedDurDic, RefreshedDurDic), //时长显示
new RecordingStatusColumn(),
new PercentageColumn(),
new DownloadSpeedColumn(SpeedContainerDic), //速度计算
Expand Down
6 changes: 6 additions & 0 deletions src/N_m3u8DL-RE/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ static async Task DoWorkAsync(MyOption option)
throw new ArgumentException("MuxAfterDone disabled, MuxImports not allowed!");
}

if (option.LivePipeMux && !option.LiveRealTimeMerge)
{
Logger.WarnMarkUp("LivePipeMux detected, forced enable LiveRealTimeMerge");
option.LiveRealTimeMerge = true;
}

//预先检查ffmpeg
if (option.FFmpegBinaryPath == null)
option.FFmpegBinaryPath = GlobalUtil.FindExecutable("ffmpeg");
Expand Down

0 comments on commit d58168a

Please sign in to comment.