diff --git a/post_parser.py b/post_parser.py index bc08055..5d8bb6a 100644 --- a/post_parser.py +++ b/post_parser.py @@ -14,8 +14,9 @@ import re import os import html import inspect +from dataclasses import dataclass from datetime import datetime -from typing import Union, Dict, Any, List, Optional +from typing import Union, Dict, Any, List, Optional, Callable, Tuple from pyrogram.types import Message from pyrogram.enums import MessageMediaType from sanitizer import sanitize_html @@ -107,6 +108,138 @@ def _story_media_object(message): return None, None +# --------------------------------------------------------------------------- # +# Single source of truth for media handling (render-pipeline refactor, stage 5). +# +# MEDIA_SOURCES maps a media type to a selector returning (media object, render +# kind). It replaces the three hand-synced ladders that used to live in +# _get_file_unique_id (dict map), _save_media_file_ids (if/elif) and +# _generate_html_media (elif cascade). All three now go through this table. +# +# kind=None means "selector-only entry": the object participates in file-id +# extraction/collection but is NOT rendered by the dispatcher. The ONLY kind=None +# entry is WEB_PAGE (its preview is rendered by _format_webpage). PAID_MEDIA has +# NO entry at all: its info block is a dedicated branch in _generate_html_media +# and it is deliberately never collected/downloaded (paid content). +# --------------------------------------------------------------------------- # +def _select_document(message): + """DOCUMENT selector: PDF documents render as a t.me link ('pdf'), everything + else as an image ('img_400'). The selected object is always message.document.""" + document = message.document + if (document is not None and hasattr(document, 'mime_type') + and document.mime_type == 'application/pdf'): + return document, 'pdf' + return document, 'img_400' + + +def _select_sticker(message): + """STICKER selector: video stickers loop as