From 57fc5ef913b377c4469131de931928abda958ed3 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Thu, 29 Sep 2022 09:10:05 +0200 Subject: [PATCH] Improve OG meta processing --- app/utils/opengraph.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/utils/opengraph.py b/app/utils/opengraph.py index 2557944..3fb034b 100644 --- a/app/utils/opengraph.py +++ b/app/utils/opengraph.py @@ -90,18 +90,22 @@ async def external_urls( if not h: continue - ph = urlparse(h) - mimetype, _ = mimetypes.guess_type(h) - if ( - ph.scheme in {"http", "https"} - and ph.hostname != note_host - and is_url_valid(h) - and ( - not mimetype - or mimetype.split("/")[0] not in ["image", "video", "audio"] - ) - ): - urls.add(h) + try: + ph = urlparse(h) + mimetype, _ = mimetypes.guess_type(h) + if ( + ph.scheme in {"http", "https"} + and ph.hostname != note_host + and is_url_valid(h) + and ( + not mimetype + or mimetype.split("/")[0] not in ["image", "video", "audio"] + ) + ): + urls.add(h) + except Exception: + logger.exception(f"Failed to check {h}") + continue return urls - tags_hrefs