Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Update Rawpixel image URLs for ingestion (#3669)
Vincent991c4bf3bdf7
diff --git a/catalog/dags/providers/provider_api_scripts/rawpixel.py b/catalog/dags/providers/provider_api_scripts/rawpixel.pyindex ac9eaf06a..c731547c7 100644--- a/catalog/dags/providers/provider_api_scripts/rawpixel.py+++ b/catalog/dags/providers/provider_api_scripts/rawpixel.py@@ -72,10 +72,19 @@ class RawpixelDataIngester(ProviderDataIngester):"creative commons","public domain",}- # Image size options- full_size_option = "image_1300"- # TODO: Use as part of https://github.com/WordPress/openverse-catalog/issues/817- thumbnail_size_option = "image_600_png"+ # Image size options, without watermark.+ full_size_option = "editor_1024" # Always serve webp format, "image_1000" can be used as an alternative with jpeg fallback+ png_full_size_option = "image_png_1300" # Serve webp format if accepted else jpeg+ png_dark_full_size_option = (+ "dark_image_png_1300" # Serve webp format if accepted else jpeg+ )+ thumbnail_size_option = "image_600" # Serve webp format if accepted else jpeg+ png_thumbnail_size_option = (+ "image_png_600" # Serve webp format if accepted else jpeg+ )+ png_dark_thumbnail_size_option = (+ "dark_image_png_600" # Serve webp format if accepted else jpeg+ )def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)@@ -133,6 +142,24 @@ class RawpixelDataIngester(ProviderDataIngester):return resultsreturn None+ @staticmethod+ def _get_full_size_preset(self, data: dict) -> str | None:+ """Get the full size preset based on the image properties."""+ if data.get("isPng"):+ if data.get("isDarkPng"):+ return RawpixelDataIngester.png_dark_full_size_option+ return RawpixelDataIngester.png_full_size_option+ return RawpixelDataIngester.full_size_option++ @staticmethod+ def _get_thumbnail_size_preset(self, data: dict) -> str | None:+ """Get the full size preset based on the thumbnail properties."""+ if data.get("isPng"):+ if data.get("isDarkPng"):+ return RawpixelDataIngester.png_dark_thumbnail_size_option+ return RawpixelDataIngester.png_thumbnail_size_option+ return RawpixelDataIngester.thumbnail_size_option+@staticmethoddef _get_image_url(data: dict, size_option: str) -> str | None:"""@@ -145,10 +172,12 @@ class RawpixelDataIngester(ProviderDataIngester):'image_png_400', 'image_500', 'image_png_500', 'image_600', 'image_png_600','image_700', 'image_png_700', 'image_800', 'image_png_800', 'image_900','image_png_900', 'image_1000', 'image_png_1000', 'image_1300',- 'image_png_1300'+ 'image_png_1300', 'editor_1024'The number refers to the width displayed, and a png option is provided for eachsize.++ Note that preset size starting from 1100 are watermarked."""style_uri = data.get("style_uri")if not style_uri:@@ -259,13 +288,19 @@ class RawpixelDataIngester(ProviderDataIngester):if not (license_info := get_license_info(metadata["licenseUrl"])):return None- if not (url := self._get_image_url(data, self.full_size_option)):+ full_size_preset = self._get_full_size_preset(self, data)+ if not (url := self._get_image_url(data, full_size_preset)):return None+ thumbnail_preset = self._get_thumbnail_size_preset(self, data)+ if not (thumbnail_url := self._get_image_url(data, thumbnail_preset)):+ thumbnail_url = None+width, height = self._get_image_properties(data)return {"foreign_landing_url": foreign_landing_url,"url": url,+ "thumbnail_url": thumbnail_url,"license_info": license_info,"foreign_identifier": foreign_identifier,"width": width,diff --git a/catalog/tests/dags/providers/provider_api_scripts/test_rawpixel.py b/catalog/tests/dags/providers/provider_api_scripts/test_rawpixel.pyindex 37b0553f3..a48fb2e6d 100644--- a/catalog/tests/dags/providers/provider_api_scripts/test_rawpixel.py+++ b/catalog/tests/dags/providers/provider_api_scripts/test_rawpixel.py@@ -291,7 +291,8 @@ def test_get_record_data():"foreign_identifier": 4032668,"foreign_landing_url": "https://www.rawpixel.com/image/4032668/photo-image-background-nature-mountain", # noqa"height": 5515,- "url": "https://images.rawpixel.com/image_1300/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIyLTA1L2ZsNDY0NDU5OTQ2MjQtaW1hZ2Uta3UyY21zcjUuanBn.jpg", # noqa+ "url": "https://images.rawpixel.com/editor_1024/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIyLTA1L2ZsNDY0NDU5OTQ2MjQtaW1hZ2Uta3UyY21zcjUuanBn.jpg", # noqa,+ "thumbnail_url": "https://images.rawpixel.com/image_600/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIyLTA1L2ZsNDY0NDU5OTQ2MjQtaW1hZ2Uta3UyY21zcjUuanBn.jpg", # noqa"license_info": LicenseInfo(license="cc0",version="1.0",