Giter Site home page Giter Site logo

youtube_rails's Introduction

Youtube Rails

Gem Version
Helper to read in YouTube urls and parse the video id and generate the youtube embed HTML code

This is based on gem https://github.com/datwright/youtube_addy by David Wright (Discontinued). Thanks so much

Author: Luiz Picolo

INSTALL

gem install youtube_rails`

or add in your gemfile

gem 'youtube_rails'

How to use

YouTubeRails.extract_video_id("http://www.youtube.com/watch?v=XwmtNk_Yb2Q")
=> "XwmtNk_Yb2Q"
YouTubeRails.extract_video_id("https://youtu.be/cD4TAgdS_Xw")
=> "cD4TAgdS_Xw"
YouTubeRails.extract_video_id("http://www.youtube.com/watch?feature=player_embedded&v=SahhfqNkHFU")
=> "SahhfqNkHFU"
YouTubeRails.extract_video_id("http://youtube.com/watch?v=Cd4g33ijd<script>this_should_not_be_here</scipt>")
=> nil
YouTubeRails.youtube_embed_url("http://youtu.be/cD4TAgdS_Xw", 420, 315)
=> '<iframe width="420" height="315" src="http://www.youtube.com/embed/cD4TAgdS_Xw" frameborder="0" allowfullscreen></iframe>'
YouTubeRails.youtube_embed_url_only("http://youtu.be/cD4TAgdS_Xw")
=> 'http://www.youtube.com/embed/cD4TAgdS_Xw'
YouTubeRails.extract_video_image("https://youtu.be/cD4TAgdS_Xw")
=> "https://i.ytimg.com/vi/cD4TAgdS_Xw/hqdefault.jpg"
# Params: default, medium, high, maximum
YouTubeRails.extract_video_image("https://youtu.be/cD4TAgdS_Xw", 'high')
=> "https://i.ytimg.com/vi/cD4TAgdS_Xw/mqdefault.jpg"

Options

Final videos suggestion: disable_suggestion: true ( default is false )

YouTubeRails.youtube_embed_url("http://youtu.be/cD4TAgdS_Xw", 420, 315, { disable_suggestion: true })
=> '<iframe width="420" height="315" src="http://www.youtube.com/embed/cD4TAgdS_Xw?rel=0" frameborder="0" allowfullscreen></iframe>'

With ssl: ssl: true ( default is false )

YouTubeRails.youtube_embed_url("http://youtu.be/cD4TAgdS_Xw", 420, 315, { ssl: true })
=> '<iframe width="420" height="315" src="https://www.youtube.com/embed/cD4TAgdS_Xw" frameborder="0" allowfullscreen></iframe>'

youtube_rails's People

Contributors

luizpicolo avatar

Stargazers

 avatar

Watchers

 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.