Sabnzbd scripts

From Bubba.org

Jump to: navigation, search

Introduction

SABnzbd is a great, multi-platform nzb client. Below are scripts that make SABnzbd even better!

User Scripts

References to atv2xml.pl should refer here: ATVFiles_Movie/TV_Categorization_Script

References to growlnotify.pl should refer here: growlnotify.pl

Movie Script for classifying, combining (movies that are in multiple files)

#!/bin/sh
#
# classify_and_combine-movie.sh
#
 
set -u
COMBINE=0  # to combine or not to combine multi-file movies (will mess up subs)
TMP="/tmp/sabtmp.out"
CATEGORY_NAME=`echo $1 | awk -F [/] '{print $(NF-1)}'`
echo "Category: $CATEGORY_NAME"
FOLDER_PATH="$1"
FOLDER_NAME=`echo $FOLDER_PATH | awk -F [/] '{print $NF}'`
echo "Folder Path: $FOLDER_PATH" 
 
cd "$FOLDER_PATH"
 
MOVIE_NAME=`echo $FOLDER_NAME | sed 's/ (.*)//g'`
 
# remove movie sample files (anything under 30MB)
if [ `find . -size -30000000c -regex '.*/.*\.avi' | wc -l` -eq 1 ]
        then 
        FILE3="$FOLDER_PATH`find . -size -30000000c -regex '.*/.*\.avi' | sed 's/^\.//'`"
        echo "Removing Sample: ${FILE3}"
        rm -f "${FILE3}"
 
fi
 
# combine 2 CD movies into 1 file (this will break subs)
if [ "${COMBINE}" = "1" ]; then
    if [ `find . -size +629145600c -regex '.*/.*\.avi' | wc -l` -eq 2 ]
                then
                FILE1="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | sort | sed -n '1p' | sed 's/^\.//'`"
                FILE2="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | sort | sed -n '2p' | sed 's/^\.//'`"
                echo "Joining Files ${FILE1} and ${FILE2} ..."
                avimerge -i "${FILE1}" "${FILE2}" -o "$FOLDER_PATH/$MOVIE_NAME".avi 2> /dev/null 1> /dev/null
                #mencoder -msglevel all=3 -forceidx -ovc copy -oac copy -o "$FOLDER_PATH/$MOVIE_NAME".avi "${FILE1}" "${FILE2}"
                echo "Removing Files ${FILE1} and ${FILE2} ..." 
                rm -f "${FILE1}"
                rm -f "${FILE2}"
   fi
fi
 
# Generate AppleTV/ATVFiles XML file for movie & download cover
atv2xml.pl -usedir -usefirst -overwrite -duration -altimg "$FOLDER_PATH" > $TMP
cat $TMP
 
# Change perms on directory
chmod -R 777 "$FOLDER_PATH"
 
cat $TMP | growlnotify.pl
rm -f $TMP

TV Script (to classify and move to proper directories)

#!/bin/sh
#
# classify_and_chperms-tv.sh
#
 
TMP="/tmp/sabtmp.out"
set -u 
FOLDER_PATH="$1"
echo "Folder Path: $FOLDER_PATH" 
CATEGORY_NAME=`echo $FOLDER_PATH | awk -F [/] '{print $(NF-2)}'`
echo "Category: $CATEGORY_NAME"
SHOW_NAME=`echo $FOLDER_PATH | awk -F [/] '{print $(NF-1)}'`
echo "Show Name: $SHOW_NAME" 
SEASON_NAME=`echo $FOLDER_PATH | awk -F [/] '{print $(NF)}'`
echo "Season Name: $SEASON_NAME"
 
SHOW_PATH=`echo $FOLDER_PATH |sed s/"${SEASON_NAME}"//g`
 
# Generate AppleTV/ATVFiles XML file for movie & download cover
atv2xml.pl -overwrite -tvshow -usefirst "$FOLDER_PATH" > $TMP
cat $TMP
 
echo "Changing perms on $SHOW_PATH"
chmod -R 777 "$SHOW_PATH"
 
cat $TMP | growlnotify.pl 
rm -f $TMP

Growl Notify (notify machine with Growl that classification is complete)

#!/usr/bin/perl
#
# growlnotify.pl - bubbaATbubba.org
#
use Net::Growl;  
use Net::hostent;
 
@data = (<STDIN>);
 
my $GROWL_HOST="growl_host";
my $GROWL_APP="sabnzbd";
my $GROWL_PASS="growl_password";
if ($GROWL_APP && $GROWL_PASS && $GROWL_HOST) {
        Net::Growl::register(host => $GROWL_HOST, application=>$GROWL_APP, password=>$GROWL_PASS) if !$ALREDY_REGISTERED;
 
        Net::Growl::notify(host=> $GROWL_HOST, application=>$GROWL_APP,
        title=>'sabnzbd download complete',
        description=>"@data",
        priority=>'1',
        sticky=>'False',
        password=>$GROWL_PASS);
}