Created
January 25, 2009 18:25
-
-
Save shinzui/52489 to your computer and use it in GitHub Desktop.
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
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