Merge branch 'master' of https://github.com/marcelveldt/plugin.video.mb3sync
This commit is contained in:
commit
6e1727dc78
4 changed files with 83 additions and 45 deletions
|
@ -50,7 +50,11 @@ class LibrarySync():
|
|||
|
||||
#what sync method to perform ?
|
||||
if syncOption == "Full Sync":
|
||||
|
||||
pr = utils.startProfiling()
|
||||
self.MoviesSync(True)
|
||||
utils.stopProfiling(pr, "MoviesSync(True)")
|
||||
|
||||
self.TvShowsSync(True)
|
||||
if syncOption == "Incremental Sync":
|
||||
self.MoviesSync(False)
|
||||
|
|
|
@ -8,7 +8,9 @@ import xbmcaddon
|
|||
import xbmcvfs
|
||||
import json
|
||||
import os
|
||||
|
||||
import cProfile
|
||||
import pstats
|
||||
import time
|
||||
import sqlite3
|
||||
import inspect
|
||||
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
|
||||
|
@ -24,11 +26,9 @@ addonSettings = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|||
language = addonSettings.getLocalizedString
|
||||
|
||||
def logMsg(title, msg, level = 1):
|
||||
|
||||
logLevel = int(addonSettings.getSetting("logLevel"))
|
||||
|
||||
if(logLevel >= level):
|
||||
if(logLevel == 1):
|
||||
if(logLevel == 2): # inspect.stack() is expensive
|
||||
try:
|
||||
xbmc.log(title + " -> " + inspect.stack()[1][3] + " : " + str(msg))
|
||||
except UnicodeEncodeError:
|
||||
|
@ -195,5 +195,35 @@ def get_params( paramstring ):
|
|||
param[splitparams[0]]=splitparams[1]+"="+splitparams[2]
|
||||
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()
|
||||
|
||||
|
||||
|
||||
|
|
@ -94,49 +94,49 @@ class WriteKodiDB():
|
|||
changes = False
|
||||
|
||||
#update artwork
|
||||
changes = self.updateArtWork(KodiItem,"poster", API().getArtwork(MBitem, "poster"),"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,"banner", API().getArtwork(MBitem, "Banner"),"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,"fanart", API().getArtwork(MBitem, "Backdrop"),"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,"clearart", API().getArtwork(MBitem, "Art"),"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,"discart", API().getArtwork(MBitem, "Disc"),"movie")
|
||||
changes |= self.updateArtWork(KodiItem,"fanart", API().getArtwork(MBitem, "Backdrop"),"movie")
|
||||
|
||||
#update common properties
|
||||
duration = (int(timeInfo.get('Duration'))*60)
|
||||
changes = self.updateProperty(KodiItem,"runtime",duration,"movie")
|
||||
changes = self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
|
||||
changes = self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
|
||||
|
||||
changes = self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie")
|
||||
changes |= self.updateProperty(KodiItem,"runtime",duration,"movie")
|
||||
changes |= self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
|
||||
changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
|
||||
|
||||
changes |= self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie")
|
||||
|
||||
if MBitem.get("CriticRating") != None:
|
||||
changes = self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"movie")
|
||||
|
||||
changes = self.updateProperty(KodiItem,"plotoutline",MBitem.get("ShortOverview"),"movie")
|
||||
changes = self.updateProperty(KodiItem,"set",MBitem.get("TmdbCollectionName"),"movie")
|
||||
changes = self.updateProperty(KodiItem,"sorttitle",MBitem.get("SortName"),"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,"set",MBitem.get("TmdbCollectionName"),"movie")
|
||||
changes |= self.updateProperty(KodiItem,"sorttitle",MBitem.get("SortName"),"movie")
|
||||
|
||||
if MBitem.get("ProviderIds") != 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 !?
|
||||
if MBitem.get("TagLines") != None:
|
||||
changes = self.updateProperty(KodiItem,"tagline",MBitem.get("TagLines")[0],"movie")
|
||||
|
||||
changes = self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"movie")
|
||||
changes = self.updatePropertyArray(KodiItem,"director",people.get("Director"),"movie")
|
||||
changes = self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"movie")
|
||||
changes |= self.updateProperty(KodiItem,"tagline",MBitem.get("TagLines")[0],"movie")
|
||||
|
||||
changes |= self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"movie")
|
||||
changes |= self.updatePropertyArray(KodiItem,"director",people.get("Director"),"movie")
|
||||
changes |= self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"movie")
|
||||
|
||||
if(studios != None):
|
||||
for x in range(0, len(studios)):
|
||||
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 !?
|
||||
self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"movie")
|
||||
|
||||
changes |= self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"movie")
|
||||
|
||||
#trailer link
|
||||
trailerUrl = None
|
||||
if MBitem.get("LocalTrailerCount") != None and MBitem.get("LocalTrailerCount") > 0:
|
||||
|
@ -145,10 +145,10 @@ class WriteKodiDB():
|
|||
if(jsonData != ""):
|
||||
trailerItem = json.loads(jsonData)
|
||||
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
|
||||
self.AddActorsToMedia(KodiItem,MBitem.get("People"),"movie")
|
||||
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"movie")
|
||||
|
||||
CreateFiles().createSTRM(MBitem)
|
||||
CreateFiles().createNFO(MBitem)
|
||||
|
@ -299,14 +299,15 @@ class WriteKodiDB():
|
|||
curValue = urllib.unquote(KodiItem['art'][artWorkName]).decode('utf8')
|
||||
if not artworkValue in curValue:
|
||||
xbmc.sleep(sleepVal)
|
||||
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))
|
||||
changes = True
|
||||
elif artworkValue != None:
|
||||
elif artworkValue != None and artworkValue != "":
|
||||
xbmc.sleep(sleepVal)
|
||||
utils.logMsg("MB3 Syncer", "updating artwork..." + str(artworkValue) + " - " + str(artWorkName))
|
||||
xbmc.executeJSONRPC(jsoncommand %(id, artWorkName, artworkValue))
|
||||
changes = True
|
||||
|
||||
|
||||
return changes
|
||||
|
||||
# adds or updates the given property on the videofile in Kodi database
|
||||
|
@ -391,7 +392,7 @@ class WriteKodiDB():
|
|||
changes = CreateFiles().createNFO(item)
|
||||
|
||||
# create strm file
|
||||
changes = CreateFiles().createSTRM(item)
|
||||
changes |= CreateFiles().createSTRM(item)
|
||||
|
||||
if changes:
|
||||
utils.logMsg("MB3 Sync","Added movie to Kodi Library",item["Id"] + " - " + item["Name"])
|
||||
|
@ -404,7 +405,7 @@ class WriteKodiDB():
|
|||
changes = CreateFiles().createNFO(item)
|
||||
|
||||
# create strm file
|
||||
changes = CreateFiles().createSTRM(item)
|
||||
changes |= CreateFiles().createSTRM(item)
|
||||
|
||||
if changes:
|
||||
utils.logMsg("MB3 Sync","Added episode to Kodi Library",item["Id"] + " - " + item["Name"])
|
||||
|
@ -482,7 +483,6 @@ class WriteKodiDB():
|
|||
if mediatype == "episode":
|
||||
id = KodiItem["episodeid"]
|
||||
|
||||
|
||||
dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db")
|
||||
connection = sqlite3.connect(dbPath)
|
||||
cursor = connection.cursor()
|
||||
|
@ -491,7 +491,9 @@ class WriteKodiDB():
|
|||
if KodiItem["cast"] != None:
|
||||
for cast in KodiItem["cast"]:
|
||||
currentcast.append(cast["name"])
|
||||
|
||||
|
||||
changes = False
|
||||
|
||||
if(people != None):
|
||||
for person in people:
|
||||
if(person.get("Type") == "Actor"):
|
||||
|
@ -518,6 +520,8 @@ class WriteKodiDB():
|
|||
if mediatype == "episode":
|
||||
peoplesql="INSERT OR REPLACE into actorlinkepisode(idActor, idEpisode, strRole, iOrder) values(?, ?, ?, ?)"
|
||||
cursor.execute(peoplesql, (actorid,id,Role,None))
|
||||
changes = True
|
||||
|
||||
connection.commit()
|
||||
cursor.close()
|
||||
return changes
|
||||
|
|
|
@ -25,7 +25,7 @@ class Service():
|
|||
def __init__(self, *args ):
|
||||
self.KodiMonitor = KodiMonitor.Kodi_Monitor()
|
||||
|
||||
utils.logMsg("MB3 Sync Service" "starting Monitor",0)
|
||||
utils.logMsg("MB3 Sync Service", "starting Monitor",0)
|
||||
|
||||
pass
|
||||
|
||||
|
@ -115,7 +115,7 @@ class Service():
|
|||
else:
|
||||
xbmc.log("Not authenticated yet")
|
||||
|
||||
utils.logMsg("MB3 Sync Service" "stopping Service",0)
|
||||
utils.logMsg("MB3 Sync Service", "stopping Service",0)
|
||||
|
||||
|
||||
#start the service
|
||||
|
|
Loading…
Reference in a new issue