pantz.org banner
YouTube video download oneliner
Posted on 02-18-2011 04:04:15 UTC | Updated on 03-25-2011 01:41:40 UTC
Section: /software/shell/ | Permanent Link

So Adobe decided to change the way it uses temp files in Flash for its newer 10.2r152 version in Linux. Before when you went to YouTube and watched a video it would temporarily put the video in your /tmp dir in the format /tmp/FlashXX*. It stayed there while you kept the webpage open. You could then copy the video from /tmp to wherever for your own use. Now the temp file is nowhere to be found. To take its place how about a shell oneliner to download a YouTube video from the command line?

Here's a oneliner bash script that uses wget, sed, awk, and tr to download a video from YouTube. Works on BSD, Linux, and Mac. Just put the code below in a file (I'll call mine ytd.sh) and make your file executable chmod +x ytd.sh.

#!/bin/bash
## Get Youtube Video using wget
## (compatible with Linux, BSD and OSX)
#
## 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 in a file and making it executable just go get your YouTube url and fire off the download. Here's an example.

./ytd.sh 'http://www.youtube.com/watch?v=J---aiyznGQ' keycat

This will make the file keycat.flv in your dir. Use a recent VLC or Mplayer to play the file.

Its very likely that this script will be out of date (broken) soon but hopefully it will be a good blueprint for anyone else in the future. Thanks to our friends at calomel.org for the fun code!

Del.icio.us! | Digg Me! | Reddit!

Related stories


RSS Feed RSS feed logo
About


3com
3ware
alsa
alsactl
alsamixer
amd
android
apache
areca
arm
ati
auditd
awk
badblocks
bind
bios
bonnie
cable
carp
cat5
cdrom
centos
chart
cifs
cisco
comcast
commands
comodo
compiz-fusion
corsair
cpufreq
cpufrequtils
cpuspeed
cron
crontab
crossover
cu
cups
cvs
database
dbus
dd
dd_rescue
ddclient
debian
decimal
dhclient
dhcp
diagnostic
diskexplorer
disks
dns
dos
dovecot
dsniff
dvdauthor
e-mail
echo
editor
emerald
ethernet
ext3
fat32
fedora
fetchmail
fiber
filesystems
firefox
firewall
flexlm
floppy
flowtools
fonts
format
freebsd
ftp
gdm
gnome
greasemonkey
greylisting
growisofs
grub
hacking
harddrive
hba
hex
hfsc
html
http
idl
ie
intel
ios
iperf
ipmi
iptables
ipv6
irix
javascript
kde
kernel
kmail
kprinter
krecord
kubuntu
ldap
linux
logfile
maradns
matlab
memory
mencoder
mhdd
mkinitrd
mkisofs
moinmoin
motherboard
mouse
movemail
mplayer
multitail
mutt
myodbc
mysql
mythtv
nagios
nameserver
netflow
nginx
nic
ntfs
ntp
nvidia
odbc
openbsd
openntpd
openoffice
openssh
openssl
opteron
parted
partimage
patch
perl
pf
pfflowd
pfsync
photorec
php
pop3
pop3s
ports
postfix
power
procmail
proftpd
proxy
putty
pxe
python
qemu
r-studio
raid
recovery
router
rpc
rsync
samba
schedule
scsi
seagate
seatools
sed
sendmail
sgi
shell
siw
smtp
snort
solaris
soundcard
spam
spamd
sql
sqlite
squid
ssh
ssh.com
ssl
su
subnet
subversion
sudo
sun
supermicro
switches
symbols
syslinux
systemrescuecd
t1
tcpip
tcpwrappers
telnet
terminal
testdisk
tftp
thttpd
thunderbird
timezone
tools
tr
trac
tuning
tunnel
vi
wget
wiki
windows
windowsxp
wireless
wpa_supplicant
x
xauth
xfree86
xfs
xinearama
xmms
zdump
zic
zlib