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!

Reddit!

Related stories


RSS Feed RSS feed logo

About


3com

3ware

alsa

alsactl

alsamixer

amd

android

apache

areca

arm

ati

auditd

awk

badblocks

bash

bind

bios

bonnie

cable

carp

cat5

cdrom

cellphone

centos

chart

chrome

chromebook

cifs

cisco

cloudera

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

dkim

dns

dos

dovecot

drac

dsniff

dvdauthor

e-mail

echo

editor

emerald

ethernet

expect

ext3

ext4

fat32

fedora

fetchmail

fiber

filesystems

firefox

firewall

flac

flexlm

floppy

flowtools

fonts

format

freebsd

ftp

gdm

gmail

gnome

google

greasemonkey

greylisting

growisofs

grub

hacking

hadoop

harddrive

hba

hex

hfsc

html

html5

http

https

hulu

idl

ie

ilo

intel

ios

iperf

ipmi

iptables

ipv6

irix

javascript

kde

kernel

kickstart

kmail

kprinter

krecord

kubuntu

kvm

lame

ldap

linux

logfile

lp

lpq

lpr

maradns

matlab

memory

mencoder

mhdd

mkinitrd

mkisofs

moinmoin

motherboard

mouse

movemail

mplayer

multitail

mutt

myodbc

mysql

mythtv

nagios

nameserver

netflix

netflow

nginx

nic

ntfs

ntp

nvidia

odbc

openbsd

openntpd

openoffice

openssh

openssl

openvpn

opteron

parted

partimage

patch

perl

pf

pfflowd

pfsync

photorec

php

pop3

pop3s

ports

postfix

power

procmail

proftpd

proxy

pulseaudio

putty

pxe

python

qemu

r-studio

raid

recovery

redhat

router

rpc

rsync

ruby

saltstack

samba

schedule

screen

scsi

seagate

seatools

sed

sendmail

sgi

shell

siw

smtp

snort

solaris

soundcard

sox

spam

spamd

spf

spotify

sql

sqlite

squid

srs

ssh

ssh.com

ssl

su

subnet

subversion

sudo

sun

supermicro

switches

symbols

syslinux

syslog

systemrescuecd

t1

tcpip

tcpwrappers

telnet

terminal

testdisk

tftp

thttpd

thunderbird

timezone

ting

tls

tools

tr

trac

tuning

tunnel

ubuntu

unbound

vi

vpn

wget

wiki

windows

windowsxp

wireless

wpa_supplicant

x

xauth

xfree86

xfs

xinearama

xmms

youtube

zdump

zeromq

zic

zlib