From dbec447b39501b1d0883e7ece75576a2a6a82ef8 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 13 Mar 2026 21:32:54 +0100 Subject: [PATCH] add source page url, open with e key --- app.py | 11 +++++++---- static/app.js | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 440c83b..c2eee57 100644 --- a/app.py +++ b/app.py @@ -38,16 +38,19 @@ def scrape_images(query, page=0): except requests.RequestException as e: return [], str(e) - # Bing encodes original image URLs as murl":"https://..." - raw_urls = re.findall(r'murl":"(https?://[^&]+)"', resp.text) + # Bing HTML-encodes image data: purl = source page, murl = image URL + entries = re.findall( + r'purl":"(https?://[^&]+)".*?murl":"(https?://[^&]+)"', + resp.text, + ) seen = set() images = [] - for img_url in raw_urls: + for page_url, img_url in entries: if img_url in seen: continue seen.add(img_url) - images.append({"url": img_url}) + images.append({"url": img_url, "source": page_url}) if len(images) >= 30: break diff --git a/static/app.js b/static/app.js index 7577818..94debe7 100644 --- a/static/app.js +++ b/static/app.js @@ -246,6 +246,7 @@ document.addEventListener("keydown", e => { if (e.key === "ArrowRight") next_image(); else if (e.key === "ArrowLeft") prev_image(); else if (e.key === "Escape") close_gallery(); + else if (e.key === "e" && images[current_idx]?.source) window.open(images[current_idx].source, "_blank"); }); // ── event listeners ────────────────────────────────────────────────────────