Translate

Translate to EnglishÜbersetzen Sie zum Deutsch/GermanΜεταφράστε στα ελληνικά/GreekПереведите к русскому/RussianOversetter til Norsk/NorwegianÖversätta till Svensk/Swedishहिन्दी अनुवाद करने के लिए/Hindi
Tradueix al català/CatalanTulkot uz latviešu/LatvianPreložiť do slovenčiny/SlovakVertaal aan het Nederlands/Dutchترجمة الى العربية/ArabicTraduzca al Español/SpanishTraduisez au Français/French
Traduca ad Italiano/ItalianTraduza ao Português/Portuguese日本語に翻訳しなさい /Japanese한국어에게 번역하십시오/Korean中文翻译/Chinese Simplified中文翻译/Chinese TraditionalПереклад на українську/Ukrainian
Image of Linux Kernel Development (3rd Edition)
Image of Beginning Google Maps API 3
Image of RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)
Image of Operating System Concepts

Linux Shell Script to Download YouTube Videos

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!
 

3 comments to Linux Shell Script to Download YouTube Videos