I'm trying to use this batch file below to process a bunch of YouTube videos.
@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
is located in cd C:\Users\username\Desktop\youtube-dl
Each of the 3 youtube-dl
commands works fine if I paste it individually into the Command Prompt.
However, when I run this batch file (.bat
extension), I get this error:
youtube-dl: error: you must provide at least one URL
What can I do to fix this batch file please?
Update: I think what's happening is that all 3 youtube-dl
commands are getting entered at the same time. What can I do so that the 2nd one is only entered after the 1st one has finished processing, and the 3rd one is only entered after the 2nd one has finished processing?
Update 2: So upon further investigation it looks like the %
symbols in my code are not interpreted the same way when executed via the Batch Script. The Batch Script ignores the content between the %
's. Any thoughts on how I can resolve this?
If you're doing this in a batch file, you need to escape your %
with another one like this: %%
. If your commands are using the correct syntax:
@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
Further reading: percent symbols