summaryrefslogtreecommitdiffstats
path: root/core/ld.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/ld.py')
-rw-r--r--core/ld.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/core/ld.py b/core/ld.py
index 24088ec..946e030 100644
--- a/core/ld.py
+++ b/core/ld.py
@@ -456,6 +456,20 @@ def parse_ld_date(value: str | None) -> datetime.datetime | None:
)
+def get_first_image_url(data) -> str | None:
+ """
+ 'icon' and 'image' fields might be a dict or a list. Return the first
+ 'url' for something that looks to be for an image.
+ """
+ if isinstance(data, list):
+ for itm in data:
+ if isinstance(itm, dict) and "url" in itm:
+ return itm["url"]
+ elif isinstance(data, dict):
+ return data.get("url")
+ return None
+
+
def media_type_from_filename(filename):
_, extension = os.path.splitext(filename)
if extension == ".png":