XBMC Library Updater
Re: XBMC Library Updater
Thanks guys for taking this further. I've since switched to XBMC Live and will be trying out wget command.
-
- Newbie
- Posts: 15
- Joined: October 12th, 2009, 10:16 am
Re: XBMC Library Updater
Anyone good with Python able to do me a favour?
I need a .py script that will run sabToSickBeard.exe with the correct parameters passed from Sab, and then after a delay of 60 seconds, call: http://media1/xbmcCmds/xbmcHttp?command ... 28video%29
This is all from a windows environment - so could happily use something other than .py providing sab will recognise it as a script and do the above?
I need a .py script that will run sabToSickBeard.exe with the correct parameters passed from Sab, and then after a delay of 60 seconds, call: http://media1/xbmcCmds/xbmcHttp?command ... 28video%29
This is all from a windows environment - so could happily use something other than .py providing sab will recognise it as a script and do the above?
Last edited by ReflexReaction on December 15th, 2010, 3:27 pm, edited 1 time in total.
Re: XBMC Library Updater
Code: Select all
[code][code]import urllib
urllib.urlopen("xbmcaddress/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video)").close()
Last edited by kLAcK on December 20th, 2010, 7:48 pm, edited 1 time in total.
Re: XBMC Library Updater
been quiet here for a while, anyway can someone help me out, I'm getting error msg below when running JohnSCS python script in SAB. I am calling the updateXBMC2.py file direcly in SAB if this makes any diference? Do I have to make a .cmd file to call it??
line 46 is this:
Running:
Win7
Python2.6.4
SABnzbd Version: 0.6.5
Thanks
Code: Select all
File "C:\scripts\updateXBMC2.py", line 46
SyntaxError: Non-ASCII character '\xb6' in file C:\scripts\updateXBMC2.py on line 46, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Code: Select all
urllib2.urlopen("http://[192.168.0.2:80]/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video," + folder_name + "\)")
Win7
Python2.6.4
SABnzbd Version: 0.6.5
Thanks
Re: XBMC Library Updater
Nooz,
The line should read
I'm not currently running 0.6.5 on Win7 (not that it makes any difference to the script), but from what you posted, the command does have an error.
The line should read
Code: Select all
urllib2.urlopen("http://192.168.0.2:80/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video," + folder_name + "\)")
-
- Newbie
- Posts: 3
- Joined: August 12th, 2011, 12:11 pm
Re: XBMC Library Updater
JohnSCS,
First of all I'd like to thank you for your script. About a year ago I had it running and it was wonderful to see XBMC updated automatically whenever I had a new file downloaded. I am having a bit of a dilemma right now though...
I've been trying to get your script to work on SAB 0.6.5 on Windows 7 to no avail. I feel like I'm doing everything right but somehow it always fails. My 2 XBMC PC's are both running on port 80, username and password are just "xbmc" and I can even see the notification if I copy and paste that line into my browser for either system. I am not using the Prowl portion and XBMC1 and XBMC2 fail whether it's commented out or not. I'm I doing something wrong? Any assistance you could provide me with would be greatly appreciated.
It should be noted that I am running python 2.6.4 as well.
Thanks!
First of all I'd like to thank you for your script. About a year ago I had it running and it was wonderful to see XBMC updated automatically whenever I had a new file downloaded. I am having a bit of a dilemma right now though...
I've been trying to get your script to work on SAB 0.6.5 on Windows 7 to no avail. I feel like I'm doing everything right but somehow it always fails. My 2 XBMC PC's are both running on port 80, username and password are just "xbmc" and I can even see the notification if I copy and paste that line into my browser for either system. I am not using the Prowl portion and XBMC1 and XBMC2 fail whether it's commented out or not. I'm I doing something wrong? Any assistance you could provide me with would be greatly appreciated.
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://192.168.0.123:80/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://192.168.0.123:80/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video)")
# End XBMC1
# Send notification to XBMC2 & Update Library
xbmc2=urllib2.Request("http://192.168.0.124:80/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://192.168.0.124:80/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video)")
# End XBMC2
Thanks!
-
- Newbie
- Posts: 1
- Joined: September 7th, 2011, 9:01 pm
Re: XBMC Library Updater
kLAcK wrote:Here is a simple script I wrote to automatically update your XBMC library when a download is complete.
Create these two files in the following directories:
C:\Program Files\sabnzbd\updatelibrary.scrReplace with your XBMC IP address and username and passwordCode: Select all
open 192.168.0.110 username password literal site updatelibrary(video) quit
C:\Program Files\sabnzbd\scripts\updatelibrary.cmdPrerequisites:Code: Select all
ftp -s:updatelibrary.scr
Now every time you download a TV show or Movie, it will automatically be added to your XBMC library. If you don't keep your Xbox on all the time, turn on the "Update library at startup" feature.
- Assign a static IP to XBMC, and enable FTP
- Setup Categories in SAB, enter a unique download folder for TV and one for Movies
- i.e. D:\Video\TV and D:\Video\Movies
- In XBMC assign a media type to the TV folder and Movies folder
Re: XBMC Library Updater
Great script. But for large libraries, it will take a while to update.
This was factored into my script so it only updates the specific TV Series or Movie.
Nether the less, always appreciate seeing variations.
This was factored into my script so it only updates the specific TV Series or Movie.
Nether the less, always appreciate seeing variations.
-
- Newbie
- Posts: 3
- Joined: August 12th, 2011, 12:11 pm
Re: XBMC Library Updater
JohnSCS
Any thoughts on my previous post (up about 3-4 posts) on the issues I'm having?
Thanks!
Any thoughts on my previous post (up about 3-4 posts) on the issues I'm having?
Thanks!
Re: XBMC Library Updater
violentsingalong
Sorry for the delay.
The script looks OK, and the fact that the commands work with a browser is promising.
I assume that the script is running and replies with 'XBMC1 Failed', etc, not that the script itself has failed.
Try removing the password from your XBMC's - as the script stands, it does not support authentication for XBMC - you would need to add the username and password into the HTTP request like http://xbmc:[email protected]:80/.......
I will be upgrading to 0.6.5 today (if it works don't break it has kept me on 0.5.6 - it has served me very well)
UPDATE #1 - Win7 64Bit, Python 2.6.4, SAB 0.6.5 - All working OK - same script with no changes (running on 0.5.6) works with 0.6.5.
UPDATE #2 - Win7 64Bit, Python 2.6.4, SAB 0.6.8 - All working OK
SAB 0.6.6+ needs .PY added to the PATHEXT variable in Win7 to support python scripts.
My Latest Code Version
Sorry for the delay.
The script looks OK, and the fact that the commands work with a browser is promising.
I assume that the script is running and replies with 'XBMC1 Failed', etc, not that the script itself has failed.
Try removing the password from your XBMC's - as the script stands, it does not support authentication for XBMC - you would need to add the username and password into the HTTP request like http://xbmc:[email protected]:80/.......
I will be upgrading to 0.6.5 today (if it works don't break it has kept me on 0.5.6 - it has served me very well)
UPDATE #1 - Win7 64Bit, Python 2.6.4, SAB 0.6.5 - All working OK - same script with no changes (running on 0.5.6) works with 0.6.5.
UPDATE #2 - Win7 64Bit, Python 2.6.4, SAB 0.6.8 - All working OK
SAB 0.6.6+ needs .PY added to the PATHEXT variable in Win7 to support python scripts.
My Latest Code Version
Code: Select all
# Python 2.6.4 | http://www.python.org/download/releases/2.6.4/
import socket,sys,urllib2,os
from urllib2 import Request, URLError, urlopen
# Get final folder name
full_path = sys.argv[1]
# Split into drive and folder names
full_path=full_path.split("\\")
# Shorten folder_name by removing Season folder (eg S:\TV Series\Showname\Season 1\ to S:\TV Series\Showname\)
# This helped fix some issues with episodes not being added to library
folder_name=full_path[0] + "\\" + full_path[1] + "\\" + full_path[2] + "\\" + full_path[3] + "\\"
print folder_name
# As SAB runs on my NAS, use the following line to change from a drive letter to a SMB share
folder_name=folder_name.replace('S:', 'SMB://NAS/RAID')
# Make folder_name URL friendly
folder_name=folder_name.replace(' ', '%20')
print folder_name
# HTTP timeout in seconds
socket.setdefaulttimeout(10)
# Get clean NZB name
job_name = sys.argv[3]
# Get category name
category_name = sys.argv[4]
# Set Prowl API
API = "XXXX"
# Set Prowl priority
priority = "0"
# Set Prowl job title/event name
job_title = "Download%20Complete"
# Rename the movie file to match the folder (job) name - ** Thanks to rudyb **
# Get the Newzbin category
cat = sys.argv[4]
# Get the folder name again
ugly_folder = sys.argv[1]
# Get the job name
ugly_jobname = sys.argv[3]
# Set movie (and related) file extensions. These are filetypes we care about. Add more if you want those renamed, too
movie_extensions = ['avi', 'mkv', 'wmv', 'ts', 'img', 'iso', 'sub', 'idx', 'srt']
print cat
def ext_count(file_list):
# Create the extensions dictionary
extensions = {}
# Loop through the file list to make a list of extensions and how many there are of each
for filename in file_list:
# Split filename by period
ext = filename.split('.')
# Get the file extension
ext = ext[-1]
# Check if the extension exists in the array list yet
if extensions.has_key(ext):
extensions[ext] = extensions[ext] + 1
# If so, add one to the existing entry
else:
# Otherwise, create the list entry
extensions[ext] = 1
return extensions
# Apply this to movies only
if (cat == "movies"):
# Make an empty dictionary for counting how many we've renamed of each extension
ext_tally = {}
# Make a list (downloaded_files) containing all of the downloaded files
downloaded_files = sorted(os.listdir(ugly_folder))
# Create a dictionary of extensions (the key) and the number of each (the value)
extensions = ext_count(downloaded_files)
# Loop through the list of downloaded files
for filename in downloaded_files:
# We don't know if this file is relevant to our interests
is_video = 0
# See if the ext matches one we care about. Loop through movie_extensions
for mov_ext in movie_extensions:
# See if the filename ends with a relevant extension
if filename.endswith('.' + mov_ext):
# Flag the file as relevant
is_video = 1
# Stop checking (theoretically, it shouldn't have more than one extension)
break
# If we determined that the file was relevant...
if is_video == 1:
# Start building the new filename
new_filename = ugly_jobname
# Get the extension of the file
file_extension = filename.split('.')[-1]
# Check to see if there was more than one of that extension
if extensions[file_extension] > 1:
# If so, add " - CD" to the end
new_filename = new_filename + ' - CD'
# Check to see if we've already renamed one file with this extension
if ext_tally.has_key(file_extension):
# If so, add one to the count
ext_tally[file_extension] = ext_tally[file_extension] + 1
else:
# If not, create a counter and set it to 1
ext_tally[file_extension] = 1
# Then append that number to the end of the filename
new_filename = new_filename + str(ext_tally[file_extension])
# Finally, add the extension
new_filename = new_filename + '.' + file_extension
# See if the new filename and the old filename match
if filename == new_filename:
# If so, end this iteration without renaming, and say so:
print "Filenames are the same. Not renaming"
continue
# Uncomment this line to print the original filename and new filename
print 'Renaming ' + filename + ' to ' + new_filename
# Last, but not least, rename the file
os.rename(ugly_folder + '\\' + filename, ugly_folder + '\\' + new_filename)
# 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 iPhone - 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'
# Lounge Room XBMC Live PC. Note the different path for the JPG image when using AppleTV XBMC.
xbmc3=urllib2.Request("http://192.168.0.5:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(" + job_title + "," + job_name + ",20000,/Applications/XBMC.frappliance/sabnzbd.jpg))")
try: urllib2.urlopen(xbmc3)
except URLError, e:
print 'Lounge Room XBMC Failed'
else:
urllib2.urlopen("http://192.168.0.5:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video," + folder_name + ")")
Re: XBMC Library Updater
Spoke a little too soon. Found that the movies were not being renamed due to the user defined category argument being changed.
Note 1:- I have used the movie sorting feature in SAB with this script and found that it works well as the movie folder gets a nice clean name for the XBMC scrapper, and the movie file gets the NZB file clean name preserving the media tags for quick identification when browsing through the folders.
Note 2:- I do not use passwords on the XBMC HTTP API.
Note 3:- To keep things simple, this script is stored in c:\scripts
Fully tested on SAB 0.6.8 with Python 2.6.4 and Win7 64Bit.
1x Apple TV 2 running XBMC
1x HP Desktop running XBMC Live
So here is the new and improved script. Please enjoy.
Note 1:- I have used the movie sorting feature in SAB with this script and found that it works well as the movie folder gets a nice clean name for the XBMC scrapper, and the movie file gets the NZB file clean name preserving the media tags for quick identification when browsing through the folders.
Note 2:- I do not use passwords on the XBMC HTTP API.
Note 3:- To keep things simple, this script is stored in c:\scripts
Fully tested on SAB 0.6.8 with Python 2.6.4 and Win7 64Bit.
1x Apple TV 2 running XBMC
1x HP Desktop running XBMC Live
So here is the new and improved script. Please enjoy.
Code: Select all
# Python 2.6.4 | http://www.python.org/download/releases/2.6.4/
#
# This version is for SAB 0.6.5+ and has been fully tested with SAB 0.6.8
#
# OS - Win7 64Bit
#
#
# Note:- SAB 0.6.6+ needs .PY added to the PATHEXT environment variable in Win7 to support python scripts.
#
#
import socket,sys,urllib2,os
from urllib2 import Request, URLError, urlopen
# Get final folder name
full_path = sys.argv[1]
# Split into drive and folder names
full_path=full_path.split("\\")
# Shorten folder_name by removing Season folder (eg S:\TV Series\Showname\Season 1\ to S:\TV Series\Showname\)
# This helped fix some issues with episodes not being added to library
folder_name=full_path[0] + "\\" + full_path[1] + "\\" + full_path[2] + "\\" + full_path[3] + "\\"
print
print "Download Location - " + folder_name
# Uncomment the following line to change from a drive letter to a SMB share
folder_name=folder_name.replace('S:', 'SMB://NAS/RAID')
# Make folder_name URL friendly
folder_name=folder_name.replace(' ', '%20')
print "XBMC Mapped Location - " + folder_name
# HTTP timeout in seconds
socket.setdefaulttimeout(10)
# Get clean NZB name
job_name = sys.argv[3]
# Get category name
category_name = sys.argv[5]
# Set Prowl API
API = "XXXXXXXX"
# Set Prowl priority
priority = "0"
# Set Prowl job title/event name
job_title = "Download%20Complete"
# Rename the movie file to match the folder (job) name - ** Thanks to rudyb **
# Get the folder name again
ugly_folder = sys.argv[1]
# Get the job name
ugly_jobname = sys.argv[3]
# Set movie (and related) file extensions. These are filetypes we care about. Add more if you want those renamed, too
movie_extensions = ['avi', 'mkv', 'wmv', 'ts', 'img', 'iso', 'sub', 'idx', 'srt']
print "User Category - " + category_name
def ext_count(file_list):
# Create the extensions dictionary
extensions = {}
# Loop through the file list to make a list of extensions and how many there are of each
for filename in file_list:
# Split filename by period
ext = filename.split('.')
# Get the file extension
ext = ext[-1]
# Check if the extension exists in the array list yet
if extensions.has_key(ext):
extensions[ext] = extensions[ext] + 1
# If so, add one to the existing entry
else:
# Otherwise, create the list entry
extensions[ext] = 1
return extensions
# Apply this to movies only. I have an extra movie category for kids movies that are stored in a sepearte directory
# if you only have the one movie category, uncomment the next line and comment the line after
# if (category_name=="movies"):
if ((category_name=="movies")or(category_name=="mixed movies")):
# Make an empty dictionary for counting how many we've renamed of each extension
ext_tally = {}
# Make a list (downloaded_files) containing all of the downloaded files
downloaded_files = sorted(os.listdir(ugly_folder))
# Create a dictionary of extensions (the key) and the number of each (the value)
extensions = ext_count(downloaded_files)
# Loop through the list of downloaded files
for filename in downloaded_files:
# We don't know if this file is relevant to our interests
is_video = 0
# See if the ext matches one we care about. Loop through movie_extensions
for mov_ext in movie_extensions:
# See if the filename ends with a relevant extension
if filename.endswith('.' + mov_ext):
# Flag the file as relevant
is_video = 1
# Stop checking (theoretically, it shouldn't have more than one extension)
break
# If we determined that the file was relevant...
if is_video == 1:
# Start building the new filename
new_filename = ugly_jobname
# Get the extension of the file
file_extension = filename.split('.')[-1]
# Check to see if there was more than one of that extension
if extensions[file_extension] > 1:
# If so, add " - CD" to the end
new_filename = new_filename + ' - CD'
# Check to see if we've already renamed one file with this extension
if ext_tally.has_key(file_extension):
# If so, add one to the count
ext_tally[file_extension] = ext_tally[file_extension] + 1
else:
# If not, create a counter and set it to 1
ext_tally[file_extension] = 1
# Then append that number to the end of the filename
new_filename = new_filename + str(ext_tally[file_extension])
# Finally, add the extension
new_filename = new_filename + '.' + file_extension
# See if the new filename and the old filename match
if filename == new_filename:
# If so, end this iteration without renaming, and say so:
print "Filenames are the same. Not renaming"
continue
# Uncomment this line to print the original filename and new filename
print 'Renaming ' + filename + ' to ' + new_filename
# Last, but not least, rename the file
os.rename(ugly_folder + '\\' + filename, ugly_folder + '\\' + new_filename)
# 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 iPhone - 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'
# Send notification to XBMC on Apple TV2 and update library
xbmc2=urllib2.Request("http://192.168.0.6:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(" + job_title + "," + job_name + ",20000,/Applications/XBMC.frappliance/sabnzbd.jpg))")
try: urllib2.urlopen(xbmc2)
except URLError, e:
print 'Kids XBMC Failed'
else:
urllib2.urlopen("http://192.168.0.6:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video," + folder_name + ")")
# Send notification to XBMC and update library
xbmc3=urllib2.Request("http://192.168.0.5:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(" + job_title + "," + job_name + ",20000,/home/xbmc/sabnzbd.jpg))")
try: urllib2.urlopen(xbmc3)
except URLError, e:
print 'Lounge Room XBMC Failed'
else:
urllib2.urlopen("http://192.168.0.5:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video," + folder_name + ")")
-
- Newbie
- Posts: 3
- Joined: August 12th, 2011, 12:11 pm
Re: XBMC Library Updater
JohnSCS,
Thank you very much for the assistance. It appears that even if I put the password in the URL as you mentioned it still wouldn't work. Simply taking the password out (and deleting the password in XBMC) made it work.
Regards,
violentsingalong
Thank you very much for the assistance. It appears that even if I put the password in the URL as you mentioned it still wouldn't work. Simply taking the password out (and deleting the password in XBMC) made it work.
Regards,
violentsingalong
Re: XBMC Library Updater
It looks like the HTTP API is deprecated and doesn't work with the Dharma release (I get a unknown command error now).
Looks like it's being replaced with JSON RPC (here's the bit for updating the video library). I'm going to have to do a little reading to learn how to use it but if anyone is familiar with how it works it would be awesome if they put together a new update script
Looks like it's being replaced with JSON RPC (here's the bit for updating the video library). I'm going to have to do a little reading to learn how to use it but if anyone is familiar with how it works it would be awesome if they put together a new update script
Re: XBMC Library Updater
Ashex,
What version of XBMC are you running and what platform?
What version of XBMC are you running and what platform?
Re: XBMC Library Updater
I'm running 10.1 Dharma on Ubuntu Lucid (10.04.3).