mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 03:32:20 +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 BililiveRecorder.ToolBox;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
using Serilog.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
using Serilog.Exceptions;
|
using Serilog.Exceptions;
|
||||||
|
using Serilog.Formatting.Compact;
|
||||||
|
|
||||||
namespace BililiveRecorder.Cli
|
namespace BililiveRecorder.Cli
|
||||||
{
|
{
|
||||||
|
@ -49,7 +51,7 @@ namespace BililiveRecorder.Cli
|
||||||
|
|
||||||
private static int RunConfigMode(string path)
|
private static int RunConfigMode(string path)
|
||||||
{
|
{
|
||||||
var logger = BuildLogger();
|
using var logger = BuildLogger();
|
||||||
Log.Logger = logger;
|
Log.Logger = logger;
|
||||||
|
|
||||||
path = Path.GetFullPath(path);
|
path = Path.GetFullPath(path);
|
||||||
|
@ -84,7 +86,7 @@ namespace BililiveRecorder.Cli
|
||||||
|
|
||||||
private static int RunPortableMode(PortableModeArguments opts)
|
private static int RunPortableMode(PortableModeArguments opts)
|
||||||
{
|
{
|
||||||
var logger = BuildLogger();
|
using var logger = BuildLogger();
|
||||||
Log.Logger = logger;
|
Log.Logger = logger;
|
||||||
|
|
||||||
var config = new ConfigV2()
|
var config = new ConfigV2()
|
||||||
|
@ -129,14 +131,23 @@ namespace BililiveRecorder.Cli
|
||||||
.AddRecorder()
|
.AddRecorder()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
private static ILogger BuildLogger() => new LoggerConfiguration()
|
private static Logger BuildLogger() => new LoggerConfiguration()
|
||||||
.MinimumLevel.Verbose()
|
.MinimumLevel.Verbose()
|
||||||
.Enrich.WithProcessId()
|
.Enrich.WithProcessId()
|
||||||
.Enrich.WithThreadId()
|
.Enrich.WithThreadId()
|
||||||
.Enrich.WithThreadName()
|
.Enrich.WithThreadName()
|
||||||
.Enrich.FromLogContext()
|
.Enrich.FromLogContext()
|
||||||
.Enrich.WithExceptionDetails()
|
.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.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();
|
.CreateLogger();
|
||||||
|
|
||||||
public class PortableModeArguments
|
public class PortableModeArguments
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
@ -8,6 +9,45 @@ namespace BililiveRecorder.Flv.Xml
|
||||||
{
|
{
|
||||||
public static XmlSerializer Serializer { get; } = new XmlSerializer(typeof(XmlFlvFile));
|
public static XmlSerializer Serializer { get; } = new XmlSerializer(typeof(XmlFlvFile));
|
||||||
|
|
||||||
|
public XmlFlvFileMeta? Meta { get; set; }
|
||||||
|
|
||||||
public List<Tag> Tags { get; set; } = new List<Tag>();
|
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;
|
FileStream? flvFileStream = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
XmlFlvFile.XmlFlvFileMeta? meta = null;
|
||||||
|
|
||||||
var memoryStreamProvider = new RecyclableMemoryStreamProvider();
|
var memoryStreamProvider = new RecyclableMemoryStreamProvider();
|
||||||
var comments = new List<ProcessingComment>();
|
var comments = new List<ProcessingComment>();
|
||||||
var context = new FlvProcessingContext();
|
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);
|
using var stream = new GZipStream(File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read), CompressionMode.Decompress);
|
||||||
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
||||||
|
meta = xmlFlvFile.Meta;
|
||||||
return new FlvTagListReader(xmlFlvFile.Tags);
|
return new FlvTagListReader(xmlFlvFile.Tags);
|
||||||
});
|
});
|
||||||
else if (inputPath.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
|
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);
|
using var stream = File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||||
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
||||||
|
meta = xmlFlvFile.Meta;
|
||||||
return new FlvTagListReader(xmlFlvFile.Tags);
|
return new FlvTagListReader(xmlFlvFile.Tags);
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
|
@ -140,6 +144,9 @@ namespace BililiveRecorder.ToolBox.Commands
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
return new CommandResponse<AnalyzeResponse> { Status = ResponseStatus.Cancelled };
|
return new CommandResponse<AnalyzeResponse> { Status = ResponseStatus.Cancelled };
|
||||||
|
|
||||||
|
if (meta is not null)
|
||||||
|
logger.Information("Xml meta: {@Meta}", meta);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
var response = await Task.Run(() =>
|
var response = await Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,8 +34,18 @@ namespace BililiveRecorder.ToolBox.Commands
|
||||||
FileStream? inputStream = null, outputStream = null;
|
FileStream? inputStream = null, outputStream = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
XmlFlvFile.XmlFlvFileMeta meta;
|
||||||
try
|
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);
|
inputStream = File.Open(request.Input, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -88,7 +98,8 @@ namespace BililiveRecorder.ToolBox.Commands
|
||||||
using var writer = new StreamWriter(new GZipStream(outputStream, CompressionLevel.Optimal));
|
using var writer = new StreamWriter(new GZipStream(outputStream, CompressionLevel.Optimal));
|
||||||
XmlFlvFile.Serializer.Serialize(writer, new XmlFlvFile
|
XmlFlvFile.Serializer.Serialize(writer, new XmlFlvFile
|
||||||
{
|
{
|
||||||
Tags = tags
|
Tags = tags,
|
||||||
|
Meta = meta
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,8 @@ namespace BililiveRecorder.ToolBox.Commands
|
||||||
FileStream? flvFileStream = null;
|
FileStream? flvFileStream = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
XmlFlvFile.XmlFlvFileMeta? meta = null;
|
||||||
|
|
||||||
var memoryStreamProvider = new RecyclableMemoryStreamProvider();
|
var memoryStreamProvider = new RecyclableMemoryStreamProvider();
|
||||||
var comments = new List<ProcessingComment>();
|
var comments = new List<ProcessingComment>();
|
||||||
var context = new FlvProcessingContext();
|
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);
|
using var stream = new GZipStream(File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read), CompressionMode.Decompress);
|
||||||
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
||||||
|
meta = xmlFlvFile.Meta;
|
||||||
return new FlvTagListReader(xmlFlvFile.Tags);
|
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);
|
using var stream = File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||||
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(stream);
|
||||||
|
meta = xmlFlvFile.Meta;
|
||||||
return new FlvTagListReader(xmlFlvFile.Tags);
|
return new FlvTagListReader(xmlFlvFile.Tags);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -162,6 +166,9 @@ namespace BililiveRecorder.ToolBox.Commands
|
||||||
return new CommandResponse<FixResponse> { Status = ResponseStatus.Cancelled };
|
return new CommandResponse<FixResponse> { Status = ResponseStatus.Cancelled };
|
||||||
|
|
||||||
// Post Run
|
// Post Run
|
||||||
|
if (meta is not null)
|
||||||
|
logger.Information("Xml meta: {@Meta}", meta);
|
||||||
|
|
||||||
if (xmlMode)
|
if (xmlMode)
|
||||||
{
|
{
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
|
|
|
@ -144,6 +144,14 @@ namespace BililiveRecorder.WPF
|
||||||
.Enrich.WithThreadName()
|
.Enrich.WithThreadName()
|
||||||
.Enrich.FromLogContext()
|
.Enrich.FromLogContext()
|
||||||
.Enrich.WithExceptionDetails()
|
.Enrich.WithExceptionDetails()
|
||||||
|
.Destructure.ByTransforming<Flv.Xml.XmlFlvFile.XmlFlvFileMeta>(x => new
|
||||||
|
{
|
||||||
|
x.Version,
|
||||||
|
x.ExportTime,
|
||||||
|
x.FileSize,
|
||||||
|
x.FileCreationTime,
|
||||||
|
x.FileModificationTime,
|
||||||
|
})
|
||||||
.WriteTo.Console(levelSwitch: levelSwitchConsole)
|
.WriteTo.Console(levelSwitch: levelSwitchConsole)
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
.WriteTo.Debug()
|
.WriteTo.Debug()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user