POSTS / Send Message to WeChat Work Bot on qBittorrent Completion

Published: 2023-12-10

Today I got an idea while looking for today’s anime in my download folder: Why not send me a notification while the downloading process completed so that I can check my phone and know which episode I want to watch.

For I have been using WeChat Work as notification channel and there have already been several bots listening messages from qinglong, I want to write some code by myself this time.

I found that qBittorrent has a function of running external program on torrent completion and after checked supported parameters, I got the below code to send messages:

import argparse
import requests


parser = argparse.ArgumentParser(description="qBittorrent Notifier")
parser.add_argument("--bot-key", action="store")
group_q = parser.add_argument_group(title="qBittorrent Supported Parameters")
group_q.add_argument("-n", "--torrent-name", action="store")
group_q.add_argument("-l", "--category", action="store")

args = parser.parse_args()

requests.post(
    "https://qyapi.weixin.qq.com/cgi-bin/webhook/send",
    params={
        "key": args.bot_key,
    },
    json={
        "msgtype": "text",
        "text": {"content": f"<< {args.torrent_name} >> 下载完成, 分类: {args.category}."},
    },
)

After that, fill the qBittorrent option with this and everything’s ready to go:

path/to/python path/to/script.py --bot-key "xxx" -n "%N" -l "%L"