mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 11:42:22 +08:00
Core: Add qn to file name template variables
This commit is contained in:
parent
6760c23cf8
commit
6b9b077a52
|
@ -39,7 +39,7 @@ namespace BililiveRecorder.Core.Recording
|
|||
protected string? streamHost;
|
||||
protected bool started = false;
|
||||
protected bool timeoutTriggered = false;
|
||||
|
||||
protected int qn;
|
||||
|
||||
private readonly object ioStatsLock = new();
|
||||
protected int ioNetworkDownloadedBytes;
|
||||
|
@ -95,20 +95,10 @@ namespace BililiveRecorder.Core.Recording
|
|||
|
||||
var (fullUrl, qn) = await this.FetchStreamUrlAsync(this.room.RoomConfig.RoomId).ConfigureAwait(false);
|
||||
|
||||
this.qn = qn;
|
||||
this.streamHost = new Uri(fullUrl).Host;
|
||||
var qnDesc = qn switch
|
||||
{
|
||||
30000 => "杜比",
|
||||
20000 => "4K",
|
||||
10000 => "原画",
|
||||
401 => "蓝光(杜比)",
|
||||
400 => "蓝光",
|
||||
250 => "超清",
|
||||
150 => "高清",
|
||||
80 => "流畅",
|
||||
-1 => "录播姬用户脚本",
|
||||
_ => "未知"
|
||||
};
|
||||
var qnDesc = StreamQualityNumber.MapToString(qn);
|
||||
|
||||
this.logger.Information("连接直播服务器 {Host} 录制画质 {Qn} ({QnDescription})", this.streamHost, qn, qnDesc);
|
||||
this.logger.Debug("直播流地址 {Url}", fullUrl);
|
||||
|
||||
|
@ -201,6 +191,7 @@ namespace BililiveRecorder.Core.Recording
|
|||
ShortId = this.room.ShortId,
|
||||
AreaParent = FileNameGenerator.RemoveInvalidFileName(this.room.AreaNameParent, ignore_slash: false),
|
||||
AreaChild = FileNameGenerator.RemoveInvalidFileName(this.room.AreaNameChild, ignore_slash: false),
|
||||
Qn = this.qn,
|
||||
Json = this.room.RawBilibiliApiJsonData,
|
||||
});
|
||||
|
||||
|
|
|
@ -102,6 +102,7 @@ namespace BililiveRecorder.Core.Templating
|
|||
};
|
||||
templateOptions.MemberAccessStrategy.MemberNameStrategy = MemberNameStrategies.CamelCase;
|
||||
templateOptions.ValueConverters.Add(o => o is JContainer j ? new JContainerValue(j) : null);
|
||||
templateOptions.Filters.AddFilter("format_qn", StreamQualityNumber.MapToStringFilterDelegateAsync);
|
||||
|
||||
var context = new TemplateContext(data, templateOptions);
|
||||
|
||||
|
@ -158,6 +159,8 @@ namespace BililiveRecorder.Core.Templating
|
|||
|
||||
public string AreaChild { get; set; } = string.Empty;
|
||||
|
||||
public int Qn { get; set; }
|
||||
|
||||
public JObject? Json { get; set; }
|
||||
}
|
||||
|
||||
|
|
29
BililiveRecorder.Core/Templating/StreamQualityNumber.cs
Normal file
29
BililiveRecorder.Core/Templating/StreamQualityNumber.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Fluid;
|
||||
using Fluid.Values;
|
||||
|
||||
namespace BililiveRecorder.Core.Templating
|
||||
{
|
||||
public static class StreamQualityNumber
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string MapToString(int qn) => qn switch
|
||||
{
|
||||
30000 => "杜比",
|
||||
20000 => "4K",
|
||||
10000 => "原画",
|
||||
401 => "蓝光(杜比)",
|
||||
400 => "蓝光",
|
||||
250 => "超清",
|
||||
150 => "高清",
|
||||
80 => "流畅",
|
||||
-1 => "录播姬脚本",
|
||||
_ => $"未知({qn})"
|
||||
};
|
||||
|
||||
|
||||
public static ValueTask<FluidValue> MapToStringFilterDelegateAsync(FluidValue input, FilterArguments arguments, TemplateContext context)
|
||||
=> new StringValue(MapToString((int)input.ToNumberValue()));
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user