RELEASE: Script to fix failed show downloads with SickBead
Posted: August 23rd, 2013, 5:26 am
I was fed up with having to manually fix so many files and manage my failed downloads so I write a script to do it, hope this can be useful to others.
Basically it tries to extract a failed file anyway then send it to Sickbeard, for me at least this almost always works. It also logs the recovery attempt and clears out any old files left behind after 10 days. This script works best when set to run on queue complete because you do not want to be trying to extract half downloaded files.
Just to be on the safe side I have protections anyway so the script will not run if there are files currently downloading.
I have only had 1 failure in many months since using this script.
Note this does not work on movies/Films only TV shows, you will need to fill in all the variables at the top for this script to function.
Basically it tries to extract a failed file anyway then send it to Sickbeard, for me at least this almost always works. It also logs the recovery attempt and clears out any old files left behind after 10 days. This script works best when set to run on queue complete because you do not want to be trying to extract half downloaded files.
Just to be on the safe side I have protections anyway so the script will not run if there are files currently downloading.
I have only had 1 failure in many months since using this script.
Note this does not work on movies/Films only TV shows, you will need to fill in all the variables at the top for this script to function.
Code: Select all
#!/bin/bash
#your sabnzbd hostname or IP
sabhost=""
#the port sabnzbd is listening on
sabport=""
#Your sabnzbd api key
sabapikey=""
#Where sabnzbd sends your incomplete files
incompletedir=""
#the user that will own your files before sending for postprocessing
runasuser=""
#location of your sab2sickbeard script
sab2sbscript=""
#do not edit this variable
finalURL="http://"$sabhost":"$sabport"/api?mode=queue&output=xml&apikey="$sabapikey""
logdate=`date`
echo "Starting Cleanup......."
cd $incompletedir
mkdir -p postprocess
queuecount=`curl -s "$finalurl" | grep filename | wc -l`
#checking the download queue is clear
if [ $queuecount -eq 0 ]; then
echo "Nothing downloading currently, continuing ...."
#removing spaces from all filesnames
find . -name '* *' | while read file;
do
target=`echo "$file" | sed 's/ /./g'`;
echo "Renaming '$file' to '$target'" >> process.log;
mv "$file" "$target";
done;
echo "Looking for files older than 10 days for deletion"
deletelist=`find ./* -mtime +10 | grep -v temp | cut -d'/' -f2 | sort -u`
deletelistcount=`echo $deletelist | wc -w`
if [ $deletelistcount -eq 0 ] ;then
echo "No Files to delete..."
else
echo "Deleting " $deletelistcount "files"
for i in $deletelist
do
echo "deleting " $i
echo $logdate " Deleting" $i "as older than 10 days" >> process.log
rm -rf $i
done
fi
list=`ls -d */ | egrep -v 'postprocess|temp'`
N=0
for i in $list
do
cd "$i"
rar=`ls | grep .rar | wc -l`
if [ $rar -gt 0 ]
then
echo .
echo "Processing "$i
#compensating for .rar and .part01 naming conventions
if [ $rar -gt 1 ]
then
unrar -o+ e `ls | grep part01` ../postprocess/
else
unrar -o+ e *.rar ../postprocess/
fi
#using exit codes to detect if the unraring was sucessful
if [ $? -eq 0 ]
then
echo $logdate " " $i "Extracted OK" >> ../process.log
N=$((N+1))
else
echo $logdate " " $i "Failed to process" >> ../process.log
fi
cd ..
rm -rf $i
else
cd ..
fi
done
else
echo "There are currently items in the queue, aborting"
fi
if [ $N -ne 0 ]
then
echo "Sending processed files to Sickbeard for post processing"
chown -R $runasuser $incompletedir\*
python $sab2sbscript $incompletedir\postprocess/
fi
echo "Processed "$N "files"
exit