2011-02-09, 21:42
I have been working on a small utility script to grab some information that is not readily available via labels. What I thought should be relatively easy has got me totally stumped. I would very very much appreciate if someone could look at my code and see where I've messed up, or any suggestions to make it easier/better.
That's what I have. The idea is that the script will be passed the ActorID from XBMC, execute the SQL query and return all the movies that the actor has appeared in.
I'm confident the SQL is right, but for the life of me I can't get this working. Any help will be very much appreciated and get total credit for the solution. I eventually want to turn this into a bit of a utility script, with a few of these calls to grab information that isn't available in places that I need it.
Thanks!!!!!!
Blacklist
PHP Code:
import xbmc
from xbmcgui import Window
from urllib import quote_plus, unquote_plus
import urllib
import re
import sys
import os
from traceback import print_exc
class Main:
# grab the home window
WINDOW = Window( 10000 )
def _parse_argv( self ):
try:
# parse sys.argv for params
params = dict( arg.split( "=" ) for arg in sys.argv[ 1 ].split( "&" ) )
except:
# no params passed
params = {}
# set our preferences
self.ACTOR = int( params.get( "actorID", "5" ) )
def __init__( self ):
self._parse_argv()
#print "### Actor: %s" % self.ACTOR
self._fetch_movie_info()
def _fetch_movie_info( self ):
# sql statement for most watched
sql_movies = "SELECT t1.strRole, t2.c09, t2.c00, t2.strFileName, t2.strPath FROM actorlinkmovie t1 LEFT JOIN movieview AS t2 ON t1.idMovie = t2.idMovie WHERE t1.idActor=%d" % (self.ACTOR, )
print "### SQL: %s" % sql_movies
# query the database
movies_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_movies ), )
# separate the records
movies = re.findall( "<record>(.+?)</record>", movies_xml, re.DOTALL )
# enumerate thru our records and set our properties
for count, movie in enumerate( movies ):
# separate individual fields
fields = re.findall( "<field>(.*?)</field>", movie, re.DOTALL )
# set properties
print "### %s - %s" % (fields[ 2 ] ,fields[ 26 ])
self.WINDOW.setProperty( "ActorAppearances.%d.ActorRole" % ( count + 1, ), fields[ 1 ] )
self.WINDOW.setProperty( "ActorAppearances.%d.MovieTitle" % ( count + 1, ), fields[ 3 ] )
self.WINDOW.setProperty( "ActorAppearances.%d.MoviePoster" % ( count + 1, ), fields[ 2 ] )
self.WINDOW.setProperty( "ActorAppearances.%d.FileName" % ( count + 1, ), fields[ 4 ] )
self.WINDOW.setProperty( "ActorAppearances.%d.FilePath" % ( count + 1, ), fields[ 5 ] )
if ( __name__ == "__main__" ):
Main()
That's what I have. The idea is that the script will be passed the ActorID from XBMC, execute the SQL query and return all the movies that the actor has appeared in.
I'm confident the SQL is right, but for the life of me I can't get this working. Any help will be very much appreciated and get total credit for the solution. I eventually want to turn this into a bit of a utility script, with a few of these calls to grab information that isn't available in places that I need it.
Thanks!!!!!!
Blacklist