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
Using the Addressable gem, you can save yourself some work. There's also a URI module in stdlib, but Addressable is more powerful.
require 'addressable/uri'
uri = Addressable::URI.parse(youtube_url)
if uri.path == "/watch"
uri.query_values["v"] if uri.query_values
else
uri.path
end
EDIT | Removed madness. Didn't notice Addressable provides #query_values
already.