|
Single-file tool that downloads photos and documents from a Telegram
chat and resumes where it left off.
Durability:
- process oldest-to-newest and persist last_id after every message, so
an interrupted run resumes instead of rescanning
- write state.json via temp file + rename; a torn write would otherwise
leave unparseable JSON and block the next run
- download to a .part file and rename on success, so a killed run cannot
leave a truncated file that the exists() check treats as complete
- retry transient errors with exponential backoff alongside the existing
FloodWait handling, and skip permanently failed files rather than
stalling the run
Usability:
- share one session across all archive dirs, so a login covers every
chat instead of one per directory; migrate an existing per-archive
session in place rather than forcing re-authentication
- create the config template before argument parsing, since --target was
required but unknowable before the API keys were set
- add --list-chats to print dialog IDs and usernames
- convert numeric targets to int; Telethon resolves a numeric string as
a username and never consults the entity cache
Hardening:
- strip path components from sender-controlled filenames
- create config and session files 0600 in a 0700 directory
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|