Script to download all the related videos from youtube with youtube-dl

Lets cut the long discussion short and directly give you the script. The script is combination of all the posts that I did in the past about youtube downloads. You need to copy all the URL\’s in a file called \”~/youtube.urls\” which you want to be downloaded. Or if you need to donwload the related videos, then save the html of the page and give it as the first argument for the script. So, here\’s the scrit:

#!/bin/bash –
#===============================================================================
#
#          FILE:  youtube_releated.sh
#
#         USAGE:  ./youtube_releated.sh
#
#   DESCRIPTION:  Get the related urls from the youtube html
#
#       OPTIONS:  —
#  REQUIREMENTS:  —
#          BUGS:  —
#         NOTES:  —
#        AUTHOR:  Amit Agarwal (AKA), [email protected]
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  05/02/2010 04:45:54 PM IST
#      REVISION:  —
#===============================================================================
user=raj77india
pass=Kukku1977
if [  $# -ge 1 ]
then
for i in $(grep video-list-item $1 |sed \’s/&.*//\’|sed \’s/.*=\”\\(.*\\)/\\1/\’)
do
echo \”Writing $i to youtube.urls file\”
echo \”http://www.youtube.com$i\” >> ~/youtube.urls
done
fi

read -p \”Download all the urls :\” ans

cd ~

if [ \”$ans\” = \”y\” ]
then
grep -v \”^#\” ~/youtube.urls > /tmp/youtube.urls
while read line
do
youtube-dl -u $user -p $pass -t $line
done < /tmp/youtube.urls
fi

read -p \”Add title to the file :\” ans1

if [ \”$ans1\” != \”y\” ]
then
exit
fi
rm -f /tmp/youtube.urls

while read line
do
echo $line|grep -c \”^#\”
if [ $(echo $line|grep -c \”^#\”) -eq 1 ]
then
echo \”#$line\” >>/tmp/youtube.urls
echo \”Skipping $line\”
continue
else
title=$(youtube-dl -u $user -p $pass -e $line)
echo \”title is $title\”
fi
done <~/youtube.urls

mv /tmp/youtube.urls ~/youtube.urls

Since the script is quite simple, its not much documented. Anyways if you need help, feel free to contact me 🙂 (contact form or comment)

\"Reblog