Re: XBMC Library Updater
Posted: November 4th, 2010, 10:02 pm
Thanks guys for taking this further. I've since switched to XBMC Live and will be trying out wget command.
Code: Select all
[code][code]import urllib
urllib.urlopen("xbmcaddress/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video)").close()
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 + "\)")
Code: Select all
urllib2.urlopen("http://192.168.0.2:80/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video," + folder_name + "\)")
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
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
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 + ")")
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 + ")")