-
-
Notifications
You must be signed in to change notification settings - Fork 496
/
ConversionRequestBuilder.cs
77 lines (67 loc) · 2.14 KB
/
ConversionRequestBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using YoutubeExplode.Converter.Utils.Extensions;
using YoutubeExplode.Videos.Streams;
namespace YoutubeExplode.Converter;
/// <summary>
/// Builder for <see cref="ConversionRequest" />.
/// </summary>
public class ConversionRequestBuilder(string outputFilePath)
{
private string? _ffmpegCliFilePath;
private Container? _container;
private ConversionPreset _preset;
private Container GetDefaultContainer() =>
new(Path.GetExtension(outputFilePath).TrimStart('.').NullIfWhiteSpace() ?? "mp4");
/// <summary>
/// Sets the path to the FFmpeg CLI.
/// </summary>
public ConversionRequestBuilder SetFFmpegPath(string path)
{
_ffmpegCliFilePath = path;
return this;
}
/// <summary>
/// Sets the output container.
/// </summary>
public ConversionRequestBuilder SetContainer(Container container)
{
_container = container;
return this;
}
/// <summary>
/// Sets the output container.
/// </summary>
public ConversionRequestBuilder SetContainer(string container) =>
SetContainer(new Container(container));
/// <summary>
/// Sets the conversion format.
/// </summary>
[Obsolete("Use SetContainer instead."), ExcludeFromCodeCoverage]
public ConversionRequestBuilder SetFormat(ConversionFormat format) =>
SetContainer(new Container(format.Name));
/// <summary>
/// Sets the conversion format.
/// </summary>
[Obsolete("Use SetContainer instead."), ExcludeFromCodeCoverage]
public ConversionRequestBuilder SetFormat(string format) => SetContainer(format);
/// <summary>
/// Sets the conversion preset.
/// </summary>
public ConversionRequestBuilder SetPreset(ConversionPreset preset)
{
_preset = preset;
return this;
}
/// <summary>
/// Builds the resulting request.
/// </summary>
public ConversionRequest Build() =>
new(
_ffmpegCliFilePath ?? FFmpeg.GetFilePath(),
outputFilePath,
_container ?? GetDefaultContainer(),
_preset
);
}