[LINUX] Collection of my bash scripts for XBMC

Come up with a useful post-processing script? Share it here!
Post Reply
konti
Newbie
Newbie
Posts: 5
Joined: December 14th, 2009, 4:32 am

[LINUX] Collection of my bash scripts for XBMC

Post by konti »

I've been working on some linux scripts for integrating sabnzbd+ with my XBMC installation. I've used some topics here and some from the XBMC.org forum. Maybe someone can use these. It's all linux written in bash. It's verry basic because i'm still a noob in bash scripting. Been learning them for 3 days now. I'll post them per functionality. I have integrated some of them into one script.

Don't expect to have these script work out of the box for you! Make sure you have the script made executable. with chmod +x myscript.sh. A read that some people had to make the script "chmod 777 myscript.sh" to get it to work. To use the move script make sure you have write permissions with your sabnzbd+ user in the xbmc library folder. I hope these can help someone!

Send notification to XBMC when download is complete.

Code: Select all

#! /bin/bash
finaldir=$1
oriname=$2
cleanname=$3
status=$7

case $status in
    0 )
        status="OK";;
    1 )
        status="Failed Veri" ;;
    2 )
        status="Failed unpack";;
    3 )
        status="FverAndFunpack";;
esac


subject="$status : $cleanname"
message="In:$oriname"
wget -q --delete-after "http://XBMC:@192.168.1.251:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification($subject,$message,18000))" > /dev/null 2>&1

#for testing purposes
#echo "$1 : $3 : $4 : $5 : $6 : $7" >> ~/.sabnzbd/scripts/scripts.log
I use twilightnzb for downloading nzb's. So when i download a movie. Let's say Transformers (i name the nzb:  Transformers (2007).nzb. The folder structure often looks like this: /complete/Transformers (2007).nzb/Transformers 2007 twilight.SRT/video_ts. So i want everything under Transformers 2007 twilight.SRT move one level up. The script checks if the is exactly one folder under the nzb folder. If that's true move that folder but use the nzb folder's name without the nzb, to you'r movie (library) folder. In this case with the name Transformers (2007).

Code: Select all

#!/bin/bash
#Sabnzbd variabled assigned to my own variables
finaldir=$1
oriname=$2
cleanname=$3
status=$7

#This is the path where you wan't to move your movie to
myLibraryDir="/home/pietje/path/to/your/xbmc/movies/"

#This part copy's the directory in the nzb dir, to your own movies (library) folder
numberdirs=`find "$finaldir" -maxdepth 1 -type d | wc -l`
if [[ $numberdirs -eq 2 ]]; then
  pathinnzb=`ls -d "$finaldir"*/`
  mv "$pathinnzb" "$myLibraryDir$cleanname"
  echo -e "\nmoved $pathinnzb to: movies\n $myLibraryDir$cleanname" >> ~/.sabnzbd/logs/sabnzbd.log
else
  if [ $numberdirs -gt 2 ]; then
  echo "Found more then 1 folder in $finaldir!" >> ~/.sabnzbd/logs/sabnzbd.log
  fi
  if [ $numberdirs -lt 2 ]; then
  echo "Did not found any dirs in $finaldir!" >> ~/.sabnzbd/logs/sabnzbd.log
  fi
fi
Ok last one is a easy one. Update my Movies library.

Code: Select all

#!/bin/bash
ipxbmc1="192.168.1.253"
portxbmc="8080"
user="XBMC"
pass=""

wget -q --delete-after "http://$user:$pass@$ipxbmc1:$portxbmc/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)" > /dev/null 2>&1


I've called the last script on line 17 in the previous script when the movie could be moved. Just before the else statement. You can ofcourse also put the script in a function and call that.
Last edited by konti on March 1st, 2010, 7:00 am, edited 1 time in total.
konti
Newbie
Newbie
Posts: 5
Joined: December 14th, 2009, 4:32 am

Re: [LINUX] Trying to reproduce the default sabnzbd info logging

Post by konti »

i'm trying to make the logging in my script as simular as possible to the default logging lines. Below is what i have until now.
echo `date '+%m-%d-%y %H:%M:%S'`"::INFO::Moved Folder $pathinnzb to:$myLibraryDir$cleanname: "`mv "$pathinnzb" "$myLibraryDir$cleanname"` >> ~/.sabnzbd/logs/sabnzbd.log

It gives me al logging line as:
03-01-10 16:20:08::INFO::Moved Folder /home/piet/Downloads/complete/piet/The Boys Are Back (2009)/The Boys Are Back (2009) NL/ to:/home/piet/Downloads/piet/movies/The Boys Are Back (2009):

I want it to be as simular as possible to the orriginal e.a.:
2010-03-01 01:05:13,943::INFO::[__init__:694] /var/www/.sabnzbd/cache/SABnzbd_article_DWSWz7 removed

Does anybode have some tips for me for improvement? thx.
Post Reply