Run code cleanup

This commit is contained in:
Malte Rosenbjerg 2025-10-16 15:14:14 +02:00
parent c60e217a2f
commit 0956870875
7 changed files with 232 additions and 199 deletions

View file

@ -1,15 +1,16 @@
using FFMpegCore.Exceptions;
namespace FFMpegCore.Arguments
{
namespace FFMpegCore.Arguments;
/// <summary>
/// Represents output parameter
/// </summary>
public class OutputSegmentArgument : IOutputArgument
{
public readonly string SegmentPattern;
public readonly bool Overwrite;
public readonly SegmentArgumentOptions Options;
public readonly bool Overwrite;
public readonly string SegmentPattern;
public OutputSegmentArgument(SegmentArgument segmentArgument)
{
SegmentPattern = segmentArgument.SegmentPattern;
@ -31,12 +32,18 @@ namespace FFMpegCore.Arguments
throw new FFMpegException(FFMpegExceptionType.Process, "Parameter SegmentWrap cannot equal to zero");
}
}
public Task During(CancellationToken cancellationToken = default) => Task.CompletedTask;
public Task During(CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
}
public void Post()
{
}
public string Text => GetText();
private string GetText()
{
var arguments = Options.Arguments
@ -60,11 +67,31 @@ namespace FFMpegCore.Arguments
{
public List<ISegmentArgument> Arguments { get; } = new();
public SegmentArgumentOptions ResetTimeStamps(bool resetTimestamps = true) => WithArgument(new SegmentResetTimeStampsArgument(resetTimestamps));
public SegmentArgumentOptions Strftime(bool enable = false) => WithArgument(new SegmentStrftimeArgument(enable));
public SegmentArgumentOptions Time(int time = 60) => WithArgument(new SegmentTimeArgument(time));
public SegmentArgumentOptions Wrap(int limit = -1) => WithArgument(new SegmentWrapArgument(limit));
public SegmentArgumentOptions WithCustomArgument(string argument) => WithArgument(new SegmentCustomArgument(argument));
public SegmentArgumentOptions ResetTimeStamps(bool resetTimestamps = true)
{
return WithArgument(new SegmentResetTimeStampsArgument(resetTimestamps));
}
public SegmentArgumentOptions Strftime(bool enable = false)
{
return WithArgument(new SegmentStrftimeArgument(enable));
}
public SegmentArgumentOptions Time(int time = 60)
{
return WithArgument(new SegmentTimeArgument(time));
}
public SegmentArgumentOptions Wrap(int limit = -1)
{
return WithArgument(new SegmentWrapArgument(limit));
}
public SegmentArgumentOptions WithCustomArgument(string argument)
{
return WithArgument(new SegmentCustomArgument(argument));
}
private SegmentArgumentOptions WithArgument(ISegmentArgument argument)
{
Arguments.Add(argument);
@ -74,9 +101,9 @@ namespace FFMpegCore.Arguments
public class SegmentArgument
{
public readonly string SegmentPattern;
public readonly bool Overwrite;
public readonly Action<SegmentArgumentOptions> Options;
public readonly bool Overwrite;
public readonly string SegmentPattern;
public SegmentArgument(string segmentPattern, bool overwrite, Action<SegmentArgumentOptions> options)
{
@ -85,4 +112,3 @@ namespace FFMpegCore.Arguments
Options = options;
}
}
}

View file

@ -1,5 +1,5 @@
namespace FFMpegCore.Arguments
{
namespace FFMpegCore.Arguments;
public class SegmentCustomArgument : ISegmentArgument
{
public readonly string Argument;
@ -8,7 +8,7 @@
{
Argument = argument;
}
public string Key => "custom";
public string Value => Argument ?? string.Empty;
}
}

View file

@ -1,11 +1,12 @@
namespace FFMpegCore.Arguments
{
namespace FFMpegCore.Arguments;
/// <summary>
/// Represents reset_timestamps parameter
/// </summary>
public class SegmentResetTimeStampsArgument : ISegmentArgument
{
public readonly bool ResetTimestamps;
/// <summary>
/// Represents reset_timestamps parameter
/// </summary>
@ -14,7 +15,7 @@
{
ResetTimestamps = resetTimestamps;
}
public string Key { get; } = "reset_timestamps";
public string Value => ResetTimestamps ? $"-reset_timestamps 1" : string.Empty;
}
public string Value => ResetTimestamps ? "-reset_timestamps 1" : string.Empty;
}

View file

@ -1,20 +1,23 @@
namespace FFMpegCore.Arguments
{
namespace FFMpegCore.Arguments;
/// <summary>
/// Use the strftime function to define the name of the new segments to write. If this is selected, the output segment name must contain a strftime function template. Default value is 0.
/// Use the strftime function to define the name of the new segments to write. If this is selected, the output segment name must contain a
/// strftime function template. Default value is 0.
/// </summary>
public class SegmentStrftimeArgument : ISegmentArgument
{
public readonly bool Enable;
/// <summary>
/// Use the strftime function to define the name of the new segments to write. If this is selected, the output segment name must contain a strftime function template. Default value is 0.
/// Use the strftime function to define the name of the new segments to write. If this is selected, the output segment name must contain a
/// strftime function template. Default value is 0.
/// </summary>
/// <param name="enable">true to enable strftime</param>
public SegmentStrftimeArgument(bool enable)
{
Enable = enable;
}
public string Key { get; } = "strftime";
public string Value => Enable ? $"-strftime 1" : string.Empty;
}
public string Value => Enable ? "-strftime 1" : string.Empty;
}

View file

@ -1,11 +1,12 @@
namespace FFMpegCore.Arguments
{
namespace FFMpegCore.Arguments;
/// <summary>
/// Represents segment_time parameter
/// </summary>
public class SegmentTimeArgument : ISegmentArgument
{
public readonly int Time;
/// <summary>
/// Represents segment_time parameter
/// </summary>
@ -14,7 +15,7 @@
{
Time = time;
}
public string Key { get; } = "segment_time";
public string Value => Time <= 0 ? string.Empty : $"-segment_time {Time}";
}
}

View file

@ -1,11 +1,12 @@
namespace FFMpegCore.Arguments
{
namespace FFMpegCore.Arguments;
/// <summary>
/// Represents segment_wrap parameter
/// </summary>
public class SegmentWrapArgument : ISegmentArgument
{
public readonly int Limit;
/// <summary>
/// Represents segment_wrap parameter
/// </summary>
@ -14,7 +15,7 @@
{
Limit = limit;
}
public string Key { get; } = "segment_wrap";
public string Value => Limit <= 0 ? string.Empty : $"-segment_wrap {Limit}";
}
}

View file

@ -2,8 +2,8 @@
using System.Text.Json.Serialization;
using FFMpegCore.Enums;
namespace FFMpegCore
{
namespace FFMpegCore;
public class FFOptions : ICloneable
{
/// <summary>
@ -46,12 +46,8 @@ namespace FFMpegCore
public FFMpegLogLevel? LogLevel { get; set; }
/// <summary>
///
/// </summary>
public Dictionary<string, string> ExtensionOverrides { get; set; } = new()
{
{ "mpegts", ".ts" },
};
public Dictionary<string, string> ExtensionOverrides { get; set; } = new() { { "mpegts", ".ts" } };
/// <summary>
/// Whether to cache calls to get ffmpeg codec, pixel- and container-formats
@ -59,11 +55,16 @@ namespace FFMpegCore
public bool UseCache { get; set; } = true;
/// <inheritdoc />
object ICloneable.Clone() => Clone();
object ICloneable.Clone()
{
return Clone();
}
/// <summary>
/// Creates a new object that is a copy of the current instance.
/// </summary>
public FFOptions Clone() => (FFOptions)MemberwiseClone();
public FFOptions Clone()
{
return (FFOptions)MemberwiseClone();
}
}