Skip to content

pascalevi4/hosted_video

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hosted_video

Gem Version Code Climate Build Status

Ruby gem for parsing urls to determine video hostings and get video details. Youtube, Rutube and Vimeo services are supported.

Installation

Add this line to your application's Gemfile:

gem 'hosted_video'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hosted_video

Usage

video = HostedVideo.from_url('http://www.youtube.com/watch?v=TBKN7_vx2xo')
video.vid         # => "TBKN7_vx2xo"
video.preview     # => "http://img.youtube.com/vi/TBKN7_vx2xo/hqdefault.jpg"
video.iframe_code # => "<iframe width='420' height='315' frameborder='0' src='http://www.youtube.com/embed/TBKN7_vx2xo?wmode=transparent'></iframe>"

You can create your own video service providers by inheriting from HostedVideo::Providers::Base and implementing parsing functions:

class MyProvider < HostedVideo::Providers::Base
  # logic to determine your service
  def self.can_parse?(url)
    url =~ /myprovider\.com\/\d{3}.*/
  end

  # how to get preview image
  def preview
    "http://myprovider.ru/api/video/#{vid}/?preview=true")
  end

  def url_for_iframe
    "http://rutube.ru/video/embed/#{vid}"
  end

  private
  # regular expression for getting video id from link
  def vid_regex
    /(https?:\/\/)?(www\.)?rutube\.ru\/video\/(?<id>\w{32}|\w{7}).*/
  end
end

HostedVideo.configure do |c|
  c.additional_providers += [MyProvider]
end

Please send me pull-requests with your providers or write an issue with pasted code.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Url parser for links from Youtube, Rutube, Vimeo, etc

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages