diff --git a/telegram_client.py b/telegram_client.py index 21b487c..baf60ab 100644 --- a/telegram_client.py +++ b/telegram_client.py @@ -5,6 +5,18 @@ from config import get_settings import os import re + +#tests +#http://127.0.0.1:8000/html/DragorWW_space/114 — video +#http://127.0.0.1:8000/html/DragorWW_space/20 - many photos +#http://127.0.0.1:8000/html/DragorWW_space/58 - photos+video +#http://127.0.0.1:8000/html/DragorWW_space/44 - poll +#http://127.0.0.1:8000/html/DragorWW_space/46 - photo +#http://127.0.0.1:8000/html/DragorWW_space/49, http://127.0.0.1:8000/html/DragorWW_space/63 — webpage +#http://127.0.0.1:8000/html/deckru/826 - animation +#http://127.0.0.1:8000/html/DragorWW_space/61 — links + + logger = logging.getLogger(__name__) settings = get_settings() @@ -78,24 +90,34 @@ class TelegramClient: # Parse media and add video markers media = [] if message.media: - # Handle animations directly from message object - if hasattr(message, "animation") and message.animation: - animation = message.animation - media.append(await self._parse_animation(animation)) - # Handle videos directly from message object - elif hasattr(message, "video") and message.video: - video = message.video - media.append(await self._parse_media(video)) - # Handle photos directly from message object - elif hasattr(message, "photo") and message.photo: - photo = message.photo - media.append(await self._parse_media(photo)) - else: - media_obj = message.media - parsed_media = await self._parse_media(media_obj) - if parsed_media["type"] not in ["webpage", "nonetype"]: - media.append(parsed_media) - logger.debug(f"Parsed media: {parsed_media}") + # Process web page with photo + web_page = getattr(message, "web_page", None) + if web_page and web_page.photo: + # Add photo from web page regardless of type + media.append({ + "type": "webpage_photo", + "url": web_page.photo.file_id, + "thumbnail_file_id": web_page.photo.file_id + }) + elif not (getattr(message, "poll", None)): + # Handle animations directly from message object + if hasattr(message, "animation") and message.animation: + animation = message.animation + media.append(await self._parse_animation(animation)) + # Handle videos directly from message object + elif hasattr(message, "video") and message.video: + video = message.video + media.append(await self._parse_media(video)) + # Handle photos directly from message object + elif hasattr(message, "photo") and message.photo: + photo = message.photo + media.append(await self._parse_media(photo)) + else: + media_obj = message.media + parsed_media = await self._parse_media(media_obj) + if parsed_media["type"] not in ["webpage", "nonetype"]: + media.append(parsed_media) + logger.debug(f"Parsed media: {parsed_media}") # Always add reactions if present reactions_text = "" @@ -125,12 +147,10 @@ class TelegramClient: f"" ) elif m.get('thumbnail_file_id'): - # Image preview for other types - overlay = f"