# הטמעת סוג סרטוני "short" של Youtube / oneboxing לא עובדת

**URL:** https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350
**Category:** Feature
**Tags:** completed
**Created:** [26 באפריל,‏ 2022,‏ 5:35pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350 "2022-04-26T17:35:39Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [26 באפריל,‏ 2022,‏ 5:35pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/1 "2022-04-26T17:35:39Z")

</div>

Hi!

Youtube video embedding works on my forums, but not short videos (those with /shorts/ in the URL) like this one:

[![](https://global.discourse-cdn.com/meta/original/4X/7/0/0/70063c2f1dd17fe04d2b7f5f44f676136cf09e5f.jpeg "Monocycle") ](https://www.youtube.com/watch?v=SWeTMdyv50Q)

The onebox request returns a 404 error.

 ![image](https://global.discourse-cdn.com/meta/original/4X/5/2/3/523b101db8ac46a08c28b7676c0bc887f1a33f64.png)

Regular youtube video embedding works.  
I don’t encounter this issue on try.discourse or meta.  
I suppose it comes from a site setting not properly configured.

Any clue?

* * *

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [26 באפריל,‏ 2022,‏ 5:59pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/3 "2022-04-26T17:59:22Z")

</div>

Youtube oneboxing is something custom we created. Someone needs to submit a #pr-welcome for shorts compatibility. Moving to #Contribute > Feature

In the meantime you can always add the manual iframe URL to the `allowed iframes` site setting:

https://www.youtube.com/embed/SWeTMdyv50Q

It’s a tall one tho 🤣

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [26 באפריל,‏ 2022,‏ 6:07pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/4 "2022-04-26T18:07:52Z")

</div>

> [@Canapin](#):
>
> I suppose it comes from a site setting not properly configured

Maybe it’s because of the location of the server, like it was/is here [Youtube embeddings have stopped working for servers in Europe](https://meta.discourse.org/t/youtube-embeddings-have-stopped-working-for-servers-in-europe/185128)

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [26 באפריל,‏ 2022,‏ 6:14pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/5 "2022-04-26T18:14:48Z")

</div>

Thanks for the clarification!

> [@Falco](#):
>
> In the meantime you can always add the manual iframe URL to the `allowed iframes` site setting:

Could you just tell me what URL should I add in allowed iframes in order to have the video shown as you did? It would perfectly do the job for now, even if it’s tall indeed.

* * *

As for the video height, it’s possible to make it less tall by setting a `max-height` with CSS on the iframe. The issue is that the iframe has no attribute of any kind that specify that it’s a short (vertical) vidéo. 😕

```xml
<iframe width="672" height="1194" src="https://www.youtube.com/embed/SWeTMdyv50Q" frameborder="0" allowfullscreen="">

```

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [26 באפריל,‏ 2022,‏ 6:18pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/6 "2022-04-26T18:18:14Z")

</div>

> [@Canapin](#):
>
> Could you just tell me what URL should I add in allowed iframes

`https://www.youtube.com/embed/`

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [26 באפריל,‏ 2022,‏ 6:27pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/7 "2022-04-26T18:27:46Z")

</div>

Thank you Falco.

I guess I’m going close, but I’m still a bit confused.

So, I’ve added this URL in the allowed iframes.

 ![image](https://global.discourse-cdn.com/meta/original/4X/0/7/f/07fe24ee084ad4e5bfd9e5dd093052ca3677c6d2.png)

But then, what should I do in order to make the video appear?

If I write in my post `https://www.youtube.com/shorts/SWeTMdyv50Q`, it won’t work.  
If I write `<iframe>https://www.youtube.com/shorts/SWeTMdyv50Q</iframe>`, it won’t work.  
If I write `https://www.youtube.com/embed/SWeTMdyv50Q`, it will work, but will display the short video with standard youtube video width/height ratio (which is OK for me, though I’d prefer having another ratio and not having to manually write “embed” in the URL):

 ![image](https://global.discourse-cdn.com/meta/original/4X/b/3/2/b32bc1f3ce296a72556077b9af67e87353ad9bad.jpeg)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [26 באפריל,‏ 2022,‏ 6:54pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/8 "2022-04-26T18:54:53Z")

</div>

Right click a shorts video and select “Copy embed code”. That is what I meant by “manual embed code”, sorry I wasn’t clear.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [26 באפריל,‏ 2022,‏ 8:26pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/9 "2022-04-26T20:26:52Z")

</div>

Also, replacing `/shorts/` by `watch?v=`, the default URL of a Youtube video, works.

[![](https://global.discourse-cdn.com/meta/original/4X/7/0/0/70063c2f1dd17fe04d2b7f5f44f676136cf09e5f.jpeg "Monocycle") ](https://www.youtube.com/watch?v=SWeTMdyv50Q)

So, in youtube, on [https://www.youtube.com/shorts/SWeTMdyv50Q](https://www.youtube.com/shorts/SWeTMdyv50Q), doing right click → Copy video URL will work since it returns `https://youtu.be/SWeTMdyv50Q` which is correctly displayed on Discourse (with the regular wide ratio though).

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [27 בנובמבר,‏ 2022,‏ 5:51pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/10 "2022-11-27T17:51:06Z")

</div>

> [@Canapin](#):
>
> replacing `/shorts/` by `watch?v=`

I’m not a developer but I’m guessing something like that might make the #pr-welcome easier for someone who is?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [27 בנובמבר,‏ 2022,‏ 8:47pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/11 "2022-11-27T20:47:57Z")

</div>

I’ve done it though I might have messed up a bit my pull request because for some reason, I’m still not used to GitHub… I really need to read the manual (and, a friend tells me, to create branches from my Discourse fork…). 🙃

Just for information, I just edited the file `lib\onebox\engine\youtube_onebox.rb` to add

```ruby
# https://www.youtube.com/shorts/wi2jAtpBl0Y
if uri.path["/shorts/"]
  id ||= uri.path[/\/shorts\/([\w\-]+)/, 1]
end

```

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [27 בנובמבר,‏ 2022,‏ 9:32pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/12 "2022-11-27T21:32:28Z")

</div>

Would it be easier just change `shorts` to `embed`?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [27 בנובמבר,‏ 2022,‏ 10:06pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/13 "2022-11-27T22:06:03Z")

</div>

I’m not sure what you mean.

People usually copy-paste their Youtube link from their address bar.

Now Youtube has new `/shorts/` URL, people will copy-paste these `/shorts/` links and they’re not supported yet by the Youtube oneboxing.

`/embed/` links are, but they require the user to actually look in Youtube for the embed URL, which pretty much nobody does 🤔

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [27 בנובמבר,‏ 2022,‏ 10:13pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/14 "2022-11-27T22:13:37Z")

</div>

I’m just wondering if it would easier job to just change that url? Because `youtube.com/shorts/something` is totally same than `youtube.com/embed/something`, and with `/embed/` oneboxing/embedding works just fine here.

`https://youtube.com/shorts/aQFdwUeZxkA` doesn’t work:

[![](https://global.discourse-cdn.com/meta/original/4X/c/5/4/c5408590eeffcd9bd4aea10bc668919dd4ae6945.jpeg "Farting during therapy #shorts") ](https://www.youtube.com/watch?v=aQFdwUeZxkA)

But `https://youtube.com/embed/aQFdwUeZxkA` works:

[![](https://global.discourse-cdn.com/meta/original/4X/c/5/4/c5408590eeffcd9bd4aea10bc668919dd4ae6945.jpeg "YouTube") ](https://www.youtube.com/watch?v=aQFdwUeZxkA)

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [27 בנובמבר,‏ 2022,‏ 10:25pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/15 "2022-11-27T22:25:38Z")

</div>

> [@Jagster](#):
>
> I’m just wondering if it would easier job to just change that url?

~~I’m still not following you. Who would change the URL? The poster? But the poster doesn’t want to manually re-write part of an URL (they won’t even know why the video doesn’t embed), they just want to copy-paste, and boom, it works.~~

* * *

Edit: or do you mean that Discourse’s Oneboxing code would replace `/shorts/` by `/embed/`?

Yes, maybe! I’m not exactly a code wizard 😄

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [28 בנובמבר,‏ 2022,‏ 7:17am UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/16 "2022-11-28T07:17:45Z")

</div>

> [@Canapin](#):
>
> do you mean that Discourse’s Oneboxing code would replace

Yes. And I can’t code a bit but I could imagine simply replacing can’t be that hard 😉

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [29 בנובמבר,‏ 2022,‏ 1:26pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/17 "2022-11-29T13:26:49Z")

</div>

> [@Canapin](#):
>
> replacing `/shorts/` by `watch?v=`

> [@Canapin](#):
>
> replace `/shorts/` by `/embed/`?

These both have the same end result, right? That a shorts video then gets nicely embedded with playback functionally?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [29 בנובמבר,‏ 2022,‏ 1:49pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/18 "2022-11-29T13:49:19Z")

</div>

Well… I’m not sure I understand. 😅

1. [https://www.youtube.com/embed/SWeTMdyv50Q](https://www.youtube.com/embed/SWeTMdyv50Q)

2. [https://www.youtube.com/shorts/SWeTMdyv50Q](https://www.youtube.com/shorts/SWeTMdyv50Q)

3. [http://youtu.be/SWeTMdyv50Q](http://youtu.be/SWeTMdyv50Q) leads to [https://www.youtube.com/watch?v=SWeTMdyv50Q](https://www.youtube.com/watch?v=SWeTMdyv50Q)

These three different link formatting lead to different displays on Youtube.

Whatever the URL format is, the code only cares about the video ID:

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

The code currently doesn’t support /shorts/ and there are multiple ways to make it work.

My suggestion, as a coding neophyte, is to duplicate this part:

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

and replace `embed` with `shorts`. I tried it on my dev install and it works perfectly.

If there’s a more elegant way to do so, I’d be happy to know it 🙂

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [1 בדצמבר,‏ 2022,‏ 7:19am UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/19 "2022-12-01T07:19:37Z")

</div>

Great work @Canapin 👏

Is it something you want to submit a pull request for?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [1 בדצמבר,‏ 2022,‏ 9:25am UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/20 "2022-12-01T09:25:58Z")

</div>

Yes, I’m just struggling with the ruby test file. It doesn’t work and I don’t know why. I’ve never used/created unit testing before so…

The file that should be modified is [discourse/spec/lib/onebox/engine/youtube\_onebox\_spec.rb at 493d437e79f88ab9829a36fa000cc6107085e424 · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/493d437e79f88ab9829a36fa000cc6107085e424/spec/lib/onebox/engine/youtube_onebox_spec.rb)

I’ve tried adding this at the bottom of the file:

```ruby
  it "can parse youtube shorts results" do
    preview = expect(Onebox.preview('https://www.youtube.com/watch?v=wi2jAtpBl0Y').placeholder_html)
    preview.to match(/reacts/)
    preview.to match(/hqdefault/)
  end

```

And also added this at the beginning of the file, in `before do`:

```ruby
stub_request(:get, "https://www.youtube.com/shorts/wi2jAtpBl0Y").to_return(status: 200, body: onebox_response("youtube-shorts"))`

```

I executed the tests with `bin/rspec spec/lib/onebox/engine/youtube_onebox_spec.rb`  
But the test I added fails.

I don’t have the error message right now and I’ll be busy for the next few hours though.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [6 בדצמבר,‏ 2022,‏ 5:19pm UTC](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350/21 "2022-12-06T17:19:56Z")

</div>

Works now:

`https://www.youtube.com/shorts/kt7jiaGVsto`

[![](https://global.discourse-cdn.com/meta/original/4X/6/4/3/643f89770b193dfe4cdeb02072f3c42010177e46.jpeg "I got him") ](https://www.youtube.com/watch?v=kt7jiaGVsto)

[Next page](https://meta.discourse.org/t/youtube-short-videos-type-embedding-oneboxing-not-working/225350.md?page=2)
