codahale.com٭blog

cheers ringtonehang on sloopy ringtonering ringtonecars gary numan ringtonecustomize ringtones
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 comments »