Script to download all the related videos from youtube with youtube-dl
2010-05-17
411 words
2 mins read
Lets cut the long discussion <a class="zem_slink freebase/en/short_subject" title="Short film" rel="wikipedia" href="http://en.wikipedia.org/wiki/Short_film">short and directly give you the script. The script is combination of all the posts that I did in the past about youtube <a class="zem_slink freebase/en/uploading_and_downloading" title="Uploading and downloading" rel="wikipedia" href="http://en.wikipedia.org/wiki/Uploading_and_downloading">downloads. You need to copy all the <a class="zem_slink freebase/en/uniform_resource_locator" title="Uniform Resource Locator" rel="wikipedia" href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator">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), amit.agarwal@amit-agarwal.co.in
# 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 $(<a class="zem_slink freebase/en/grep" title="Grep" rel="wikipedia" href="http://en.wikipedia.org/wiki/Grep">grep video-<a class="zem_slink freebase/en/html_element" title="HTML element" rel="wikipedia" href="http://en.wikipedia.org/wiki/HTML_element">list-item $1 |sed ’s/&.*//’|sed ’s/.*=”\(.*\)/\1/’)
do
echo ”<a class="zem_slink freebase/en/writing" title="Writing" rel="wikipedia" href="http://en.wikipedia.org/wiki/Writing">Writing $i to youtube.urls file”
echo ”http://www.youtube.com$i” » ~/youtube.urls
done
firead -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
firead -p ”Add title to the file :” ans1
if [ ”$ans1” != ”y” ]
then
exit
fi
rm -f /tmp/youtube.urlswhile 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.urlsmv /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)<h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://mashable.com/2010/05/12/youtube-unlisted-videos/">YouTube Introduces New Privacy Option for Videos (mashable.com) <li class="zemanta-article-ul-li"><a href="http://blog.amit-agarwal.co.in/2010/05/03/download-youtube-video-command-line-youtubedl/">Download youtube video directly from the command line with youtube-dl (amit-agarwal.co.in) <li class="zemanta-article-ul-li"><a href="http://www.mt-soft.com.ar/2010/05/08/bytubed-makes-it-easier-than-ever-to-download-multiple-youtube-videos-in-one-go/">BYTubeD Makes It Easier Than Ever To Download Multiple Youtube Videos In One Go (mt-soft.com.ar) <li class="zemanta-article-ul-li"><a href="http://news.cnet.com/8301-27076_3-20004804-248.html?part=rss&subj=news&tag=2547-1_3-0-20">YouTube gets a very useful ’unlisted’ video option (news.cnet.com) <li class="zemanta-article-ul-li"><a href="http://r.zemanta.com/?u=http%3A//www.telegraph.co.uk/technology/google/7718944/YouTube-to-allow-private-videos.html&a=17971522&rid=c0dd8728-f84d-4fa7-9713-82709d89e076&e=60f5225d824312c9b68b523582484d50">YouTube to allow ’private’ videos (telegraph.co.uk) <div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/c0dd8728-f84d-4fa7-9713-82709d89e076/"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_b88.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">
Related Articles:
- 2010/05/16 Downloading all related videos from youtube with youtube-dl
- 2010/05/03 Download youtube video directly from the command line with youtube-dl
- 2010/03/29 Extract all urls from the last firefox sessionstore.js file used.
- 2010/05/16 They own your CPU (and so so in Windows and Mac, too)
- 2010/05/11 Firefox 4.0 mockups for LInux/Windows and Mac