Linux console downloading Youtube audio and video files

Default featured post

Youtube-dl is a very powerful tool which provides bunch of great facilities. For instance, you easily can download an audio file of Youtube video directly with the following command,

$ youtube-dl --extract-audio --audio-format mp3 [Link]

In my case I wanted to download both audio and video files without typing another command. In fact, my objective was to make everything integrated for easy use. After doing some research and trying many times, I have come up with the below command which downloads both audio and video flash files for you,

$ echo "Please wait, your video is downloading";var=$(youtube-dl ''|grep Destination|cut -d ':' -f2|xargs);output=$(echo $var | sed 's/...$//');output=$output"mp3";avconv -i "$var" "$output";echo "Video File Name : " $var;echo "Audio File Name : " $output;

The above code can be run as a command or Linux script, just remember to replace the URL. My personal suggestion is to use it as script and add the script in .bashrc file with defining an alias for that. Check the neat script,

echo "Please wait, your video is downloading"
var=$(youtube-dl $1 | grep "Destination")
var=$(echo $var | cut -d ':' -f2)
var=$(echo $var | xargs)
output=$(echo $var | sed 's/...$//')
avconv -i "$var" "$output"
echo "Video File Name : " $var
echo "Audio File Name : " $output

Then you can save the script and add the following line in your .bashrc file.

alias youtube-dl-audio-video=['']