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

Downloading all related videos from youtube with youtube-dl

How many time did you want to see all the videos (related) to the one you were watching on youtube but decided otherwise as the downloaded was not fast enough. Or has it happened to you that you wanted to download all the related videos, in either case you can use the youtube-dl utility I blogged about some times back. First you need to get all the URL\’s in a text file, and the simplest way to do this is :

press Ctrl+u

copy the html and paste it in a text file and save it.

Note: Ctrl+u in most browsers is for viewing the source. If you do not want to do this then you can simply do a save as and save the html file 🙂

Now time to get all the URL\’s from the html:

for i in $(grep video-list-item <filename> |sed \’s/&amp.*//\’|sed \’s/.*=\”\\(.*\\)/\\1/\’)
do
echo \”Writing $i to youtube.urls file\”
echo \”http://www.youtube.com$i\” >> ~/youtube.urls
done

Just change the filename in the above with the file that you just saved and you will get all the URL\’s in the file \”~/youtube.urls\”. Once this is done you can simply do

youtube-dl -a ~/youtube.urls

\"Reblog