Script ruby pour récupérer les videos sur Vimeo
dimanche 28 juin 2009 à 17:43 | Dev
Ce weekend étant particulièrement chaud, je suis resté un peu dans la maison pour profiter de la fraicheur.
Mettant a profit cette période, je me suis lancer dans la réalisation un script pour télécharger des vidéos de bodyboard sur Vimeo.
Après une brève analyse, je suis arrivé à ce bout de code qui enregistre la vidéo demandée dans le répertoire courant :
#!/usr/bin/ruby
require 'net/http'
if ARGV.size < 1
puts "usage vimeo.rb <id_video>"
exit 1
else
id = ARGV[0]
Net::HTTP.start('www.vimeo.com') {|http|
req = Net::HTTP::Get.new("/moogaloop/load/clip:#{id}", nil)
response = http.request(req)
/(.*)<\/caption>/.match(response.body)
title = $1
/(.*)<\/request_signature>/.match(response.body)
signature = $1
/(.*)<\/request_signature_expires>/.match(response.body)
signatureExp = $1
req = Net::HTTP::Get.new("/moogaloop/play/clip:#{id}/
#{signature}/#{signatureExp}/?q=hd", nil)
http.request(req) { |response|
puts response['location']
/(mp4|flv)/.match(response['location'])
ext = $1
/http:\/\/(.*\.vimeo\.com)(\/.*)/.match(response['location'])
Net::HTTP.start($1) {|http|
req = Net::HTTP::Get.new($2)
http.request(req) { |response|
File.open("#{title}.#{ext}",'w') {|f|
f.write(response.body)
}
}
}
}
}
end
Partagez cet article :






I've just made a test on Windows it works out of the box. Please check the copy paste you've made perhaps there something wrong here ?!
So I've tried to figure out what's happen without succes ... I've tried my script on several "Live distros" and it works !
But since I've write this script Vimeo seems to have made some small changes and I must handled them and change a bit my script, I will update it in few days.
I get the same error when I tried on Ubuntu 9,04. Nothing different from the SW/ZW. :-(
I am talking about this file: http://vimeo.com/3963325
I am trying to run the script in Zenwalk (a frenchman-initiated slackware distro). You may be interested ;-)
Strange, I'll try to figure out what's happen ... I'll give you and answer as soon as possible :)
I running this script on kubuntu jaunty, trying with your id dont get any error, but got an empty file ?!
Tried to run the script, but got the following error:
$ vimeo.rb 3963325
/usr/lib/ruby/1.8/net/http.rb:2022:in `read_status_line': wrong status line: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" (Net::HTTPBadResponse)
from /usr/lib/ruby/1.8/net/http.rb:2009:in `read_new'
from /usr/lib/ruby/1.8/net/http.rb:1050:in `request'
from /usr/bin/vimeo.rb:21
from /usr/lib/ruby/1.8/net/http.rb:543:in `start'
from /usr/lib/ruby/1.8/net/http.rb:440:in `start'
from /usr/bin/vimeo.rb:10