Here is a bash shell script which downloads a YouTube video and plays it using GNOME’s Totem movie player which is based on the GStreamer open source multimedia framework.
#!/bin/bash
#
# Author: Finnbarr P. Murphy
# Date: July 27th, 2010
#
# Copyright (c) Finnbarr P. Murphy 2010
#
echo -n "Enter the YouTube ID to copy: "
read ID
[[ -z $ID ]] && exit 1
TMP=/var/tmp/yt.$$
#QUIET="-q"
QUIET="--progress=bar"
WGET=/usr/bin/wget
SED=/bin/sed
TR=/usr/bin/tr
$WGET ${QUIET} -O ${TMP} "http://www.youtube.com/watch?v=${ID}"
[[ $? > 0 ]] && exit 2
VIDEOFILE=$($SED -n "/fmt_url_map/{s/[\'\"\|]/\n/g;p}" ${TMP} | \
$SED -n '/^fmt_url_map/,/videoplayback/p' | \
$SED -e :a -e '$q;N;5,$D;ba' | $TR -d '\n' | \
$SED -e 's/\(.*\),\(.\)\{1,3\}/\1/')
rm -f $TMP
echo -n "Downloading video ...."
# download video to file named "downfile". Change as necessary
$WGET ${QUIET} -O downfile "${VIDEOFILE}"
[[ $? > 0 ]] && {
echo "ERROR: Download failed"
exit 3
}
echo " Done"
# play the video using totem. Change as necessary
totem downfile
exit 0
Enjoy!






wow thank you!! finally a script that works after the YouTube change!! If you guys had a donate button I would donate. Thanks again.
Unfortunately, script can’t download YT clip anymore… YT probably has changed since July 2010…
There’s a new script for linux to search and watch youtube’s video on linux shell, called YouShell.
http://code.google.com/p/youshell/