Reputation: 199
for i in `cat input`
do
youtube-dl $i &&
done
Here input file contains a list of YouTube video links. I expected this code to do a parallel download of the videos from the list. But the job was completed one after the other. Is it a problem with the code?
Upvotes: 1
Views: 291
Reputation: 10663
for i in `cat input`; do
youtube-dl "$i" &
done
Also, if you don't want to spam youtube with too many simultaneous downloads, you can use this:
cat file.txt | xargs -d '\n' -L 1 -P 5 youtube-dl
This code will be downloading only 5 videos at the same time. I am pretty sure that it is exactly what you're trying to do. This code will also work for links that contain spaces.
Upvotes: 1
Reputation: 185530
You have an extra &
, so :
for i in $(< input); do
youtube-dl "$i" &
done
&&
operator is used in boolean tests, like : ((1 == 1)) && echo "1 == 1" || echo "1 != 1"
$( )
form. It's more readable, and easy to nest.Upvotes: 1
Reputation: 33367
Use the &
symbol instead of the &&
to run a process in the background. The script should look like this:
while read -r i
do
youtube-dl "$i" &
done < "input"
wait ## Optional if you want the script to wait for all videos to download before exiting
Upvotes: 1