Retry transient video download failures, friendlier fallback link text, enable previews

- yt-dlp: retry transient failures (stall/timeout) up to 2x before falling
  back to a link-only post; permanent errors (private/removed) still fail fast
- Fallback note: friendlier wording, "Смотреть видео" as link text instead of
  a bare "ссылка", plus a link to the original VK wall post as a backup
- TG: enable link preview for text-only fallback posts (was unconditionally
  disabled, leaving fallback posts with no visual at all)
- MAX: attach the VK video's own thumbnail as an image so failed/oversized
  video fallbacks still show a preview picture (MAX has no OG-preview for
  arbitrary URLs, but does accept a remote image url without upload)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-21 20:36:22 +05:00
parent 3a086d9e54
commit 4ad047b5c3
6 changed files with 64 additions and 7 deletions
+12 -4
View File
@@ -140,7 +140,9 @@ def normalize_wrapper_text(text: str, parse_mode: str = "html") -> str:
return parser.normalized()
def build_media_unavailable_note(link_only_items: list, parse_mode: str = "html") -> str:
def build_media_unavailable_note(
link_only_items: list, parse_mode: str = "html", vk_url: Optional[str] = None
) -> str:
"""Builds a short note listing media that couldn't be attached (too big,
too long, private, download failed, etc.) with a link to the original,
so readers aren't left with no idea that media was omitted."""
@@ -152,13 +154,19 @@ def build_media_unavailable_note(link_only_items: list, parse_mode: str = "html"
media_type = str(getattr(item, "media_type", "медиа") or "медиа")
if not url:
continue
label = "Смотреть видео" if media_type == "video" else media_type
if parse_mode == "html":
lines.append(f'- {html.escape(media_type)}: <a href="{html.escape(url, quote=True)}">ссылка</a>')
lines.append(f'- <a href="{html.escape(url, quote=True)}">{html.escape(label)}</a>')
else:
lines.append(f"- {media_type}: {url}")
lines.append(f"- {label}: {url}")
if not lines:
return ""
header = "Не удалось прикрепить медиа, оригинал:"
if vk_url:
if parse_mode == "html":
lines.append(f'- <a href="{html.escape(vk_url, quote=True)}">Открыть пост в VK</a>')
else:
lines.append(f"- пост в VK: {vk_url}")
header = "Не поместилось в пост:"
if parse_mode == "html":
header = f"<i>{html.escape(header)}</i>"
return header + "\n" + "\n".join(lines)