From 22410862f3d2cab24a5888f0c7245d63f107c3d7 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 11 Dec 2022 18:15:30 +0100 Subject: [PATCH] Tweak/fix opengraph parsing --- app/utils/opengraph.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/utils/opengraph.py b/app/utils/opengraph.py index 24eb873..05e7752 100644 --- a/app/utils/opengraph.py +++ b/app/utils/opengraph.py @@ -62,6 +62,13 @@ def _scrap_og_meta(url: str, html: str) -> OpenGraphMeta | None: if u := raw.get(maybe_rel): raw[maybe_rel] = make_abs(u, url) + if not is_url_valid(raw[maybe_rel]): + logger.info(f"Invalid url {raw[maybe_rel]}") + if maybe_rel == "url": + raw["url"] = url + elif maybe_rel == "image": + raw["image"] = None + return OpenGraphMeta.parse_obj(raw)