支持设置直播获取最新N个分片 `live-take-count` #218

This commit is contained in:
nilaoda 2023-07-07 16:59:52 +08:00
parent 8bf50a3f5a
commit e3c4cbb01b
6 changed files with 17 additions and 4 deletions

View File

@ -79,6 +79,7 @@ namespace N_m3u8DL_RE.Common.Resource
public static string cmd_liveRecordLimit { get => GetText("cmd_liveRecordLimit"); }
public static string cmd_taskStartAt { get => GetText("cmd_taskStartAt"); }
public static string cmd_liveWaitTime { get => GetText("cmd_liveWaitTime"); }
public static string cmd_liveTakeCount { get => GetText("cmd_liveTakeCount"); }
public static string cmd_liveFixVttByAudio { get => GetText("cmd_liveFixVttByAudio"); }
public static string cmd_liveRealTimeMerge { get => GetText("cmd_liveRealTimeMerge"); }
public static string cmd_livePerformAsVod { get => GetText("cmd_livePerformAsVod"); }

View File

@ -346,6 +346,12 @@ namespace N_m3u8DL_RE.Common.Resource
zhTW: "手動設置直播列表刷新間隔",
enUS: "Manually set the live playlist refresh interval"
),
["cmd_liveTakeCount"] = new TextContainer
(
zhCN: "手动设置录制直播时首次获取分片的数量",
zhTW: "手動設置錄製直播時首次獲取分片的數量",
enUS: "Manually set the number of segments downloaded for the first time when recording live"
),
["cmd_customHLSMethod"] = new TextContainer
(
zhCN: "指定HLS加密方式 (AES_128|AES_128_ECB|CENC|CHACHA20|NONE|SAMPLE_AES|SAMPLE_AES_CTR|UNKNOWN)",

View File

@ -18,7 +18,7 @@ namespace N_m3u8DL_RE.CommandLine
{
internal partial class CommandInvoker
{
public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20230628";
public const string VERSION_INFO = "N_m3u8DL-RE (Beta version) 20230707";
[GeneratedRegex("((best|worst)\\d*|all)")]
private static partial Regex ForStrRegex();
@ -85,6 +85,7 @@ namespace N_m3u8DL_RE.CommandLine
private readonly static Option<bool> LivePipeMux = new(new string[] { "--live-pipe-mux" }, description: ResString.cmd_livePipeMux, getDefaultValue: () => false);
private readonly static Option<TimeSpan?> LiveRecordLimit = new(new string[] { "--live-record-limit" }, description: ResString.cmd_liveRecordLimit, parseArgument: ParseLiveLimit) { ArgumentHelpName = "HH:mm:ss" };
private readonly static Option<int?> LiveWaitTime = new(new string[] { "--live-wait-time" }, description: ResString.cmd_liveWaitTime) { ArgumentHelpName = "SEC" };
private readonly static Option<int> LiveTakeCount = new(new string[] { "--live-take-count" }, description: ResString.cmd_liveTakeCount, getDefaultValue: () => 16) { ArgumentHelpName = "NUM" };
private readonly static Option<bool> LiveFixVttByAudio = new(new string[] { "--live-fix-vtt-by-audio" }, description: ResString.cmd_liveFixVttByAudio, getDefaultValue: () => false);
@ -495,6 +496,7 @@ namespace N_m3u8DL_RE.CommandLine
CustomProxy = bindingContext.ParseResult.GetValueForOption(CustomProxy),
CustomRange = bindingContext.ParseResult.GetValueForOption(CustomRange),
LiveWaitTime = bindingContext.ParseResult.GetValueForOption(LiveWaitTime),
LiveTakeCount = bindingContext.ParseResult.GetValueForOption(LiveTakeCount),
NoDateInfo = bindingContext.ParseResult.GetValueForOption(NoDateInfo),
NoLog = bindingContext.ParseResult.GetValueForOption(NoLog),
};
@ -561,7 +563,7 @@ namespace N_m3u8DL_RE.CommandLine
LogLevel, UILanguage, UrlProcessorArgs, Keys, KeyTextFile, DecryptionBinaryPath, UseShakaPackager, MP4RealTimeDecryption,
MuxAfterDone,
CustomHLSMethod, CustomHLSKey, CustomHLSIv, UseSystemProxy, CustomProxy, CustomRange, TaskStartAt,
LivePerformAsVod, LiveRealTimeMerge, LiveKeepSegments, LivePipeMux, LiveFixVttByAudio, LiveRecordLimit, LiveWaitTime,
LivePerformAsVod, LiveRealTimeMerge, LiveKeepSegments, LivePipeMux, LiveFixVttByAudio, LiveRecordLimit, LiveWaitTime, LiveTakeCount,
MuxImports, VideoFilter, AudioFilter, SubtitleFilter, DropVideoFilter, DropAudioFilter, DropSubtitleFilter, MoreHelp
};

View File

@ -220,6 +220,10 @@ namespace N_m3u8DL_RE.CommandLine
/// See: <see cref="CommandInvoker.LiveWaitTime"/>.
/// </summary>
public int? LiveWaitTime { get; set; }
/// <summary>
/// See: <see cref="CommandInvoker.LiveTakeCount"/>.
/// </summary>
public int LiveTakeCount { get; set; }
public MuxOptions MuxOptions { get; set; }
//public bool LiveWriteHLS { get; set; } = true;
/// <summary>

View File

@ -790,7 +790,7 @@ namespace N_m3u8DL_RE.DownloadManager
public async Task<bool> StartRecordAsync()
{
var takeLastCount = 15;
var takeLastCount = DownloaderConfig.MyOptions.LiveTakeCount;
ConcurrentDictionary<int, SpeedContainer> SpeedContainerDic = new(); //速度计算
ConcurrentDictionary<StreamSpec, bool?> Results = new();
//同步流

View File

@ -172,7 +172,7 @@ namespace N_m3u8DL_RE.Util
//取最新的N个分片
if (selectedSteams.Any(x => x.Playlist!.MediaParts[0].MediaSegments.Count > takeLastCount))
{
var skipCount = selectedSteams.Min(x => x.Playlist!.MediaParts[0].MediaSegments.Count) - takeLastCount;
var skipCount = selectedSteams.Min(x => x.Playlist!.MediaParts[0].MediaSegments.Count) - takeLastCount + 1;
if (skipCount < 0) skipCount = 0;
foreach (var item in selectedSteams)
{