The Ultimate Guide to NZBGet Automation and Scripting NZBGet is a high-performance Usenet downloader. Its speed and low resource usage make it excellent for media servers. However, its true power lies in automation. By using built-in settings and extension scripts, you can turn NZBGet into a fully automated media pipeline.
This guide covers everything you need to automate your Usenet downloads, from basic sorting to advanced custom scripting. 1. Built-In Automation Features
Before adding external scripts, utilize the powerful automation tools already built into NZBGet. Automated Categories
Categories allow NZBGet to handle different types of files automatically. You can assign incoming NZBs from Sonarr, Radarr, or RSS feeds to specific categories like tv, movies, or music. DestDir: Define a unique final folder for each category.
Unpack: Enable or disable automatic RAR extraction per category.
Aliases: Match indexer tags automatically to route files to the correct category.
You can automate file discovery directly inside NZBGet without third-party managers. Go to Settings > RSS. Add your favorite indexer’s RSS feed URL.
Filter by keywords or sizes using the Filter field to automatically download matching releases. 2. Understanding NZBGet Extension Scripts
Extension scripts are external programs (usually written in Python or Bash) that interact with NZBGet. They extend functionality by processing files before, during, or after a download. Script Types
Scan Scripts (ScanScript): Run when a new NZB file is added to the queue. Useful for analyzing or renaming the NZB file before downloading starts.
Queue Scripts (QueueScript): Execute during the download process to modify priority, pause items, or alter parameters.
Post-Processing Scripts (PPScript): Run immediately after a download finishes and unpacks. This is the most common script type, used for moving, renaming, and notifying. Where to Put Scripts
Place your downloaded scripts into the directory defined in Settings > PATHS > ScriptDir. Once added, click Reload in the NZBGet interface to make them visible in the settings. 3. Essential Scripts for Your Pipeline
To achieve complete automation, consider integrating these popular extension scripts into your setup:
VideoSort: Automatically renames and organizes your TV shows and movies into clean folder structures based on video metadata.
EMail / Notify: Sends instant notifications to your phone or inbox via services like Discord, Telegram, Pushbullet, or email when a download succeeds or fails.
Logger: Cleans up or archives download logs to keep your server storage optimized.
Flatten: Removes unnecessary subfolders created during unpacking, leaving you with just the clean media files. 4. Writing Your First Custom Python Script
If existing scripts do not meet your exact needs, you can write a custom Python script. NZBGet communicates with scripts using standard environment variables and exit codes. The Basic Script Template
Save the code below as CustomNag.py in your script directory. This example logs a message and sends a custom alert.
#!/usr/bin/env python3 # Check the official documentation for NZBGet script configuration structure. ### NZBGET POST-PROCESSING SCRIPT # # This script logs a completion message to the NZBGet console. # # Do not modify lines above. import os import sys # NZBGet exit codes # 93 = SUCCESS, 94 = WARNING, 95 = ERROR EXIT_SUCCESS = 93 EXIT_ERROR = 95 def main(): print(“[INFO] Custom Post-Processing Script Started.”) # Fetch data provided by NZBGet environment variables nzb_name = os.environ.get(‘NZBOP_NZBNAME’, ‘Unknown Download’) status = os.environ.get(‘NZBPP_STATUS’, ‘Unknown Status’) print(f”[INFO] Download Name: {nzb_name}“) print(f”[INFO] Download Status: {status}“) # Custom automation logic here (e.g., triggering a webhook, custom API call) sys.exit(EXIT_SUCCESS) if name == “main”: main() Use code with caution. Key Environment Variables to Use NZBPP_DIRECTORY: The path to the downloaded files. NZBPP_NZBNAME: The original name of the NZB file. NZBPP_CATEGORY: The assigned category.
NZBPP_TOTALSTATUS: Tells you if the download was successful (SUCCESS, WARNING, FAILURE). 5. Troubleshooting and Best Practices
Check the Log: When a script fails, NZBGet highlights the log messages in red. Review Messages to read the exact error output from your script.
Set Executable Permissions: On Linux and macOS systems, ensure your script files have execution permissions. Run chmod +x yourscript.py in your terminal.
Verify Python Paths: Ensure the first line of your script (#!/usr/bin/env python3) points to the correct location of Python on your host machine or Docker container.
Script Order Matters: You can chain multiple post-processing scripts together in Settings > Extension Scripts. Ensure file-moving scripts (like VideoSort) run before cleanup or notification scripts. If you want to customize your setup further, let me know:
What operating system or Docker environment runs your NZBGet instance?
Which media managers (like Sonarr or Radarr) you want to link it to? The specific task you want your custom script to handle?
I can provide tailored configurations or write a specific script for your server.
Leave a Reply