Skip to content

Commit 797f44c

Browse files
committed
fix: force yt-dlp pipe output to UTF-8
1 parent bfe0328 commit 797f44c

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

YoutubeDLSharp/YoutubeDLProcess.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@ public YoutubeDLProcess(string executablePath = "yt-dlp.exe")
5757
}
5858

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

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

0 commit comments

Comments
 (0)