advertisement

Article:
  Putting Google Video onto Your iPod
Subject:   Upgraded script
Date:   2006-01-29 14:17:09
From:   menkhaf
After browsing slashdot.org and finding a link for the "Fear of Girls" D&D documentary, http://video.google.com/videoplay?docid=7521044027821122670 , I got annoyed with the flash-based viewer, and couldn't immediately get the sound to work, I decided to update your script a bit.
The script now has no need for the external un-escape program, and automatically finds the title of the video and saves the video as $TITLE.flv unless you specify another filename as a second optional variable.
As it is my first real bash script (hooray), and feedback is appreciated.


***


#!/bin/bash
# Filename: googlevid


# Google video downloader.
# 2006, Rune Juhl Jacobsen, listepik.net
# Based on script by Erica Sadun, http://www.macdevcenter.com/pub/a/mac/2006/01/24/google-video.html


# For readability
URL="$1"
FILENAME="$2"


# Check the input
if [ -z $URL ]; then
echo -e "Error: You need to specify a URL.\n\n"
echo -e "Google video downloader\n\nUsage:\n ./googlevid URL [filename]"
exit 0
fi


# Get the source
SOURCE=`curl -s "$URL"`
# Determine the title of the video
TITLE=`echo $SOURCE | sed "s/ - Google Video<\/title>.*//" | sed "s/.*<title>//"`
# Determine the URL of the actual video
VIDURL=`echo $SOURCE | sed "s/autoPlay=true.*/autoPlay=true/" | sed "s/.*videoUrl=//" | grep google.com`
# Unescape the URL
VIDURL=`echo $VIDURL | sed "s/%3A/:/g" | sed "s/%2F/\//g" | sed "s/%3F/?/g" | sed "s/%3D/=/g" | sed "s/%26/\&/g"`
# Determine the filename to save the video as
if [ -z $FILENAME ]; then
FILENAME="$TITLE.flv"
fi


curl "$VIDURL" > "$FILENAME"
echo "File has been output to \"$FILENAME\""
exit 0