Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

TPB Telegram Bot

Docker image

A self-hosted Telegram bot that searches The Pirate Bay and sends the torrents you pick to your qBittorrent client. It can also save Telegram files and Mega links straight to a folder on your server.

Runs anywhere Docker runs, including a Raspberry Pi.

Features

  • Torrent search: browse results by category, sort and filter them, preview a torrent's details and file list, and add the ones you pick to qBittorrent. Torrents you already have are marked.
  • Automatic categories: torrents are added to qBittorrent with a matching category (movies, tv, music, books…), handy for Plex or Jellyfin libraries.
  • Inline mode: type @yourbot <keywords> in any chat to search without opening the bot.
  • Magnet links: paste a magnet link in the chat to add it to qBittorrent.
  • Live status: progress bars, speed and ETA for every torrent, with buttons to pause, resume, force start or delete, and a slow mode that switches qBittorrent to its alternative speed limits.
  • Notifications: the bot messages you when a torrent you added finishes downloading, and when disk space runs low.
  • File downloads: forward Telegram files (up to 2 GB) or send Mega links, and the bot saves them in a folder you browse from the chat.
  • Access control: only the Telegram users you list can use the bot.

Requirements

  • Docker with Docker Compose 2.23 or later (x86_64 or arm64, e.g. Raspberry Pi with a 64-bit OS)
  • A Telegram bot token from @BotFather
  • A Telegram API ID and hash from my.telegram.org, used by the local Bot API server

Quick start

git clone https://github.com/memoryleak07/TPBTelegramBOT.git
cd TPBTelegramBOT
cp .env.example .env    # then edit .env
mkdir -p <your DOWNLOAD_DIR>
docker compose up -d

Open your bot in Telegram and send /help.

The stack runs three containers: the bot, qBittorrent and a local Telegram Bot API server. qBittorrent needs no setup: its Web UI (http://<server-ip>:8080) uses the login from .env, applied at every start, so changing the password only takes an edit and docker compose up -d.

docker compose up -d pulls the published image. To update to the latest release:

docker compose pull && docker compose up -d

To run your own changes instead, build the image locally with the same name: docker build -t ghcr.io/memoryleak07/tpb-telegram-bot:latest .

Note: the compose file includes a local Telegram Bot API server, which raises the file download limit from 20 MB to 2 GB. Before you first use the bot with it, log the bot out of Telegram's cloud API once:

curl https://api.telegram.org/bot<BOT_TOKEN>/logOut

Configuration

All settings go in the .env file next to docker-compose.yml.

Variable Required Description
BOT_TOKEN Yes Bot token from @BotFather
ALLOWED_USERS Recommended Comma-separated Telegram usernames or numeric user ids allowed to use the bot, e.g. alice,123456789. User ids are safer, since usernames can change. If empty, anyone can use it
DOWNLOAD_DIR Yes Host folder for everything the bot downloads: torrents, Telegram files and Mega links
QBITTORRENT_USERNAME Yes Login for the qBittorrent Web UI, used by you and by the bot. Default admin
QBITTORRENT_PASSWORD Yes Password for the qBittorrent Web UI
TELEGRAM_API_ID Yes API ID for the local Bot API server
TELEGRAM_API_HASH Yes API hash for the local Bot API server
LOG_LEVEL DEBUG, INFO (default), WARNING or ERROR
TZ Time zone for qBittorrent, e.g. Europe/Rome, used by its speed limit schedule. Default UTC
PUID / PGID Owner of the downloaded files. Default 1000, the first user on most Linux systems; check yours with id
QBITTORRENT_URL Only to use your own qBittorrent instead of the bundled one, see below

Where files are saved

Torrents, Telegram files and Mega links all go to DOWNLOAD_DIR, owned by your user (PUID/PGID), so you can move or delete them without sudo. Torrents added from a search get a qBittorrent category based on their Pirate Bay category (movies, tv, music…), and each category is saved in its own subfolder:

DOWNLOAD_DIR/
├── movies/
├── tv/
├── music/
└── ...        Telegram files and Mega links go to the folder you pick in /dwtelegram

Using your own qBittorrent

Remove the qbittorrent service (and the configs section) from docker-compose.yml and set QBITTORRENT_URL, QBITTORRENT_USERNAME and QBITTORRENT_PASSWORD to your instance. If qBittorrent runs on the Docker host, use http://host.docker.internal:8080 and make sure its Web UI listens on all addresses (Tools → Options → Web UI → IP address: *), not only on localhost. To get one folder per category there too, enable Automatic Torrent Management in Tools → Options → Downloads.

The bot warns every authorized user who has used it when the download folder is 90% full or qBittorrent has less than 10 GiB free.

Usage

Command Description
/search Search torrents. /search <keywords> skips the category menu
/status Torrents status and controls
/dwtelegram Save Telegram files or Mega links to a folder
/dwlist Telegram/Mega download list, with buttons to retry or remove items
/space Disk space
/help List of commands

You can also paste a magnet link at any time to add it to qBittorrent. Inside a conversation, /cancel stops it.

The bot registers its commands with Telegram at startup, so they show up in the / menu with no BotFather setup.

To use inline mode, enable it once in @BotFather with /setinline. Picking an inline result sends the torrent's magnet link; in the bot's chat you can then add it with one tap.

Development

Requires Python 3.12+.

python -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install -r requirements.txt pytest
pip install --no-deps mega.py==1.0.8
pytest

To run the bot outside Docker, add DOWNLOAD_DIR and DATA_DIR pointing to local folders in .env, then:

cd src
python -m tpb_bot

Without LOCAL_API_URL, the bot uses Telegram's cloud API (20 MB file limit).

Releases

Pushing a tag such as telegrambot-v2.0.0 builds and publishes ghcr.io/memoryleak07/tpb-telegram-bot for linux/amd64 and linux/arm64.

Disclaimer

This project is provided for educational purposes. You are responsible for complying with the copyright laws of your country. Only download content you have the right to download.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages