Coder Social home page Coder Social logo

video_info's Introduction

VideoInfo Gem Version Build Status Dependency Status Code Climate Coverage Status

Simple Ruby Gem to get video info from youtube and vimeo url. Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.

Install

  gem install video_info

Usage

  video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4")

  # video.video_id         => "mZqGqE0D0n4"
  # video.provider         => "YouTube"
  # video.title            => "Cherry Bloom - King Of The Knife"
  # video.description      => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
  # video.duration         => 175 (in seconds)
  # video.date             => Sat Apr 12 22:25:35 UTC 2008
  # video.thumbnail_small  => "http://i.ytimg.com/vi/mZqGqE0D0n4/default.jpg"
  # video.thumbnail_medium => "http://i.ytimg.com/vi/mZqGqE0D0n4/mqdefault.jpg"
  # video.thumbnail_large  => "http://i.ytimg.com/vi/mZqGqE0D0n4/hqdefault.jpg"
  # video.embed_url        => "http://www.youtube.com/embed/mZqGqE0D0n4"
  # video.embed_code       => "'<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"

  video = VideoInfo.get("http://vimeo.com/898029")

  # video.video_id         => "898029"
  # video.provider         => "Vimeo"
  # video.title            => "Cherry Bloom - King Of The Knife"
  # video.description      => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
  # video.keywords         => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
  # video.duration         => 175 (in seconds)
  # video.date             => Mon Apr 14 13:10:39 +0200 2008
  # video.width            => 640
  # video.height           => 360
  # video.thumbnail_small  => "http://b.vimeocdn.com/ts/343/731/34373130_100.jpg"
  # video.thumbnail_medium => "http://b.vimeocdn.com/ts/343/731/34373130_200.jpg"
  # video.thumbnail_large  => "http://b.vimeocdn.com/ts/343/731/34373130_640.jpg"
  # video.embed_url        => "http://player.vimeo.com/video/898029"
  # video.embed_code       => "'<iframe src="http://player.vimeo.com/video/898029?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=0" frameborder="0"></iframe>'"

Options

  video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4", "User-Agent" => "My Youtube Mashup Robot/1.0")
  video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer"    => "http://my-youtube-mashup.com/")
  video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer"    => "http://my-youtube-mashup.com/",
                                                                      "User-Agent" => "My Youtube Mashup Robot/1.0")

You can also use symbols instead of strings (any non-word (/[^a-z]/i) character would be converted to hyphen).

  video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4", :referer    => "http://my-youtube-mashup.com/",
                                                                      :user_agent => "My Youtube Mashup Robot/1.0")

User-Agent when empty defaults to "VideoInfo/VERSION" - where version is current VideoInfo version, e.g. "VideoInfo/0.2.7".

It supports all openURI header fields (options), for more information see: openURI DOCS

You can also include an iframe_attributes or url_attributes hash to the embed_code method to include arbitrary attributes in the iframe embed code or as additional URL params:

VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(:iframe_attributes => { :width => 800, :height => 600, "data-key" => "value" })
=> '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen" width="800" height="600" data-key="value"></iframe>

'VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(:url_attributes => { :autoplay => 1 })
=> '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4?autoplay=1" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'

Author

Thibaud Guillaume-Gentil (@thibaudgg)

Contributors

https://github.com/thibaudgg/video_info/contributors

video_info's People

Contributors

thibaudgg avatar maciejsmolinski avatar narkoz avatar patchfx avatar juliend2 avatar muan avatar filipechagas avatar mhaylock avatar pomartel avatar papipo avatar tomasc avatar

Watchers

kimihito avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.