Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Simple script to throttle nzb clients for plexpy
- if you add script args, the first is expected to be {duration}, if you add that, all download will be paused for that time.
- You can edit this script to list number of {stream_count} and restore the nzbclient to full speed if its above xx etc.
- The nzbget part is untested.
- """
- ### Edit vars ###
- i_use = 'sabnzbd' # or nzbget
- reduce_speed_to = 1000 # in kbit\s
- sabnzbd_host = '192.168.1.7'
- sabnzbd_port = 8080
- sabnzbd_apikey = '******************************'
- sabnzbd_ssl = False
- sabnzbd_webdir = '/sabnzbd/'
- nzbget_host = 'localhost'
- nzbget_port = 6789
- nzbget_username = ''
- nzbget_password = 'tegbzn6789 '
- nzbget_ssl = False
- nzbget_webdir = '/'
- #### Edit stop ####
- import requests # pip install requests
- import sys
- from jsonrpclib import jsonrpc # pip install jsonrpclib-pelix
- if len(sys.argv) > 1:
- duration = sys.argv[1] # {duration} tag from plexpy, in minutes
- else:
- duration = None
- class Sab(object):
- def __init__(self, apikey, host,
- port, ssl, webdir):
- ssl = 's' if ssl else ''
- self.url = 'http%s://%s:%s%sapi?output=json&apikey=%s&' % (ssl, host, port, webdir, apikey)
- def changespeed(self, speed):
- return self.request('mode=config&name=speedlimit&value=' + speed)
- def pause_for(self, sec):
- return self.request('mode=config&name=set_pause&value=' + sec)
- def request(self, s):
- try:
- requests.get(self.url + s)
- except Exception as e:
- print e
- class Nzbget(object):
- def __init__(self, username, password, host, port, ssl, webdir):
- if username and password:
- authstring = '%s:%s@' % (username, password)
- else:
- authstring = ''
- ssl = 's' if ssl else ''
- self.url = 'http%s://%s%s:%s%sjsonrpc' % (ssl, authstring, host, port, webdir)
- self.action = jsonrpc.ServerProxy(self.url)
- def pause(self):
- return self.action.pause()
- def changespeed(self, speed):
- return self.action.rate(int(speed))
- def pause_for(self, sec):
- self.action.pause()
- self.action.scheduleresume(int(sec) * 60) # convert from minutes to sec
- if i_use == 'sabnzbd':
- sab = Sab(host=sabnzbd_host, port=sabnzbd_port, apikey=sabnzbd_apikey, ssl=sabnzbd_ssl, webdir=sabnzbd_webdir)
- if duration:
- sab.pause_for(str(duration))
- else:
- sab.changespeed(str(reduce_speed_to))
- else:
- nzbget = Nzbget(host=nzbget_host, port=nzbget_port,
- username=nzbget_username, password=nzbget_password,
- ssl=nzbget_ssl, webdir=nzbget_webdir)
- if duration:
- nzbget.pause_for(duration)
- else:
- nzbget.changespeed(reduce_speed_to)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement