06.07.2009

Bash YouTube Downloader

by Rahul Pisharody

Here is a simple bash script to download YouTube Videos in mp4 via command line.

#!/bin/bash
if [ $# -eq 0 ] ; then
echo ""; echo "";
echo "Usage: ./ytd <URL of the YouTube Video>";
echo "********************************************";
echo "Example: ./ytd http://www.youtube.com/watch?v=klteYv1Uv9A";
echo ""; echo "";
exit 1;
fi
down1="http://www.youtube.com/get_video?fmt=";
down2="&video_id=";
down3="&t=";
wget -O index.html $1;
val1=`grep isHDAvailable index.html | sed ‘s/[; ]//g’|cut -d"=" -f2 | awk ‘/false/{print "18";} /true/{print "22";}’`
val2=`grep swfArgs index.html | grep -o ‘"video_id":.*"’|cut -d":" -f2 | cut -d"," -f1|sed ‘s/[" ]//g’`;
val3=`grep swfArgs index.html | grep -o ‘"t":.*’|cut -d":" -f2|cut -d"," -f1 | sed ‘s/[ "]//g’`;
file=`grep ‘<title>’ index.html | sed -e ‘s!</*title>!!g’ -e ‘s!^s!!g’`;
rm index.html;
wget -O "$file.mp4" $down1$val1$down2$val2$down3$val3;
 

You can download the script and the help file from here.

Related

Comments

  1. Binny V A on 06.08.2009

    Cool – this is replacing my own greasemonkey scirpt to download youtube videos

  2. rpisharody on 06.08.2009

    Wow, Thanks :)

  3. hermes handbags on 07.06.2010

    Wow, Thanks

Leave a Reply