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>
99 lines
3.0 KiB
Python
99 lines
3.0 KiB
Python
"""
|
|
YouTube Auto-Post Notification Script
|
|
|
|
Polls the YouTube RSS feed for recently published videos and posts to:
|
|
- Telegram (Bot API)
|
|
- Bluesky (AT Protocol)
|
|
- Discord (Webhook, optional)
|
|
- Mastodon (REST API, optional)
|
|
|
|
Exit code is 1 when any configured platform failed, so the CI-failure notifier fires.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import random
|
|
import sys
|
|
import time
|
|
from datetime import UTC, datetime
|
|
|
|
from config import LOOKBACK_HOURS, YOUTUBE_CHANNEL_ID
|
|
from http_client import HttpError
|
|
from platforms import post_to_all, summarize
|
|
from state import load_posted_ids, save_posted_ids
|
|
from youtube import fetch_feed, is_public, select_recent
|
|
|
|
|
|
def main() -> int:
|
|
if not YOUTUBE_CHANNEL_ID:
|
|
print("[ERROR] YOUTUBE_CHANNEL_ID not set.")
|
|
return 1
|
|
|
|
now = datetime.now(UTC)
|
|
print(f"[INFO] Checking YouTube RSS for channel: {YOUTUBE_CHANNEL_ID}")
|
|
|
|
try:
|
|
videos = fetch_feed()
|
|
except HttpError as e:
|
|
print(f"[ERROR] Failed to fetch RSS: {e}")
|
|
return 1
|
|
|
|
recent = select_recent(videos, now=now, lookback_hours=LOOKBACK_HOURS)
|
|
if not recent:
|
|
print(f"[INFO] No videos published in the last {LOOKBACK_HOURS}h. Exiting.")
|
|
return 0
|
|
|
|
posted_ids = load_posted_ids()
|
|
new_videos = [v for v in recent if v["video_id"] not in posted_ids]
|
|
if not new_videos:
|
|
print("[INFO] All recent videos already posted. Exiting.")
|
|
return 0
|
|
|
|
print(f"[INFO] Found {len(new_videos)} new video(s) to post.")
|
|
|
|
successfully_posted: list[str] = []
|
|
had_failure = False
|
|
attempted = 0
|
|
|
|
for i, video in enumerate(new_videos):
|
|
if i > 0:
|
|
delay = random.uniform(1, 5) # noqa: S311 — pacing only
|
|
print(f"[INFO] Waiting {delay:.1f}s before next video...")
|
|
time.sleep(delay)
|
|
|
|
print(f"\n[INFO] Video {i + 1}/{len(new_videos)}: {video['title']}")
|
|
if not is_public(video["video_id"], now=now):
|
|
print(f"[INFO] Skipping '{video['video_id']}' for now; will retry next run.")
|
|
continue
|
|
|
|
attempted += 1
|
|
results = post_to_all(video)
|
|
any_ok, any_failed = summarize(results)
|
|
for platform, status in results.items():
|
|
print(f" {platform}: {status.value}")
|
|
|
|
if any_ok:
|
|
successfully_posted.append(video["video_id"])
|
|
else:
|
|
print(f"[WARN] No platform posted '{video['video_id']}'. Will retry next run.")
|
|
if any_failed:
|
|
had_failure = True
|
|
|
|
if successfully_posted:
|
|
save_posted_ids(successfully_posted)
|
|
print(f"\n[INFO] State saved: {len(successfully_posted)} new ID(s).")
|
|
|
|
print(f"\n[SUMMARY] {len(successfully_posted)}/{len(new_videos)} videos posted.")
|
|
|
|
if had_failure:
|
|
print("[ERROR] At least one configured platform failed.")
|
|
return 1
|
|
if attempted and not successfully_posted:
|
|
print("[ERROR] No platform is configured; nothing was posted.")
|
|
return 1
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|