SABcmd - A bash based command line interface for SABnzbd

Got a program that plays well with SABnzbd? Share it here!
Post Reply
fetzerms
Newbie
Newbie
Posts: 2
Joined: July 26th, 2015, 6:44 am

SABcmd - A bash based command line interface for SABnzbd

Post by fetzerms »

Hi everybody!

I recently created some Bash API-Client for SABnzbd. The main goal of this project was to require as few dependencies as possible,
as I did not have any python installation available on some restricted and chrooted environment.

The script/tool can be found here: https://github.com/fetzerms/sabcmd

I will simply paste the README from GitHub here:

SABcmd

Bash based command line interface for SABnzbd. The goal of this project is to nearly run without dependencies. So it could be run on embedded devices such as routers or in restricted chrooted environments.

If you have python available, https://github.com/TobiasTheViking/sabcli is worth a look aswell.

This script acts as an api client to SABnzbd. It offers basic operations, such as adding/removing nzb files to/from SABnzbd.

The features are quiet basic, but feel free to contribute new features or bug fixes.

Installation

Copy sabcmd to $PATH (e.g. /usr/local/bin).
Copy sabcmd.conf.sample to /etc/sabcmd.conf or ~/.sabcmd.conf and edit.

Code: Select all

sudo cp sabcmd /usr/local/bin/
cp sabcmd ~/.sabcmd.conf
vim ~/.sabcmd.conf
To make the script work, curl and xmlstarlet need to be installed.

Code: Select all

Ubuntu/Debian: sudo apt-get install curl xmlstarlet
CentOS: sudo yum install xmlstarlet curl
Usage

SABcmd can be invoked on the command line, passing commands and parameters.

Code: Select all

Usage: sabcmd <command> <parameters>

   Commands:
     - status      : Print queue status
     - long-status : Print queue status (verbose)
     - add         : Adds a nzb to the queue
     - delete      : Deletes a nzb from the queue
     - pause       : Pauses SABnzbd
     - resume      : Resumes a paused SABnzbd
     - restart     : Restarts SABnzbd

   Parameters:
     - --category/-c : The category to add a nzb to.
     - --nzb/-n      : Path or url to the nzb file to add.
     - --target/-t   : The queue target to operate on.
                       Can be: nzo_id, nzb-name or number

                       Caution: When passing a nzb-name, the operations
                                will affect all matching queue entries.

   Examples:
     - sabcmd status
     - sabcmd add --nzb http://here.is.my.nzb/ubuntu14_04.nzb
     - sabcmd add --nzb /tmp/here.is.my.nzb/ubuntu14_04.nzb
     - sabcmd delete --target ubuntu14_04
     - sabcmd delete --target SABnzbd_nzo_wRDhlV
     - sabcmd delete --target 2
Contributing

Contributions and feature requests are always welcome!

If you have any additions, examples or bugfixes ready, feel free to create a pull request on GitHub. The pull requests will be reviewed and will be merged as soon as possible.
To ease the process of merging the pull requests, please create one pull request per feature/fix, so those can be selectively included in SABcmd.

Cheers,

Matthias
Last edited by fetzerms on July 26th, 2015, 5:06 pm, edited 1 time in total.
User avatar
sander
Release Testers
Release Testers
Posts: 8811
Joined: January 22nd, 2008, 2:22 pm

Re: SABcmd - A bash based command line interface for SABnzbd

Post by sander »

Cool!

Some remarks / bugs:

sabcmd.conf.sample says

Code: Select all

"saburl="
which doesn't work: must be

Code: Select all

"sabUrl="
So: capital U.

Without xmlstarlet installed, I get:

Code: Select all

$ ./sabcmd status
./sabcmd: line 71: xmlstarlet: command not found
./sabcmd: line 72: xmlstarlet: command not found
+----[ SABcmd ]------------------------------------------------>
| Currently enqueued nzbs:
| 
./sabcmd: line 79: [: : integer expression expected
| 
| Current transfer speed: /s
+-------------------------------------------------------------->
That could be a bit more beautiful & explaining message

With xmlstarlet installed, I get:

Code: Select all

$ ./sabcmd add /home/sander/Downloads/ubuntu.nzb
Error: Add command requires a second argument.
That is not what the help says:

Code: Select all

   Examples:
     - sabcmd status
     - sabcmd add http://here.is.my.nzb/ubuntu14_04.nzb
     - sabcmd add /tmp/here.is.my.nzb/ubuntu14_04.nzb
     - sabcmd delete ubuntu14_04
It seems the correct syntax is:

Code: Select all

$ ./sabcmd add -n /home/sander/Downloads/ubuntu.nzb
with result:

Code: Select all

Test
+----[ SABcmd ]------------------------------------------------>
<?xml version="1.0" encoding="UTF-8" ?> <result><status>True</status> <nzo_ids><item>SABnzbd_nzo_XkkeDY</item> </nzo_ids> </result>
| SABnzbd added file /home/sander/Downloads/ubuntu.nzb successfully.
+-------------------------------------------------------------->
Why is the XML stuff there? Is the "echo $rawData" a debugging leftover? With two echo's commented out, it looks better:

Code: Select all

$ ./sabcmd add -n /home/sander/Downloads/ubuntu.nzb
+----[ SABcmd ]------------------------------------------------>
| SABnzbd added file /home/sander/Downloads/ubuntu.nzb successfully.
+-------------------------------------------------------------->
HTH
fetzerms
Newbie
Newbie
Posts: 2
Joined: July 26th, 2015, 6:44 am

Re: SABcmd - A bash based command line interface for SABnzbd

Post by fetzerms »

Thank you very much sander, for your issue reports on GitHub.

I fixed them all. Seems i was a littly sloppy after refactoring the code...

In case anyone finds more issues or has any feature requests, i try to do my very best!
Post Reply