Skip to content

Commit 10201af

Browse files
committed
feat: enhance UTF-8 encoding support in output
1 parent 7e86a5c commit 10201af

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

powershell/yt-download.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ param(
1111
# Stop the script if an error occurs.
1212
$ErrorActionPreference = 'Stop'
1313

14-
$ScriptVersion = "2.5.0-beta.3"
14+
$ScriptVersion = "2.5.0-beta.4"
1515

1616
function TerminateWithError {
1717
param(
@@ -693,6 +693,9 @@ public static extern void CoTaskMemFree(IntPtr pv);
693693
}
694694

695695
if (-not $IsTest) {
696+
# Important for the function Out-ColoredLog
697+
$options += @("--encoding", "utf-8")
698+
696699
# If video title contains a dot as last character, delete it
697700
$options += @("--replace-in-metadata", "title", '\.$', "")
698701
# escape every pwsh chars in title
@@ -780,6 +783,10 @@ public static extern void CoTaskMemFree(IntPtr pv);
780783
& yt-dlp $options
781784
}
782785
else {
786+
# If we don’t set everything in utf-8, the $InputObject from pipeline will be corrupted
787+
# Check https://github.com/PowerShell/PowerShell/issues/25698#issuecomment-4599829781
788+
[Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
789+
783790
& yt-dlp $options 2>&1 | Out-ColoredLog
784791
}
785792

0 commit comments

Comments
 (0)