Is there a way to determine if sabnzbd is currently downloading programmatically

Support for the Debian/Ubuntu package, created by JCFP.
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
plarser48
Newbie
Newbie
Posts: 2
Joined: November 5th, 2010, 9:58 pm

Is there a way to determine if sabnzbd is currently downloading programmatically

Post by plarser48 »

Hi all,

I'm a happy sab user on a mythtv ubuntu system. I have a script that runs when mythtv is closed that checks to see if is ok to shutdown. It checks for samba transfers, ssh user logins, specific programs, etc.

I'd hate for the system to shut down abruptly while sabnzbd is in the middle of a download. Is there any way via shell script that I can determine if sabnzbd is in a middle of a download? I considered two techniques:

1) Some direct interface to sabnzbd or parsing log entry (if so, which one?), or
2) Some script to monitor CURRENT download rate.

Any thoughts or ideas? Thanks!
User avatar
inpheaux
Administrator
Administrator
Posts: 563
Joined: January 16th, 2008, 9:14 pm

Re: Is there a way to determine if sabnzbd is currently downloading programmatically

Post by inpheaux »

This, and basically everything else SABnzbd does, is available through the API.

Here's the queue. You want the tag. If that's not 0.00 then it's downloading.
plarser48
Newbie
Newbie
Posts: 2
Joined: November 5th, 2010, 9:58 pm

Re: Is there a way to determine if sabnzbd is currently downloading programmatically

Post by plarser48 »

inpheaux:

Great recommendation!! I didn't ever use the api before, and didn't realize how super easy it was to use even with basic scripting languages. I wasn't sure of the best way of parsing the xml file in shell script (tried xpath for a few mins before giving up), so I wrote a quick sed/awk line to grab that number for me. Off the top of my head I wasn't sure  how to compare a string with a number  in a shell script so I just hard coded "0.00"

Code: Select all

#!/bin/sh
# This script checks sabnzbd to see if it is currently downloading through the API
# Note, change [apikey] to YOUR api key
#

wget -q -O /tmp/sab.xml "http://192.168.1.51:8082/sabnzbd/api?mode=queue&output=xml&apikey=34d797e9549843146cf3f14747b46fc6"
TRAFFIC=`cat /tmp/sab.xml | grep kbpersec | sed -e "s/[><\/]/ /g" | awk '{print $2}'`
NOTRAFFIC="0.00"
rm /tmp/sab.xml
echo "$TRAFFIC"


if [ "$TRAFFIC" = "$NOTRAFFIC" ]; then
	echo "Not Currently downloading"
	exit 0
else
	echo "Currently downloading"
	exit 1
fi
Post Reply