SABnzbd API python module
Posted: December 17th, 2009, 7:55 pm
I hadn't updated SABnzbd for quite some time and was pleasantly surprised to see all the new functionality. So, I was going to update some of my scripts to work with the new API, and created some helper functions for that. I kinda got carried away and created a module to interface with the SABnzbd API, so I thought that I'd share it. Apparently I'm not allowed to attach zip files, so I uploaded it to mediafire:
http://www.mediafire.com/?zii2l3znmmq
I've put in in the typical distutils format, so to install, just unzip the archive, go into the Sabapi-0.1 directory, and run:
The usage is detailed in the Manual.html file included in the archive. In any case, here's a simple example:
You get the picture. I think that I've implemented all of the API methods but this certainly hasn't been tested exhaustively, so let me know if you have any issues.
A few notes on this:
* All methods that return data are setup to return a python dictionary that's created from the JSON
* The dictionaries contain strings in unicode format, not sure if that's the best way to go, but that's how it works for now.
* Not all API methods are a one-to-one mapping. In some cases, I've combined two or more SABnzbd API methods into one function here. For instance pause() can pause a single item as well as the entire queue. When in doubt, check the manual I've included.
* You'll need the simplejson module in order to use this. Simplejson is pretty common, and on many systems, you can install it with:
http://www.mediafire.com/?zii2l3znmmq
I've put in in the typical distutils format, so to install, just unzip the archive, go into the Sabapi-0.1 directory, and run:
Code: Select all
python setup.py install
Code: Select all
#Setup the API connection
import Sabapi
api = Sabapi(apikey='xxxxxxxxxxxxxxxxxxxxxxx') #Assuming http://localhost:8080
#Pause and resume all
api.pause()
api.resume()
#Pause for 30 minutes
api.pause(time='30')
#Pause a single item
api.pause(nzo_id='SABnzbd_nzo_zt2syz')
#Add an item from a URL
api.add(url='http://myawesomenzbsite.com/nzbs/TotallyLegalBinaryItem.nzb')
#Add an item using a newzbin id
api.add(id='123456')
A few notes on this:
* All methods that return data are setup to return a python dictionary that's created from the JSON
* The dictionaries contain strings in unicode format, not sure if that's the best way to go, but that's how it works for now.
* Not all API methods are a one-to-one mapping. In some cases, I've combined two or more SABnzbd API methods into one function here. For instance pause() can pause a single item as well as the entire queue. When in doubt, check the manual I've included.
* You'll need the simplejson module in order to use this. Simplejson is pretty common, and on many systems, you can install it with:
Code: Select all
easy_install simplejson