This script uses the Telethon library to automate the transfer of files from one Telegram channel to another. It filters specific file types, downloads them, and uploads them to another channel.
- Python 3.x
- Telethon package
Install Telethon using pip:
pip install telethon
- Setup API Keys: First, obtain your
api_id
andapi_hash
from my.telegram.org. - Configure Script: Open the script and replace
api_id
andapi_hash
with your actual API credentials. Setchannel_url
to the source channel's URL andchannel_b_username
to the target channel's username. - Run Script: Execute the script. On the first run, you'll need to authenticate with your phone number.
-
Initialization:
import os from telethon import TelegramClient, events api_id = 123 # Replace with your API ID api_hash = '123' # Replace with your API Hash client = TelegramClient('session_name', api_id, api_hash)
-
Function to Check if a File is Uploaded:
def is_file_uploaded(file_name): ...
-
Main Function:
- Connect to Telegram.
- Authenticate if not already authorized.
- Set up source (
channel_url
) and target (channel_b_username
) channels. - Iterate through messages in the source channel, downloading and re-uploading specified file types.
-
File Download and Upload:
- Check file extensions.
- Download files to
downloads/
folder. - Retry mechanism for both downloading and uploading.
- Delete the file locally after uploading.
-
Running the Client:
with client.start(): client.loop.run_until_complete(main())
- This script requires a persistent internet connection.
- Ensure sufficient local storage for temporary file downloads.
- Be aware of Telegram's rate limits to avoid being temporarily banned.
This project is licensed under the GNU General Public License, version 3 (GPL-3.0). See the LICENSE file for details.
This script was developed by SecWithMoh.