mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-15 19:22:19 +08:00
Toolbox: Switch compression format to zip. close #340
This commit is contained in:
parent
ebdf677da0
commit
bb37dbdd3f
|
@ -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);
|
||||
|
|
|
@ -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<ExportResponse> { Status = ResponseStatus.OK, Data = new ExportResponse() };
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace BililiveRecorder.ToolBox
|
|||
this.RegisterCommand<ExportHandler, ExportRequest, ExportResponse>("export", null, c =>
|
||||
{
|
||||
c.Add(new Argument<string>("input", "example: input.flv"));
|
||||
c.Add(new Argument<string>("output", "example: output.brec.xml.gz"));
|
||||
c.Add(new Argument<string>("output", "example: output.xml or output.zip"));
|
||||
});
|
||||
|
||||
this.RegisterCommand<DanmakuStartTimeHandler, DanmakuStartTimeRequest, DanmakuStartTimeResponse>("danmaku-start-time", null, c =>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user