YouTubeIdentifier
YouTubeIdentifier provides information about any valid YouTube URL.
- It can figure out the video ID of a YouTube URL.
- It can build a canonical YouTube URL based on any other YouTube URL or just the video ID.
Installation
Add this line to your application's Gemfile:
gem 'youtube_identifier'
And then execute:
$ bundle
Or install it yourself as:
$ gem install youtube_identifier
Usage
url = 'www.youtube.com/watch?v=7OLQnKr_sh8'
YouTubeIdentifier::Identifier.new(url).valid? # => true
YouTubeIdentifier::Identifier.new(url).id # => '7OLQnKr_sh8'
YouTubeIdentifier::Identifier.new(url).canonical_url # => 'http://www.youtube.com/watch?v=7OLQnKr_sh8'
url = 'http://google.com'
YouTubeIdentifier::Identifier.new(url).valid? # => false
YouTubeIdentifier::Identifier.new(url).id # => YouTubeIdentifier::InvalidURLError
YouTubeIdentifier::Identifier.new(url).canonical_url # => YouTubeIdentifier::InvalidURLError
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request