我正在尝试让 youtube-dl 调用我编写的一个小型 PowerShell 脚本,该脚本将下载的音频转换为 mp3,同时对其进行标准化,以便我下载的所有歌曲的音量大致相同。问题是,显然youtube-dl
尝试执行的方式会阻止它:
PS > youtube-dl -i -f bestaudio --exec "powershell D:\PowerShell\ConvertAndNormalize.ps1 {}" https
://www.youtube.com/watch?v=8v_4O44sfjM
[youtube] 8v_4O44sfjM: Downloading webpage
[youtube] 8v_4O44sfjM: Downloading video info webpage
[download] Destination: Christina Perri - Jar of Hearts [Official Music Video]-8v_4O44sfjM.webm
[download] 100% of 4.20MiB in 00:00
[exec] Executing command: powershell D:\PowerShell\ConvertAndNormalize.ps1 "Christina Perri - Jar of Hearts [Official Music Video]-8v_4O44sfjM.webm"
D:\PowerShell\ConvertAndNormalize.ps1 : File D:\PowerShell\ConvertAndNormalize.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ D:\PowerShell\ConvertAndNormalize.ps1 Christina Perri - Jar of Hearts ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
ERROR: Command returned error code 1
PS > Get-ExecutionPolicy
RemoteSigned
直接从 powershell 调用脚本可以按预期工作:
PS > D:\PowerShell\ConvertAndNormalize.ps1 "Christina Perri - Jar of Hearts [Official Music Video]
-8v_4O44sfjM.webm"
如何让 youtube-dl 调用我的 PowerShell 脚本?
答案1
我需要添加-ExecutionPolicy RemoteSinged
如下命令:
PS > youtube-dl -i -f bestaudio --exec "powershell -ExecutionPolicy RemoteSigned D:\PowerShel\ConvertAndNormalize.ps1 {}" https://www.youtube.com/watch?v=8v_4O44sfjM
我仍然不确定我需要给予它什么范围以便不必这样做但它有效,所以这就是我想要的。