Skip to content

A Telegram bot to download files via HTTP(S)/BitTorrent and upload them to Google Drive

License

Notifications You must be signed in to change notification settings

TeamFirangi/firangi-bot

 
 

Repository files navigation

aria-telegram-mirror-bot

This is a Telegram bot that uses aria2 to download files over BitTorrent / HTTP(S) and uploads them to your Google Drive. This can be useful for downloading from slow servers.

Limitations

This bot is meant to be used in small, closed groups. So, once deployed, it only works in whitelisted groups. Also, it does not scale, so only one file can be downloaded at a time. This reduces the load on the server running the bot. Download queuing is planned, but not implemented yet.

Bot commands

  • /mirror <url>: Download from the given URL and upload it to Google Drive. can be HTTP(S), a BitTorrent magnet, or a HTTP(S) url to a BitTorrent .torrent file. A status message will be shown and updated while downloading.
  • /mirrorTar <url>: Same as /mirror, but archive multiple files into a tar before uploading it.
  • /mirrorStatus: Send a status message about the current download.
  • /cancelMirror: Cancel the current mirroring task. Only the person who started the task, SUDO_USERS, and chat admins can use this command.

Pre-installation

  1. Create a new bot using Telegram's BotFather and copy your TOKEN.

  2. Add the bot to your groups and give it the permission to delete messages. This permission is used to clean up status request messages from users.

  3. Install aria2.

    • For Ubuntu: sudo apt install aria2
  4. Get Drive folder ID:

    • Visit Google Drive.
    • Create a new folder. The bot will upload files inside this folder.
    • Open the folder.
    • The URL will be something like https://drive.google.com/drive/u/0/folders/012a_345bcdefghijk. Copy the part after folders/ (012a_345bcdefghijk). This is the GDRIVE_PARENT_DIR_ID that you'll need in step 5 of the Installation section.

Installation

  1. Clone the repo:

    git clone https://github.com/out386/aria-telegram-mirror-bot
    cd aria-telegram-mirror-bot
  2. Run npm install

  3. Copy the example files:

    cp .constants.js.example .constants.js
    cp aria.sh.example aria.sh
  4. Configure the aria2 startup script:

    • nano aria.sh
    • ARIA_RPC_SECRET (defined in line 1) is the secret (password) used to connect to aria2. Set this to whatever you want, and save the file with ctrl + x.
  5. Configure the bot:

    • nano .constants.js
    • Now replace the placeholder values in this file with your values. Use the Constants description section below for reference.
  6. Set up OAuth:

    • 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 Other and Create.
    • Use the download button to download your credentials.
    • Move that file to the root of aria-telegram-mirror-bot, and rename it to client_secret.json
  7. Enable the Drive API:

    • Visit the Google API Library page.
    • Search for Drive.
    • Make sure that it's enabled. Enable it if not.
  8. Start aria2 with ./aria.sh

  9. Start the bot with npm --max_old_space_size=128 start

  10. Open Telegram, and send /mirror https://raw.githubusercontent.com/out386/aria-telegram-mirror-bot/master/README.md to the bot.

  11. In the terminal, it'll ask you to visit an authentication URL. Visit it, grant access, copy the code on that page, and paste it in the terminal.

That's it.

Constants description

This is a description of the fields in .constants.js:

  • TOKEN: This is the Telegram bot token that you will get from Botfather in step 1 of Pre-installation.
  • ARIA_SECRET: This is the password used to connect to the aria2 RPC. You will get this from step 4 of Installation.
  • ARIA_DOWNLOAD_LOCATION: This is the directory that aria2 will download files into, before uploading them. Make sure that there is no trailing "/" in this path. The suggested path is /path/to/aria-telegram-mirror-bot/downloads
  • ARIA_DOWNLOAD_LOCATION_ROOT: This is the mountpoint that contains ARIA_DOWNLOAD_LOCATION. This is used internally to calculate the space available before downloading.
  • ARIA_FILTERED_DOMAINS: The bot will refuse to download files from these domains. Can be an empty list.
  • GDRIVE_PARENT_DIR_ID: This is the ID of the Google Drive folder that files will be uploaded into. You will get this from step 4 of Pre-installation.
  • SUDO_USERS: This is a list of Telegram user IDs. These users can use the bot in any chat. Can be an empty list, if AUTHORIZED_CHATS is not empty.
  • AUTHORIZED_CHATS: This is a list of Telegram Chat IDs. Anyone in these chats can use the bot in that particular chat. Anyone not in one of these chats and not in SUDO_USERS cannot use the bot. Someone in one of the chats in this list can use the bot only in that chat, not elsewhere. Can be an empty list, if SUDO_USERS is not empty.

Starting after installation

After the initial installation, use these instructions to (re)start the bot.

  1. Start aria2 by running ./aria.sh
  2. Start a new tmux session with tmux new -s tgbot, or connect to an existing session with tmux a -t tgbot. Running the bot inside tmux will let you disconnect from the server without terminating the bot. You can also use nohup instead.
  3. Start the bot with npm --max_old_space_size=128 start

License

The MIT License (MIT)

Copyright © 2018 out386

About

A Telegram bot to download files via HTTP(S)/BitTorrent and upload them to Google Drive

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%