from app.exceptions import ( TiktokThumbnailException, ) from app.image import Image from app.models import ( Creative, ) from .base import BaseCreativeProcessor class TiktokCreativeProcessor(BaseCreativeProcessor): TIKTOK_EMBEDDED_URL = "https://www.tiktok.com/oembed" async def _get_image_for_creative(self, creative: Creative) -> Image: creative_url_response = await self.web_client.get( self.TIKTOK_EMBEDDED_URL, params={"url": creative.source_url}, ) creative_url_response.raise_for_status() thumbnail_url = creative_url_response.json().get("thumbnail_url") if not thumbnail_url: raise TiktokThumbnailException thumbnail_response = await self.web_client.get(thumbnail_url) thumbnail_response.raise_for_status() image = Image(thumbnail_response.content) return image