Skip to content

Instantly share code, notes, and snippets.

@tarmolehtpuu
Created June 27, 2011 10:44
Show Gist options
  • Save tarmolehtpuu/1048658 to your computer and use it in GitHub Desktop.
Save tarmolehtpuu/1048658 to your computer and use it in GitHub Desktop.
Youtube Downloader (Ruby)
#!/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
@rdetert
Copy link

rdetert commented Dec 18, 2013

Doesn't work for me unfortunately

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