Skip to content

Instantly share code, notes, and snippets.

@shinzui
Created January 25, 2009 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinzui/52489 to your computer and use it in GitHub Desktop.
Save shinzui/52489 to your computer and use it in GitHub Desktop.
def parse_youtube(url)
youtube = "http://www.youtube.com/"
# url =~ /(?:http\:\/\/.*youtube.com\/(?:watch\?v=|v\/))?(.*)$/
url =~ /watch\?v=(.*)/
video_id = $1
video_id = video_id.split("&")[0]
flv_url = nil
open("#{youtube}watch\?v=#{video_id}") do |f|
f.each_line do |line|
if line =~ /watch_fullscreen\?(.*?)video_id=([\w-]+)&(.*?)&t=([\w-]+)&/
# p line
flv_url = "#{youtube}get_video?video_id=#{$2}&t=#{$4};auto"
break
end
end
end
flv_url
end
USER_AGENT = %{Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11)
Gecko/20071231 Firefox/2.0.0.11 Flock/1.0.5}
IO.popen("curl -o \"#{file_name}\" -L -A \"#{USER_AGENT}\" \"#{parse_youtube(url)}\" 2>&1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment