Skip to content

Commit

Permalink
Merge pull request #1011 from torchbox/feature/6809-wix-embed
Browse files Browse the repository at this point in the history
#6809 - Enable embed codes Intranet and Main Site
  • Loading branch information
patrickcuagan authored Jun 10, 2024
2 parents ec9b767 + e204bcb commit 5b6e22c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions rca/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@

WAGTAILEMBEDS_FINDERS = [
{"class": "rca.utils.embed_finders.CustomOEmbedFinder"},
{"class": "rca.utils.embed_finders.WixEmbedFinder"},
]


Expand Down
31 changes: 31 additions & 0 deletions rca/utils/embed_finders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import re

import requests
from bs4 import BeautifulSoup
from wagtail.embeds.finders.base import EmbedFinder
from wagtail.embeds.finders.oembed import OEmbedFinder


Expand All @@ -20,3 +24,30 @@ def find_embed(self, url, max_width=None):
embed["html"] = str(soup)

return embed


class WixEmbedFinder(EmbedFinder):
"""Embed finder support for Wix. Wix does not have oEmbed support."""

def accept(self, url):
return re.match(r"^https?://(?:www\.)?embed.wix\.com/.+$", url)

def find_embed(self, url, max_width=None):
# Attempt to fetch the page content and scrape the title.
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")

title_tag = soup.find("title")
title = title_tag.string if title_tag else None

return {
# Title does not support None.
"title": title if title else "",
"provider_name": "Wix",
"type": "video",
"html": '<iframe src="{url}" frameborder="0" allowfullscreen title={title}></iframe>'.format(
url=url, title=title
),
"width": 800,
"height": 600,
}

0 comments on commit 5b6e22c

Please sign in to comment.