No description
  • Python 80.3%
  • PowerShell 18.6%
  • Batchfile 1.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
wearyfax 52523402c8 Send a Facebook post's own media instead of a random video
A Facebook share/p/ link to a photo post came back as an unrelated video.
yt-dlp takes whatever video it finds on a post page, so for a post with no
video it returned an older video from the same page on one run and an ad on
the next.

Before downloading a share/p/ or story.php link, the bot now reads the post
page, finds the first attachment after the post's id, and downloads that
directly: /photo/?fbid= through gallery-dl, or /watch/?v= through yt-dlp.
A post with several photos only sends the first one.

Cache hits are now logged too. They were silent before, which made a
re-sent old video look like a wrong download.
2026-10-07 23:26:49 -07:00
.env.example Stop the cookie refresh walking YouTube's recommendations feed 2026-09-12 00:06:10 -07:00
.gitignore Let the operating system hold the single-instance lock 2026-09-11 16:10:21 -07:00
bot.py Send a Facebook post's own media instead of a random video 2026-10-07 23:26:49 -07:00
install.cmd Launch the installer from a .cmd so a PowerShell profile cannot break it 2026-09-07 19:02:03 -07:00
install.ps1 Start the bot at logon, because a boot-start token cannot read the cookies 2026-09-12 00:01:02 -07:00
launch.py Stop the pull failure message guessing at the cause 2026-09-12 00:15:16 -07:00
README.md Start the bot at logon, because a boot-start token cannot read the cookies 2026-09-12 00:01:02 -07:00
requirements.txt Initial release 2026-09-02 23:36:02 -07:00
uninstall.cmd Launch the installer from a .cmd so a PowerShell profile cannot break it 2026-09-07 19:02:03 -07:00
uninstall.ps1 Launch the installer from a .cmd so a PowerShell profile cannot break it 2026-09-07 19:02:03 -07:00

Telegram media bot

Send a link to your own Telegram bot. It downloads the video or the images and sends them straight back to you.

It works with the sites that yt-dlp and gallery-dl support, which is most of them: YouTube, Instagram, TikTok, X, Reddit, Rednote, and many more.

Only you can use your bot. The bot ignores everyone else and tells you when a stranger messages it.

What it does

  • Downloads the video or the images behind almost any link.
  • Re-encodes video to H.264, so it plays on every phone and computer.
  • Keeps HDR video in HDR when you want that.
  • Uses your browser cookies, so it can reach anything you are logged in to.
  • Remembers what it already sent, so the same link the second time is instant.
  • Starts by itself when the computer starts.
  • Updates itself when the computer restarts.

What you need

  • Windows 10 or Windows 11.
  • Python 3.9 or newer. If you do not have it, the installer offers to install it.
  • Git. Get it from https://git-scm.com/download/win and accept every default.
  • A Telegram account.

Install it

There are four steps. The whole thing takes about ten minutes, and most of that is the installer downloading files.

Step 1: Make your bot on Telegram

  1. Open Telegram and search for @BotFather.
  2. Send him /newbot.
  3. Pick a name and a username for your bot.
  4. Copy the long token he sends back. It looks like 1234567890:AAF....
  5. Search for @userinfobot and send him any message.
  6. Copy the number he replies with. That number is your user id.

Keep both of these open in a window. You need them in step 3.

Step 2: Download the bot

Open PowerShell and run these two lines. They put the bot in a folder called telegram-media-bot inside your user folder.

git clone https://git.kemono.online/wearyfax/telegram-media-bot.git "$HOME\telegram-media-bot"
cd "$HOME\telegram-media-bot"

Use git clone rather than downloading a ZIP file. The bot updates itself through git, and that only works in a cloned folder.

Step 3: Run the installer

Double-click install.cmd.

Use install.cmd, not install.ps1. Both do the same work, but the .cmd starts PowerShell cleanly. Right-clicking the .ps1 and choosing "Run with PowerShell" loads your personal PowerShell profile first, and if that profile is slow or prints errors, the installer looks broken before it has done anything.

Windows asks for administrator rights once. Say yes. The installer needs them only to register the startup task. The bot itself runs with ordinary user rights.

The bot starts when you log in, not at boot. Windows will only run a program before login if it is given a token with no saved credentials, and such a token cannot read the key your browser encrypted its cookies with. Starting at login keeps the cookies working, which matters more.

The installer does all of this for you:

  • Builds a private Python environment in a .venv folder inside the bot folder.
  • Downloads ffmpeg into a bin folder inside the bot folder.
  • Creates your configuration file, .env.
  • Registers the two scheduled tasks that run the bot.

Nothing is installed anywhere else on your computer. Everything stays in this one folder.

The bot runs its own copy of Python from .venv and never uses the system Python again after this step. Other Python programs on your computer cannot affect it, and it cannot affect them. If you later upgrade or remove the system Python, run install.cmd again and it rebuilds the private environment.

Partway through, the installer opens .env in Notepad and stops. It prints which lines it still needs. Fill in the two lines at the top with the values from step 1:

BOT_TOKEN=1234567890:AAF-your-real-token-here
ALLOWED_USER_ID=123456789

Save the file. Close Notepad. Then double-click install.cmd again. The second run finishes the job and starts the bot.

Step 4: Test it

Open Telegram, find your new bot, and send it /start. Then send it any link.

The bot replies with the video or the images. If it does, you are finished.

Give it your cookies

The bot works without cookies, but many sites only show their content to a user who has logged in. Your cookies let the bot see what you see.

Open .env in Notepad and set this line to the browser you use:

COOKIES_FROM_BROWSER=firefox

Firefox is the easiest choice, because it works while the browser is open. The permitted values are firefox, chrome, chromium, edge, brave, opera, vivaldi, and safari.

CAUTION: Chrome, Edge, Brave, and Chromium lock their cookie database while they run. If you pick one of those, close the browser completely before the bot starts.

Save .env, then restart the bot:

Stop-ScheduledTask -TaskName TelegramMediaBot; Start-ScheduledTask -TaskName TelegramMediaBot

Commands

Send these to your bot in Telegram.

Command What it does
/help Lists these commands
/status Shows the current configuration
/reencode on|off Turns H.264 re-encoding on or off
/quality <number> Sets the video quality, from 18 (best) to 32 (smallest)
/preset <name> Sets the encoding speed, from ultrafast to veryslow
/tune <name> Tunes for the content: animation, film, grain, stillimage, none
/hdr on|off Keeps HDR video in HDR, or re-encodes it for older devices
/clearcache Forgets every link the bot has already sent
/whoami Shows your Telegram user id

How it updates itself

You do not have to do anything. The bot updates itself in two ways.

Every time the computer starts, the bot runs git pull and downloads any new code from the repository. It then updates yt-dlp and gallery-dl, which matters because sites change often and break them.

If your computer stays on for weeks, the bot restarts itself every day at 4 AM and updates then instead.

If you have edited the code yourself, the update is refused rather than forced, and the bot keeps running your version. Your configuration and your cookies are never touched by an update.

To update right now instead of waiting, run this in the bot folder:

git pull

To turn automatic code updates off, set AUTO_UPDATE_CODE=0 in .env.

Turn it off

To stop the bot until the next restart:

Stop-ScheduledTask -TaskName TelegramMediaBot

To stop the bot from ever starting by itself, double-click uninstall.cmd. Your files stay where they are. To remove the bot completely, run uninstall.cmd first, then delete the folder.

When something goes wrong

The bot writes to two files in the bot folder:

  • bot.log keeps errors and warnings. Read this one first.
  • bot.out.log keeps everything the bot printed on its last run. It is rewritten each time the bot starts.

If the bot is not running at all, the fastest way to find out why is to start it by hand. Open PowerShell in the bot folder and run:

.\.venv\Scripts\python.exe launch.py

That runs the bot in the window instead of in the background, so the error appears on screen. Press Ctrl+C to stop it when you are done.

What you see What to do
The bot never replies Check it is running: Get-ScheduledTask -TaskName TelegramMediaBot. Running is good, Ready means it stopped.
It says Ready, not Running It crashed on startup. Run it by hand with the command above to see the error.
It is running but ignores you ALLOWED_USER_ID in .env is not your id. Send /whoami to your bot and compare.
A download fails on one site only Your cookies are stale. Close your browser, then restart the bot.
Cookies never refresh Look for Cookie export finished in Ns in bot.log. If it says it gave up, raise COOKIE_REFRESH_TIMEOUT in .env. A large browser profile can take many minutes.
Every download fails Run install.cmd again. It repairs a broken .venv folder.
The bot stopped after a Python update Run install.cmd again. It rebuilds the private Python environment.
"ffmpeg: MISSING" in /status Run install.cmd again to download ffmpeg.
Red errors the moment the installer starts You ran install.ps1 instead of install.cmd. Those errors come from your own PowerShell profile. Use install.cmd.
The window closes before you can read it Use install.cmd. It keeps the window open when something goes wrong.
Uploads stop at 50 MB That is the Telegram limit. See "Bigger uploads" below.

Bigger uploads

Telegram limits a normal bot to 50 MB per file. To send files up to 2 GB, you need your own Telegram Bot API server. Set its address in .env:

LOCAL_BOT_API=https://example.com/tgapi

The bot moves itself onto that server on the next start. If the server is unreachable, the bot falls back to Telegram and keeps working.

This step is optional and it is the only part that needs a server of your own.

Configuration

Every setting lives in .env. The file .env.example lists all of them with a comment explaining what each one does. Copy a line out of it whenever you want to change something.

These files are yours and are never uploaded to the repository:

  • .env holds your token and your settings.
  • cookies.txt holds your cookies.
  • settings.json holds the options you changed with a command.
  • cache.json holds the list of links already sent.
  • bot.log holds the errors.