Created
June 27, 2011 10:44
-
-
Save tarmolehtpuu/1048658 to your computer and use it in GitHub Desktop.
Youtube Downloader (Ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -rubygems | |
require 'uri' | |
require 'curb' | |
if ARGV.size == 0 | |
puts "Usage: ytget <video>" | |
exit 0 | |
end | |
video = ARGV.shift | |
# video page request, parse out video auth url | |
curl = Curl::Easy.new(video) | |
curl.on_body do |data| | |
if data =~ /img.src = '(.*?)'/ | |
$url = $1.gsub(/\\/, '') | |
end | |
data.length | |
end | |
curl.perform | |
# video auth thingie | |
curl = Curl::Easy.new($url) | |
curl.perform | |
flv_url = $url.gsub(/generate_204/, 'videoplayback') | |
# download video | |
curl = Curl::Easy.new(flv_url) | |
file = File.open('data.flv', 'w') | |
curl.on_body do |data| | |
file.write(data) | |
data.length | |
end | |
curl.perform | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work for me unfortunately