Page 1 of 1

High priority server option?

Posted: September 30th, 2011, 4:50 pm
by Baka no Kami
Any chance of adding (unless it's already there and I just missed it) a 'backup server' like option, but for high priority NZBs?

I have 2 slow, but free, primary servers and 1 fast, but paid, backup server. Turning off the backup switch for the paid server typically quintuples my download speed, so sometimes I'll do that when I run across something I want to watch sooner rather than later. When it's done downloading however, I have to remember to mark the paid server as a backup again or, depending on how many items are still in the queue, run the risk of maxing out my quota for the month. It be nice if there was a setting that allowed backup servers to start acting like primaries if a high priority item is added to the queue.

Re: High priority server option?

Posted: October 1st, 2011, 3:12 am
by shypike
Sorry, that would make the design so much more complicated, for too little gain...

Re: High priority server option?

Posted: March 28th, 2012, 8:13 pm
by suntzu212
You can write a script that does this using the API. It would need to run all the time and poll the server to figure out the priority of the top item on the queue. If the priority is "High" (for example), it can disable the backup option for one or more servers. Here are the bones (in python), but you would need to add more code to handle exceptions and unusual events if you want this to be robust. Note that I use this script and I plan to add more code to handle the corner cases, so I'll share the updates if/when I ever make them.

Code: Select all

import time
import urllib
import xml.etree.ElementTree as etree

# edit the next three strings so they match your setup -- the rest of the script does not need to be changed
server = "localhost:8080"
apikey = "Y0uRAPIKeYHErE"
newsserver = "someserver.thatisusually.backup.net"

authString = "&apikey=" + apikey
listQueueCommand = "/api?mode=queue&limit=1&output=xml"
listQueueURL = "http://" + server + listQueueCommand + authString

getBackupCommand = "/api?mode=get_config&output=xml&section=servers&keyword=" + newsserver 
getBackupURL = "http://" + server + getBackupCommand + authString

setBackupCommand = "/api?mode=set_config&section=servers&keyword=" + newsserver + "&fillserver="
setBackupTrueCommand = setBackupCommand + "1" 
setBackupFalseCommand = setBackupCommand + "0" 
setBackupTrueURL = "http://" + server + setBackupTrueCommand + authString
setBackupFalseURL = "http://" + server + setBackupFalseCommand + authString

while True:
	print "fetching queue with: " + listQueueURL
	f = urllib.urlopen(listQueueURL)
	queueText = f.read()
	f.close()
	queueXML = etree.fromstring(queueText)
	topPriority = list(queueXML.find("slots"))[0].findtext("priority")
	print "top priority is: " + topPriority

	print "getting server settings with: " + getBackupURL
	f = urllib.urlopen(getBackupURL)
	backupText = f.read();
	f.close();
	backupXML = etree.fromstring(backupText)
	isFillServer = list(backupXML.find("servers").getchildren())[0].findtext("fillserver")
	print "fill server setting is: " + isFillServer

	if topPriority == "High":
		if isFillServer == "1":
			print "setting backup server to false with: " + setBackupFalseURL
			f = urllib.urlopen(setBackupFalseURL)
			cmdResult = f.read()
			f.close()
	else: 
		if isFillServer == "0":
			print "setting backup server to true with: " + setBackupTrueURL
			f = urllib.urlopen(setBackupTrueURL)
			cmdResult = f.read()
			f.close()


	time.sleep(10)