我有这个脚本(在我的个人资料中别名为ydl
):
param(
[string]$url,
[switch]$vid=$false
)
$ydl = "D:\youtube-dl\youtube-dl.exe"
$mp3conf = "--config-location `"D:/youtube-dl/config-mp3.txt`""
$vidconf = "--config-location `"D:/youtube-dl/config-mp4.txt`""
$finalArgs = $mp3conf
If ($vid) {
$finalArgs = $vidconf
}
Write-Host $ydl $url $finalArgs
& $ydl $url $finalArgs
Powershell 输出:
PS D:\> ydl https://www.youtube.com/watch?v=c_7Mcb6iLN0
D:\youtube-dl\youtube-dl.exe https://www.youtube.com/watch?v=123 --config-location "D:/youtube-dl/config-mp3.txt"
Usage: youtube-dl.exe [OPTIONS] URL [URL...]
youtube-dl.exe: error: no such option: --config-location D:/youtube-dl/config-mp3.txt
好吧?真不幸……但如果我尝试直接运行该命令——Write-Host
从脚本的输出中复制它,会怎么样?
Powershell 说参数列表的结果如下:
D:\youtube-dl\youtube-dl.exe https://www.youtube.com/watch?v=123 --config-location "D:/youtube-dl/config-mp3.txt"
好的,我们来尝试一下:
PS D:\> D:\youtube-dl\youtube-dl.exe https://www.youtube.com/watch?v=123 --config-location "D:/youtube-dl/config-mp3.txt"
[youtube] 123: Downloading webpage
[youtube] 123: Downloading video info webpage
[youtube] 123: Extracting video information
[youtube] 123: Downloading MPD manifest
[download] Destination: D:\youtube-dl\MP3\123.webm
[download] 100% of 2.48MiB in 00:00
[ffmpeg] Destination: D:\youtube-dl\MP3\123.mp3
Deleting original file D:\youtube-dl\MP3\123.webm (pass -k to keep)
怎么回事?它在命令行中可以工作,但在脚本中却不行?