XBMC Library Updater

Come up with a useful post-processing script? Share it here!
User avatar
interfacelift
Jr. Member
Jr. Member
Posts: 75
Joined: June 19th, 2008, 12:58 am
Location: Coruscant

Re: XBMC Library Updater

Post by interfacelift »

Open up Terminal, navigate to the script, and type "chmod +x scriptname.sh" to allow execution.
bigdaddyo811
Newbie
Newbie
Posts: 20
Joined: October 22nd, 2008, 10:15 am

Re: XBMC Library Updater

Post by bigdaddyo811 »

Thanks. Did that. Get:

External processing by /users/MCM/Library/Scripts/plexscript.sh:
/users/MCM/Library/Scripts/plexscript.sh: /users/MCM/Library/Scripts/plexscript.sh: cannot execute binary file


?
User avatar
interfacelift
Jr. Member
Jr. Member
Posts: 75
Joined: June 19th, 2008, 12:58 am
Location: Coruscant

Re: XBMC Library Updater

Post by interfacelift »

bigdaddy, is your script attempting to update XBMC/Plex? If so, you'll have to make sure it's a true shell script.

This is what I use for Plex (Plex is running on my LAN at 192.168.0.20):

Code: Select all

#!/bin/bash
echo "Updating Plex"
curl --get "http://192.168.0.20:3000/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)" > /dev/null 2>&1
Copy and paste that in to a text file and save it in your scripts folder, then chmod +x it, and set SAB to use it.
tbird2340
Newbie
Newbie
Posts: 20
Joined: December 19th, 2008, 3:10 pm

Re: XBMC Library Updater

Post by tbird2340 »

Can anyone help me get this working for the XBMC Windows port? It doens't have the FTP option on the Windows version so I'm stuck on what to do.. I seen someone posted this:

Code: Select all

import urllib

urllib.urlopen("xbmcaddress/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)").close()


And then said to call it from the cmd file but I'm not sure how to do that.. I'm totally new to XBMC.. So I put all that code above in a .py file but then what? What command do I put in the "updatelibrary.cmd" file? And where to I put the .py file?

Thanks much!
BrandonG777
Jr. Member
Jr. Member
Posts: 79
Joined: February 9th, 2009, 5:21 pm
Location: Tulsa, OK

Re: XBMC Library Updater

Post by BrandonG777 »

tbird2340 wrote: Can anyone help me get this working for the XBMC Windows port? It doens't have the FTP option on the Windows version so I'm stuck on what to do.. I seen someone posted this:

Code: Select all

import urllib

urllib.urlopen("xbmcaddress/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)").close()


And then said to call it from the cmd file but I'm not sure how to do that.. I'm totally new to XBMC.. So I put all that code above in a .py file but then what? What command do I put in the "updatelibrary.cmd" file? And where to I put the .py file?

Thanks much!
Ok, first bit of advise, ditch Windows and load Ubuntu. However, if you're unwilling to do that the first thing you're going to need to do is find a python interpeter for Windows. http://www.python.org/download/windows/ That is what you'll use to run the .py file. The next bit is in the options of XBMC, you're not looking for FTP you're looking for HTTP.

Another options would to be find a Windows version of curl and use interfacelift's script. It would work as a .BAT file for windows. That's probably the way to go but like I said ditch Windows and you'll open yourself to infinite possibilities to make stuff run the way you want it to.
kulprit
Release Testers
Release Testers
Posts: 16
Joined: October 3rd, 2009, 12:41 am

Re: XBMC Library Updater

Post by kulprit »

Did you ever get this working as a script for windows? Just wondering if anyone has any ideas or instructions to get it going.
peteo
Newbie
Newbie
Posts: 13
Joined: October 24th, 2009, 12:25 pm

Re: XBMC Library Updater

Post by peteo »

interfacelift wrote: bigdaddy, is your script attempting to update XBMC/Plex? If so, you'll have to make sure it's a true shell script.

This is what I use for Plex (Plex is running on my LAN at 192.168.0.20):

Code: Select all

#!/bin/bash
echo "Updating Plex"
curl --get "http://192.168.0.20:3000/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)" > /dev/null 2>&1
Copy and paste that in to a text file and save it in your scripts folder, then chmod +x it, and set SAB to use it.
the Curl command does not seem to exist on AppleTV. Any one know how i might get this script to work on ATV?
peteo
Newbie
Newbie
Posts: 13
Joined: October 24th, 2009, 12:25 pm

Re: XBMC Library Updater

Post by peteo »

peteo wrote: the Curl command does not seem to exist on AppleTV. Any one know how i might get this script to work on ATV?
Ok i figured this out. If you want to run this locally on your apple TV create this script save as .sh and put it into your scripts folder. Have SABnbzd call it when something is downloaded.

Code: Select all

#!/bin/sh
wget "http://xbmc:[email protected]:8081/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)" >/dev/null 2>&1
JohnSCS
Newbie
Newbie
Posts: 42
Joined: August 17th, 2009, 12:23 am

Re: XBMC Library Updater + XBMC Notification + Prowl

Post by JohnSCS »

My latest Pyhton script for updating the XBMC library, XBMC on screen notification & Prowl notification of completed downloads

SAB 0.4.12 (should work but untested on 0.5.0B1) 0.5.0B4
WinXp SP3
Python IDLE 2.6.4 (will not work with Python 3.0+)

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

# 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=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)")
# 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)")
# End XBMC2
Save the above code as update.py (or whatever you like) to the scripts directory, and save the SABNZBD image to the root of c: drive. Set your Prowl API key and IP address details of your XBMC's, and set this as your default script or as needed in your categories/RSS filters.

When this script runs, firstly the Prowl notification is sent, then XBMC1 on screen notification is sent - if this is successful, then the library update command is sent. Then, same again for XBMC2.

Because of the need to install Python 2.6, this script therefore can be run from the command line or other files aswell, but only reads variable #3 that is passed to it.
Last edited by JohnSCS on December 23rd, 2009, 6:49 am, edited 1 time in total.
seanseymour
Newbie
Newbie
Posts: 2
Joined: September 20th, 2009, 5:44 pm

Re: XBMC Library Updater + XBMC Notification + Prowl

Post by seanseymour »

JohnSCS wrote: My latest Pyhton script for updating the XBMC library, XBMC on screen notification & Prowl notification of completed downloads

SAB 0.4.12 (should work but untested on 0.5.0B1)
WinXp SP3
Python IDLE 2.6.4 (will not work with Python 3.0+)

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

# 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=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)")
# 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)")
# End XBMC2
Save the above code as update.py (or whatever you like) to the scripts directory, and save the SABNZBD image to the root of c: drive. Set your Prowl API key and IP address details of your XBMC's, and set this as your default script or as needed in your categories/RSS filters.

When this script runs, firstly the Prowl notification is sent, then XBMC1 on screen notification is sent - if this is successful, then the library update command is sent. Then, same again for XBMC2.

Because of the need to install Python 2.6, this script therefore can be run from the command line or other files aswell, but only reads variable #3 that is passed to it.
I've set up basically the same thing except my library update includes the folder as the second, optional parameter.

If you run xbmc on the same machine as sabnzbd it will be pretty easy to include the folder but, since I run mine via an SMB share I had to change D:\Series\ShowTitle\Season\Show.avi To smb:\\servername\sharename\Series\ShowTitle\Season\Show.avi

Since my library is pretty large, a full update can take several minutes. This way, the updates are almost instant.
kulprit
Release Testers
Release Testers
Posts: 16
Joined: October 3rd, 2009, 12:41 am

Re: XBMC Library Updater

Post by kulprit »

Can you give some more info on how to edit JohnSCS script to only update the show that has been added. Also thanks for the original JohnSCS, works great so far.
weldon
Release Testers
Release Testers
Posts: 21
Joined: October 29th, 2009, 3:22 pm

Re: XBMC Library Updater

Post by weldon »

kulprit wrote: Can you give some more info on how to edit JohnSCS script to only update the show that has been added. Also thanks for the original JohnSCS, works great so far.
Also looking for the same thing. Looks like the perfect script for my needs
WP7 Sabnzbd/NZBMatrix/Newzbin App: Sab Watch http://forums.sabnzbd.org/index.php?topic=5556.0
JohnSCS
Newbie
Newbie
Posts: 42
Joined: August 17th, 2009, 12:23 am

Re: XBMC Library Updater

Post by JohnSCS »

To get the script to only update only the show downloaded, add the following changes

Note : This uses the path set in SAB. ie, SAB places my TV Series in Y:\2..TV Series\Show Name\Season which is the exact path XBMC uses. Both SAB & XBMC runs on the same PC. If your XBMC library uses a different share to get to the same location, the drive mapping needs to be changed to a \\server name\share name. I have not tested this, and it may not work as expected and could double up your shows.


Add this

Code: Select all

# 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')
Just after

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
Then change

Code: Select all

        urllib2.urlopen("http://[IP Address:Port]/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)")
to

Code: Select all

        urllib2.urlopen("http://[IP Address:Port]/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video," + folder_name + "\)")

FYI : Win XP SP3 running SAB 0.5.0B4
Last edited by JohnSCS on December 19th, 2009, 8:53 am, edited 1 time in total.
weldon
Release Testers
Release Testers
Posts: 21
Joined: October 29th, 2009, 3:22 pm

Re: XBMC Library Updater

Post by weldon »

Just wanted to thank you JohnSCS, finally got your script working and it works great! Thanks again :) Is making the same script for music as simple as changing the word video in the call to music? 
WP7 Sabnzbd/NZBMatrix/Newzbin App: Sab Watch http://forums.sabnzbd.org/index.php?topic=5556.0
JohnSCS
Newbie
Newbie
Posts: 42
Joined: August 17th, 2009, 12:23 am

Re: XBMC Library Updater

Post by JohnSCS »

Change Video to Music in the update library command. The XBMC HTTP API only mentions the ability to update a specific path (not the whole library) for the Video library. But in saying that, the Wiki hasn't been updated for a while and XBMC may now support it.

I'm glad people are finding this script useful. SAB, XBMC & Prowl have become a fantastic combination.
Post Reply