Page 1 of 1

SABnzbd API python module

Posted: December 17th, 2009, 7:55 pm
by popcornarsonist
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:

Code: Select all

python setup.py install
The usage is detailed in the Manual.html file included in the archive. In any case, here's a simple example:

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')
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:

Code: Select all

easy_install simplejson

Re: SABnzbd API python module

Posted: December 28th, 2009, 11:25 am
by popcornarsonist
So, I've been working with this a bit, and I also built an API for newbin, it works much the same way as the Sabnzbd API. In any case, I'm attaching the the Newzbin API module, as well as an updated SAbnzbd API module, and a script that I've written to utilize both APIs.

The script is an update of one that I wrote some time ago, it scans for movies on Newzbin, checks their IMDB rating (or Rotten Tomatoes rating), and if it's over a certain value, and I don't already have the movie, it'll be added to the queue.

You'll need to update a couple of lines.

You'll need to put in your newzbin and sabnzbd info at the top, as well as the directories that you store your movies in.

Code: Select all

#Setup Enviroment (Sabnzbd and Newzbin authentication)
sab_api = Sabapi.setup(host='192.168.1.102',apikey='ads988s1ca0563b6d38310911324829nde0')
newz_api = Newzbython.setup('popcornarsonist','aSuperStrongPassword')

#The directories in which I keep movies
movie_dirs = ['/mnt/piracy/Movies','/var/share/Movies']
I set this one up to look for movies in x264 or h.264 format which are in the english language. If you want something different, you'll need to update line 65:

Code: Select all

hd_movies = newz_api.search(category='movies',video_format=['x264','h.264'],language=['english'])
You can set the video_format to ['xvid','divx'] or just 'wmv', or specify video_genre='romance', whatever. Basically any of the parameters available on the newzbin search page are available here.

I coded this to look for movies with at elast a 7.5 on IMDB, and 1000 votes. If you want something different, change line 75:

Code: Select all

if (rating > 75) and (votes > 1000):
That's about it.

Re: SABnzbd API python module

Posted: January 30th, 2010, 12:13 pm
by dmann
You are the man!  This is exactly what I was looking for.  Much nicer config than the previous scripts.  I think this would get much more attention if you posted it as an automated movie downloader.

If you update this - would you mind posting any updates?

A few suggestions if you get bored one day:

    Filter by year - in the past I saw something in your script that allowed me to filter out a few years - I'll see if I can figure this out with what you had - but I dont see it.  Basically someone would want to only download movies as old as 2008 or something like that.

    Track deleted movies - in the past someone added a log to your old script to track downloaded movies.  If you could somehow track history - this covers if someone watches a movie and then deletes it - so it would not be downloaded again


Again - very nice work and thank you for the contribution.  I am going to try this out today!