# Hoe kan ik automatisch een Bandcamp-speler op mijn site insluiten?

**URL:** https://meta.discourse.org/t/how-can-i-automatically-embed-a-bandcamp-player-on-my-site/255579
**Category:** Development
**Tags:** unsupported-install, embedding
**Created:** [18 februari 2023 om 22:49 UTC](https://meta.discourse.org/t/how-can-i-automatically-embed-a-bandcamp-player-on-my-site/255579 "2023-02-18T22:49:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![orbita](https://avatars.discourse-cdn.com/v4/letter/o/8baadc/32.png) [@orbita](https://meta.discourse.org/u/orbita)
#### Post date: [18 februari 2023 om 22:49 UTC](https://meta.discourse.org/t/how-can-i-automatically-embed-a-bandcamp-player-on-my-site/255579/1 "2023-02-18T22:49:34Z")

</div>

If I post a Bandcamp URL to a discourse forum, it pulls in their Embedded player. How can I achieve this with my own music site?

I’ve tried setting og:video tags to no avail.

Thanks!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [18 februari 2023 om 23:47 UTC](https://meta.discourse.org/t/how-can-i-automatically-embed-a-bandcamp-player-on-my-site/255579/2 "2023-02-18T23:47:21Z")

</div>

You mean in your site that isn’t discourse?

You can look in the discourse source and search for “onebox” or maybe “one\_box”

Or maybe see [https://get.bandcamp.help/hc/en-us/articles/360013561254-How-do-I-create-a-Bandcamp-embedded-player-#:~:text=To%20create%20an%20embedded%20player,your%20merchandise%2C%20and%20so%20on](https://get.bandcamp.help/hc/en-us/articles/360013561254-How-do-I-create-a-Bandcamp-embedded-player-#:~:text=To%20create%20an%20embedded%20player,your%20merchandise%2C%20and%20so%20on). And use that to develop code for your site.

---

<div class="post-metadata">

### Author: ![orbita](https://avatars.discourse-cdn.com/v4/letter/o/8baadc/32.png) [@orbita](https://meta.discourse.org/u/orbita)
#### Post date: [19 februari 2023 om 00:05 UTC](https://meta.discourse.org/t/how-can-i-automatically-embed-a-bandcamp-player-on-my-site/255579/3 "2023-02-19T00:05:31Z")

</div>

Hi Jay,

I have a website, a bit similar to Bandcamp. I have created embeds similar to the link you have pasted so you can add an iframe to another website and my embed will appear.

But what I’m taking about is some magic that seems to be happening when you simply post a bandcamp URL, a full iframe embed appears. Is this something configured on the discourse server?

Let’s see if this works here. I’ll post paste a bandcamp url below.

> [@](#):
>
> `https://mosessumney.bandcamp.com/track/man-on-the-moon-reprise`

https://bandcamp.com/EmbeddedPlayer/v=2/track=3851427628/size=large/tracklist=false/artwork=small/

Yes ^ as you can see an functional embedded music player has appeared.. I didnt paste any iframe or js, just the embed url I quoted above.

Is this something special that discourse knows how to do for specific sites or it there some magic header tags you can set to tell it which embed url to use.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [19 februari 2023 om 09:58 UTC](https://meta.discourse.org/t/how-can-i-automatically-embed-a-bandcamp-player-on-my-site/255579/4 "2023-02-19T09:58:13Z")

</div>

As Jay pointed out you should look at the source code.

‘Onebox’ is the library that, in part, converts some URLs into embeds.

Have you looked at?:

> <https://github.com/discourse/discourse/blob/64171730827c58df26a7ad75f0e58f17c2add118/lib/onebox/engine/band_camp_onebox.rb>

I think the original intention was that this code be also used on non-Discourse sites.

To that end there’s a (now unmaintained) gem that you might be able to leverage (assuming your site is RoR), maybe you’d be interested in maintaining it?

[https://github.com/discourse/onebox](https://github.com/discourse/onebox)

A word of caution: the code on Discourse will have positively evolved since.

---

<div class="post-metadata">

### Author: ![orbita](https://avatars.discourse-cdn.com/v4/letter/o/8baadc/32.png) [@orbita](https://meta.discourse.org/u/orbita)
#### Post date: [19 februari 2023 om 12:07 UTC](https://meta.discourse.org/t/how-can-i-automatically-embed-a-bandcamp-player-on-my-site/255579/5 "2023-02-19T12:07:20Z")

</div>

Hi Robert,

Thank you for digging that out for me. So yes, there there is specific code for it in Discourse. It’s not something I need to do on my site as such. That answers that part. So if I want my site supported in the same way as Bandcamp on Discourse (and potentially other forums), I’ll need to ask or contribute the code to make it work for mine too.

My site’s not RoR but I do know some ruby so I might be able to contribute.

* * *

I have a 2nd question too. As well as pasting the URL, I also attempted to add the embed with the iframe tag. This works fine on a normal website but doing it on my discourse forum doesn’t work. A square box appeared but not the embed inside. I presumed it was a permission issue so I added my host to the allowed iframes but it still doesn’t work.

–

OK so just as I was about to get a screenshot to show it not working it seems to have started working! So I wonder if there is some kind of delay in the system for applying the allowed hosts.

I’ll explore further. Thanks for your help so far.

---

<div class="post-metadata">

### Author: ![orbita](https://avatars.discourse-cdn.com/v4/letter/o/8baadc/32.png) [@orbita](https://meta.discourse.org/u/orbita)
#### Post date: [19 februari 2023 om 12:20 UTC](https://meta.discourse.org/t/how-can-i-automatically-embed-a-bandcamp-player-on-my-site/255579/6 "2023-02-19T12:20:18Z")

</div>

Ok I’ve just realised what’s happening. When you change the allow iframe settings, it’s doesn’t effect existing posts (at least not immediately). It’s possible they do later..not sure.

But - when you create a new post or edit existing post, the settings take effect then.

So now both my embed and URL work - so this means I’ll just need to contact the relevant forums and ask them to add my domain name to the allowed hosts and it should work from that point on.

Cheers

---

<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: [19 februari 2023 om 12:53 UTC](https://meta.discourse.org/t/how-can-i-automatically-embed-a-bandcamp-player-on-my-site/255579/7 "2023-02-19T12:53:22Z")

</div>

> [@orbita](#):
>
> it’s doesn’t effect existing posts (at least not immediately). It’s possible they do later…not sure.

Hi 👋🙂

Older posts need to be rebaked. You can do manually that by clicking the three dots icon below the post, then the wrench, then Rebuild HTML.  
 ![image](https://global.discourse-cdn.com/meta/original/4X/7/2/a/72a7c83cb898c533ef9a4e9404b01ba7e581e61f.png)

If you have a lot of posts that need to be rebaked, you may need the [rake task](https://meta.discourse.org/t/rebake-all-posts/69340/2) to rebake all posts or use a custom rails script to rebake just some of them using the needed criteria.

Something like this I think:

```ruby
Post.where('raw LIKE ?', 'a specific URL').find_each do |p|
    p.rebake!
end

```
