diff --git a/src/snek/system/template.py b/src/snek/system/template.py
index 097f21a..6113ec8 100644
--- a/src/snek/system/template.py
+++ b/src/snek/system/template.py
@@ -402,17 +402,17 @@ def embed_url(text):
)
page_image = (
- get_element_options(head_info, None, "image", "image", "image")
- or get_element_options(
- head_info, None, "image:url", "image:url", "image:url"
- )
- or get_element_options(
+ get_element_options(
head_info,
None,
"image:secure_url",
"image:secure_url",
"image:secure_url",
)
+ or get_element_options(
+ head_info, None, "image:url", "image:url", "image:url"
+ )
+ or get_element_options(head_info, None, "image", "image", "image")
)
page_image_height = get_element_options(
head_info, None, "image:height", "image:height", "image:height"
@@ -425,17 +425,17 @@ def embed_url(text):
)
page_video = (
- get_element_options(head_info, None, "video", "video", "video")
- or get_element_options(
- head_info, None, "video:url", "video:url", "video:url"
- )
- or get_element_options(
+ get_element_options(
head_info,
None,
"video:secure_url",
"video:secure_url",
"video:secure_url",
)
+ or get_element_options(
+ head_info, None, "video:url", "video:url", "video:url"
+ )
+ or get_element_options(head_info, None, "video", "video", "video")
)
page_video_height = get_element_options(
head_info, None, "video:height", "video:height", "video:height"
@@ -443,21 +443,28 @@ def embed_url(text):
page_video_width = get_element_options(
head_info, None, "video:width", "video:width", "video:width"
)
+ page_video_type = get_element_options(
+ head_info, None, "video:type", "video:type", "video:type"
+ )
page_audio = (
- get_element_options(head_info, None, "audio", "audio", "audio")
- or get_element_options(
- head_info, None, "audio:url", "audio:url", "audio:url"
- )
- or get_element_options(
+ get_element_options(
head_info,
None,
"audio:secure_url",
"audio:secure_url",
"audio:secure_url",
)
+ or get_element_options(
+ head_info, None, "audio:url", "audio:url", "audio:url"
+ )
+ or get_element_options(head_info, None, "audio", "audio", "audio")
)
+ page_player = get_element_options(head_info, twitter="player")
+ page_player_width = get_element_options(head_info, twitter="player:width")
+ page_player_height = get_element_options(head_info, twitter="player:height")
+
(get_element_options(head_info, twitter="card") or "summary_large_image")
attachment_base = BeautifulSoup(str(element), "html.parser")
@@ -470,7 +477,32 @@ def embed_url(text):
render_element = attachment
- if page_image:
+ if page_player:
+ style = {
+ "width": page_player_width + "px" if page_player_width else None,
+ "height": f"{(page_player_height or '400')}px",
+ }
+
+ style_string = "; ".join(
+ f"{key}: {value}" for key, value in style.items() if value
+ )
+ player_template = f''
+ render_element.append(BeautifulSoup(player_template, "html.parser"))
+ elif page_video:
+ style = {
+ "width": page_video_width + "px" if page_video_width else None,
+ "height": f"{(page_video_height or '400')}px",
+ }
+
+ style_string = "; ".join(
+ f"{key}: {value}" for key, value in style.items() if value
+ )
+ if not page_video_type or page_video_type.startswith("video/"):
+ video_template = f''
+ else:
+ video_template = f''
+ render_element.append(BeautifulSoup(video_template, "html.parser"))
+ elif page_image:
style = {
"width": page_image_width + "px" if page_image_width else None,
"height": page_image_height + "px" if page_image_height else None,
@@ -483,18 +515,6 @@ def embed_url(text):
image_template = f'
'
render_element.append(BeautifulSoup(image_template, "html.parser"))
- if page_video:
- style = {
- "width": page_video_width + "px" if page_video_width else None,
- "height": page_video_height + "px" if page_video_height else None,
- }
-
- style_string = "; ".join(
- f"{key}: {value}" for key, value in style.items() if value
- )
- video_template = f''
- render_element.append(BeautifulSoup(video_template, "html.parser"))
-
if page_audio:
audio_template = f''
render_element.append(BeautifulSoup(audio_template, "html.parser"))
@@ -608,4 +628,3 @@ class PythonExtension(Extension):
return "".join(to_write)
return str(fn(caller()))
-