-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransplex.sh
More file actions
executable file
·78 lines (60 loc) · 2.59 KB
/
transplex.sh
File metadata and controls
executable file
·78 lines (60 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
########################################################
# #
# transplex.sh #
# Created by KronK0321 #
# Used for controlling Transmission's upstream limit #
# based on outgoing Plex streams. #
# #
########################################################
# Desired Transmission upload speeds in KB/s
maxupspeed=1850
minupspeed=350
# Transmission info
tr_hostname=localhost
tr_port=9091
tr_username=USERNAME
tr_password=PASSWORD
# Plex info
plex_server=localhost
token=REDACTED
# Local network
local_ip=192.168.1
# How long, in seconds, between checking for outgoing plex streams
delay=10
while true; do
totalbandwidth=0
while read LINE; do
if [[ $LINE == \<Video* ]]; then
# start of a video section
bandwidth=0
isremote=0
elif [[ $LINE == \<Session* ]]; then
# each stream entry is read and parsed to extract the bandwidth
streambandwidth=$(echo $LINE | grep -o bandwidth=\"[0-9]* | sed 's/bandwidth=\"//g')
if [[ $streambandwidth =~ [0-9]+$ ]]; then
let bandwidth+=$streambandwidth
fi
elif [[ $LINE == \<Player* ]]; then
# determine if is a remote stream
ip=$(echo $LINE | grep -o address=\"[0-9]*\.[0-9]*\.[0-9]*\.[0-9]* | sed 's/address=\"//g')
if [[ ! $ip =~ $local_ip ]]; then
isremote=1
fi
elif [[ $LINE == *\<\/Video\>* ]]; then
# end of a video section, count this if its remote
if [[ $isremote = 1 ]]; then
let totalbandwidth+=$bandwidth
fi
fi
# pull the information from plex web app
done < <(curl --silent -k https://$plex_server:32400/status/sessions?X-Plex-Token=$token)
# need to work in Kb/s
upspeed=$(( $maxupspeed - ( $totalbandwidth / 8 ) ))
# never set the upload speed below specified value
if [[ $upspeed -lt $minupspeed ]]; then
upspeed=$minupspeed
fi
/usr/bin/transmission-remote $tr_hostname:$tr_port -n "$tr_username":"$tr_password" -u $upspeed
sleep $delay
done;