acumulate change values with |= and dont set art if it is ""

This commit is contained in:
faush01 2015-03-20 10:48:59 +11:00
parent 5b65e1cfda
commit c38ecfa462
4 changed files with 83 additions and 45 deletions

View file

@ -50,7 +50,11 @@ class LibrarySync():
#what sync method to perform ? #what sync method to perform ?
if syncOption == "Full Sync": if syncOption == "Full Sync":
pr = utils.startProfiling()
self.MoviesSync(True) self.MoviesSync(True)
utils.stopProfiling(pr, "MoviesSync(True)")
self.TvShowsSync(True) self.TvShowsSync(True)
if syncOption == "Incremental Sync": if syncOption == "Incremental Sync":
self.MoviesSync(False) self.MoviesSync(False)

View file

@ -8,7 +8,9 @@ import xbmcaddon
import xbmcvfs import xbmcvfs
import json import json
import os import os
import cProfile
import pstats
import time
import sqlite3 import sqlite3
import inspect import inspect
from xml.etree.ElementTree import Element, SubElement, Comment, tostring from xml.etree.ElementTree import Element, SubElement, Comment, tostring
@ -24,11 +26,9 @@ addonSettings = xbmcaddon.Addon(id='plugin.video.mb3sync')
language = addonSettings.getLocalizedString language = addonSettings.getLocalizedString
def logMsg(title, msg, level = 1): def logMsg(title, msg, level = 1):
logLevel = int(addonSettings.getSetting("logLevel")) logLevel = int(addonSettings.getSetting("logLevel"))
if(logLevel >= level): if(logLevel >= level):
if(logLevel == 1): if(logLevel == 2): # inspect.stack() is expensive
try: try:
xbmc.log(title + " -> " + inspect.stack()[1][3] + " : " + str(msg)) xbmc.log(title + " -> " + inspect.stack()[1][3] + " : " + str(msg))
except UnicodeEncodeError: except UnicodeEncodeError:
@ -195,5 +195,35 @@ def get_params( paramstring ):
param[splitparams[0]]=splitparams[1]+"="+splitparams[2] param[splitparams[0]]=splitparams[1]+"="+splitparams[2]
return param return param
def startProfiling():
pr = cProfile.Profile()
pr.enable()
return pr
def stopProfiling(pr, profileName):
pr.disable()
ps = pstats.Stats(pr)
addondir = xbmc.translatePath(xbmcaddon.Addon(id='plugin.video.mb3sync').getAddonInfo('profile'))
fileTimeStamp = time.strftime("%Y-%m-%d %H-%M-%S")
tabFileNamepath = os.path.join(addondir, "profiles")
tabFileName = os.path.join(addondir, "profiles" , profileName + "_profile_(" + fileTimeStamp + ").tab")
if not xbmcvfs.exists(tabFileNamepath):
xbmcvfs.mkdir(tabFileNamepath)
f = open(tabFileName, 'wb')
f.write("NumbCalls\tTotalTime\tCumulativeTime\tFunctionName\tFileName\r\n")
for (key, value) in ps.stats.items():
(filename, count, func_name) = key
(ccalls, ncalls, total_time, cumulative_time, callers) = value
try:
f.write(str(ncalls) + "\t" + "{:10.4f}".format(total_time) + "\t" + "{:10.4f}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n")
except ValueError:
f.write(str(ncalls) + "\t" + "{0}".format(total_time) + "\t" + "{0}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n")
f.close()

View file

@ -94,48 +94,48 @@ class WriteKodiDB():
changes = False changes = False
#update artwork #update artwork
changes = self.updateArtWork(KodiItem,"poster", API().getArtwork(MBitem, "poster"),"movie") changes |= self.updateArtWork(KodiItem,"poster", API().getArtwork(MBitem, "poster"),"movie")
changes = self.updateArtWork(KodiItem,"clearlogo", API().getArtwork(MBitem, "Logo"),"movie") changes |= self.updateArtWork(KodiItem,"clearlogo", API().getArtwork(MBitem, "Logo"),"movie")
changes = self.updateArtWork(KodiItem,"clearart", API().getArtwork(MBitem, "Art"),"movie") changes |= self.updateArtWork(KodiItem,"clearart", API().getArtwork(MBitem, "Art"),"movie")
changes = self.updateArtWork(KodiItem,"banner", API().getArtwork(MBitem, "Banner"),"movie") changes |= self.updateArtWork(KodiItem,"banner", API().getArtwork(MBitem, "Banner"),"movie")
changes = self.updateArtWork(KodiItem,"landscape", API().getArtwork(MBitem, "Thumb"),"movie") changes |= self.updateArtWork(KodiItem,"landscape", API().getArtwork(MBitem, "Thumb"),"movie")
changes = self.updateArtWork(KodiItem,"discart", API().getArtwork(MBitem, "Disc"),"movie") changes |= self.updateArtWork(KodiItem,"discart", API().getArtwork(MBitem, "Disc"),"movie")
changes = self.updateArtWork(KodiItem,"fanart", API().getArtwork(MBitem, "Backdrop"),"movie") changes |= self.updateArtWork(KodiItem,"fanart", API().getArtwork(MBitem, "Backdrop"),"movie")
#update common properties #update common properties
duration = (int(timeInfo.get('Duration'))*60) duration = (int(timeInfo.get('Duration'))*60)
changes = self.updateProperty(KodiItem,"runtime",duration,"movie") changes |= self.updateProperty(KodiItem,"runtime",duration,"movie")
changes = self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie") changes |= self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
changes = self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie") changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
changes = self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie") changes |= self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie")
if MBitem.get("CriticRating") != None: if MBitem.get("CriticRating") != None:
changes = self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"movie") changes |= self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"movie")
changes = self.updateProperty(KodiItem,"plotoutline",MBitem.get("ShortOverview"),"movie") changes |= self.updateProperty(KodiItem,"plotoutline",MBitem.get("ShortOverview"),"movie")
changes = self.updateProperty(KodiItem,"set",MBitem.get("TmdbCollectionName"),"movie") changes |= self.updateProperty(KodiItem,"set",MBitem.get("TmdbCollectionName"),"movie")
changes = self.updateProperty(KodiItem,"sorttitle",MBitem.get("SortName"),"movie") changes |= self.updateProperty(KodiItem,"sorttitle",MBitem.get("SortName"),"movie")
if MBitem.get("ProviderIds") != None: if MBitem.get("ProviderIds") != None:
if MBitem.get("ProviderIds").get("Imdb") != None: if MBitem.get("ProviderIds").get("Imdb") != None:
changes = self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"movie") changes |= self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"movie")
# FIXME --> Taglines not returned by MB3 server !? # FIXME --> Taglines not returned by MB3 server !?
if MBitem.get("TagLines") != None: if MBitem.get("TagLines") != None:
changes = self.updateProperty(KodiItem,"tagline",MBitem.get("TagLines")[0],"movie") changes |= self.updateProperty(KodiItem,"tagline",MBitem.get("TagLines")[0],"movie")
changes = self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"movie") changes |= self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"movie")
changes = self.updatePropertyArray(KodiItem,"director",people.get("Director"),"movie") changes |= self.updatePropertyArray(KodiItem,"director",people.get("Director"),"movie")
changes = self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"movie") changes |= self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"movie")
if(studios != None): if(studios != None):
for x in range(0, len(studios)): for x in range(0, len(studios)):
studios[x] = studios[x].replace("/", "&") studios[x] = studios[x].replace("/", "&")
changes = self.updatePropertyArray(KodiItem,"studio",studios,"movie") changes |= self.updatePropertyArray(KodiItem,"studio",studios,"movie")
# FIXME --> ProductionLocations not returned by MB3 server !? # FIXME --> ProductionLocations not returned by MB3 server !?
self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"movie") changes |= self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"movie")
#trailer link #trailer link
trailerUrl = None trailerUrl = None
@ -145,10 +145,10 @@ class WriteKodiDB():
if(jsonData != ""): if(jsonData != ""):
trailerItem = json.loads(jsonData) trailerItem = json.loads(jsonData)
trailerUrl = "plugin://plugin.video.mb3sync/?id=" + trailerItem[0].get("Id") + '&mode=play' trailerUrl = "plugin://plugin.video.mb3sync/?id=" + trailerItem[0].get("Id") + '&mode=play'
changes = self.updateProperty(KodiItem,"trailer",trailerUrl,"movie") changes |= self.updateProperty(KodiItem,"trailer",trailerUrl,"movie")
#add actors #add actors
self.AddActorsToMedia(KodiItem,MBitem.get("People"),"movie") changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"movie")
CreateFiles().createSTRM(MBitem) CreateFiles().createSTRM(MBitem)
CreateFiles().createNFO(MBitem) CreateFiles().createNFO(MBitem)
@ -302,8 +302,9 @@ class WriteKodiDB():
utils.logMsg("MB3 Syncer", "updating artwork..." + str(artworkValue) + " - " + str(curValue)) utils.logMsg("MB3 Syncer", "updating artwork..." + str(artworkValue) + " - " + str(curValue))
xbmc.executeJSONRPC(jsoncommand %(id, artWorkName, artworkValue)) xbmc.executeJSONRPC(jsoncommand %(id, artWorkName, artworkValue))
changes = True changes = True
elif artworkValue != None: elif artworkValue != None and artworkValue != "":
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
utils.logMsg("MB3 Syncer", "updating artwork..." + str(artworkValue) + " - " + str(artWorkName))
xbmc.executeJSONRPC(jsoncommand %(id, artWorkName, artworkValue)) xbmc.executeJSONRPC(jsoncommand %(id, artWorkName, artworkValue))
changes = True changes = True
@ -391,7 +392,7 @@ class WriteKodiDB():
changes = CreateFiles().createNFO(item) changes = CreateFiles().createNFO(item)
# create strm file # create strm file
changes = CreateFiles().createSTRM(item) changes |= CreateFiles().createSTRM(item)
if changes: if changes:
utils.logMsg("MB3 Sync","Added movie to Kodi Library",item["Id"] + " - " + item["Name"]) utils.logMsg("MB3 Sync","Added movie to Kodi Library",item["Id"] + " - " + item["Name"])
@ -404,7 +405,7 @@ class WriteKodiDB():
changes = CreateFiles().createNFO(item) changes = CreateFiles().createNFO(item)
# create strm file # create strm file
changes = CreateFiles().createSTRM(item) changes |= CreateFiles().createSTRM(item)
if changes: if changes:
utils.logMsg("MB3 Sync","Added episode to Kodi Library",item["Id"] + " - " + item["Name"]) utils.logMsg("MB3 Sync","Added episode to Kodi Library",item["Id"] + " - " + item["Name"])
@ -482,7 +483,6 @@ class WriteKodiDB():
if mediatype == "episode": if mediatype == "episode":
id = KodiItem["episodeid"] id = KodiItem["episodeid"]
dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db") dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db")
connection = sqlite3.connect(dbPath) connection = sqlite3.connect(dbPath)
cursor = connection.cursor() cursor = connection.cursor()
@ -492,6 +492,8 @@ class WriteKodiDB():
for cast in KodiItem["cast"]: for cast in KodiItem["cast"]:
currentcast.append(cast["name"]) currentcast.append(cast["name"])
changes = False
if(people != None): if(people != None):
for person in people: for person in people:
if(person.get("Type") == "Actor"): if(person.get("Type") == "Actor"):
@ -518,6 +520,8 @@ class WriteKodiDB():
if mediatype == "episode": if mediatype == "episode":
peoplesql="INSERT OR REPLACE into actorlinkepisode(idActor, idEpisode, strRole, iOrder) values(?, ?, ?, ?)" peoplesql="INSERT OR REPLACE into actorlinkepisode(idActor, idEpisode, strRole, iOrder) values(?, ?, ?, ?)"
cursor.execute(peoplesql, (actorid,id,Role,None)) cursor.execute(peoplesql, (actorid,id,Role,None))
changes = True
connection.commit() connection.commit()
cursor.close() cursor.close()
return changes

View file

@ -25,7 +25,7 @@ class Service():
def __init__(self, *args ): def __init__(self, *args ):
self.KodiMonitor = KodiMonitor.Kodi_Monitor() self.KodiMonitor = KodiMonitor.Kodi_Monitor()
utils.logMsg("MB3 Sync Service" "starting Monitor",0) utils.logMsg("MB3 Sync Service", "starting Monitor",0)
pass pass
@ -115,7 +115,7 @@ class Service():
else: else:
xbmc.log("Not authenticated yet") xbmc.log("Not authenticated yet")
utils.logMsg("MB3 Sync Service" "stopping Service",0) utils.logMsg("MB3 Sync Service", "stopping Service",0)
#start the service #start the service