Posted by: arun on: November 10, 2008
I had posted long back about a bash wrapper over youtube-dl to fetch youtube videos using your own download manager. The youtube-dl script had changed long since then. And good news is now we don’t need to change the script in any way to get the download url. So here we go!
Grab the latest youtube-dl from here
Minor update to the linux youtube-dl script:
#!/bin/bash
if [ $# -ne 2 ]
then
echo “Usage : $0 ”
echo “e.g : $0 http://www.youtube.com/watch?v=D1R-jKKp3NA steve_jobs”
else
outputfile=”.avi”
todnload=$(youtube-dl -g $1) # youtube-dl is in path, right?
echo “Got the file..”$todnload
axel -n 100 $todnload -o $2″.flv” # wget -c $todnload -O $2″.flv” .if you don’t use axel
echo “Download Completed…”
ffmpeg -i $2″.flv” $2$outputfile # get the avi file
fi
Enjoy ![]()
Thanks Jay for pointing this out!
Ok, apparently new versions of youtube-dl return the URL before it has been redirected and axel doesn’t understand these URLs. I’m now using the following script to get it working with the most recent version of youtube-dl:
#!/bin/bash
url=$(xsel -b -o)
title=$(/home/ph/bin/youtube-dl -e $url)
/home/ph/bin/youtube-dl -g -b $url | xargs wget –spider 2>&1 | grep Location: | awk ‘{print $2}’ | xargs axel -q -o /home/ph/ytvids/”$title.mp4″
mplayer /home/ph/ytvids/”$title.mp4″
It downloads the video corresponding to the URL I currently have in my clipboard. The important part is the fourth line, where the redirected URL is determined using wget, so that axel can understand it.
#!/bin/bash
if [ $# -ne 2 ]
then
echo “Usage : $0 ”
echo “e.g : $0 http://www.youtube.com/watch?v=D1R-jKKp3NA steve_jobs”
else
outputfile=”.avi”
todnload=$(youtube-dl -g -b $2 | xargs wget –spider 2>&1 | grep Location: | awk ‘{print $2}’)
echo “Got the file..”$todnload
axel -n 100 $todnload -o -q $1″.flv”
echo “Download Completed…”
ffmpeg -i $1″.flv” $1$outputfile
fi
this works. thanks to phillip hartwig’s code.
oh and i changed the syntax to:
utube NAME url
aaaaaaaaaand a working version:
#!/bin/bash
if [ $# -ne 2 ]
then
echo “Usage : $0 ”
echo “e.g : $0 steve_jobs http://www.youtube.com/watch?v=D1R-jKKp3NA”
else
todnload=$(youtube-dl -g -b $2 | xargs wget –spider 2>&1 | grep Location: | awk ‘{print $2}’)
#echo -e “Got the file…\n$todnload”
axel -n 100 $todnload -o $1.flv
echo “Download Completed…”
ffmpeg -i $1.flv $1.avi
fi
The author of youtube-dl just informed me that in the latest version of youtube-dl the old behavior of the “-g” flag has been restored, rendering my workaround unnecessary.
July 20, 2009 at 1:57 am
Hi,
this sounds like a good tip, but unfortunately alex doesn’t seem to accept youtube urls (anymore). I always get an HTTP/1.0 404 Not Found. The urls work with wget, but the download isl rather slow then. Does it still work for you?