codahale.com٭blog

Coda Hale lives in Berkeley, CA, where he writes about Ruby on Rails, usability, web design and development, and the occasional bit about bicycles.

GVP Download: A quick and dirty Ruby script to download Google Videos

So Google Video has a bunch of really awesome content, but watching it with Flash is a CPU-hogging, lowest-common-denominator experience. So here’s a quick script to go from video URL to watchable AVI:

#!/usr/bin/env ruby

require "open-uri"

puts "Downloading descriptor file..."
gvp_id = ARGV[0].gsub(/\D/, "")
gvp_doc = open("http://video.google.com/videogvp/gvp-download.gvp?docid=#{gvp_id}").read.split("\\n")

gvp_doc.find { |x| x =~ /^url:(.*)$/ }
gvp_movie_url = $1.gsub(/&/, '\\\\\\&').gsub(/\\?/, '\\\\\\?')

gvp_doc.find { |x| x =~ /^title:(.*)$/ }
gvp_title = $1

puts "Downloading \"#{gvp_title}\"..."
puts "wget -O #{(gvp_title + ".avi").inspect} #{gvp_movie_url}"

If you want to use curl instead of wget, change the last line of code.

This probably violates some terms of use, so this is only a intellectual demonstration of the wonderment and possibilitude of the programmablemated webernet.

BTW, it’s amazing how much I had to escape things to pass the right values through Wordpress, Ruby’s weird-ass string escaping, and finally Bash. Lots of backslashes.

9 Responses to “GVP Download: A quick and dirty Ruby script to download Google Videos”

  1. kamal Says:

    I think WP ate your read.split(”\n”) (in case this doesn’t show up, it’s the backslash before n.

  2. Coda Says:

    Good catch, kamal. Thanks!

  3. silverfang Says:

    Hello Coda, I copied your script and after tried to execute it I get this message:

    D:\development\programs\ruby>ruby google_video_saver.rb 6640225987281635407
    google_video_saver.rb:10: invalid regular expression; there’s no previous pattern, to which ‘?’ would define cardinality at 1: /?/

    I hope you can help me out here, I’m new to Ruby and can’t seem anything wrong.

  4. Coda Says:

    Sorry, silverfang — Wordpress ate yet another backslash. Re-copy the source and try it now.

  5. silverfang Says:

    Hello Coda, thanks for your quick reply.

    The last problem is solved, now there aren’t any errors, but it seems like the video isn’t downloading. This is the output I get in the console and the program exits immediately:

    D:\development\programs\ruby>ruby google_video_saver.rb 6640225987281635407
    Downloading descriptor file…
    Downloading “Lady Punch”…
    wget -O “Lady Punch.avi” http://vp.video.google.com/videodownload\?version=0\&se
    cureurl=rAAAAL24zF3cRiVq7Cqgr0SDvMlsZ41IU_zBhdErW9ThymAGWjS5Buk-LERYd0DxQ1lZv5ql
    EVgXYxMXnOwf2×4nnb3Ff5y-bUCmWfsJKMbUV9MsygCFJNgh1VTbwUhm2K8Cbni04vBMd9WmR3dQDL_G
    eFkN2j29kf7mGl5TRY-LcsJSFyDM-seGwyrE0e1-81AhdxHTvGhZUCRMB5N8VDnX-BZVr9n5kxcnSLHW
    jf1kCKUc\&sigh=e7nCc644dIxDldcxxtWzBnZ5W7s\&begin=0\&len=9375\&docid=66402259872
    81635407

  6. Coda Says:

    Silverfang — you appear to be on Windows. You’ll need to install wget, or change the code to use a command-line HTTP downloader that you do have installed. Having not used Windows for several years, I don’t have much advice for which of those options is preferable.

  7. silverfang Says:

    Hello Coda,

    I installed wget, tested it (it’s working), but still, the program doesn’t seem to work as intended :(

    I did an experiment and pasted the generated URL for download on my browser, and I got a: “Google Error Not Found” page. Maybe that’s the problem, this is what google had to say about it:

    The requested URL /videodownload/?version=0%5C&secureurl=sAAAAHAnYAc69lcZGjHFvI5GyCVJY2vyBaj5dMxQuIIUaWvc2hcIoRYiWAHbFrtXl8FLeCNx415yQxx_WIM1DzEHe3CfeXIkvGtfJGzTbIPtuKqlaEVtiY9BL9AY8HVfwV4HeWs0eU8e8noYK3o6JeetPe2RbnIMjdBzl46NUnik_1BUnG4XkNiztvUgUIGkgvH8UaLbiWLchDQohtBh7NLWo3yYQIStZz1Y87A8ZRZShYnie5mfqNUz0eBhFj3vkH7YjQ%5C&sigh=xtO6tyO7_5ii2fReGz3RC80g_os%5C&begin=0%5C&len=34633%5C&docid=646720995622198501 was not found on this server.

  8. Srini Says:

    Hi,

    Iam new to ruby..
    Can u explain how to use above specified code. by step by step

  9. she Says:

    ‘This probably violates some terms of use’

    I was looking through but I actually have not found any terms of use for a visitor. I have only found something that connects it to “google services” in general but it was related to google acounts, not to a way to download this. (If there would be a breach, firefox would be “breaching” it too because the flash data stream is sent to the one browsing it anyway)
    (Its different if you are uploading videos too because those that upload videos must ensure that they hold copyright notices or it is a fair use clause, i.e. a few seconds for a clip but not a whole movie).