Skip to content

ishwar585/Python-Aria-Telegram-Mirror-Bot

Repository files navigation

Introduction

This is a python-based telegram bot for mirroring files to G-Drive You can contact me on telegram at https://t.me/ishwar585 or https://t.me/dp001 if you face some problems in deploying the bot Deploying this bot on Heroku will lead to suspension of your app/account but still if you want to try, then you can message me and I'll help you out.

Features supported:

  • Mirror direct download links to google drive
  • Mirror Telegram files to google drive
  • Mirror all youtube-dl supported links
  • Extract these filetypes and uploads to google drive

.zip, .rar, .tar, .7z, .iso, .wim, .cab, .gzip, .bzpi2, .apm, .arj, .chm, .cpio, .CramFS, .deb, .dmg, .fat, .hfs, .lzh, .lzma, .lzma2, .mbr, .msi, .mslz, .nsis, .ntfs, .rpm, .SquashFS, .udf, .vhd, .xar, .z

  • Clone drive files using Autorclone
  • Service account support in cloning and uploading
  • Download/upload progress
  • Download/upload speed and ETA
  • Docker support
  • Uploading To Team Drives.
  • Index Link support

Pre=Installation

  • Open telegram and search for @botfather
  • Create new bot using command /newbot and follow the instructions.
  • Set the commands that you'll be using in your bot using /setcommands

Bot commands to be set in botfather

mirror - Start Mirroring
tarmirror - Upload tar (zipped) file
unzipmirror - Extract files
clone - copy folder to drive
watch - mirror YT-DL support link
tarwatch - mirror youtube playlist link as tar
cancel - Cancel a task
cancelall - Cancel all tasks
del - Delete file from Drive
list - [query] searches files in G-Drive
status - Get Mirror Status message
stats - Bot Usage Stats
help - Get Detailed Help
log - Bot Log [owner only]

Steps to deploy

  • Clone this repo:
git clone https://github.com/ishwar585/Python-Aria-Telegram-Mirror-Bot
cd Python-Aria-Telegram-Mirror-Bot
  • Install requirements for Debian based distros (Ubuntu)
sudo apt install python3
sudo snap install docker 

Setting up config file

  • Run
cp config_sample.env config.env
nano config.env

(For above process you can edit the sample.env file by opening it in your default text editor. You will find sample.env in your directory.)

Things you have to edit in sample.env file

  • Remove the first line saying:
_____REMOVE_THIS_LINE_____=True

Fill up rest of the fields. Meaning of each fields are discussed below:

  • BOT_TOKEN : The telegram bot token that you get from @BotFather
  • GDRIVE_FOLDER_ID : This is the folder ID of the Google Drive Folder to which you want to upload all the mirrors.
  • TELEGRAPH_TOKEN : Telegraph token generated by running :
python3 generate_telegraph_token.py

If you get an error saying "ModuleNotFoundError: No module named 'telegraph'" Then enter pip3 install telegraph

  • DOWNLOAD_DIR : The path to the local folder where the downloads should be stored temperoarily.
  • DOWNLOAD_STATUS_UPDATE_INTERVAL : The interval time (in seconds)in which the Mirror progress should be updated intelegram. (Keep it 5 seconds at least)
  • OWNER_ID : The Telegram user ID (not username) of the owner of the bot.
  • AUTO_DELETE_MESSAGE_DURATION : Interval of time (in seconds), after which the bot deletes it's message (and command message) which is expected to be viewed instantly. Note: Set to -1 to never automatically delete messages
  • IS_TEAM_DRIVE : Set to True if GDRIVE_FOLDER_ID is from a Team Drive else set it to false.
  • INDEX_URL : (Optional field) Refer to https://github.com/maple3142/GDIndex/ (Remove / from the end of URL. For eg: google.com / )
  • API_KEY : This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org DO NOT put this in quotes.
  • API_HASH : This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org
  • USER_SESSION_STRING : Generate String session by clicking here OR you can generate by running :
python3 generate_string_session.py
  • USE_SERVICE_ACCOUNTS : (Optional field) (Leave empty if unsure) Whether to use service accounts or not. For this to work see "Using service accounts" section below.

  • Note: You can limit maximum concurrent downloads by changing the value of MAX_CONCURRENT_DOWNLOADS in aria.sh. By default, it's set to 4

Getting Google OAuth API credential file

  • Visit the Google Cloud Console
  • Go to the OAuth Consent tab, fill it, and save.
  • Go to the Credentials tab and click Create Credentials -> OAuth Client ID
  • Choose Desktop and Create.
  • Use the download button to download your credentials.
  • Move that file to the root of mirror-bot, and rename it to credentials.json
  • Visit Google API page
  • Search for Drive and enable it if it is disabled
  • Finally, run the script to authenticate bot with Google Drive:
pip3 install google-api-python-client google-auth-httplib2 google-auth-oauthlib
python3 generate_drive_token.py

Deploying

  • Check if your docker doaemon is running using:
sudo docker ps
  • If not running, then start docker daemon using:
sudo dockerd
  • Build Docker image:
sudo docker build . -t mirror-bot
  • Run the image:
sudo docker run mirror-bot

Deploy Heroku

The easiest way to deploy this bot! is click on the image below

Deploy to Heroku

Using service accounts for uploading to avoid user rate limit

For Service Account to work, you must set USE_SERVICE_ACCOUNTS="True" in config file or environment variables Many thanks to AutoRClone for the scripts

Generating service accounts

Step 1. Generate service accounts What is service account

Let us create only the service accounts that we need. Warning: abuse of this feature is not the aim of autorclone and we do NOT recommend that you make a lot of projects, just one project and 100 sa allow you plenty of use, its also possible that overabuse might get your projects banned by google.

Note: 1 service account can copy around 750gb a day, 1 project makes 100 service accounts so thats 75tb a day, for most users this should easily suffice. 

python3 gen_sa_accounts.py --quick-setup 1 --new-only

A folder named accounts will be created which will contain keys for the service accounts created

NOTE: If you have created SAs in past from this script, you can also just re download the keys by running:

python3 gen_sa_accounts.py --download-keys project_id

Add all the service accounts to the Team Drive or folder

  • Run:
python3 add_to_team_drive.py -d SharedTeamDriveSrcID

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages