Page 1 of 1

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

Posted: November 5th, 2010, 10:16 pm
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!

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

Posted: November 5th, 2010, 10:49 pm
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.

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

Posted: November 5th, 2010, 11:55 pm
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