Skip to content

Instantly share code, notes, and snippets.

@tesla-srt
Created October 8, 2023 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tesla-srt/8f4d6a0351e3f5f97c8ddcac682e71f5 to your computer and use it in GitHub Desktop.
Save tesla-srt/8f4d6a0351e3f5f97c8ddcac682e71f5 to your computer and use it in GitHub Desktop.
qBitTorrent Discord Announcer
import argparse
import subprocess
from discord_webhook import DiscordWebhook, DiscordEmbed
"""
QBittorrent Discord Webhook
Version: 1.0
This script will send a notification to Discord via webhook, that your download are finished.
:param name: The torrent name that will be sended
:param size: Torrent sizes in bytes.
:param hash: Torrent hash
"""
# Python Version: 3.6+
# Requirements: `pip3 install discord-webhook``
# Help: `python3 announce.py -h``
#################################################
WEBHOOK_URL = 'YOUR_WEBHOOK_URL'
DISCORD_ID = 'A_GOOD_NAME'
#################################################
def sizeof_fmt(num, suffix='B'):
num = int(num)
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
if abs(num) < 1024.0:
return "%3.1f %s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f %s%s" % (num, 'Yi', suffix)
parser = argparse.ArgumentParser(description='QBittorrent Discord Announcer')
parser.add_argument('--name', required=True, help="Torrent name")
parser.add_argument('--size', required=True, help="Torrent size")
parser.add_argument('--hash', required=True, help="Torrent hash")
args = parser.parse_args()
print('@@ Sending First Webhook Notifier')
hook = DiscordWebhook(WEBHOOK_URL, content="Torrent `{}` uploaded to your cloud storage\n<@!{}>".format(args.name, DISCORD_ID))
embed = DiscordEmbed(title="Torrent Downloaded", color=0xf8c1b8)
embed.add_embed_field(name='Torrent', value=args.name)
embed.add_embed_field(name='Size', value=sizeof_fmt(args.size))
embed.set_footer(text=args.hash)
embed.set_timestamp()
hook.add_embed(embed)
hook.execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment