Use BBC's clean image variant (cpsprodpb) instead of the branded one
BBC's og:image comes from the "branded_news" CDN path with a "BBC NEWS" logo baked into the picture (shows as "…EWS" once the hero crops it). The identical photo is served under "cpsprodpb" with no logo, so rewrite branded_news → cpsprodpb. Best of both: full-resolution hero, no burned-in branding. Re-enriched recent briefs so live images swap over. 99 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+15
-2
@@ -58,6 +58,19 @@ def _is_generic_image(url: str) -> bool:
|
||||
return any(marker in lowered for marker in _GENERIC_IMAGE_MARKERS)
|
||||
|
||||
|
||||
def _prefer_unbranded(url: str) -> str:
|
||||
"""Swap BBC's logo-branded image variant for its clean one.
|
||||
|
||||
BBC's og:image is served from the "branded_news" CDN path with a "BBC NEWS"
|
||||
logo baked into the picture (it shows as "…EWS" once the hero crops it). The
|
||||
identical photo is served under "cpsprodpb" with no logo, so prefer that — a
|
||||
clean hero at the same full resolution.
|
||||
"""
|
||||
if "ichef.bbci.co.uk" in url and "/branded_news/" in url:
|
||||
return url.replace("/branded_news/", "/cpsprodpb/")
|
||||
return url
|
||||
|
||||
|
||||
def _attr(tag: bytes, name: bytes) -> bytes | None:
|
||||
m = re.search(name + rb"""\s*=\s*["']([^"']*)["']""", tag, re.IGNORECASE)
|
||||
return m.group(1) if m else None
|
||||
@@ -73,9 +86,9 @@ def og_image_from_html(html: bytes) -> str | None:
|
||||
if not content:
|
||||
continue
|
||||
image = canonicalize_url(content.decode("utf-8", "replace"))
|
||||
# Skip branded/generic share images; keep scanning for a real one.
|
||||
# Skip generic placeholders; keep scanning for a real one.
|
||||
if image and not _is_generic_image(image):
|
||||
return image
|
||||
return _prefer_unbranded(image)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user