Skip to content

Instantly share code, notes, and snippets.

@jamie
Created March 22, 2011 18:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamie/881697 to your computer and use it in GitHub Desktop.
Save jamie/881697 to your computer and use it in GitHub Desktop.
Get around vimeo's stupid daily download limit restrictions
Usage:
./vimeo.rb video-id [password] [output filename, no extension]
Known issues:
I should put some better arg handling in, if you download a video w/ password it will use the password as output filename.
#!/usr/bin/env ruby
require 'rubygems'
require 'isolate'
Isolate.now! do
gem 'mechanize'
end
require 'open-uri'
require 'mechanize'
class Vimeo
def initialize(id, password=nil)
@id = parse_id(id)
@password = password
@agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
end
def download_to(outfile=nil)
outfile ||= "#{@id}.mp4"
get_page
get_video || get_video('sd')
write_video(outfile)
end
def get_page
@page ||= begin
page = @agent.get(url)
token = page.body.match(/token" value="(.*)" /)[1]
Mechanize::Cookie.parse(URI.parse("http://www.vimeo.com/"), "xsrft=#{token};") do |c|
@agent.cookie_jar.jar["vimeo.com"]["/"]["xsrft"] = c
end
if pass_form = page.form_with(:action => /password/)
pass_form.pass = @password
pass_form['token'] = token
@agent.submit(pass_form)
else
page
end
end
end
def get_video(quality='hd')
@video ||= begin
sig = @page.body.match(/"signature":"([^"]+)",/)[1]
time = @page.body.match(/"timestamp":([0-9]+),/)[1]
url = "http://player.vimeo.com/play_redirect?clip_id=#{@id}&sig=#{sig}&time=#{time}&quality=#{quality}&codecs=H264,VP8,VP6&type=moogaloop_local&embed_location="
content = @agent.get(url).body
content if content.size > 5000
end
end
def parse_id(id)
id =~ /^http/ ? id.split('/').last : id
end
def url
"http://www.vimeo.com/#{@id}"
end
def write_video(outfile)
File.open(outfile, 'w') {|f| f << @video } if @video
end
end
v = Vimeo.new(ARGV.shift, ARGV.first)
file = ARGV.last ? ARGV.last+'.mp4' : nil
v.download_to(file)
@jesset55
Copy link

This is great! Excuse my ignorance, but how do I use this??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment