Windows 上的 youtube-dl 批处理文件无法正常工作

batch file on Windows for youtube-dl not working

我正在尝试使用下面的这个批处理文件来处理一堆 YouTube 视频。

@echo off
echo Starting batch script
cd C:\Users\username\Desktop\youtube-dl
youtube-dl -o "%(playlist_index)s-%(title)s.%(ext)s" --extract-audio --audio-format mp3 --prefer-ffmpeg --ffmpeg-location "..\..\FFMPEG" "https://www.youtube.com/playlist?list=OLAK5uy_l9XKOFt6oHtwWWnt_zNg3PX5Wssi4s4Ss" --audio-quality 0
youtube-dl -o "%(playlist_index)s-%(title)s.%(ext)s" --extract-audio --audio-format mp3 --prefer-ffmpeg --ffmpeg-location "..\..\FFMPEG" "https://www.youtube.com/playlist?list=OLAK5uy_kP8cX8DV33AWt9L5QCuwQzWYqae2jMcIo" --audio-quality 0
youtube-dl -o "%(playlist_index)s-%(title)s.%(ext)s" --extract-audio --audio-format mp3 --prefer-ffmpeg --ffmpeg-location "..\..\FFMPEG" "https://www.youtube.com/playlist?list=OLAK5uy_nNJBk4Zdivjgrj54NgPsubqd4VolevUd0" --audio-quality 0
echo all file operations complete

youtube-dl 位于 cd C:\Users\username\Desktop\youtube-dl

如果我将 3 个 youtube-dl 命令单独粘贴到命令提示符中,每个命令都可以正常工作。

但是,当我 运行 这个批处理文件(.bat 扩展名)时,我得到这个错误:

youtube-dl: error: you must provide at least one URL

我该怎么做才能修复这个批处理文件?

更新:我认为发生的情况是同时输入所有 3 个 youtube-dl 命令。怎么才能让第一个处理完才进第二个,第二个处理完才进第三个?

更新 2:因此,经过进一步调查,我的代码中的 % 符号在通过批处理脚本执行时似乎没有以相同的方式解释。批处理脚本忽略 % 之间的内容。关于如何解决这个问题有什么想法吗?

如果您在批处理文件中执行此操作,则需要使用另一个像这样的 % 转义您的 %%%。如果您的命令使用了正确的语法:

@echo off

echo Starting batch script
cd C:\Users\username\Desktop\youtube-dl
youtube-dl -o "%%(playlist_index)s-%%(title)s.%%(ext)s" --extract-audio --audio-format mp3 --prefer-ffmpeg --ffmpeg-location "..\..\FFMPEG" "https://www.youtube.com/playlist?list=OLAK5uy_l9XKOFt6oHtwWWnt_zNg3PX5Wssi4s4Ss" --audio-quality 0
youtube-dl -o "%%(playlist_index)s-%%(title)s.%%(ext)s" --extract-audio --audio-format mp3 --prefer-ffmpeg --ffmpeg-location "..\..\FFMPEG" "https://www.youtube.com/playlist?list=OLAK5uy_kP8cX8DV33AWt9L5QCuwQzWYqae2jMcIo" --audio-quality 0
youtube-dl -o "%%(playlist_index)s-%%(title)s.%%(ext)s" --extract-audio --audio-format mp3 --prefer-ffmpeg --ffmpeg-location "..\..\FFMPEG" "https://www.youtube.com/playlist?list=OLAK5uy_nNJBk4Zdivjgrj54NgPsubqd4VolevUd0" --audio-quality 0
echo all file operations complete

进一步阅读:percent symbols