mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 11:42:22 +08:00
ToolBox: Add some metadata
This commit is contained in:
parent
8615e1421f
commit
df9b22eff9
|
@ -12,8 +12,10 @@ using BililiveRecorder.DependencyInjection;
|
|||
using BililiveRecorder.ToolBox;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
using Serilog.Exceptions;
|
||||
using Serilog.Formatting.Compact;
|
||||
|
||||
namespace BililiveRecorder.Cli
|
||||
{
|
||||
|
@ -49,7 +51,7 @@ namespace BililiveRecorder.Cli
|
|||
|
||||
private static int RunConfigMode(string path)
|
||||
{
|
||||
var logger = BuildLogger();
|
||||
using var logger = BuildLogger();
|
||||
Log.Logger = logger;
|
||||
|
||||
path = Path.GetFullPath(path);
|
||||
|
@ -84,7 +86,7 @@ namespace BililiveRecorder.Cli
|
|||
|
||||
private static int RunPortableMode(PortableModeArguments opts)
|
||||
{
|
||||
var logger = BuildLogger();
|
||||
using var logger = BuildLogger();
|
||||
Log.Logger = logger;
|
||||
|
||||
var config = new ConfigV2()
|
||||
|
@ -129,14 +131,23 @@ namespace BililiveRecorder.Cli
|
|||
.AddRecorder()
|
||||
.BuildServiceProvider();
|
||||
|
||||
private static ILogger BuildLogger() => new LoggerConfiguration()
|
||||
private static Logger BuildLogger() => new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose()
|
||||
.Enrich.WithProcessId()
|
||||
.Enrich.WithThreadId()
|
||||
.Enrich.WithThreadName()
|
||||
.Enrich.FromLogContext()
|
||||
.Enrich.WithExceptionDetails()
|
||||
.Destructure.ByTransforming<Flv.Xml.XmlFlvFile.XmlFlvFileMeta>(x => new
|
||||
{
|
||||
x.Version,
|
||||
x.ExportTime,
|
||||
x.FileSize,
|
||||
x.FileCreationTime,
|
||||
x.FileModificationTime,
|
||||
})
|
||||
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Verbose, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{RoomId}] {Message:lj}{NewLine}{Exception}")
|
||||
.WriteTo.File(new CompactJsonFormatter(), "./logs/bilirec.txt", shared: true, rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true)
|
||||
.CreateLogger();
|
||||
|
||||
public class PortableModeArguments
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
|
@ -8,6 +9,45 @@ namespace BililiveRecorder.Flv.Xml
|
|||
{
|
||||
public static XmlSerializer Serializer { get; } = new XmlSerializer(typeof(XmlFlvFile));
|
||||
|
||||
public XmlFlvFileMeta? Meta { get; set; }
|
||||
|
||||
public List<Tag> Tags { get; set; } = new List<Tag>();
|
||||
|
||||
public class XmlFlvFileMeta
|
||||
{
|
||||
public string? Version { get; set; }
|
||||
|
||||
[XmlElement(nameof(ExportTime))]
|
||||
public string ExportTimeForXml
|
||||
{
|
||||
get => this.ExportTime.ToString("o");
|
||||
set => this.ExportTime = DateTimeOffset.Parse(value);
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public DateTimeOffset ExportTime { get; set; }
|
||||
|
||||
public long FileSize { get; set; }
|
||||
|
||||
[XmlElement(nameof(FileCreationTime))]
|
||||
public string FileCreationTimeForXml
|
||||
{
|
||||
get => this.FileCreationTime.ToString("o");
|
||||
set => this.FileCreationTime = DateTimeOffset.Parse(value);
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public DateTimeOffset FileCreationTime { get; set; }
|
||||
|
||||
[XmlElement(nameof(FileModificationTime))]
|
||||
public string FileModificationTimeForXml
|
||||
{
|
||||
get => this.FileModificationTime.ToString("o");
|
||||
set => this.FileModificationTime = DateTimeOffset.Parse(value);
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public DateTimeOffset FileModificationTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
FileStream? flvFileStream = null;
|
||||
try
|
||||
{
|
||||
XmlFlvFile.XmlFlvFileMeta? meta = null;
|
||||
|
||||
var memoryStreamProvider = new RecyclableMemoryStreamProvider();
|
||||
var comments = new List<ProcessingComment>();
|
||||
var context = new FlvProcessingContext();
|
||||
|
@ -72,6 +74,7 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
{
|
||||
using var stream = new GZipStream(File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read), CompressionMode.Decompress);
|
||||
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
||||
meta = xmlFlvFile.Meta;
|
||||
return new FlvTagListReader(xmlFlvFile.Tags);
|
||||
});
|
||||
else if (inputPath.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
|
||||
|
@ -79,6 +82,7 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
{
|
||||
using var stream = File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
||||
meta = xmlFlvFile.Meta;
|
||||
return new FlvTagListReader(xmlFlvFile.Tags);
|
||||
});
|
||||
else
|
||||
|
@ -140,6 +144,9 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
if (cancellationToken.IsCancellationRequested)
|
||||
return new CommandResponse<AnalyzeResponse> { Status = ResponseStatus.Cancelled };
|
||||
|
||||
if (meta is not null)
|
||||
logger.Information("Xml meta: {@Meta}", meta);
|
||||
|
||||
// Result
|
||||
var response = await Task.Run(() =>
|
||||
{
|
||||
|
|
|
@ -34,8 +34,18 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
FileStream? inputStream = null, outputStream = null;
|
||||
try
|
||||
{
|
||||
XmlFlvFile.XmlFlvFileMeta meta;
|
||||
try
|
||||
{
|
||||
var fi = new FileInfo(request.Input);
|
||||
meta = new XmlFlvFile.XmlFlvFileMeta
|
||||
{
|
||||
ExportTime = DateTimeOffset.Now,
|
||||
Version = GitVersionInformation.InformationalVersion,
|
||||
FileSize = fi.Length,
|
||||
FileCreationTime = fi.CreationTime,
|
||||
FileModificationTime = fi.LastWriteTime
|
||||
};
|
||||
inputStream = File.Open(request.Input, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -88,7 +98,8 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
using var writer = new StreamWriter(new GZipStream(outputStream, CompressionLevel.Optimal));
|
||||
XmlFlvFile.Serializer.Serialize(writer, new XmlFlvFile
|
||||
{
|
||||
Tags = tags
|
||||
Tags = tags,
|
||||
Meta = meta
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
FileStream? flvFileStream = null;
|
||||
try
|
||||
{
|
||||
XmlFlvFile.XmlFlvFileMeta? meta = null;
|
||||
|
||||
var memoryStreamProvider = new RecyclableMemoryStreamProvider();
|
||||
var comments = new List<ProcessingComment>();
|
||||
var context = new FlvProcessingContext();
|
||||
|
@ -78,6 +80,7 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
{
|
||||
using var stream = new GZipStream(File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read), CompressionMode.Decompress);
|
||||
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
||||
meta = xmlFlvFile.Meta;
|
||||
return new FlvTagListReader(xmlFlvFile.Tags);
|
||||
});
|
||||
}
|
||||
|
@ -88,6 +91,7 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
{
|
||||
using var stream = File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
||||
meta = xmlFlvFile.Meta;
|
||||
return new FlvTagListReader(xmlFlvFile.Tags);
|
||||
});
|
||||
}
|
||||
|
@ -162,6 +166,9 @@ namespace BililiveRecorder.ToolBox.Commands
|
|||
return new CommandResponse<FixResponse> { Status = ResponseStatus.Cancelled };
|
||||
|
||||
// Post Run
|
||||
if (meta is not null)
|
||||
logger.Information("Xml meta: {@Meta}", meta);
|
||||
|
||||
if (xmlMode)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
|
|
|
@ -144,6 +144,14 @@ namespace BililiveRecorder.WPF
|
|||
.Enrich.WithThreadName()
|
||||
.Enrich.FromLogContext()
|
||||
.Enrich.WithExceptionDetails()
|
||||
.Destructure.ByTransforming<Flv.Xml.XmlFlvFile.XmlFlvFileMeta>(x => new
|
||||
{
|
||||
x.Version,
|
||||
x.ExportTime,
|
||||
x.FileSize,
|
||||
x.FileCreationTime,
|
||||
x.FileModificationTime,
|
||||
})
|
||||
.WriteTo.Console(levelSwitch: levelSwitchConsole)
|
||||
#if DEBUG
|
||||
.WriteTo.Debug()
|
||||
|
|
Loading…
Reference in New Issue
Block a user