speed improvement

moved all sleeps to the kodi api calls only
This commit is contained in:
Marcel van der Veldt 2015-03-19 11:13:49 +01:00
parent 593d969669
commit fe35d84e1e
3 changed files with 15 additions and 16 deletions

View file

@ -28,8 +28,6 @@ dataPath = os.path.join(addondir,"library")
movieLibrary = os.path.join(dataPath,'movies')
tvLibrary = os.path.join(dataPath,'tvshows')
sleepVal = 20
class LibrarySync():
def syncDatabase(self):
@ -113,7 +111,6 @@ class LibrarySync():
item['Tag'].append(view.get('title'))
if item["Id"] not in allKodiIds:
xbmc.sleep(sleepVal)
WriteKodiDB().addMovieToKodiLibrary(item)
updateNeeded = True
@ -185,8 +182,6 @@ class LibrarySync():
allEmbyMovieIds = set(allEmbyMovieIds)
for kodiId in allKodiIds:
if not kodiId in allEmbyMovieIds:
xbmc.sleep(sleepVal)
print "delete needed for: " + kodiId
WriteKodiDB().deleteMovieFromKodiLibrary(dir)
cleanNeeded = True
@ -246,7 +241,6 @@ class LibrarySync():
return True
#we have to compare the lists somehow
xbmc.sleep(sleepVal)
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
matchFound = False
if kodiEpisodes != None:
@ -290,7 +284,6 @@ class LibrarySync():
return True
#we have to compare the lists somehow
xbmc.sleep(sleepVal)
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
if kodiEpisodes != None:
@ -332,7 +325,6 @@ class LibrarySync():
count = 1
for item in tvShowData:
xbmc.sleep(sleepVal)
if item.get('IsFolder'):
kodiItem = ReadKodiDB().getKodiTVShow(item["Id"])
allTVShows.append(item["Id"])
@ -390,7 +382,6 @@ class LibrarySync():
#we have to compare the lists somehow
for item in episodeData:
xbmc.sleep(sleepVal)
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
matchFound = False
if kodiEpisodes != None:
@ -448,7 +439,6 @@ class LibrarySync():
#we have to compare the lists somehow
for item in episodeData:
xbmc.sleep(sleepVal)
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
matchFound = False
if kodiEpisodes != None:
@ -574,8 +564,6 @@ class LibrarySync():
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
total = int(round(float(timeInfo.get("TotalTime"))))*60
if kodiresume != resume:
xbmc.sleep(sleepVal)
print "updating resumepoint for movie " + str(kodiItem['movieid'])
WriteKodiDB().setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
if(self.ShouldStop()):
@ -634,7 +622,6 @@ class LibrarySync():
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
total = int(round(float(timeInfo.get("TotalTime"))))*60
if kodiresume != resume:
xbmc.sleep(sleepVal)
WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
if(self.ShouldStop()):

View file

@ -15,9 +15,13 @@ dataPath = os.path.join(addondir,"library")
movieLibrary = os.path.join(dataPath,'movies')
tvLibrary = os.path.join(dataPath,'tvshows')
#sleepval is used to throttle the calls to the xbmc json API
sleepVal = 15
class ReadKodiDB():
def getKodiMovie(self, id):
#returns a single movie from Kodi db selected on MB item ID
xbmc.sleep(sleepVal)
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties" : ["art", "rating", "thumbnail", "resume", "runtime", "year", "genre", "cast", "trailer", "country", "studio", "set", "imdbnumber", "mpaa", "tagline", "plotoutline","plot", "sorttitle", "director", "writer", "playcount", "tag", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMovies"}')
jsonobject = json.loads(json_response.decode('utf-8','replace'))
movie = None
@ -32,6 +36,7 @@ class ReadKodiDB():
def getKodiMovies(self,fullInfo = False):
#returns all movies in Kodi db inserted by MB
xbmc.sleep(sleepVal)
if fullInfo:
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties" : ["art", "rating", "thumbnail", "resume", "runtime", "year", "genre", "cast", "trailer", "country", "studio", "set", "imdbnumber", "mpaa", "tagline", "plotoutline","plot", "sorttitle", "director", "writer", "playcount", "tag", "file"] }, "id": "libMovies"}')
else:
@ -88,6 +93,7 @@ class ReadKodiDB():
def getKodiTvShows(self,fullInfo = False):
#returns all tvshows in Kodi db inserted by MB
xbmc.sleep(sleepVal)
if fullInfo:
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "premiered", "rating", "thumbnail", "playcount", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
else:
@ -103,6 +109,7 @@ class ReadKodiDB():
return tvshows
def getKodiTVShow(self, id):
xbmc.sleep(sleepVal)
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "premiered", "rating", "thumbnail", "playcount", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
jsonobject = json.loads(json_response.decode('utf-8','replace'))
tvshow = None
@ -114,6 +121,7 @@ class ReadKodiDB():
return tvshow
def getKodiEpisodes(self, id,fullInfo = True):
xbmc.sleep(sleepVal)
episodes = None
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["title", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
jsonobject = json.loads(json_response.decode('utf-8','replace'))
@ -136,6 +144,7 @@ class ReadKodiDB():
return episodes
def getKodiEpisodeByMbItem(self, MBitem):
xbmc.sleep(sleepVal)
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "is", "field": "title", "value": "' + MBitem.get("SeriesName").encode('utf-8') + '"} }, "id": "libTvShows"}')
jsonobject = json.loads(json_response.decode('utf-8','replace'))
episode = None

View file

@ -23,12 +23,14 @@ addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
dataPath = os.path.join(addondir,"library")
movieLibrary = os.path.join(dataPath,'movies')
tvLibrary = os.path.join(dataPath,'tvshows')
sleepVal = 10
sleepVal = 20
class WriteKodiDB():
def updatePlayCountFromKodi(self, id, type, playcount=0):
#when user marks item watched from kodi interface update this in MB3
xbmc.sleep(sleepVal)
xbmc.log("WriteKodiDB -> updatePlayCountFromKodi Called")
mb3Id = None
@ -432,6 +434,7 @@ class WriteKodiDB():
utils.logMsg("Added TV Show to Kodi Library ",item["Id"] + " - " + item["Name"])
def deleteTVShowFromKodiLibrary(self, id ):
xbmc.sleep(sleepVal)
kodiItem = ReadKodiDB().getKodiTVShow(id)
utils.logMsg("deleting tvshow from Kodi library",id)
if kodiItem != None:
@ -444,7 +447,7 @@ class WriteKodiDB():
#todo --> submit PR to kodi team to get this added to the jsonrpc api
utils.logMsg("MB3 Sync","setting resume point in kodi db..." + fileType + ": " + str(id))
xbmc.sleep(sleepVal)
dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db")
connection = sqlite3.connect(dbPath)
cursor = connection.cursor( )
@ -470,7 +473,7 @@ class WriteKodiDB():
def AddActorsToMedia(self, KodiItem, people, mediatype):
#use sqlite to set add the actors while json api doesn't support this yet
#todo --> submit PR to kodi team to get this added to the jsonrpc api
xbmc.sleep(sleepVal)
downloadUtils = DownloadUtils()
if mediatype == "movie":
id = KodiItem["movieid"]