Skip to content

Latest commit

History

82 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

tgfilestream

This project is released under the GNU AGPL v3 license.
You are free to use, modify, and distribute it — as long as you share your changes under the same license.

tgfilestream is a lightweight web server and Telegram client that acts as a proxy between Telegram servers and HTTP clients, allowing direct downloads of Telegram media files via HTTP.

📌 Check out TODO.md for the latest development progress and planned features.


📝 Notes


🚀 Features

  • Download Telegram media via HTTP links
  • Fast, concurrent chunked downloading

🛠️ Setup

1. Clone the repository

git clone https://github.com/SpringsFern/tgfilestream.git
cd tgfilestream

2. Install dependencies

pip install -r requirements.txt

3. Create a .env file

Store the required environment variables in a .env file:

API_ID=1234567API_HASH=1a2b3c4d5e6f7g8h9i0jklmnopqrstuvBOT_TOKEN=1234567890:AAExampleBotTokenGeneratedHereBIN_CHANNEL=-1002605638795HOST=0.0.0.0PORT=8080PUBLIC_URL=http://127.0.0.1:8080DB_BACKEND=mongodbMONGODB_URI=mongodb://admin:pAswaRd@192.168.27.1

4. Run the server

python3 -m tgfs

⚙️ Environment Variables

VariableRequired/DefaultDescription
API_IDApp ID from my.telegram.org
API_HASHAPI hash from my.telegram.org
BOT_TOKENBot token from @BotFather
BIN_CHANNELChannel ID where files sent to the bot are stored
DB_BACKENDmongodbWhich Database server to use.
HOST0.0.0.0Host address to bind the server (default: 0.0.0.0)
PORT8080Port to run the server on (default: 8080)
PUBLIC_URLhttps://0.0.0.0:8080Public-facing URL used to generate download links
DEBUGFalseShow Extra Logs
CONNECTION_LIMIT5Number of connections to create per DC for a single client
DOWNLOAD_PART_SIZE1048576 (1MB)Number of bytes to request in a single chunk
NO_UPDATEFalseWhether to reply to messages sent to the bot (True to disable replies)
NO_MAINFalseSkip main bot and use only worker bots for Telegram file requests
SEQUENTIAL_UPDATESFalseHandle telegram updates sequentially
FILE_INDEX_LIMIT10Number of files to display at once with /files command
MAX_WARNS3Maximum number of warns before user get banned
ADMIN_IDSNoneUser id of users who can use admin commands. Each id is seperated by ,
ALLOWED_IDSNoneOnly users with these IDs can use the bot. Separate multiple IDs with ,

Multi Token Environment Variables

VariableRequired/DefaultDescription
MULTI_TOKENxUse Multiple Telegram Clients when downloading files to avoid flood wait, Replace x with Number
Example:
MULTI_TOKEN1MULTI_TOKEN1=1234567890:AAExampleBotTokenGeneratedHere
MULTI_TOKEN2MULTI_TOKEN2=0987654321:AAExampleBotTokenGeneratedHere
MULTI_TOKEN3MULTI_TOKEN3=5432167890:AAExampleBotTokenGeneratedHere

MongoDB Environment Variables

Set the following variables if you choose MongoDB as the database in DB_BACKEND

VariableRequired/DefaultDescription
MONGODB_URIMongoDB Database URI
MONGODB_DBNAMETGFSMongoDB Database name

📂 Usage

Once the server is running, you can:

  • Access Telegram media files via HTTP:

  • Or simply send a file to your bot, and it will respond with a download link.

This will stream the file directly from Telegram servers to the client.


🛠️ Contributing & Reporting Issues

Found a bug or have a feature request? Please open an issue on GitHub.

🐞 Reporting Issues

When reporting a bug, please include:

  • Steps to reproduce the issue
  • Expected behavior vs actual behavior
  • Relevant logs, screenshots, or error messages (if any)
  • Environment details (OS, Python version, etc.)

Example issue title:
[Bug] Download fails for large files

💡 Requesting Features

When suggesting a new feature, please include:

  • A clear and concise description of the feature
  • The motivation or use case for it
  • Expected behavior (input/output examples if applicable)
  • Any alternatives you've considered

Example feature title:
[Feature] Add support for viewing generated links


Contributions are welcome!
Feel free to fork the project and open a pull request.

🔍 Note: Make sure to test your code thoroughly before submitting a PR to help maintain stability and performance.


💡 Credits

  • Deekshith SH – Me
  • Tulir – Original author of tgfilestream, whose code inspired this project and is referenced in paralleltransfer.py

About

A lightweight web server and Telegram client that acts as a proxy between Telegram servers and HTTP clients, allowing direct downloads of Telegram media files via HTTP.

Resources

Stars

31 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages