Looking for a command to detect pause state

Feel free to talk about anything and everything in this board.
Post Reply
tret
Full Member
Full Member
Posts: 148
Joined: August 2nd, 2008, 2:07 pm

Looking for a command to detect pause state

Post by tret »

I use SABnzbd on the same Karmic box that I use for a media center with XBMC. I have written a small python script that will run via crontab every 5 minutes to detect whether or not XBMC is in video playback mode and if so will pause SABnbzd (I do this to avoid choppy video during SABnzbd post-processing.) If XBMC is not in video playback mode it will then unpause SABnzbd. Right now I have the script simply sending a pause or resume command depending on the XBMC playback state but I would like to only send a command to SABnzbd if necessary. For example if a video is playing and SABnzbd is already paused there is no need to send a pause command. The same is true if no video is playing and SABnzbd is already unpaused.

Does anyone know a web command I can use to verify the current SABnzbd pause state. I can use a url request in python and then evaluate the html returned. I am currently using similar code to determine XBMC's video playback state. Here is a bit of code I am using to do that.

Code: Select all

req = urllib2.Request('http://' + xbmcAddress + '/xbmcCmds/xbmcHttp?command=getcurrentlyplaying')
try: handle = urllib2.urlopen(req)
except IOError, e:
  print "XBMC Connection Error\n"
  exit
else:
  page = handle.read()
  if page.find('Filename:[Nothing Playing]') >= 0:
    req = urllib2.Request('http://' + sabnzbdAddress + '/sabnzbd/api?mode=resume&apikey=' + sabnzbdAPIKey + '&ma_username=' + sabnzbdUser + '&ma_password=' + sabnzbdPass)
    try: handle = urllib2.urlopen(req)
    except IOError, e:
      print "SABnzbd Connection Error\n"
      exit
    else:
      page = handle.read()
      print "Nothing Playing, SABnzbd unpaused\n"
This code searches the results of the XBMC url request and then resumes SABnzbd downloading if XBMC reports that nothing is playing.

Thanks,
Rob
Last edited by tret on January 12th, 2010, 3:01 pm, edited 1 time in total.
User avatar
inpheaux
Administrator
Administrator
Posts: 562
Joined: January 16th, 2008, 9:14 pm

Re: Looking for a command to detect pause state

Post by inpheaux »

Use the API.

Specifically, either the XML or JSON version of the queue output.

You'll need to pass in the api key, username and password as usual.
tret
Full Member
Full Member
Posts: 148
Joined: August 2nd, 2008, 2:07 pm

Re: Looking for a command to detect pause state

Post by tret »

Thanks for the info, I ended up using the XML output. For anyone interested here is a link to the finished script and information.

http://forums.sabnzbd.org/index.php?topic=3368.0
Post Reply