Page 3 of 8

Re: XBMC Library Updater

Posted: January 10th, 2010, 5:27 pm
by razwer
i like this script, thanks for writing it.
As i'm relatively new to sabnzb and XBMC, i'm unsure on how to execute this script automatically once a download has finished.
I prefer this script to be executed on only additions to the Movies and TV categories.

Can someone please assist this n00b?

Using: Windows 7 X64
Python 2.6.4 installed
Sabnzbd 0.5.0 Beta5
XBMC 9.11

Re: XBMC Library Updater

Posted: January 10th, 2010, 11:11 pm
by JohnSCS
razwer,

Just create Movie and TV categories (Config>Categories) and set this script only for these two categories. Leave the Default User Script blank in Config>Switches

Re: XBMC Library Updater

Posted: January 11th, 2010, 9:33 am
by razwer
Hi John,

Thanks for your reply.

in the config-->categories section i do not see any fields to add post processing scripts
the table has the following options:
Category Processing Priority Folder/Path NewzBin/ Groups
processing is a pulldown menu with default set options (repair, unpack, delete).

Could the skin i am using prevent me from seeing the required fields or is there another way to sort this out?

Re: XBMC Library Updater

Posted: January 11th, 2010, 4:23 pm
by JohnSCS
Make sure that you have specified a scripts folder in Config>Folders otherwise the field may not be shown. Avoid using folder names with spaces in them, ie c:\program files\Sabnzbd\scripts. Use c:\scripts instead.

Re: XBMC Library Updater

Posted: January 11th, 2010, 8:57 pm
by razwer
Thanks for the assistance, the script works like a charm!

The parameter "20000" in the URL to XBMC is i presume the delay for the screen with the notification to close?

Re: XBMC Library Updater

Posted: January 12th, 2010, 1:14 am
by JohnSCS
Correct. The notification stays on the screen for 20secs. The SAB graphic (sabnzbd.jpg) needs to be in the root of C: drive on the XBMC PC. You can change the location if required, even to a network path - just update the script as needed.

Re: XBMC Library Updater

Posted: January 12th, 2010, 11:03 am
by calmdown
So many scripts posted, however not a single one seems to work for me :)

I'm running xbmclive 9.11 camelot, and sabnzbd+ 0.5.0Beta5, both on the same box, a ASROck ION 330 HT.

I've made a file called update.py, inside this code:

Code: Select all

import urllib

urllib.urlopen("http://192.168.1.4:8081/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))").close()
set a folder for scripts under settingsd>folders in sab, and specified the script in the correct correct categories.

If i paste the url:

Code: Select all

http://192.168.1.4:8081/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))
from my laptop, the library upadtes just fine, but it seems like it wont do it properly in SAB..

maybe iv'e got something wrong in the formatting of the script, or do someone have any other suggestions?

Re: XBMC Library Updater

Posted: January 12th, 2010, 5:04 pm
by razwer
@JohnSCS, thanks for the clarification. The image code part was already clear to me :) Thank you very much for your assistance.

@calmdown
Presuming you run windows, have you installed Python 2.6.4?
if not, install from here: http://www.python.org/ftp/python/2.6.4/python-2.6.4.msi

also, i used JohnSCS's script as followed:

Code: Select all

# Python 2.6.4 | http://www.python.org/download/releases/2.6.4/
import socket,sys,urllib2
from urllib2 import Request, URLError, urlopen

# Get final folder name
folder_name = sys.argv[1]
# Uncomment the following line to change from a drive letter to a SMB share !!Note - I have not tested this!!
# folder_name=folder_name.replace('Y:\', '\\Servername\Sharename\')
folder_name=folder_name.replace(' ', '%20')

# timeout in seconds
socket.setdefaulttimeout(10)
# Get clean NZB name
job_name = sys.argv[3]
# Set Prowl API
API = "XXXXXX"
# Set Prowl priority
priority = "0"
# Set job title/event name
job_title = "Download%20Complete"

# Get current date/time and strip spaces
from time import gmtime, strftime
event_time = strftime("%d/%m/%y %H:%M")
event_time=event_time.replace(' ', '%20')

# Strip illegal/unwanted chars from NZB name
job_name=job_name.replace(' ', '%20')
job_name=job_name.replace('_', '%20')
job_name=job_name.replace('.', '%20')

# Send download complete notification to Prowl - swap 'job_title' for 'event_time' if time is required in message instead of 'download complete'
# -- Prowl not needed for me, so commented out ---
#prowl=urllib2.Request("https://prowl.weks.net/publicapi/add?apikey=" + API + "&priority=" + priority + "&application=SABnzbd&event=" + job_title + "&description=" + job_name)
#try: urllib2.urlopen(prowl)
#except URLError, e:
#        print 'Prowl Failed'
# End Prowl

# Send notification to XBMC1 & Update Library
xbmc1=urllib2.Request("http://[IP Address:Port]/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(" + job_title + "," + job_name + ",20000,c:\sabnzbd.jpg))")
try: urllib2.urlopen(xbmc1)
except URLError, e:
        print 'XBMC1 Failed'
else:
        urllib2.urlopen("http://[IP Address:Port]/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video," + folder_name + "\)")

# End XBMC1

# Send notification to XBMC2 & Update Library    
xbmc2=urllib2.Request("http://[IP Address:Port]/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(" + job_title + "," + job_name + ",20000,c:\sabnzbd.jpg))")
try: urllib2.urlopen(xbmc2)
except URLError, e:
        print 'XBMC2 Failed'
else:
        urllib2.urlopen("http://[IP Address:Port]/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video," + folder_name + "\)")

# End XBMC2
please note i commented prowl out as i dont require this.

original post: http://forums.sabnzbd.org/http://forums ... 147#p22147

Re: XBMC Library Updater

Posted: January 13th, 2010, 10:51 am
by calmdown
thanks for your reply, xbmclive is however a stripped down ubuntu linux version.

If i execute the command in a terminal window:

Code: Select all

$ python /mnt/xbmc-internal/downloads/py/library.py
witch is the path to my script, xbmc also updates just fine, so it seems like there is noting wrong with my actual script either, this is weird

well, eventually it will work i guess :)

EDIT: also if i search the sabnzbd logfile for something that would point me to either the actual script "library.py" or the path, nothing comes up, dunno if such things are supposed to be seen in the logfile tho.

also fron the wiki:

Code: Select all

The script will receive these parameters. Use %1 in Windows scripts and $1 in Unix scripts.

Please note that in Windows the parameters will be enclosed in double quotes ("my name").
In Posix systems (OSX, Linux, Unix) the parameters will not have quotes at all.
This is somewhat unclear to me, can someone please explain.. maybe afterall there is some kind of error in my script that sab cant read.

EDIT2: I simply forgot to tell it to use python, finished code looks like this:

Code: Select all

#!/usr/bin/python
import urllib

urllib.urlopen("http://192.168.1.4:8081/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))").close()
EDIT3: lol, its not working now either, sab simply says:

Exit(-1) Cannot run script /home/xbmc/script/library.py

It is the right path, script is chmod'ed to 755, im all out of ideas.

Re: XBMC Library Updater

Posted: January 19th, 2010, 6:47 am
by JohnSCS
I haven't spent much time with SAB or XBMC running on Linux - I focus mainly on WinXP.

check here http://forums.sabnzbd.org/http://forums ... 359#p21359 for some assistance - your not alone :)

I think it's permissions.

Re: XBMC Library Updater

Posted: January 20th, 2010, 1:44 pm
by calmdown
Read that thread, but nothing helped me..

Why is this so hard? I mean, i for sure have no clue about coding and stuff... but like open a http string and execute a command, makes me sick to think of how much time i have spent googling for python support in general.

I'll try again, this is what i got so far:

Code: Select all

#!/usr/bin/python

import urllib
urllib.urlopen("http://192.168.1.4:8081/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))").close()
after adding that script in sab, i performed this in a terminal:

Code: Select all

sudo chmod +x library.py
still all i get is this error message is sab:

Code: Select all

Exit(-1) Cannot run script /home/xbmc/script/library.py
Executing this script directly from terminal updates library just fine, running the adress from a webbrowser also updates the library fine.

this is ridiculous lol, i've encountered lots of computer related problems that seems more difficult than this, but still....

anyone just gotta know what to do?

Re: XBMC Library Updater

Posted: February 8th, 2010, 9:02 am
by jason32835
I'm having the exact same issue. Everything was working fine before I upgraded to "Karmic". I wonder what that could have to do with it?

Re: XBMC Library Updater

Posted: February 16th, 2010, 10:23 pm
by SlackMaster
I don't know if this is the easiest way, but if you're running sabnzbd+ on a windows machine like I am, this worked for me.

Make one file called UpdateLibrary.cmd

Code: Select all

cd \programfiles\sabnzbd\scripts\
update.py
Then make a file called update.py with

Code: Select all

import urllib
urllib.urlopen("http://username:[email protected]:8081/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))").close()
put both files in your script directory.

Then go to the categories section and set it to run the .cmd file you created whenever you want to update the library.

Re: XBMC Library Updater

Posted: February 17th, 2010, 7:09 am
by JohnSCS
@jason32835

Something broke when you upgraded to Karmic - there seems to be mixed results with python in Karmic (and not just with SAB) - try reinstalling python 2.6 libraries.


@SlackMaster

If you are having issues running scripts from SAB, but they run Ok from the command line, make sure that you have no spaces in the path.
ie. do not have c:\program files\sabnzbd\scripts
use c:\scripts

Anything after a space in the file path is treated as an argument.

Re: XBMC Library Updater

Posted: February 24th, 2010, 10:29 am
by Shady
I have built growl/xbmc/email/gtalk(/jabber)/rss notification support in my program "postman" written in java.
I was wondering if anyone would like a wake on lan before update and shutdown/suspend action to be sent?
For example your mediacenter isn't on and you want to update it's library:

SEND WOL packet to XBMC instance.
wait for predefined time...
SEND Notification "Xbmc has been remotely started to update it's library. "
SEND action "updatelibrary(video)"
SEND shutdown/suspend.

Would this feature be desired by any of you?