Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 35 additions & 28 deletions src/Ytdlp.NET/Ytdlp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,12 @@
/// <summary>
/// Builds the command-line arguments for a given URL based on the current configuration.
/// </summary>
/// <param name="url"></param>

Check warning on line 291 in src/Ytdlp.NET/Ytdlp.cs

View workflow job for this annotation

GitHub Actions / Validate PR

XML comment has a param tag for 'url', but there is no parameter by that name

Check warning on line 291 in src/Ytdlp.NET/Ytdlp.cs

View workflow job for this annotation

GitHub Actions / Validate PR

XML comment has a param tag for 'url', but there is no parameter by that name

Check warning on line 291 in src/Ytdlp.NET/Ytdlp.cs

View workflow job for this annotation

GitHub Actions / Validate PR

XML comment has a param tag for 'url', but there is no parameter by that name

Check warning on line 291 in src/Ytdlp.NET/Ytdlp.cs

View workflow job for this annotation

GitHub Actions / Validate PR

XML comment has a param tag for 'url', but there is no parameter by that name

Check warning on line 291 in src/Ytdlp.NET/Ytdlp.cs

View workflow job for this annotation

GitHub Actions / Validate PR

XML comment has a param tag for 'url', but there is no parameter by that name

Check warning on line 291 in src/Ytdlp.NET/Ytdlp.cs

View workflow job for this annotation

GitHub Actions / Validate PR

XML comment has a param tag for 'url', but there is no parameter by that name
/// <returns></returns>
private List<string> BuildArguments(string url)
private List<string> BuildConnectionArguments()
{
var args = new List<string>();

bool usingAbsoluteOutput = !string.IsNullOrWhiteSpace(_outputFolder);

if (usingAbsoluteOutput && !string.IsNullOrWhiteSpace(_tempFolder))
{
_logger.Log(LogType.Debug, "Temp folder ignored because absolute output template is used.");
}

// Authentication
if (_auth is not null)
{
Expand All @@ -324,6 +317,40 @@
args.Add("-"); // tells yt-dlp to read from stdin
}

// Options
if (_options.Length > 0)
{
foreach (var kv in _options)
{
args.Add(kv.Key);
if (kv.Value != null)
args.Add(kv.Value);
}
}

// Special single-value options
if (_cookiesFile is not null) { args.Add("--cookies"); args.Add(_cookiesFile); }
if (_cookiesFromBrowser is not null) { args.Add("--cookies-from-browser"); args.Add(_cookiesFromBrowser); }
if (_proxy is not null) { args.Add("--proxy"); args.Add(_proxy); }
if (_ffmpegLocation is not null) { args.Add("--ffmpeg-location"); args.Add(_ffmpegLocation); }
if (_sponsorblockMark is not null) { args.Add("--sponsorblock-mark"); args.Add(_sponsorblockMark); }
if (_sponsorblockRemove is not null) { args.Add("--sponsorblock-remove"); args.Add(_sponsorblockRemove); }
if (_sponsorblockChapterTitle is not null) { args.Add("--sponsorblock-chapter-title"); args.Add(_sponsorblockChapterTitle); }

return args;
}

private List<string> BuildArguments(string url)
{
var args = BuildConnectionArguments();

bool usingAbsoluteOutput = !string.IsNullOrWhiteSpace(_outputFolder);

if (usingAbsoluteOutput && !string.IsNullOrWhiteSpace(_tempFolder))
{
_logger.Log(LogType.Debug, "Temp folder ignored because absolute output template is used.");
}

// temp folder
if (!usingAbsoluteOutput && !string.IsNullOrWhiteSpace(_tempFolder))
{
Expand Down Expand Up @@ -372,26 +399,6 @@
if (_flags.Length > 0)
args.AddRange(_flags);

// Options
if (_options.Length > 0)
{
foreach (var kv in _options)
{
args.Add(kv.Key);
if (kv.Value != null)
args.Add(kv.Value);
}
}

// Special single-value options
if (_cookiesFile is not null) { args.Add("--cookies"); args.Add(_cookiesFile); }
if (_cookiesFromBrowser is not null) { args.Add("--cookies-from-browser"); args.Add(_cookiesFromBrowser); }
if (_proxy is not null) { args.Add("--proxy"); args.Add(_proxy); }
if (_ffmpegLocation is not null) { args.Add("--ffmpeg-location"); args.Add(_ffmpegLocation); }
if (_sponsorblockMark is not null) { args.Add("--sponsorblock-mark"); args.Add(_sponsorblockMark); }
if (_sponsorblockRemove is not null) { args.Add("--sponsorblock-remove"); args.Add(_sponsorblockRemove); }
if (_sponsorblockChapterTitle is not null) { args.Add("--sponsorblock-chapter-title"); args.Add(_sponsorblockChapterTitle); }

// URL last
args.Add(url);

Expand Down
5 changes: 5 additions & 0 deletions src/Ytdlp.NET/Ytdlp/Ytdlp.Probe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ public async Task<List<SubtitleTrack>> GetSubtitlesAsync(string url, Cancellatio

var result = await runner.ExecuteAsync(
arguments,
auth: _auth,
adobePass: _adobePass,
onLineReceived: null,
ct: ct,
tuneProcess: tuneProcess,
Expand Down Expand Up @@ -475,7 +477,10 @@ public async Task<List<SubtitleTrack>> GetSubtitlesAsync(string url, Cancellatio
if (string.IsNullOrWhiteSpace(url))
throw new ArgumentException("URL cannot be empty.", nameof(url));

var connectionArguments = string.Join(" ", BuildConnectionArguments().Select(EscapeArgument));

var arguments =
(connectionArguments.Length > 0 ? connectionArguments + " " : string.Empty) +
"--dump-single-json " +
"--simulate " +
"--skip-download " +
Expand Down
Loading