Putting Google Video onto Your iPod
Pages: 1, 2
The unescape Utility
Unfortunately, there's no "unescape URL" utility built into the Macintosh (or at least not one that I could find). There is, however, an unescape routine distributed as part of the standard developer library. The following utility takes one argument, an escaped URL (in quotes, please!) and returns it unescaped.
// cc unescape.c -o unescape -lcurl
#include <curl/curl.h>
#include <stdio.h>
main(argc, argv)
int argc;
char **argv;
{
if (argc < 2)
{
fprintf(stderr, "Usage: %s URL\n", argv[0]);
exit(2);
}
printf("%s\n", curl_unescape(argv[1], strlen(argv[1])));
return(0);
}
If you don't have the developer package installed, you'll find a pre-compiled version of this utility here.
Setting Things Up
You'll need to create both the getGoogle shell script and unescape.c source as plain text files in a new folder on your Desktop. Launch Terminal and change directories to that folder.
$ cd ~/Desktop/Escapestuff
$ ls
getGoogle unescape.c
$
Compile the unescape utility. (Feel free to ignore the warnings.)
$ cc unescape.c -o unescape -lcurl
unescape.c: In function 'main':
unescape.c:14: warning: incompatible implicit declaration of built-in function 'exit'
unescape.c:17: warning: incompatible implicit declaration of built-in function 'strlen'
$
Make the getGoogle shell script executable.
$ chmod 755 getGoogle
$
Now you're ready to perform the download. The getGoogle utility takes one argument, the main Google Video URL in double quotes. curl provides live updates as the download progresses.
$ ./getGoogle "http://video.google.com/videoplay?docid=-6739710473912337648"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12.3M 0 12.3M 0 0 156k 0 --:--:-- 0:01:20 --:--:-- 160k
File has been output to ~/Desktop/GoogleOut.flv
$
After the download ends, you'll have a brand new file on your desktop: GoogleOut.flv.
Converting the Video
Figure 3: Drop the FLV file onto the From field to start setting up your encoding.
It should come as no surprise that the FLV video you download will not play back on your iPod. Or in QuickTime. Or pretty much anything else. Even VLC won't play it--they dropped support as of 0.8.2. (Sure, if you've got $30 to blow, you could download the Wimpy AV player, which offers FLV support for both Windows and OS X, but let's get back to the whole iPod thing, right?)
Here's where the fabulous ffmpegX comes in. Or at least it does for the Mac. Windows users? You'll have use it the ffmpeg command-line utility or search for a Windows-based ffmpeg GUI like PSPEnc. With ffmpegX, converting your videos couldn't be simpler.
After installing ffmpegX (make sure to install all those extra components, namely mplayer, mencoder and mpeg2enc), just follow these steps:
- Drop the GoogleOut.flv file onto the From field.
- Select PSP MP4 from the To pop-up menu.
- If desired, edit the Save As output filename.
- Click Encode.
An ffmpegX progress window opens, letting you keep track of your encoding job. When finished, it chimes. The new MP4 file appears on your desktop (unless you chose to save it somewhere else) and is ready to play in QuickTime and iTunes.
All that's left now is to add your movie to your iPod. Drag the new MP4 file into your iPod playlist in iTunes. (You can also drop it directly onto the iPod icon there if you prefer.) iTunes copies the video and places it into your iPod's Videos-->Movies collection. Simply select it, sit back, watch, and enjoy.
Editor's note: Just in case you were wondering, it's OK to download this content for your own personal use. Here's the word from Google: "Accordingly, you 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."
Erica Sadun has written, co-written, and contributed to almost two dozen books about technology, particularly in the areas of programming, digital video, and digital photography.
Return to the Mac DevCenter
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 7 of 7.
-
Upgraded script
2006-01-29 14:17:09 menkhaf [Reply | View]
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
-
URL Unescaping
2006-01-29 07:11:31 rkt [Reply | View]
Unfortunately, there's no "unescape URL" utility built into the Macintosh (or at least not one that I could find).
Of course There's More Than One Way To Do It applies, but Python -- distributed with Mac OS X so Developer Tools not required -- can happily be used to unmangle the extracted URL:
python -c "import sys,urllib; print urllib.unquote(sys.argv[1])" URL
This command is a straight drop in replacement forunescapeutility. -
URL Unescaping
2006-01-29 08:43:45 Erica Sadun |
[Reply | View]
Excellent point. I tend to use perl (URI::Escape) myself. But as all my "man -k" 'ing turned up nothing command-line wise, I thought "why not just put together what's essentially a one-liner C-wise?".
-
iSquint
2006-01-25 11:16:33 Iljitsch van Beijnum |
[Reply | View]
I didn't have much luck with the shell script on my Powerbook, but after downloading Bohemian Rhapsody manually (for free!) I did discover an easier way to convert the video: with iSquint. This is a simple to use program to convert video to iPod-compatible formats that uses ffmpg as its engine.
I did get very low bitrate sound though, not sure if that's because of the base material or thriftiness on the part of iSquint. I guess I'll retry and set the sound bitrate higher in the advanced settings.
http://www.versiontracker.com/dyn/moreinfo/macosx/28250
-
An easier way
2006-01-24 22:13:24 hailstone [Reply | View]
Would have been to click the drop box and select Video iPod then click the download button. From the screen shot in your article it looks like this feature was not available when the shot was taken. -
RE: An easier way
2006-01-24 23:12:18 Derrick Story |
[Reply | View]
Yes, that feature was added recently. I think we'll put a note at the top of the article citing it. That aside, I still want folks to know about Google Video and how to move it to the iPod... because, well, it's cool.






you will be able to download the video instantly.