diff --git a/YoutubeDLSharp/YoutubeDLProcess.cs b/YoutubeDLSharp/YoutubeDLProcess.cs index dbd1133..79b5a88 100644 --- a/YoutubeDLSharp/YoutubeDLProcess.cs +++ b/YoutubeDLSharp/YoutubeDLProcess.cs @@ -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);