Youtube-dl 输出模板 %(title)s.%(ext)s 在 windows 中无法使用 set /p

Youtube-dl OUTPUT TEMPLATE %(title)s.%(ext)s is not working with set /p in windows

我使用批处理文件和命令:-
设置/p ytlink="Enter the link of Youtube Video:- "
youtube-dl -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" -o "D:\Videos\%(title)s.%(ext)s" %ytlink%
暂停

但输出文件名是 (ext)s.webm ,似乎 cmd 正在处理 %(title)s.% in -o "D:\Videos\%(title)s.%(ext)s" as variable.So 如何获取视频标题?
OS=Windows 10 64 位 1909
youtube-dl=2020.01.24

您必须在批处理文件中使用双 %。

   set /p ytlink="Enter the link of Youtube Video:- "
youtube-dl -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" -o "D:\Videos\%%(title)s.%%(ext)s"     %ytlink%
pause

也许有人会需要它。基于1957年的经典答案。使用从剪贴板中获取的 url 原始名称,以最佳质量将视频和音频下载到您的桌面。

setlocal enabledelayedexpansion
for %%I in (powershell.exe) do if "%%~$PATH:I" neq "" (
    set getclip=powershell "Add-Type -AssemblyName System.Windows.Forms;$tb=New-Object System.Windows.Forms.TextBox;$tb.Multiline=$true;$tb.Paste();$tb.Text"
)
for /f "delims=" %%I in ('%getclip% ^| findstr /n "^"') do (
    set "line=%%I" & set "line=!line:*:=!"
)
set "psCommand="[Environment]::GetFolderPath('DesktopDirectory')""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "Desktop=%%I"
%~d0"%~p0"youtube-dl.exe -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" -o "!Desktop!\%%(title)s.%%(ext)s" !line!