SABnzbd Post Process Scripts
Post Processing Scripts are ran after SABnzbd has retrieved content from your News Server via an NZB-File.
A sample script might look like this:
#!/usr/bin/env python # -*- encoding: utf-8 -*- ##### Declaration from nzbget import SABPostProcessScript class MyScript(SABPostProcessScript): """Inheriting SABPostProcessScript grants you access to of the API defined throughout this wiki """ def main(self, *args, **kwargs): """Write all your code here """ # Want a specific variable from the SAB_.* environment? final_dir = self.get('COMPLETE_DIR') # fetches SAB_COMPLETE_DIR category = self.get('CAT') # fetches SAB_CAT # Keys are not case sensitive, so consider the 'Debug' option defined # above. You can fetch it like this: debug = self.get('Debug') # or self.get('DEBUG') works too # Want an nzb/dnzb variable? propername = self.nzb_get('propername') # The above is parsed straight out of the fetched NZB-File for you! # Return True if you were successful # Return False if you experienced a failure # Return None if you just have nothing bad or good to report return True
To make your code easy to read, it would be a good idea to get in the habit of fetching system values in uppercase and script specific options you defined at the top (such as Debug) in the same case sensitivity they were defined in. That way it'll be easy to locate all locations you fetch the variable from in your code.
You can also use the API_validate() function to verify the options are correctly set. You can also use the API_health_check()](API_health_check) to check that content can even be scanned:
from nzbget import SABPostProcessScript class MyScript(SABPostProcessScript): """Inheriting SABPostProcessScript grants you access to of the API defined throughout this wiki """ def main(self, *args, **kwargs): if not self.health_check() # Content was never unpacked, there is nothing to Post-Process # but there is also no reason to fail (return False) since # there isn't anything we can do anyway. return None # Write your code here knowing all of your options are correctly # set in memory return True
Post-Process scripts automatically do the following for you:
- Attempts to change into the SAB_COMPLETE_DIR if it exists (where end content exists). So you will always be working relative to what was just retrieved.
- The NZB-File file referenced is automatically parsed and stored into an nzb hash table which you can access by calling nzb_get().