I\'ve written a ruby youtube url parser. It\'s designed to take an input of a youtube url of one of the following structures (these are currently the youtube url structures tha
require 'uri'
require 'cgi'
urls = %w[http://youtu.be/sGE4HMvDe-Q
http://www.youtube.com/watch?v=Lp7E973zozc&feature=relmfu
http://www.youtube.com/p/A0C3C1D163BE880A?hl=en_US&fs=1]
def parse_youtube url
u = URI.parse url
if u.path =~ /watch/
p CGI::parse(u.query)["v"].first
else
p u.path
end
end
urls.each { |url| parse_youtube url }
#=> "/sGE4HMvDe-Q"
#=> "Lp7E973zozc"
#=> "/p/A0C3C1D163BE880A"