From 171820736413531942034ae3da45e58756f4a9ea Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Wed, 8 Nov 2023 02:27:47 +0530 Subject: [PATCH] disable autoplay on phone --- routers/root.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/routers/root.py b/routers/root.py index c8cc71295..e2b82f907 100644 --- a/routers/root.py +++ b/routers/root.py @@ -1,5 +1,6 @@ import datetime import os.path +import re import subprocess import tempfile import typing @@ -39,6 +40,7 @@ DEFAULT_LOGIN_REDIRECT = "/explore/" DEFAULT_LOGOUT_REDIRECT = "/" +MOBILE_UA_PATTERN = re.compile(r"(Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini)", re.MULTILINE) @app.get("/sitemap.xml/") @@ -336,3 +338,23 @@ def page_wrapper(request: Request, render_fn: typing.Callable, **kwargs): st.html(templates.get_template("footer.html").render(**context)) st.html(templates.get_template("login_scripts.html").render(**context)) + if is_mobile(request): + render_on_mobile_only() + + +def render_on_mobile_only() -> str: + # disable video autoplay on mobile + st.html(""" + + """) + + +def is_mobile(request: Request) -> bool: + user_agent = request.headers.get("user-agent", "") + return bool(MOBILE_UA_PATTERN.search(user_agent))