[Update] Download youtube videos in linux

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!

About these ads

7 thoughts on “[Update] Download youtube videos in linux

  1. 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?

  2. 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.

  3. #!/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.

  4. 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

  5. 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.

  6. Hey ya’all! Thanks for the axel usage. They JUST updated youtube today, and i have the new youtube-dl , but now I can’t figure out how to get axel to download it again. With the code and the way it was working, yourabove script would have something in todownload variable, but now its blank.
    any help would be greatly appreciated.

    great site btw!
    ~~David

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s