Add partition by file size (#497)

This commit is contained in:
Andrew Kolos
2021-04-12 06:50:32 -04:00
committed by GitHub
parent ad3655396f
commit eb89ea5b40
23 changed files with 331 additions and 22 deletions

View File

@@ -31,8 +31,9 @@ namespace DiscordChatExporter.Cli.Commands.Base
[CommandOption("before", Description = "Only include messages sent before this date or message ID.")]
public Snowflake? Before { get; init; }
[CommandOption("partition", 'p', Description = "Split output into partitions limited to this number of messages.")]
public int? PartitionLimit { get; init; }
[CommandOption("partition", 'p', Converter = typeof(PartitionConverter),
Description = "Split output into partitions limited to this number of messages or a maximum file size (e.g. \"25mb\").")]
public IPartitioner Partitoner { get; init; } = new NullPartitioner();
[CommandOption("parallel", Description = "Limits how many channels can be exported in parallel.")]
public int ParallelLimit { get; init; } = 1;
@@ -74,7 +75,7 @@ namespace DiscordChatExporter.Cli.Commands.Base
ExportFormat,
After,
Before,
PartitionLimit,
Partitoner,
ShouldDownloadMedia,
ShouldReuseMedia,
DateFormat

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using ByteSizeLib;
using CliFx.Extensibility;
using DiscordChatExporter.Core;
using DiscordChatExporter.Core.Exporting;
namespace DiscordChatExporter.Cli.Commands.Base
{
public class PartitionConverter : BindingConverter<IPartitioner>
{
public override IPartitioner Convert(string? rawValue)
{
if (rawValue == null) return new NullPartitioner();
if (ByteSize.TryParse(rawValue, out ByteSize filesize))
{
return new FileSizePartitioner((long)filesize.Bytes);
}
else
{
int messageLimit = int.Parse(rawValue);
return new MessageCountPartitioner(messageLimit);
}
}
}
}