Home

Awesome

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. Parallel downloading and download queuing are supported. There are some features to try to reduce piracy.

Limitations

This bot is meant to be used in small, closed groups. So, once deployed, it only works in whitelisted groups.

Warning

There is very little preventing users from using this to mirror pirated content. Hence, make sure that only trusted groups are whitelisted in AUTHORIZED_CHATS.

Bot commands

Notes

Migrating from v1.0.0

Aria-telegram-mirror-bot is now written in TypeScript. If you are migrating from v1.0.0, move your existing .constants.js to src/.constants.js, and re-read the installation section and the section on updating, as some steps have changed.

Pre-installation

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

  2. Add the bot to your groups and optionally, give it the permission to delete messages. This permission is used to clean up status request messages from users. Not granting it will quickly fill the chat with useless 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 src/.constants.js.example src/.constants.js
    cp aria.sh.example aria.sh
    
  4. Configure the aria2 startup script:

    • nano aria.sh
    • ARIA_RPC_SECRET is the secret (password) used to connect to aria2. Set this to whatever you want, and save the file with ctrl + x.
    • MAX_CONCURRENT_DOWNLOADS is the number of download jobs that can be active at the same time. Note that this does not affect the number of concurrent uploads. There is currently no limit for the number of concurrent uploads.
  5. Configure the bot:

    • nano src/.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 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 src/.constants.js:

Starting after installation

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

Using tmux

  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 start

Using systemd

  1. Install the systemd unit file sudo cp -v contrib/mirror-bot.service /etc/systemd/system/
  2. Open /etc/systemd/system/mirror-bot.service with an editor of your choice and modify the path and user as per your environment.
  3. Reload the systemctl daemon so it can see your new systemd unit sudo systemctl daemon-reload
  4. Start the service sudo systemctl start mirror-bot
  5. If you want the bot to automatically start on boot, run sudo systemctl enable mirror-bot

Notifying an external webserver on download completion

This bot can make an HTTP request to an external web server once a download is complete. This can be when a download fails to start, fails to download, is cancelled, or completes successfully. See the section on constants for details on how to configure it.

Your web server should listen for a POST request containing the following JSON data:

{
    'successful': boolean,
    'file': {
        'name': string,
        'driveURL': string,
        'size': string
    },
    originGroup: number
}

If successful is false, any or all of the fields of file might be absent. However, if present, they are correct/reliable.

Updating

Run git pull, then run tsc. After compilation has finished, you can start the bot as described in the above section.

Common issues

License

The MIT License (MIT)

Copyright © 2020 out386