Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luizpicolo/youtube_rails
:video_camera: Helper to read in YouTube urls and parse the video id and generate the youtube embed HTML cod
https://github.com/luizpicolo/youtube_rails
Last synced: 24 days ago
JSON representation
:video_camera: Helper to read in YouTube urls and parse the video id and generate the youtube embed HTML cod
- Host: GitHub
- URL: https://github.com/luizpicolo/youtube_rails
- Owner: luizpicolo
- Created: 2016-02-08T13:51:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-04T01:31:52.000Z (almost 2 years ago)
- Last Synced: 2024-10-10T06:54:11.683Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 24.4 KB
- Stars: 21
- Watchers: 5
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Youtube Rails
[![Gem Version](https://badge.fury.io/rb/youtube_rails.svg)](https://badge.fury.io/rb/youtube_rails)
Helper to read in YouTube urls and parse the video id and generate the youtube embed HTML codeThis 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
```ruby
gem 'youtube_rails'
```## How to use
```ruby
YouTubeRails.extract_video_id("http://www.youtube.com/watch?v=XwmtNk_Yb2Q")
=> "XwmtNk_Yb2Q"
``````ruby
YouTubeRails.extract_video_id("https://youtu.be/cD4TAgdS_Xw")
=> "cD4TAgdS_Xw"
``````ruby
YouTubeRails.extract_video_id("http://www.youtube.com/watch?feature=player_embedded&v=SahhfqNkHFU")
=> "SahhfqNkHFU"
``````ruby
YouTubeRails.extract_video_id("http://youtube.com/watch?v=Cd4g33ijdthis_should_not_be_here</scipt>")
=> nil
``````ruby
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>'
``````ruby
YouTubeRails.youtube_embed_url_only("http://youtu.be/cD4TAgdS_Xw")
=> 'http://www.youtube.com/embed/cD4TAgdS_Xw'
``````ruby
YouTubeRails.extract_video_image("https://youtu.be/cD4TAgdS_Xw")
=> "https://i.ytimg.com/vi/cD4TAgdS_Xw/hqdefault.jpg"
``````ruby
# 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 )
```ruby
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 )
```ruby
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>'
```