Skip to content

Instantly share code, notes, and snippets.

@mba811
Created April 29, 2015 10:13
Show Gist options
  • Select an option

  • Save mba811/151d64a4808f40a4f48e to your computer and use it in GitHub Desktop.

Select an option

Save mba811/151d64a4808f40a4f48e to your computer and use it in GitHub Desktop.
ruby-youtube-downloader
#!/usr/bin/env ruby
require 'cgi'
def video_token(video_id)
token = CGI.parse(%x!curl http://www.youtube.com/get_video_info?video_id=#{video_id}!)['token'][0]
end
def video_id(url)
CGI.parse(url.split('?')[1])['v']
end
url = ARGV[0]
download = "http://youtube.com/get_video?t=#{video_token(video_id(url))}&video_id=#{video_id(url)}&asv=2"
%x!/usr/bin/env curl -L -C - -o test '#{download}'!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment