macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Putting Google Video onto Your iPod

by Erica Sadun
01/24/2006

Editor's note -- Google recently added a "download to video iPod" as this article was in production. I wanted to post this piece anyway because I think Google Video has lots to offer iPod users, and I still find this article interesting. Just know that there's now an easier way to grab the video.

Roughly speaking, most things forwarded to my email inbox are garbage. The latest political humor. The best pictures from Hubble. Another useless internet petition. Yawn, delete, delete. Sometimes, though, someone forwards me a link that really tickles my fancy.

A friend recently pointed me to a Google Video link. In it, two Chinese students lip-synched to the Backstreet Boys. It was cute. It was cool. I wanted it on my iPod.

So here's what I did. In this article, you'll discover how I downloaded the video, converted it to an iPod-friendly format, and loaded it onto my new 5G video iPod.

figure 1

Figure 1: Google Video iPod fun.

Please take a second to note that there's a big difference between copying a video to your iPod for personal viewing, and broadcasting it as a torrent to others. Use your Google Video powers for good not evil. Google Terms of Service states "[Y]ou agree that you will not copy, reproduce, alter, modify, create derivative works, or publicly display any content (except for your own personal, non-commercial use) from the Site".

From Google to My Mac

To start, navigate to the Google Video web page that hosts the video you want to download. Copy the URL of the page and paste it somewhere safe, where you can access it again. For the Chinese Backstreet Boys video, this was:

http://video.google.com/videoplay?docid=-6739710473912337648

Delving Down to the Real URL

Behind this URL lurks the web page source code. The source code knows where to find the actual video file, and with a little hunting around, you can find it too. Begin by opening the page source:

  • In Safari, choose View-->View Source.
  • In Internet Explorer, View-->Source.
  • In Firefox, choose View-->Page Source.

The source code opens in a new window. Here, you need to search for videoURL=. Just after this phrase is an important sequence, the slightly encoded version of the video URL. It ends with autoPlay=true.

For the Chinese BSB video, it looks like this:

http%3A%2F%2Fvp.video.google.com%2Fvideoplayback%3Fid%
3D2efa74be06d7001%26begin%3D0%26len%3D215666%26itag%3D5%2
6urlcreated%3D1135291639%26docid%3D-6739710473912337648%26
urlcreated%3D1135291639%26sigh%3DgP3sGiMoQJ5gjCqZtq1ds8rwOg8
&autoPlay=true

(Please note that I've added line breaks to make this a little more readable.)

figure 2

Figure 2: Make a note of the video's URL.

When I say "slightly encoded," I mean that it uses escape sequences for many of the normal URL characters. Instead of http://, for example, you get http%3A%2F%2F. This encoding prevents you from using simple tools like the Unix curl command-line download utility.

For those strong of heart, you can unescape this URL in Firefox or Explorer. Enter javascript:unescape("URL") into the address bar and press Return. This produces a clean URL you can use for downloading.

Of course, it's always better to automate and take the guesswork out of the equation. So I put together a couple of utilities to get the job done. These utilities consist of a shell script that automates the URL capture and download process, and an unescape program that converts an escaped URL into a normal unescaped version. And yes, these are for the Mac.

The getGoogle Shell Script

My getGoogle shell script grabs the page source directly from a main Google Video URL, like the one you just copied down. It uses sed, the Unix stream editor, to cut off the text before videoURL= and after autoPlay=true to recover the escaped URL.

Then it uses my unescape utility (described below) to convert to an unescaped URL. It calls curl to fetch the data, which is saved to your desktop as GoogleOut.flv. (Google uses the FLV format for its videos.)

#!/bin/csh

# Grab the escape-coded video URL from Google Video
set escBAR = `curl -s "$1" | sed "s/autoPlay=true.*/autoPlay=true/" | sed "s/.*v
ideoUrl=//" | grep google.com`

# Unescape the URL
set unBAR = `./unescape "$escBAR"`

# Perform the download
curl "$unBAR" > ~/Desktop/GoogleOut.flv
echo "File has been output to ~/Desktop/GoogleOut.flv"

exit 0

Pages: 1, 2

Next Pagearrow