speed improvement
moved all sleeps to the kodi api calls only
This commit is contained in:
parent
593d969669
commit
fe35d84e1e
3 changed files with 15 additions and 16 deletions
|
@ -28,8 +28,6 @@ dataPath = os.path.join(addondir,"library")
|
||||||
movieLibrary = os.path.join(dataPath,'movies')
|
movieLibrary = os.path.join(dataPath,'movies')
|
||||||
tvLibrary = os.path.join(dataPath,'tvshows')
|
tvLibrary = os.path.join(dataPath,'tvshows')
|
||||||
|
|
||||||
sleepVal = 20
|
|
||||||
|
|
||||||
class LibrarySync():
|
class LibrarySync():
|
||||||
|
|
||||||
def syncDatabase(self):
|
def syncDatabase(self):
|
||||||
|
@ -113,7 +111,6 @@ class LibrarySync():
|
||||||
item['Tag'].append(view.get('title'))
|
item['Tag'].append(view.get('title'))
|
||||||
|
|
||||||
if item["Id"] not in allKodiIds:
|
if item["Id"] not in allKodiIds:
|
||||||
xbmc.sleep(sleepVal)
|
|
||||||
WriteKodiDB().addMovieToKodiLibrary(item)
|
WriteKodiDB().addMovieToKodiLibrary(item)
|
||||||
updateNeeded = True
|
updateNeeded = True
|
||||||
|
|
||||||
|
@ -185,8 +182,6 @@ class LibrarySync():
|
||||||
allEmbyMovieIds = set(allEmbyMovieIds)
|
allEmbyMovieIds = set(allEmbyMovieIds)
|
||||||
for kodiId in allKodiIds:
|
for kodiId in allKodiIds:
|
||||||
if not kodiId in allEmbyMovieIds:
|
if not kodiId in allEmbyMovieIds:
|
||||||
xbmc.sleep(sleepVal)
|
|
||||||
print "delete needed for: " + kodiId
|
|
||||||
WriteKodiDB().deleteMovieFromKodiLibrary(dir)
|
WriteKodiDB().deleteMovieFromKodiLibrary(dir)
|
||||||
cleanNeeded = True
|
cleanNeeded = True
|
||||||
|
|
||||||
|
@ -246,7 +241,6 @@ class LibrarySync():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#we have to compare the lists somehow
|
#we have to compare the lists somehow
|
||||||
xbmc.sleep(sleepVal)
|
|
||||||
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
||||||
matchFound = False
|
matchFound = False
|
||||||
if kodiEpisodes != None:
|
if kodiEpisodes != None:
|
||||||
|
@ -290,7 +284,6 @@ class LibrarySync():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#we have to compare the lists somehow
|
#we have to compare the lists somehow
|
||||||
xbmc.sleep(sleepVal)
|
|
||||||
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
||||||
|
|
||||||
if kodiEpisodes != None:
|
if kodiEpisodes != None:
|
||||||
|
@ -332,7 +325,6 @@ class LibrarySync():
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
for item in tvShowData:
|
for item in tvShowData:
|
||||||
xbmc.sleep(sleepVal)
|
|
||||||
if item.get('IsFolder'):
|
if item.get('IsFolder'):
|
||||||
kodiItem = ReadKodiDB().getKodiTVShow(item["Id"])
|
kodiItem = ReadKodiDB().getKodiTVShow(item["Id"])
|
||||||
allTVShows.append(item["Id"])
|
allTVShows.append(item["Id"])
|
||||||
|
@ -390,7 +382,6 @@ class LibrarySync():
|
||||||
|
|
||||||
#we have to compare the lists somehow
|
#we have to compare the lists somehow
|
||||||
for item in episodeData:
|
for item in episodeData:
|
||||||
xbmc.sleep(sleepVal)
|
|
||||||
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
|
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
|
||||||
matchFound = False
|
matchFound = False
|
||||||
if kodiEpisodes != None:
|
if kodiEpisodes != None:
|
||||||
|
@ -448,7 +439,6 @@ class LibrarySync():
|
||||||
|
|
||||||
#we have to compare the lists somehow
|
#we have to compare the lists somehow
|
||||||
for item in episodeData:
|
for item in episodeData:
|
||||||
xbmc.sleep(sleepVal)
|
|
||||||
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
|
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
|
||||||
matchFound = False
|
matchFound = False
|
||||||
if kodiEpisodes != None:
|
if kodiEpisodes != None:
|
||||||
|
@ -574,8 +564,6 @@ class LibrarySync():
|
||||||
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
||||||
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
||||||
if kodiresume != resume:
|
if kodiresume != resume:
|
||||||
xbmc.sleep(sleepVal)
|
|
||||||
print "updating resumepoint for movie " + str(kodiItem['movieid'])
|
|
||||||
WriteKodiDB().setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
|
WriteKodiDB().setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
|
@ -634,7 +622,6 @@ class LibrarySync():
|
||||||
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
||||||
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
||||||
if kodiresume != resume:
|
if kodiresume != resume:
|
||||||
xbmc.sleep(sleepVal)
|
|
||||||
WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
|
WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
|
|
|
@ -15,9 +15,13 @@ dataPath = os.path.join(addondir,"library")
|
||||||
movieLibrary = os.path.join(dataPath,'movies')
|
movieLibrary = os.path.join(dataPath,'movies')
|
||||||
tvLibrary = os.path.join(dataPath,'tvshows')
|
tvLibrary = os.path.join(dataPath,'tvshows')
|
||||||
|
|
||||||
|
#sleepval is used to throttle the calls to the xbmc json API
|
||||||
|
sleepVal = 15
|
||||||
|
|
||||||
class ReadKodiDB():
|
class ReadKodiDB():
|
||||||
def getKodiMovie(self, id):
|
def getKodiMovie(self, id):
|
||||||
#returns a single movie from Kodi db selected on MB item 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"}')
|
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'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
movie = None
|
movie = None
|
||||||
|
@ -32,6 +36,7 @@ class ReadKodiDB():
|
||||||
|
|
||||||
def getKodiMovies(self,fullInfo = False):
|
def getKodiMovies(self,fullInfo = False):
|
||||||
#returns all movies in Kodi db inserted by MB
|
#returns all movies in Kodi db inserted by MB
|
||||||
|
xbmc.sleep(sleepVal)
|
||||||
if fullInfo:
|
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"}')
|
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:
|
else:
|
||||||
|
@ -88,6 +93,7 @@ class ReadKodiDB():
|
||||||
|
|
||||||
def getKodiTvShows(self,fullInfo = False):
|
def getKodiTvShows(self,fullInfo = False):
|
||||||
#returns all tvshows in Kodi db inserted by MB
|
#returns all tvshows in Kodi db inserted by MB
|
||||||
|
xbmc.sleep(sleepVal)
|
||||||
if fullInfo:
|
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"}')
|
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:
|
else:
|
||||||
|
@ -103,6 +109,7 @@ class ReadKodiDB():
|
||||||
return tvshows
|
return tvshows
|
||||||
|
|
||||||
def getKodiTVShow(self, id):
|
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"}')
|
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'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
tvshow = None
|
tvshow = None
|
||||||
|
@ -114,6 +121,7 @@ class ReadKodiDB():
|
||||||
return tvshow
|
return tvshow
|
||||||
|
|
||||||
def getKodiEpisodes(self, id,fullInfo = True):
|
def getKodiEpisodes(self, id,fullInfo = True):
|
||||||
|
xbmc.sleep(sleepVal)
|
||||||
episodes = None
|
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"}')
|
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'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
|
@ -136,6 +144,7 @@ class ReadKodiDB():
|
||||||
return episodes
|
return episodes
|
||||||
|
|
||||||
def getKodiEpisodeByMbItem(self, MBitem):
|
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"}')
|
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'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
episode = None
|
episode = None
|
||||||
|
|
|
@ -23,12 +23,14 @@ addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
|
||||||
dataPath = os.path.join(addondir,"library")
|
dataPath = os.path.join(addondir,"library")
|
||||||
movieLibrary = os.path.join(dataPath,'movies')
|
movieLibrary = os.path.join(dataPath,'movies')
|
||||||
tvLibrary = os.path.join(dataPath,'tvshows')
|
tvLibrary = os.path.join(dataPath,'tvshows')
|
||||||
sleepVal = 10
|
|
||||||
|
sleepVal = 20
|
||||||
|
|
||||||
class WriteKodiDB():
|
class WriteKodiDB():
|
||||||
|
|
||||||
def updatePlayCountFromKodi(self, id, type, playcount=0):
|
def updatePlayCountFromKodi(self, id, type, playcount=0):
|
||||||
#when user marks item watched from kodi interface update this in MB3
|
#when user marks item watched from kodi interface update this in MB3
|
||||||
|
xbmc.sleep(sleepVal)
|
||||||
xbmc.log("WriteKodiDB -> updatePlayCountFromKodi Called")
|
xbmc.log("WriteKodiDB -> updatePlayCountFromKodi Called")
|
||||||
|
|
||||||
mb3Id = None
|
mb3Id = None
|
||||||
|
@ -432,6 +434,7 @@ class WriteKodiDB():
|
||||||
utils.logMsg("Added TV Show to Kodi Library ",item["Id"] + " - " + item["Name"])
|
utils.logMsg("Added TV Show to Kodi Library ",item["Id"] + " - " + item["Name"])
|
||||||
|
|
||||||
def deleteTVShowFromKodiLibrary(self, id ):
|
def deleteTVShowFromKodiLibrary(self, id ):
|
||||||
|
xbmc.sleep(sleepVal)
|
||||||
kodiItem = ReadKodiDB().getKodiTVShow(id)
|
kodiItem = ReadKodiDB().getKodiTVShow(id)
|
||||||
utils.logMsg("deleting tvshow from Kodi library",id)
|
utils.logMsg("deleting tvshow from Kodi library",id)
|
||||||
if kodiItem != None:
|
if kodiItem != None:
|
||||||
|
@ -444,7 +447,7 @@ class WriteKodiDB():
|
||||||
#todo --> submit PR to kodi team to get this added to the jsonrpc api
|
#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))
|
utils.logMsg("MB3 Sync","setting resume point in kodi db..." + fileType + ": " + str(id))
|
||||||
|
xbmc.sleep(sleepVal)
|
||||||
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( )
|
||||||
|
@ -470,7 +473,7 @@ class WriteKodiDB():
|
||||||
def AddActorsToMedia(self, KodiItem, people, mediatype):
|
def AddActorsToMedia(self, KodiItem, people, mediatype):
|
||||||
#use sqlite to set add the actors while json api doesn't support this yet
|
#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
|
#todo --> submit PR to kodi team to get this added to the jsonrpc api
|
||||||
|
xbmc.sleep(sleepVal)
|
||||||
downloadUtils = DownloadUtils()
|
downloadUtils = DownloadUtils()
|
||||||
if mediatype == "movie":
|
if mediatype == "movie":
|
||||||
id = KodiItem["movieid"]
|
id = KodiItem["movieid"]
|
||||||
|
|
Loading…
Reference in a new issue