Skip to content

Instantly share code, notes, and snippets.

@weslley39
Forked from Generator/Deluge_Throttle.md
Created November 17, 2020 23:53
Show Gist options
  • Save weslley39/a7b8ef363c35067f629c882b854eb7be to your computer and use it in GitHub Desktop.
Save weslley39/a7b8ef363c35067f629c882b854eb7be to your computer and use it in GitHub Desktop.
Throttle Deluge on Plex stream Start/Stop

Dependencies

  • deluge-console

Install

$ wget -O deluge_throttle.sh https://gist.githubusercontent.com/Generator/67da7dc859634046165320ef061769e0/raw/deluge_throttle.sh
$ chmod +x deluge_throttle.sh

Script Setup

Edit deluge_throttle.sh and set deluged username password .

If want's to use different username, password and level see Deluge documentation
https://dev.deluge-torrent.org/wiki/UserGuide/Authentication

Tautulli Setup

Commum Scripts Settings in Tautulli:
Taultulli > Settings > Notification Agents > Add a Notification Agent > Script
Set Script Folder
Select deluge_throttle.sh
Script Timeout 0

Throttle Download/Upload Speed

Triggers:

  • Playback Start
  • Playback Stop

Arguments: Set Download/Upload limit in KBps. Set -1 for unlimited

  • Playback Start: -D 100 -U 10
  • Playback Stop: -D -1 -U -1

Throttle Pause

Triggers:

  • Playback Start
  • Playback Stop

Arguments:

  • Playback Start: -p
  • Playback Stop: -r

Usage

-U		- Set max upload speed [KBs], use "-1" to set unlimited
-D		- Set max download speed [KBs], use "-1" to set unlimited
-p		- Pause active torrent
-r		- Restore paused torrents (previously active only)
-i		- Shows torrent information status
-h | --help	- Help
#!/bin/bash
# Options
D_USERNAME= # deluged username
D_PASSWORD= # deluged password
D_HOST=localhost # deluged host
D_PORT=58846 # deluged port
## CODE ##
# List active (non-paused) torrents
list_active() {
deluge-console "connect $D_HOST:$D_PORT $D_USERNAME $D_PASSWORD ; info --sort=progress" | \
grep -B1 -E "State: Downloading|State: Seeding|State: Queued" | \
awk '/ID:/{ print $2 }' ORS=' '
}
if [ -f /tmp/deluge_active ]; then
get_active=$(cat /tmp/deluge_active)
fi
# Pause (active) torrents
pause_active() {
list_active > /tmp/deluge_active
deluge-console "connect $D_HOST:$D_PORT $D_USERNAME $D_PASSWORD ; pause ${get_active}"
}
# Resume torrents
resume_active() {
if [ -f /tmp/deluge_active ]; then
deluge-console "connect $D_HOST:$D_PORT $D_USERNAME $D_PASSWORD ; resume ${get_active}"
rm /tmp/deluge_active
else
deluge-console "connect $D_HOST:$D_PORT $D_USERNAME $D_PASSWORD ; resume '*'"
fi
}
# Set maximum speed
max_speed() {
[ -n "${U}" ] && U_Speed="; config -s max_upload_speed ${U} "
[ -n "${D}" ] && D_Speed="; config -s max_download_speed ${D} "
deluge-console "connect $D_HOST:$D_PORT $D_USERNAME $D_PASSWORD ${U_Speed}${D_Speed}"
echo "${U_Speed}${D_Speed}"
}
# Show torrent status
info() {
deluge-console "connect $D_HOST:$D_PORT $D_USERNAME $D_PASSWORD ; info --sort=progress" | grep -e 'Name:' -A7 | grep -e '--' -e 'Name' -e 'Progress' -e 'State'
}
# Usage
usage() {
echo "[-U <KBs|-1>] [-D <KBs|-1>] [-p] [-r] [-h] "
}
# Help
help() {
cat <<EOF
-U - Set max upload speed [KBs], use "-1" to set unlimited
-D - Set max download speed [KBs], use "-1" to set unlimited
-p - Pause active torrent
-r - Restore paused torrents (previously active only)
-i - Shows torrent information status
-h | --help - Help
EOF
exit 0; }
# CLI options
while getopts ":U:D:prhi" arg; do
case "${arg}" in
D)
D="${OPTARG}"
max_speed
;;
U)
U="${OPTARG}"
max_speed
;;
p)
pause_deluge
;;
r)
resume_stream
;;
i)
info
;;
h|-help)
help
;;
\? )
echo "Invalid Option: -$OPTARG" 1>&2
exit 1
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment