Parsing youtube url

前端 未结 3 1802
野的像风
野的像风 2021-02-03 13:06

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

3条回答
  •  时光取名叫无心
    2021-02-03 13:44

    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.

提交回复
热议问题