Download a youtube video using bash

Categories: bash

Was bored today,so i just thought to code a simple bash script to download a youtube video using bash. You can have a look at the source to be clear about how it’s done. Mostly i have used wget command to download source and the video file from youtube and cut, awk and grep to parse various values from the source.

#!/bin/bash
#Youtube video downloader
#coder : Anil Dewani

read -p "Youtube.com URL :" url
read -p "Name the video(no spaces please) :" name
wget ${url} -O source.txt >/dev/null 2>&1
videoid=$(echo $url | awk -F "v=" '{print $2}')
ticket=$(grep "&t=" source.txt | awk -F "&t=" '{print $2}' | cut -d"&" -f1)
base="http://www.youtube.com/get_video?video_id="
downloadurl=${base}${videoid}"&t="${ticket}
rm -f source.txt
echo "Downloading video..."
echo "This may take a while...please wait"
wget ${downloadurl} -O ${name}.flv >/dev/null 2>&1
echo "Video Download Succesfull. File saved as ${name}.flv"

Usage:

[anil@server ~]$ ./utube.sh
Youtube.com URL :http://www.youtube.com/watch?v=oaO-LgxNjB8
Name the video(no spaces please) :justdance
Downloading video...
This may take a while...please wait
Video Download Succesfull. File saved as justdance.flv
Tags: , , ,
3 Comments

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>