嗯,我找到的最简单的方法是使用Viddle-rb gem获取直接视频网址,然后使用ruby' s open-uri
下载
require 'viddl-rb'
require 'open-uri'
url = ViddlRb.get_urls('https://www.youtube.com/watch?v=zs7xO5P3Az4').first
open('my_video.avi', 'wb') do |file|
file << open(url).read
end
puts Dir['./*.avi'] #=> ./my_video.avi