I want to play youtube videos on a loop from my terminal using mplayer, and for that I've written the following code taking pieces from here and there:
#!/bin/bash if [[ $(echo $*) ]]; then searchterm="$*" else read -p "Enter the video ID: " searchterm fi searchterm=$(echo $searchterm | sed -e 's/\ /+/g') video=$(youtube-dl -g https://youtube.com/v/$searchterm) while true; do mplayer $video sleep 2; done
To play the video you need to feed the video ID to the script. For example if this is the video you're watching: https://www.youtube.com/watch?v=daQhI1JFXn4 Then the video ID is the part after
v= which is
Everything works fine, except it still downloads the video every time that it goes trough the loop. I am wondering if there is any way that this could be changed so that it downloads the file only once and play it over and over.