Putting Google Video onto Your iPod

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.

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: 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.

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

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.)