-
Notifications
You must be signed in to change notification settings - Fork 3
/
SABThrottle.py
45 lines (37 loc) · 1.07 KB
/
SABThrottle.py
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
import sys
import urllib
import urllib2
from xml.dom import minidom
from config import config
PMS_IP = config['PMS_IP']
PMS_PORT = config['PMS_PORT']
SAB_URL = config['SAB_URL']
SAB_API = config['SAB_API']
PMS_URL = 'http://%s:%s/status/sessions' % (PMS_IP, PMS_PORT)
SAB_URL = 'http://%s/sabnzbd/api?mode=config&name=speedlimit&apikey=%s&value=' % (SAB_URL, SAB_API)
def get_active_streams(url):
dom = minidom.parse(urllib.urlopen(url))
total = dom.getElementsByTagName('MediaContainer')
for i in total:
return int(i.attributes['size'].value)
active = get_active_streams(PMS_URL)
if active < 1:
speed = config['NONE']
url = SAB_URL+speed
req = urllib2.Request(url)
result = urllib2.urlopen(req)
elif active < 3:
speed = config['UNDER_THREE']
url = SAB_URL+speed
req = urllib2.Request(url)
result = urllib2.urlopen(req)
elif active < 5:
speed = config['UNDER_FIVE']
url = SAB_URL+speed
req = urllib2.Request(url)
result = urllib2.urlopen(req)
elif active < 7:
speed = config['UNDER_SEVEN']
url = SAB_URL+speed
req = urllib2.Request(url)
result = urllib2.urlopen(req)