]> git.rmz.io Git - dotfiles.git/commitdiff
bin: finally add addnzb script
authorSamir Benmendil <me@rmz.io>
Sun, 24 Nov 2019 14:46:46 +0000 (14:46 +0000)
committerSamir Benmendil <me@rmz.io>
Sun, 24 Nov 2019 14:46:46 +0000 (14:46 +0000)
bin/addnzb [new file with mode: 0755]

diff --git a/bin/addnzb b/bin/addnzb
new file mode 100755 (executable)
index 0000000..fdd5ca7
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+set -e
+
+source $XDG_CONFIG_HOME/sabnzbd/config
+
+version="0.1"
+
+function usage ()
+{
+    echo "Usage :  $0 [options]
+
+    Options:
+    --category      Sets the category
+    -h,--help       Display this message
+    -v,--version    Display script version"
+}
+
+# Parse arguments
+declare -a args
+while [[ $# -gt 0 ]]; do
+    opt="$1"
+
+    case $opt in
+        -h|--help)     usage; exit 0 ;;
+        -v|--version)  echo "$0 -- Version $version"; exit 0 ;;
+        --category)    category=$2; shift 2 ;;
+        -* )
+            echo -e "\n  Option does not exist : $opt\n"
+            usage; exit 1 ;;
+
+        *) args+=("$opt"); shift ;;
+    esac
+done
+
+if [[ -n $category ]]; then
+    extra_data="-F cat=$category"
+fi
+
+for f in ${args[@]}; do
+    curl -s -F apikey="$API_KEY" -F mode="addfile" -F name=@"$f" $extra_data $URL/sabnzbd/api &> /dev/null
+    if [[ $? -eq 0 ]]; then
+        rm $f
+    else
+        echo "Failed to upload '$f'"
+    fi
+done