Downlaod YouTube videos with bash script

Valic —  May 18, 2011 — 3 Comments

Here’s a oneliner bash script that uses wget, sed, awk, and tr to download a video from YouTube.

Tested on Debian and Mac. Just put the code below in a file and make your file executable using:

chmod +x yourfile.sh

#!/bin/bash

## Two arguments
# $1 Youtube URL
# $2 You name for the video
wget -c –no-check-certificate –user-agent=”" $1 -qO- | \
sed ‘s/\\u0026/\&/g’| \
awk ‘/fmt_url_map/{gsub(/[\|\"]/,”\n”);print}’ | \
sed -n “/^fmt_url_map/,/videoplayback/p” | \
sed -e :a -e ‘$q;N;2,$D;ba’ | tr -d ‘\n’ | \
sed -e “s/\(.*\),\(.\)\{1,3\}/\1/;s/\\\//g” | \
wget -c –no-check-certificate –user-agent=”" -i – -O $2.flv

After putting in a file and making it executable just go get your YouTube url and fire off the download.
Here’s an example.

./youtube_downloader.sh ‘http://www.youtube.com/watch?v=FRWLfY7hMgQ’ filename_to_save

This will make the file filename_to_save.flv in your dir.

Enjoy.

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

3 responses to Downlaod YouTube videos with bash script

  1. Hello, thanks for your tutorial. But it seems not to work for me! I don’t know if I’m getting things well.
    This is what I get on the terminal (by the way I am a new-commer to Linux) Thanks for your reply!

    [email protected]:/home/mydodjy/Desktop/Goodies# ./Youtube_Dowloader.sh http://www.youtube.com/watch?feature=player_detailpage&v=6o_OQkrEKw4#t=0s Africando_Doni_Doni
    [1] 14958
    bash: Africando_Doni_Doni: command not found
    [email protected]:/home/mydodjy/Desktop/Goodies# –2012-02-18 13:43:12– http://%E2%80%93no-check-certificate/
    Resolving –no-check-certificate… failed: Name or service not known.
    wget: unable to resolve host address “–no-check-certificate”
    –user-agent=” http://www.youtube.com/watch?feature=player_detailpage -qO- | sed ‘s/\u0026/\&/g’| awk ‘/fmt_url_map/{gsub(/[\|"]/,”\n”);print}’ | sed -n “/^fmt_url_map/,/videoplayback/p” | sed -e :a -e ‘;N;2,;ba’ | tr -d ‘\n’ | sed -e “s/\(.*\),\(.\)\{1,3\}/\1/;s/\\//g” | wget -c –no-check-certificate –user-agent=”: Scheme missing.
    –: No such file or directory
    No URLs found in –.

  2. hello,
    that script does not work anymore. i’ll try to create another script soon

  3. Thanks for your reply!

Leave a Reply