|
| 1 | +# TG-FileStream |
| 2 | + |
| 3 | +> This project is released under the **GNU AGPL v3** license. |
| 4 | +> You are free to use, modify, and distribute it — as long as you share your changes under the same license. |
| 5 | +
|
| 6 | +**TG-FileStream** 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. |
| 7 | + |
| 8 | +> 📌 Check out [TODO.md](./TODO.md) for the latest development progress and planned features. |
| 9 | +
|
| 10 | +--- |
| 11 | + |
| 12 | +## 📝 Notes |
| 13 | + |
| 14 | +- If you want one without database checkout [DeekshithSH/tgfilestream](https://github.com/DeekshithSH/tgfilestream) or [simple branch](https://github.com/SpringsFern/TG-FileStream/tree/simple) |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## 🚀 Features |
| 19 | + |
| 20 | +- Download Telegram media via HTTP links |
| 21 | +- Fast, concurrent chunked downloading |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## 🛠️ Setup |
| 26 | + |
| 27 | +### 1. Clone the repository |
| 28 | + |
| 29 | +```bash |
| 30 | +git clone https://github.com/SpringsFern/TG-FileStream.git |
| 31 | +cd TG-FileStream |
| 32 | +``` |
| 33 | + |
| 34 | +### 2. Install dependencies |
| 35 | + |
| 36 | +```bash |
| 37 | +pip install -r requirements.txt |
| 38 | +``` |
| 39 | + |
| 40 | +### 3. Create a `.env` file |
| 41 | + |
| 42 | +Store the required environment variables in a `.env` file: |
| 43 | + |
| 44 | +```env |
| 45 | +API_ID=1234567 |
| 46 | +API_HASH=1a2b3c4d5e6f7g8h9i0jklmnopqrstuv |
| 47 | +BOT_TOKEN=1234567890:AAExampleBotTokenGeneratedHere |
| 48 | +BIN_CHANNEL=-1002605638795 |
| 49 | +HOST=0.0.0.0 |
| 50 | +PORT=8080 |
| 51 | +PUBLIC_URL=http://127.0.0.1:8080 |
| 52 | +DB_BACKEND=mongodb |
| 53 | +MONGODB_URI=mongodb://admin:pAswaRd@192.168.27.1 |
| 54 | +``` |
| 55 | + |
| 56 | +### 4. Run the server |
| 57 | + |
| 58 | +```bash |
| 59 | +python3 -m tgfs |
| 60 | +``` |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## ⚙️ Environment Variables |
| 65 | + |
| 66 | +| Variable | Required/Default | Description | |
| 67 | +| -------------------- | ---------------------- | ---------------------------------------------------------------------------- | |
| 68 | +| `API_ID` | ✅ | App ID from [my.telegram.org](https://my.telegram.org) | |
| 69 | +| `API_HASH` | ✅ | API hash from [my.telegram.org](https://my.telegram.org) | |
| 70 | +| `BOT_TOKEN` | ✅ | Bot token from [@BotFather](https://t.me/BotFather) | |
| 71 | +| `BIN_CHANNEL` | ✅ | Channel ID where files sent to the bot are stored | |
| 72 | +| `DB_BACKEND` | ✅ | Which Database server to use. either `mongodb` or `mysql` | |
| 73 | +| `HOST` | `0.0.0.0` | Host address to bind the server (default: `0.0.0.0`) | |
| 74 | +| `PORT` | `8080` | Port to run the server on (default: `8080`) | |
| 75 | +| `PUBLIC_URL` | `https://0.0.0.0:8080` | Public-facing URL used to generate download links | |
| 76 | +| `DEBUG` | `False` | Show Extra Logs | |
| 77 | +| `CONNECTION_LIMIT` | `5` | Number of connections to create per DC for a single client | |
| 78 | +| `DOWNLOAD_PART_SIZE` | `1048576 (1MB)` | Number of bytes to request in a single chunk | |
| 79 | +| `NO_UPDATE` | `False` | Whether to reply to messages sent to the bot (True to disable replies) | |
| 80 | +| `SEQUENTIAL_UPDATES` | `False` | Handle telegram updates sequentially | |
| 81 | +| `FILE_INDEX_LIMIT` | `10` | Number of files to display at once with `/files` command | |
| 82 | +| `MAX_WARNS` | `3` | Maximum number of warns before user get banned | |
| 83 | +| `ADMIN_IDS` | `None` | User id of users who can use admin commands. Each id is seperated by `,` | |
| 84 | +| `ALLOWED_IDS` | `None` | Only users with these IDs can use the bot. Separate multiple IDs with `,` | |
| 85 | + |
| 86 | + |
| 87 | +### Multi Token Environment Variables |
| 88 | +| Variable | Required/Default | Description | |
| 89 | +| -------------- | ---------------- | ---------------------------------------------------------------------------- | |
| 90 | +| `MULTI_TOKENx` | ✅ | Use Multiple Telegram Clients when downloading files to avoid flood wait, Replace x with Number | |
| 91 | +| | | Example: | |
| 92 | +| `MULTI_TOKEN1` | | MULTI_TOKEN1=1234567890:AAExampleBotTokenGeneratedHere| |
| 93 | +| `MULTI_TOKEN2` | | MULTI_TOKEN2=0987654321:AAExampleBotTokenGeneratedHere| |
| 94 | +| `MULTI_TOKEN3` | | MULTI_TOKEN3=5432167890:AAExampleBotTokenGeneratedHere| |
| 95 | + |
| 96 | +### MySQL Environment Variables |
| 97 | +Set the following variables if you choose MySQL as the database in `DB_BACKEND` |
| 98 | + |
| 99 | +| Variable | Required/Default | Description | |
| 100 | +| ---------------- | ---------------- | ------------------------------------------ | |
| 101 | +| `MYSQL_HOST` | ✅ | MySQL DataBase Host Name | |
| 102 | +| `MYSQL_PORT` | ✅ | MySQL Database Port Number | |
| 103 | +| `MYSQL_USER` | ✅ | MySQL Database Username | |
| 104 | +| `MYSQL_PASSWORD` | ✅ | MySQL Database Password | |
| 105 | +| `MYSQL_DB` | ✅ | MySQL Database Name | |
| 106 | +| `MYSQL_MINSIZE` | `1` | Minimum sizes of the MySQL Connection pool | |
| 107 | +| `MYSQL_MAXSIZE` | `5` | Maximum sizes of the MySQL Connection pool | |
| 108 | + |
| 109 | +### MongoDB Environment Variables |
| 110 | +Set the following variables if you choose MongoDB as the database in `DB_BACKEND` |
| 111 | + |
| 112 | +| Variable | Required/Default | Description | |
| 113 | +| ---------------- | ---------------- | --------------------- | |
| 114 | +| `MONGODB_URI` | ✅ | MongoDB Database URI | |
| 115 | +| `MONGODB_DBNAME` | `TGFS` | MongoDB Database name | |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## 📂 Usage |
| 120 | + |
| 121 | +Once the server is running, you can: |
| 122 | + |
| 123 | +- Access Telegram media files via HTTP: |
| 124 | + |
| 125 | +- Or simply send a file to your bot, and it will respond with a download link. |
| 126 | + |
| 127 | +This will stream the file directly from Telegram servers to the client. |
| 128 | + |
| 129 | +--- |
| 130 | + |
| 131 | +## 🛠️ Contributing & Reporting Issues |
| 132 | + |
| 133 | +Found a bug or have a feature request? Please [open an issue](https://github.com/SpringsFern/TG-FileStream/issues) on GitHub. |
| 134 | + |
| 135 | +### 🐞 Reporting Issues |
| 136 | +When reporting a bug, **please include**: |
| 137 | +- Steps to reproduce the issue |
| 138 | +- Expected behavior vs actual behavior |
| 139 | +- Relevant logs, screenshots, or error messages (if any) |
| 140 | +- Environment details (OS, Python version, etc.) |
| 141 | + |
| 142 | +**Example issue title:** |
| 143 | +`[Bug] Download fails for large files` |
| 144 | + |
| 145 | +### 💡 Requesting Features |
| 146 | +When suggesting a new feature, **please include**: |
| 147 | +- A clear and concise description of the feature |
| 148 | +- The motivation or use case for it |
| 149 | +- Expected behavior (input/output examples if applicable) |
| 150 | +- Any alternatives you've considered |
| 151 | + |
| 152 | +**Example feature title:** |
| 153 | +`[Feature] Add support for viewing generated links` |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +Contributions are welcome! |
| 158 | +Feel free to fork the project and open a pull request. |
| 159 | + |
| 160 | +> 🔍 **Note:** Make sure to test your code thoroughly before submitting a PR to help maintain stability and performance. |
| 161 | +
|
| 162 | +--- |
| 163 | + |
| 164 | +## 💡 Credits |
| 165 | + |
| 166 | +- **Deekshith SH** – Me |
| 167 | +- **Tulir** – Original author of [`tgfilestream`](https://github.com/tulir/tgfilestream), whose code inspired this project and is referenced in `paralleltransfer.py` |
| 168 | + |
| 169 | +--- |
0 commit comments