fix: now supports video / gif baners

This commit is contained in:
2026-06-12 12:15:31 +03:00
parent c3390a5887
commit 2770ae1ccc
2 changed files with 11 additions and 4 deletions

View File

@@ -37,7 +37,7 @@ from .. import utils, loader
from ..types import BotInlineCall, InlineCall from ..types import BotInlineCall, InlineCall
logger = logging.getLogger("Limoka") logger = logging.getLogger("Limoka")
__version__ = (1, 5, 5) __version__ = (1, 5, 6)
def _parse_version_from_source(source: str): def _parse_version_from_source(source: str):
@@ -879,6 +879,9 @@ class Limoka(loader.Module):
except (aiohttp.ClientError, asyncio.TimeoutError) as head_error: except (aiohttp.ClientError, asyncio.TimeoutError) as head_error:
logger.debug(f"_validate_url: HEAD failed ({type(head_error).__name__}), will try GET for {url}") logger.debug(f"_validate_url: HEAD failed ({type(head_error).__name__}), will try GET for {url}")
def _is_supported_media(content_type: str) -> bool:
return content_type.startswith("image/") or content_type.startswith("video/mp4")
# If HEAD didn't work or returned non-200, try GET # If HEAD didn't work or returned non-200, try GET
if ct is None: if ct is None:
max_retries = 2 max_retries = 2
@@ -897,7 +900,7 @@ class Limoka(loader.Module):
try: try:
data = await response.content.read(2048) data = await response.content.read(2048)
mime = filetype.guess_mime(data, mime=True) mime = filetype.guess_mime(data, mime=True)
if mime and mime.startswith("image/"): if mime and _is_supported_media(mime):
return url return url
else: else:
self._invalid_banners.add(url) self._invalid_banners.add(url)
@@ -913,7 +916,7 @@ class Limoka(loader.Module):
return None return None
# Check Content-Type from successful request # Check Content-Type from successful request
if ct and ct.startswith("image/"): if ct and _is_supported_media(ct):
return url return url
elif ct: elif ct:
self._invalid_banners.add(url) self._invalid_banners.add(url)

View File

@@ -523,6 +523,10 @@ class Limoka(loader.Module):
async def _validate_url(self, url: str) -> Optional[str]: async def _validate_url(self, url: str) -> Optional[str]:
if not url or url in self._invalid_banners: if not url or url in self._invalid_banners:
return None return None
def _is_supported_media(content_type: str) -> bool:
return content_type.startswith("image/") or content_type.startswith("video/mp4")
try: try:
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.head( async with session.head(
@@ -532,7 +536,7 @@ class Limoka(loader.Module):
self._invalid_banners.add(url) self._invalid_banners.add(url)
return None return None
ct = response.headers.get("Content-Type", "").lower() ct = response.headers.get("Content-Type", "").lower()
if not ct.startswith("image/"): if not _is_supported_media(ct):
self._invalid_banners.add(url) self._invalid_banners.add(url)
return None return None
return url return url