Skip to content

Instantly share code, notes, and snippets.

@sdapkus
Forked from fltd/qbittorrent-slack-notify.sh
Last active March 20, 2021 07:43
Show Gist options
  • Save sdapkus/0edfdb77ed07119ab689d3965c12abbe to your computer and use it in GitHub Desktop.
Save sdapkus/0edfdb77ed07119ab689d3965c12abbe to your computer and use it in GitHub Desktop.
#!/bin/bash
# A shell scirpt designed to be executed by qBittorrent's "Run external program on torrent completion"
# This scirpt will send a Slack notification using Slack's Incoming Webhooks with the information of completed torrent
#
# An example how to fill in qBittorrent's "Run external program on torrent completion" to execute this script
# /bin/bash -c "chmod +x /path/to/qbittorrent-slack-notify.sh; /path/to/qbittorrent-slack-notify.sh '%N' 'https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ'"
#
# Supported parameters (case sensitive):
# - %N: Torrent name
# - %L: Category
# - %G: Tags (separated by comma)
# - %F: Content path (same as root path for multifile torrent)
# - %R: Root path (first torrent subdirectory path)
# - %D: Save path
# - %C: Number of files
# - %Z: Torrent size (bytes)
# - %T: Current tracker
# - %I: Info hash
name="$1"
if [ -z "$name" ]; then
echo "ERROR: Expected <name> as the 1st argument but none given, <name> should be the Torrent name (\"%N\") from qBittorrent"
exit 1
fi
slack_webhook="$2"
if [ -z "$slack_webhook" ]; then
echo "ERROR: Expected <slack_webhook> as the 2nd argument but none given, <slack_webhook> should be the incoming webhook for a channel obtained from Slack"
exit 1
fi
ts=`date "+%s"`
/usr/bin/curl -sS \
-X POST \
-H 'Content-type: application/json' \
--data "{\"text\":\":white_check_mark: Download completed - $name\"}" \
$slack_webhook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment