diff --git a/BililiveRecorder.ToolBox/Tool/Analyze/AnalyzeHandler.cs b/BililiveRecorder.ToolBox/Tool/Analyze/AnalyzeHandler.cs index a80d8b6..9355daf 100644 --- a/BililiveRecorder.ToolBox/Tool/Analyze/AnalyzeHandler.cs +++ b/BililiveRecorder.ToolBox/Tool/Analyze/AnalyzeHandler.cs @@ -4,6 +4,7 @@ using System.IO; using System.IO.Compression; using System.IO.Pipelines; using System.Linq; +using System.Text; using System.Threading; using System.Threading.Tasks; using BililiveRecorder.Flv; @@ -60,6 +61,15 @@ namespace BililiveRecorder.ToolBox.Tool.Analyze meta = xmlFlvFile.Meta; return new FlvTagListReader(xmlFlvFile.Tags); }); + else if (inputPath.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) + tagReader = await Task.Run(() => + { + using var zip = new ZipArchive(File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read), ZipArchiveMode.Read, false, Encoding.UTF8); + var entry = zip.Entries.First(x => x.Name.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)); + var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(entry.Open()); + meta = xmlFlvFile.Meta; + return new FlvTagListReader(xmlFlvFile.Tags); + }); else { flvFileStream = new FileStream(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan); diff --git a/BililiveRecorder.ToolBox/Tool/Export/ExportHandler.cs b/BililiveRecorder.ToolBox/Tool/Export/ExportHandler.cs index 8fc6091..4739329 100644 --- a/BililiveRecorder.ToolBox/Tool/Export/ExportHandler.cs +++ b/BililiveRecorder.ToolBox/Tool/Export/ExportHandler.cs @@ -51,7 +51,7 @@ namespace BililiveRecorder.ToolBox.Tool.Export try { - outputStream = File.OpenWrite(request.Output); + outputStream = new FileStream(request.Output, FileMode.Create); } catch (Exception ex) { @@ -93,17 +93,40 @@ namespace BililiveRecorder.ToolBox.Tool.Export await Task.Run(() => { - using var writer = XmlWriter.Create(new GZipStream(outputStream, CompressionLevel.Optimal), new() + switch (Path.GetExtension(request.Output)) { - Encoding = Encoding.UTF8, - Indent = true - }); + case ".zip": + default: + { + using var zip = new ZipArchive(outputStream, ZipArchiveMode.Create, false, Encoding.UTF8); + using var writer = XmlWriter.Create(new StreamWriter(zip.CreateEntry(Path.GetFileName(request.Input) + ".brec.xml").Open(), Encoding.UTF8), new() + { + Encoding = Encoding.UTF8, + Indent = true + }); - XmlFlvFile.Serializer.Serialize(writer, new XmlFlvFile - { - Tags = tags, - Meta = meta - }); + XmlFlvFile.Serializer.Serialize(writer, new XmlFlvFile + { + Tags = tags, + Meta = meta + }); + } + break; + case ".xml": + { + using var writer = XmlWriter.Create(new StreamWriter(outputStream, Encoding.UTF8), new() + { + Encoding = Encoding.UTF8, + Indent = true + }); + XmlFlvFile.Serializer.Serialize(writer, new XmlFlvFile + { + Tags = tags, + Meta = meta + }); + } + break; + } }); return new CommandResponse { Status = ResponseStatus.OK, Data = new ExportResponse() }; diff --git a/BililiveRecorder.ToolBox/Tool/Fix/FixHandler.cs b/BililiveRecorder.ToolBox/Tool/Fix/FixHandler.cs index da6c7f4..f3f48c2 100644 --- a/BililiveRecorder.ToolBox/Tool/Fix/FixHandler.cs +++ b/BililiveRecorder.ToolBox/Tool/Fix/FixHandler.cs @@ -68,6 +68,18 @@ namespace BililiveRecorder.ToolBox.Tool.Fix return new FlvTagListReader(xmlFlvFile.Tags); }); } + else if (inputPath.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) + { + xmlMode = true; + tagReader = await Task.Run(() => + { + using var zip = new ZipArchive(File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read), ZipArchiveMode.Read, false, Encoding.UTF8); + var entry = zip.Entries.First(x => x.Name.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)); + var xmlFlvFile = (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(entry.Open()); + meta = xmlFlvFile.Meta; + return new FlvTagListReader(xmlFlvFile.Tags); + }); + } else { flvFileStream = new FileStream(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan); diff --git a/BililiveRecorder.ToolBox/ToolCommand.cs b/BililiveRecorder.ToolBox/ToolCommand.cs index f2cbb2f..e47350f 100644 --- a/BililiveRecorder.ToolBox/ToolCommand.cs +++ b/BililiveRecorder.ToolBox/ToolCommand.cs @@ -30,7 +30,7 @@ namespace BililiveRecorder.ToolBox this.RegisterCommand("export", null, c => { c.Add(new Argument("input", "example: input.flv")); - c.Add(new Argument("output", "example: output.brec.xml.gz")); + c.Add(new Argument("output", "example: output.xml or output.zip")); }); this.RegisterCommand("danmaku-start-time", null, c => diff --git a/BililiveRecorder.WPF/Pages/ToolboxAutoFixPage.xaml.cs b/BililiveRecorder.WPF/Pages/ToolboxAutoFixPage.xaml.cs index 9d9cd50..baa27fa 100644 --- a/BililiveRecorder.WPF/Pages/ToolboxAutoFixPage.xaml.cs +++ b/BililiveRecorder.WPF/Pages/ToolboxAutoFixPage.xaml.cs @@ -44,7 +44,7 @@ namespace BililiveRecorder.WPF.Pages Filters = { new CommonFileDialogFilter("FLV",".flv"), - new CommonFileDialogFilter("dev's toy",".xml,.gz") + new CommonFileDialogFilter("dev's toy",".xml,.gz,.zip") } }; if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok) @@ -266,7 +266,7 @@ namespace BililiveRecorder.WPF.Pages OverwritePrompt = true, InitialDirectory = Path.GetDirectoryName(inputPath), DefaultDirectory = Path.GetDirectoryName(inputPath), - DefaultFileName = Path.GetFileNameWithoutExtension(inputPath) + ".brec.xml.gz" + DefaultFileName = Path.GetFileNameWithoutExtension(inputPath) + ".brec.xml.zip" }; if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok) outputPath = fileDialog.FileName;