I wrote this as I want my PC to come on at 4am check for downloads , download them and then go back to sleep. As sometimes there is more to download then other times there was no sure way of specifying a time to shut it down unless I said ok well max time will be 4 hours so shutdown at 8am, however sometimes it may finish in an hour so 3 hours wasted. So I wrote this VBScript to check the queue and if 0 to put PC to sleep. This is then ran as a scheduled task and repeated for 4 hours.
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load("http://localhost:port/api?mode=qstatus&output=xml&ma_username=<username>&ma_password=<password>&apikey=<apikey>")
strQuery = "/queue/noofslots"
Set colItem = xmlDoc.selectNodes(strQuery)
For Each objItem in colItem
IF objitem.text = "0" Then
set objShell = wscript.createObject("wscript.shell")
objShell.Run "%comspec% /c rundll32 powrprof.dll,SetSuspendState"
Set objNet = Nothing
Else
End If
next
for me the point is my PC gets powered up at say 5:30am it grabs the lowdef copies of tv shows then and sometimes can take till 12pm to pick up highdef. So my queue could empty before hand. Ok I could just have a script runs which runs the API command to set end of queue to sleep but heres the point.
That is only useful if I have items in my queue. I don't wanna shutdown too early but then again at 12pm there might be nothing to download so a script which checks if my queue is empty works best. I did try setting end of queue to shutdown but you have to have something download first to then empty the queue first. Just setting it to that when the queue is already empty will not work.
I hope that explains my need for the script i wrote. If no one else needs it , well I am just sharing.
I'm actually having sleep problems with sabnzbd as per http://forums.sabnzbd.org/index.php?topic=2974.0 so taking power management out of its hands is quite useful for me. Thanks for the script!