# Youtube Onebox revisited

**URL:** https://meta.discourse.org/t/youtube-onebox-revisited/22764
**Category:** Feature
**Created:** [December 2, 2014, 9:37pm UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764 "2014-12-02T21:37:43Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![sperok](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sperok/32/114977_2.png) [@sperok](https://meta.discourse.org/u/sperok)
#### Post date: [December 2, 2014, 9:37pm UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/1 "2014-12-02T21:37:43Z")

</div>

AFAIK the current onebox implementation works with urls of the form: [YouTube](http://www.youtube.com/watch?v=)

This form of the URL accepts limited player parameters while alternate forms offer a [much bigger parameter list](http://www.techairlines.com/youtube-parameters/) that can come in very handy (better playlist control, branding, looping, etc). I am not competent to modify the existing onebox implementation without help. Any thoughts on how tough it would be to support these alternate forms?

[YouTube](http://www.youtube.com/v/)  
[YouTube](http://www.youtube.com/embed/)  
[http://www.youtube.com/apiplayer?video\_id=](http://www.youtube.com/apiplayer?video_id=)

Continuing the discussion from [Youtube times feature for replies to an embedded youtube video?](https://meta.discourse.org/t/youtube-times-feature-for-replies-to-an-embedded-youtube-video/16294):

> [@Youtube times feature for replies to an embedded youtube video?](https://meta.discourse.org/t/youtube-times-feature-for-replies-to-an-embedded-youtube-video/16294/1):
>
> I thought it might be cool (if it were possible) to also have the automatic youtube play@time function when a user replies with an arbitrary time say 0:45. Not sure if it is possible for embedded videos but it’s just a thought. I would imagine it may be possible with some js though? And if many videos are posted, I guess the original post should be replied to directly so the time is linked to the right video. If there are multiple videos in one post however, well, I don’t know. Just thoughts out on a line. Super nit-picky feature but thought I’d share 😛

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [December 3, 2014, 1:12am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/2 "2014-12-03T01:12:41Z")

</div>

It already supports youtu.be and ?t= and #t= as well, and `&loop` and `&start=1m&end=2m`.

---

<div class="post-metadata">

### Author: ![sperok](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sperok/32/114977_2.png) [@sperok](https://meta.discourse.org/u/sperok)
#### Post date: [December 3, 2014, 1:44am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/3 "2014-12-03T01:44:30Z")

</div>

Yes - those functions are supported but there are a bunch more options available with the other forms of the URL that are of value. The [official Google docs](https://developers.google.com/youtube/player_parameters) list all of them, and most are not available with the /watch form of the URL.

The ones we care about are:

- autohide (for the controls)
- rel (to enable/disable related videos)
- showinfo (title information display)

The challenge we have is that on our YouTube channel it is beneficial to have videos in a playlist that will automatically roll from one to the next. Within the forum this behavior is NOT desirable - we want to stop after playing 1 video and discuss it. The rel= parameter lets us accomplish that, but it is not available with the /watch form of the URL, and the other YouTube URLs don’t onebox correctly.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [December 3, 2014, 2:00am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/4 "2014-12-03T02:00:06Z")

</div>

> [@sperok](#):
>
> The rel= parameter lets us accomplish that, but it is not available with the /watch form of the URL

Ah, but you COULD include a magic parameter that the oneboxer interprets to set the `rel` value 😉

> <https://github.com/discourse/onebox/blob/main/lib/onebox/engine/youtube_onebox.rb#L63-L91>

---

<div class="post-metadata">

### Author: ![sperok](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sperok/32/114977_2.png) [@sperok](https://meta.discourse.org/u/sperok)
#### Post date: [December 3, 2014, 4:10am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/5 "2014-12-03T04:10:03Z")

</div>

OK, so never having written a line of Ruby in my life, would adding something like this at line 81 get the job done? Then I need to figure out how to make this a plugin? About time I learned how …

Documented Youtube [parameter definitions](https://developers.google.com/youtube/player_parameters#iv_load_policy) are all in the form key=[0..3]

```
p['rel'] = params['rel'] if params.include? 'rel'
p['autohide'] = params['autohide'] if params.include? 'autohide'
p['cc_load_policy'] = params['cc_load_policy' if params.include? 'cc_load_policy'
p['fs'] = params['fs'] if params.include? 'fs'
p['hl'] = params['hl'] if params.include? 'hl'
p['iv_load_policy'] = params['iv_load_policy'] if params.include? 'iv_load_policy'
p['modestbranding'] = params['modestbranding'] if params.include? 'modestbranding'
p['color'] = params['color'] if params.include? 'color'
p['theme'] = params['theme'] if params.include? 'theme'

```

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [December 3, 2014, 5:14am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/6 "2014-12-03T05:14:51Z")

</div>

I would turn that into a loop instead of repeating it every time.

Also, do we really need all those to be supported?

---

<div class="post-metadata">

### Author: ![sperok](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sperok/32/114977_2.png) [@sperok](https://meta.discourse.org/u/sperok)
#### Post date: [December 3, 2014, 5:50am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/7 "2014-12-03T05:50:33Z")

</div>

Yes - this is the brain-dead way of doing it. Creating an array of parameters of interest and looping through it would be nicer. Whatever the correct Ruby syntax is for something like this:

```
['rel', 'autohide', 'cc_load_policy', 'fs', 'hl', 'iv_load_policy', 'modestbranding', 'color', 'theme'].each { |ytparm|
  p[ytparm] = params[ytparm] if params.include? ytparm }

```

Of the 24 available parameters for the YouTube players I tried to pick the most useful.

- rel is important to prevent playing every video in a playlist
- modestbranding gets rid of YouTube logos
- color and theme help the player match the site they site they are part of
- autohide may improve the user experience
- closed captioning may be important to somebody (not to me)
- disabling full screen is important
- annotations (iv\_load\_policy) I don’t really care about

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [December 3, 2014, 5:59am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/8 "2014-12-03T05:59:05Z")

</div>

This is the kind of request that could get prioritized for [a Discourse customer](https://discourse.org/pricing). Too bad you aren’t a customer! 😉

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [December 3, 2014, 6:17am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/9 "2014-12-03T06:17:38Z")

</div>

LGTM, feel free to PR that to the onebox repository

---

<div class="post-metadata">

### Author: ![sperok](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sperok/32/114977_2.png) [@sperok](https://meta.discourse.org/u/sperok)
#### Post date: [December 3, 2014, 7:10am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/10 "2014-12-03T07:10:17Z")

</div>

@codinghorror - We would rather host with you than at Amazon. A couple things block us:

1. I don’t think we can use the locale-override plugin if we host with you. The customized strings are important to us.
2. We are integrated with a SquareSpace front end and use the Discourse API from SquareSpace, requiring a custom X-Frame-Options setting to allow cross-domain operation. We use the API to create new topics from a simple box (less confusing than the markdown editor for a certain class of users). We also plan to use the API to extract recent posts related to videos.

If I am wrong about these items we would gladly become a customer.

@riking - Having never created a PR and being a complete novice with Ruby I’ll probably screw something up. You are forewarned.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 3, 2014, 8:50am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/11 "2014-12-03T08:50:02Z")

</div>

> [@sperok](#):
>
> Having never created a PR and being a complete novice with Ruby I’ll probably screw something up. You are forewarned.

give it a shot, don’t be afraid we will help you out by reviewing it.

---

<div class="post-metadata">

### Author: ![sperok](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sperok/32/114977_2.png) [@sperok](https://meta.discourse.org/u/sperok)
#### Post date: [December 3, 2014, 8:57am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/12 "2014-12-03T08:57:03Z")

</div>

@sam and @riking - Being able to submit a PR means:

- executing the Discourse Contributor Agreement (not a problem)
- setting up a Discourse Development Environment that actually works
- Making the change
- Testing it
- Submitting the PR

All of this is good stuff that I have been putting off for months and will try to get done in the next day or two. If I fail, then please feel free to grab this code and insert it the right way. My biggest blocker right now is understanding exactly how to deploy the modified file on to my Discourse instance. I have no idea how to add the modified “onebox” code back into Discourse. As it is approaching 1AM, it will wait until later today …

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 3, 2014, 8:58am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/13 "2014-12-03T08:58:10Z")

</div>

No probs, keep in mind, when working on onebox you only need a limited dev environment not the full Postgres + Redis environment.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [December 3, 2014, 9:24am UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/14 "2014-12-03T09:24:50Z")

</div>

> [@sperok](#):
>
> Having never created a PR and being a complete novice with Ruby I’ll probably screw something up. You are forewarned.

Go for it. a custom onebox is a good place to start i.e.

- Save a file whatever\_name\_onebox.rb in the lib/onebox/engine folder

```plaintext
module Onebox
  module Engine
    class WhateverNameOnebox
      include Engine
 
      matches_regexp /^http:\/\/www\.domian\.com\/forums\/.*/
 
      def to_html
        "<iframe src='#{@url}' style='border-width:0' frameborder='0' scrolling='no' width='100%'></iframe>"
      end
    end
  end
end

```

Regex might be tricky, and I hope you have better design skills than I do, but this will hopefully give you a starting point.

\* my iframe line is a single but it got crunched here.

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [October 3, 2025, 7:08pm UTC](https://meta.discourse.org/t/youtube-onebox-revisited/22764/15 "2025-10-03T19:08:05Z")

</div>


