Skip to content
Open
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
13 changes: 12 additions & 1 deletion YoutubeDLSharp/YoutubeDLProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ public YoutubeDLProcess(string executablePath = "yt-dlp.exe")
}

internal string ConvertToArgs(string[] urls, OptionSet options)
=> options.ToString() + " -- " + (urls != null ? String.Join(" ", urls.Select(s => $"\"{s}\"")) : String.Empty);
{
var args = options.ToString();
// By default, force yt-dlp to write its standard output and error output in UTF-8,
// which is the encoding the process output is always read with below. Without this,
// yt-dlp (a Python program) uses the system locale's ANSI code page (e.g. GBK on
// Chinese Windows) for redirected pipes, and decoding those bytes as UTF-8 turns
// every non-ASCII character into a U+FFFD replacement character. An explicit
// OptionSet.Encoding is respected and left untouched.
if (options.Encoding == null)
args += " --encoding utf-8";
return args + " -- " + (urls != null ? String.Join(" ", urls.Select(s => $"\"{s}\"")) : String.Empty);
}

internal void RedirectToError(DataReceivedEventArgs e)
=> ErrorReceived?.Invoke(this, e);
Expand Down