Removes X/Twitter and Facebook Page from the posting pipeline at the owner's request. - Deleted `scripts/platforms/x_twitter.py` and `facebook.py`; registry now posts to Telegram, Bluesky, Discord, Mastodon. - Removed `X_*` / `FACEBOOK_*` config and the corresponding `env:` lines in `notify.yml`. - Removed the X-specific 280-weighted-char fitting from `message.py` and its tests. - README, `SETUP_NEW_PLATFORMS.md` (now Mastodon + Discord only) and `changelog/1.x.md` (1.3.0) updated. The `X_*` repository secrets are no longer read; they can be deleted from Settings at any time. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
"""
|
|
Notification text shared by every platform.
|
|
|
|
Platforms differ only in markup (bold, hashtags) and length limits, so the body is
|
|
built here once and each platform decorates it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
|
|
HEADER = "🎬 New Video / Video Mới"
|
|
PLAY = "▶️"
|
|
ELLIPSIS = "…"
|
|
|
|
BLUESKY_MAX_GRAPHEMES = 300
|
|
|
|
|
|
def build_message(
|
|
video: dict, *, hashtags: str = "", title: str | None = None, header: str = HEADER
|
|
) -> str:
|
|
"""Header, title, play line, optional hashtags — separated by blank lines."""
|
|
parts = [header, video["title"] if title is None else title, f"{PLAY} {video['url']}", hashtags]
|
|
return "\n\n".join(p for p in parts if p)
|
|
|
|
|
|
def truncate(text: str, max_len: int, suffix: str = ELLIPSIS) -> str:
|
|
"""Cut `text` to at most `max_len` code points, ending with `suffix` when cut."""
|
|
if len(text) <= max_len:
|
|
return text
|
|
if max_len <= len(suffix):
|
|
return text[:max_len]
|
|
return text[: max_len - len(suffix)].rstrip() + suffix
|
|
|
|
|
|
def _fit(video: dict, hashtags: str, measure: Callable[[str], int], limit: int) -> str:
|
|
"""Shrink the title until `measure(text) <= limit`. Everything else is kept."""
|
|
text = build_message(video, hashtags=hashtags)
|
|
if measure(text) <= limit:
|
|
return text
|
|
title = video["title"]
|
|
budget = len(title)
|
|
while budget > 0:
|
|
budget -= 1
|
|
text = build_message(video, hashtags=hashtags, title=truncate(title, budget))
|
|
if measure(text) <= limit:
|
|
return text
|
|
return build_message(video, hashtags=hashtags, title="")
|
|
|
|
|
|
def fit_bluesky(video: dict, hashtags: str = "") -> str:
|
|
"""Bluesky allows 300 graphemes; code points are a safe upper bound."""
|
|
return _fit(video, hashtags, len, BLUESKY_MAX_GRAPHEMES)
|