Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Vimeo Downloader
#!/usr/bin/env ruby
=begin
Vimeo Downloader v1.0 by Jaroslaw Zabiello (http://zabiello.com)
based on http://cl.ly/2T1x180I251j301L1C3r/vimeo_downloader.sh
found thanks to http://goo.gl/AN5sf :)
Requirements:
* Ruby 1.8 or newer
* nokogiri (http://nokogiri.org)
* wget or curl
=end
require 'rubygems' if RUBY_VERSION =~ /^1.8/
require 'net/http'
require 'open-uri'
begin
require 'nokogiri'
rescue Exception => ex
puts "Installing nokogiri, please wait..."
puts `gem install nokogiri`
end
begin
vimeo_id = ARGV[0].split('/').last
rescue
puts <<-HELP
Usage: ruby #{File.basename(__FILE__)} vimeo_id_or_url
E.g. ruby #{File.basename(__FILE__)} 31733477
ruby #{File.basename(__FILE__)} http://vimeo.com/31733477
HELP
exit
end
url = "http://www.vimeo.com/moogaloop"
xml = Nokogiri::XML open("#{url}/load/clip:#{vimeo_id}")
signature = xml.xpath('//request_signature').text
expires = xml.xpath('//request_signature_expires').text
caption = xml.xpath('//caption').text
ishd = xml.xpath('//isHD').text == '1' ? 'hd' : 'sd'
filename = "#{vimeo_id}-#{ishd}.flv"
uri = "#{url}/play/clip:#{vimeo_id}/#{signature}/#{expires}/?q=#{ishd}"
if !`which curl`.empty?
`curl -A wget -L #{uri} > #{filename}`
elsif !`which wget`.empty?
`wget -c -t 0 #{uri} -O #{filename}`
else
puts "You need wget or curl installed"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment