more unicode fixes
fixes for wrong dif detection added logging to see if item gets updates libraries can be enabled/disabled
This commit is contained in:
parent
a1a074b66f
commit
5e8f63831c
3 changed files with 229 additions and 209 deletions
|
@ -96,7 +96,7 @@ class API():
|
||||||
else:
|
else:
|
||||||
if(item.get("Studios") != None):
|
if(item.get("Studios") != None):
|
||||||
for studio_string in item.get("Studios"):
|
for studio_string in item.get("Studios"):
|
||||||
temp=studio_string.get("Name").encode('utf-8')
|
temp=studio_string.get("Name")
|
||||||
studios.append(temp)
|
studios.append(temp)
|
||||||
return studios
|
return studios
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,10 @@ tvLibrary = os.path.join(dataPath,'tvshows')
|
||||||
sleepVal = 10
|
sleepVal = 10
|
||||||
showProgress = True
|
showProgress = True
|
||||||
|
|
||||||
|
processMovies = True
|
||||||
|
processTvShows = True
|
||||||
|
|
||||||
|
|
||||||
class LibrarySync():
|
class LibrarySync():
|
||||||
|
|
||||||
def syncDatabase(self):
|
def syncDatabase(self):
|
||||||
|
@ -51,6 +55,7 @@ class LibrarySync():
|
||||||
updateNeeded = False
|
updateNeeded = False
|
||||||
|
|
||||||
#process full movies sync
|
#process full movies sync
|
||||||
|
if processMovies:
|
||||||
allMovies = list()
|
allMovies = list()
|
||||||
|
|
||||||
views = self.getCollections("movies")
|
views = self.getCollections("movies")
|
||||||
|
@ -74,7 +79,8 @@ class LibrarySync():
|
||||||
kodiItem = self.getKodiMovie(item["Id"])
|
kodiItem = self.getKodiMovie(item["Id"])
|
||||||
allMovies.append(item["Id"])
|
allMovies.append(item["Id"])
|
||||||
progMessage = "Processing"
|
progMessage = "Processing"
|
||||||
item['Tag'] = view.get('title')
|
item['Tag'] = []
|
||||||
|
item['Tag'].append(view.get('title'))
|
||||||
if kodiItem == None:
|
if kodiItem == None:
|
||||||
self.addMovieToKodiLibrary(item)
|
self.addMovieToKodiLibrary(item)
|
||||||
updateNeeded = True
|
updateNeeded = True
|
||||||
|
@ -93,6 +99,7 @@ class LibrarySync():
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
#process full tv shows sync
|
#process full tv shows sync
|
||||||
|
if processTvShows:
|
||||||
allTVShows = list()
|
allTVShows = list()
|
||||||
allEpisodes = list()
|
allEpisodes = list()
|
||||||
tvShowData = self.getTVShows(True)
|
tvShowData = self.getTVShows(True)
|
||||||
|
@ -180,8 +187,8 @@ class LibrarySync():
|
||||||
pDialog.update(percentage, message=progMessage + " Episode: " + str(count))
|
pDialog.update(percentage, message=progMessage + " Episode: " + str(count))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
# process deletes
|
|
||||||
# TODO --> process deletes for episodes !!!
|
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
pDialog.update(0, message="Removing Deleted Items")
|
pDialog.update(0, message="Removing Deleted Items")
|
||||||
|
|
||||||
|
@ -189,6 +196,9 @@ class LibrarySync():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
cleanNeeded = False
|
cleanNeeded = False
|
||||||
|
|
||||||
|
# process deletes for movies
|
||||||
|
if processMovies:
|
||||||
allLocaldirs, filesMovies = xbmcvfs.listdir(movieLibrary)
|
allLocaldirs, filesMovies = xbmcvfs.listdir(movieLibrary)
|
||||||
allMB3Movies = set(allMovies)
|
allMB3Movies = set(allMovies)
|
||||||
for dir in allLocaldirs:
|
for dir in allLocaldirs:
|
||||||
|
@ -199,6 +209,9 @@ class LibrarySync():
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# process deletes for episodes
|
||||||
|
if processTvShows:
|
||||||
|
# TODO --> process deletes for episodes !!!
|
||||||
allLocaldirs, filesTVShows = xbmcvfs.listdir(tvLibrary)
|
allLocaldirs, filesTVShows = xbmcvfs.listdir(tvLibrary)
|
||||||
allMB3TVShows = set(allTVShows)
|
allMB3TVShows = set(allTVShows)
|
||||||
for dir in allLocaldirs:
|
for dir in allLocaldirs:
|
||||||
|
@ -236,6 +249,7 @@ class LibrarySync():
|
||||||
pDialog.create('Sync PlayCounts', 'Sync PlayCounts')
|
pDialog.create('Sync PlayCounts', 'Sync PlayCounts')
|
||||||
|
|
||||||
#process movies
|
#process movies
|
||||||
|
if processMovies:
|
||||||
views = self.getCollections("movies")
|
views = self.getCollections("movies")
|
||||||
for view in views:
|
for view in views:
|
||||||
movieData = self.getMovies(view.get('id'),False)
|
movieData = self.getMovies(view.get('id'),False)
|
||||||
|
@ -257,12 +271,13 @@ class LibrarySync():
|
||||||
userData=API().getUserData(item)
|
userData=API().getUserData(item)
|
||||||
timeInfo = API().getTimeInfo(item)
|
timeInfo = API().getTimeInfo(item)
|
||||||
if kodiItem != None:
|
if kodiItem != None:
|
||||||
self.updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode")
|
self.updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie")
|
||||||
|
|
||||||
kodiresume = int(round(kodiItem['resume'].get("position")))
|
kodiresume = int(round(kodiItem['resume'].get("position")))
|
||||||
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:
|
||||||
|
print "updating resumepoint for movie " + str(kodiItem['movieid'])
|
||||||
self.setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
|
self.setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
|
@ -275,6 +290,7 @@ class LibrarySync():
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
#process Tv shows
|
#process Tv shows
|
||||||
|
if processTvShows:
|
||||||
tvshowData = self.getTVShows(False)
|
tvshowData = self.getTVShows(False)
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
|
@ -403,8 +419,10 @@ class LibrarySync():
|
||||||
downloadUtils = DownloadUtils()
|
downloadUtils = DownloadUtils()
|
||||||
userid = downloadUtils.getUserId()
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
|
print "updateplaycount called!"
|
||||||
|
|
||||||
# TODO --> extend support for episodes
|
# TODO --> extend support for episodes
|
||||||
json_response = self.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": { "movieid": ' + str(id) + ', "properties" : ["playcount", "file"] }, "id": "1"}')
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": { "movieid": ' + str(id) + ', "properties" : ["playcount", "file"] }, "id": "1"}')
|
||||||
if json_response != None:
|
if json_response != None:
|
||||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
movie = None
|
movie = None
|
||||||
|
@ -456,7 +474,8 @@ class LibrarySync():
|
||||||
self.updateProperty(KodiItem,"runtime",duration,"movie")
|
self.updateProperty(KodiItem,"runtime",duration,"movie")
|
||||||
self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
|
self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
|
||||||
self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
|
self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
|
||||||
self.updateProperty(KodiItem,"tag",MBitem.get("Tag"),"movie")
|
|
||||||
|
self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie")
|
||||||
|
|
||||||
if MBitem.get("CriticRating") != None:
|
if MBitem.get("CriticRating") != None:
|
||||||
self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"movie")
|
self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"movie")
|
||||||
|
@ -748,7 +767,8 @@ class LibrarySync():
|
||||||
root = Element(rootelement)
|
root = Element(rootelement)
|
||||||
SubElement(root, "id").text = item["Id"]
|
SubElement(root, "id").text = item["Id"]
|
||||||
if item.get("Tag") != None:
|
if item.get("Tag") != None:
|
||||||
SubElement(root, "tag").text = item.get("Tag")# TODO --> fix for TV etc
|
for tag in item.get("Tag"):
|
||||||
|
SubElement(root, "tag").text = tag
|
||||||
|
|
||||||
SubElement(root, "thumb").text = API().getArtwork(item, "Primary")
|
SubElement(root, "thumb").text = API().getArtwork(item, "Primary")
|
||||||
SubElement(root, "fanart").text = API().getArtwork(item, "Backdrop")
|
SubElement(root, "fanart").text = API().getArtwork(item, "Backdrop")
|
||||||
|
@ -888,7 +908,7 @@ class LibrarySync():
|
||||||
kodiItem = self.getKodiMovie(id)
|
kodiItem = self.getKodiMovie(id)
|
||||||
utils.logMsg("deleting movie from Kodi library",id)
|
utils.logMsg("deleting movie from Kodi library",id)
|
||||||
if kodiItem != None:
|
if kodiItem != None:
|
||||||
self.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveMovie", "params": { "movieid": %i}, "id": 1 }' %(kodiItem["movieid"]))
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveMovie", "params": { "movieid": %i}, "id": 1 }' %(kodiItem["movieid"]))
|
||||||
|
|
||||||
path = os.path.join(movieLibrary,id)
|
path = os.path.join(movieLibrary,id)
|
||||||
xbmcvfs.rmdir(path)
|
xbmcvfs.rmdir(path)
|
||||||
|
@ -908,7 +928,7 @@ class LibrarySync():
|
||||||
kodiItem = self.getKodiTVShow(id)
|
kodiItem = self.getKodiTVShow(id)
|
||||||
utils.logMsg("deleting tvshow from Kodi library",id)
|
utils.logMsg("deleting tvshow from Kodi library",id)
|
||||||
if kodiItem != None:
|
if kodiItem != None:
|
||||||
self.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveTVShow", "params": { "tvshowid": %i}, "id": 1 }' %(kodiItem["tvshowid"]))
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveTVShow", "params": { "tvshowid": %i}, "id": 1 }' %(kodiItem["tvshowid"]))
|
||||||
path = os.path.join(tvLibrary,id)
|
path = os.path.join(tvLibrary,id)
|
||||||
xbmcvfs.rmdir(path)
|
xbmcvfs.rmdir(path)
|
||||||
|
|
||||||
|
@ -991,7 +1011,7 @@ class LibrarySync():
|
||||||
|
|
||||||
|
|
||||||
def getKodiMovie(self, id):
|
def getKodiMovie(self, id):
|
||||||
json_response = self.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
|
||||||
|
|
||||||
|
@ -1004,7 +1024,7 @@ class LibrarySync():
|
||||||
return movie
|
return movie
|
||||||
|
|
||||||
def getKodiTVShow(self, id):
|
def getKodiTVShow(self, id):
|
||||||
json_response = self.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", "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", "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
|
||||||
if(jsonobject.has_key('result')):
|
if(jsonobject.has_key('result')):
|
||||||
|
@ -1016,7 +1036,7 @@ class LibrarySync():
|
||||||
|
|
||||||
def getKodiEpisodes(self, id):
|
def getKodiEpisodes(self, id):
|
||||||
episodes = None
|
episodes = None
|
||||||
json_response = self.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", "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", "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
|
||||||
if(jsonobject.has_key('result')):
|
if(jsonobject.has_key('result')):
|
||||||
|
@ -1025,7 +1045,7 @@ class LibrarySync():
|
||||||
tvshows = result['tvshows']
|
tvshows = result['tvshows']
|
||||||
tvshow = tvshows[0]
|
tvshow = tvshows[0]
|
||||||
|
|
||||||
json_response = self.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "plot", "season", "episode", "showtitle", "file", "lastplayed", "rating", "resume", "art", "streamdetails", "firstaired", "runtime", "writer", "cast", "dateadded"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "plot", "season", "episode", "showtitle", "file", "lastplayed", "rating", "resume", "art", "streamdetails", "firstaired", "runtime", "writer", "cast", "dateadded"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
||||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
episodes = None
|
episodes = None
|
||||||
if(jsonobject.has_key('result')):
|
if(jsonobject.has_key('result')):
|
||||||
|
@ -1035,7 +1055,7 @@ class LibrarySync():
|
||||||
return episodes
|
return episodes
|
||||||
|
|
||||||
def getKodiEpisodeByMbItem(self, MBitem):
|
def getKodiEpisodeByMbItem(self, MBitem):
|
||||||
json_response = self.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
|
||||||
if(jsonobject.has_key('result')):
|
if(jsonobject.has_key('result')):
|
||||||
|
@ -1045,7 +1065,7 @@ class LibrarySync():
|
||||||
tvshow = tvshows[0]
|
tvshow = tvshows[0]
|
||||||
|
|
||||||
# find the episode by combination of season and episode
|
# find the episode by combination of season and episode
|
||||||
json_response = self.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["playcount","season", "resume", "episode"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["playcount","season", "resume", "episode"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
||||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
episodes = None
|
episodes = None
|
||||||
if(jsonobject.has_key('result')):
|
if(jsonobject.has_key('result')):
|
||||||
|
|
|
@ -26,7 +26,7 @@ language = addonSettings.getLocalizedString
|
||||||
def logMsg(title, msg, level = 1):
|
def logMsg(title, msg, level = 1):
|
||||||
|
|
||||||
#todo --> get this from a setting
|
#todo --> get this from a setting
|
||||||
logLevel = 0
|
logLevel = 1
|
||||||
|
|
||||||
if(logLevel >= level):
|
if(logLevel >= level):
|
||||||
if(logLevel == 1):
|
if(logLevel == 1):
|
||||||
|
|
Loading…
Reference in a new issue