Hayashikawa

Hayashikawa

Send qBittorrent notifications to Telegram with Python

Introduction#

Previously, I used qBittorrent to complete tasks and then sent notifications via email. However, since reinstalling qBittorrent, email platforms have tightened the permissions for SMTP services, requiring additional steps such as mobile two-factor authentication and application-specific passwords, which has become cumbersome. Therefore, I decided to switch to using Telegram Bot for notifications.

Script Content#

import requests
import sys

def send_telegram_message(bot_token, chat_id, message):
    url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
    payload = {
        "chat_id": chat_id,
        "text": message
    }
    response = requests.post(url, json=payload)
    return response.json()

# Replace Telegram Bot token and chat ID
bot_token = "Telegram Bot Token"
chat_id = "Telegram Chat ID"

if __name__ == "__main__":
    if len(sys.argv) > 2:
        # Get external parameters
        torrent_name = sys.argv[1]
        save_path = sys.argv[2]

        # Build the message to be sent
        message = f"Torrent Completed\nTorrent Name: {torrent_name}\nSave Path: {save_path}"

        # Call the send message function and pass the message to it
        response = send_telegram_message(bot_token, chat_id, message)
        print(response)

Usage#

After saving the script content as a Python file, set the script execution command in qBittorrent - Downloads - Run External Program.

python "Python Script File Location" "%N" "%D"

Conclusion#

Using Telegram Bot notifications not only avoids the hassle of email settings, but also allows for real-time notifications, providing a clear understanding of the status of download tasks. Now, with Telegram Bot, you can stay updated on download progress and completion, resulting in a smoother and more efficient downloading experience.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.