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:
|
||||
if(item.get("Studios") != None):
|
||||
for studio_string in item.get("Studios"):
|
||||
temp=studio_string.get("Name").encode('utf-8')
|
||||
temp=studio_string.get("Name")
|
||||
studios.append(temp)
|
||||
return studios
|
||||
|
||||
|
|
|
@ -33,6 +33,10 @@ tvLibrary = os.path.join(dataPath,'tvshows')
|
|||
sleepVal = 10
|
||||
showProgress = True
|
||||
|
||||
processMovies = True
|
||||
processTvShows = True
|
||||
|
||||
|
||||
class LibrarySync():
|
||||
|
||||
def syncDatabase(self):
|
||||
|
@ -51,6 +55,7 @@ class LibrarySync():
|
|||
updateNeeded = False
|
||||
|
||||
#process full movies sync
|
||||
if processMovies:
|
||||
allMovies = list()
|
||||
|
||||
views = self.getCollections("movies")
|
||||
|
@ -74,7 +79,8 @@ class LibrarySync():
|
|||
kodiItem = self.getKodiMovie(item["Id"])
|
||||
allMovies.append(item["Id"])
|
||||
progMessage = "Processing"
|
||||
item['Tag'] = view.get('title')
|
||||
item['Tag'] = []
|
||||
item['Tag'].append(view.get('title'))
|
||||
if kodiItem == None:
|
||||
self.addMovieToKodiLibrary(item)
|
||||
updateNeeded = True
|
||||
|
@ -93,6 +99,7 @@ class LibrarySync():
|
|||
count += 1
|
||||
|
||||
#process full tv shows sync
|
||||
if processTvShows:
|
||||
allTVShows = list()
|
||||
allEpisodes = list()
|
||||
tvShowData = self.getTVShows(True)
|
||||
|
@ -180,8 +187,8 @@ class LibrarySync():
|
|||
pDialog.update(percentage, message=progMessage + " Episode: " + str(count))
|
||||
count += 1
|
||||
|
||||
# process deletes
|
||||
# TODO --> process deletes for episodes !!!
|
||||
|
||||
|
||||
if(pDialog != None):
|
||||
pDialog.update(0, message="Removing Deleted Items")
|
||||
|
||||
|
@ -189,6 +196,9 @@ class LibrarySync():
|
|||
return True
|
||||
|
||||
cleanNeeded = False
|
||||
|
||||
# process deletes for movies
|
||||
if processMovies:
|
||||
allLocaldirs, filesMovies = xbmcvfs.listdir(movieLibrary)
|
||||
allMB3Movies = set(allMovies)
|
||||
for dir in allLocaldirs:
|
||||
|
@ -199,6 +209,9 @@ class LibrarySync():
|
|||
if(self.ShouldStop()):
|
||||
return True
|
||||
|
||||
# process deletes for episodes
|
||||
if processTvShows:
|
||||
# TODO --> process deletes for episodes !!!
|
||||
allLocaldirs, filesTVShows = xbmcvfs.listdir(tvLibrary)
|
||||
allMB3TVShows = set(allTVShows)
|
||||
for dir in allLocaldirs:
|
||||
|
@ -236,6 +249,7 @@ class LibrarySync():
|
|||
pDialog.create('Sync PlayCounts', 'Sync PlayCounts')
|
||||
|
||||
#process movies
|
||||
if processMovies:
|
||||
views = self.getCollections("movies")
|
||||
for view in views:
|
||||
movieData = self.getMovies(view.get('id'),False)
|
||||
|
@ -257,12 +271,13 @@ class LibrarySync():
|
|||
userData=API().getUserData(item)
|
||||
timeInfo = API().getTimeInfo(item)
|
||||
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")))
|
||||
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
||||
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
||||
if kodiresume != resume:
|
||||
print "updating resumepoint for movie " + str(kodiItem['movieid'])
|
||||
self.setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
|
||||
|
||||
if(self.ShouldStop()):
|
||||
|
@ -275,6 +290,7 @@ class LibrarySync():
|
|||
count += 1
|
||||
|
||||
#process Tv shows
|
||||
if processTvShows:
|
||||
tvshowData = self.getTVShows(False)
|
||||
|
||||
if(self.ShouldStop()):
|
||||
|
@ -403,8 +419,10 @@ class LibrarySync():
|
|||
downloadUtils = DownloadUtils()
|
||||
userid = downloadUtils.getUserId()
|
||||
|
||||
print "updateplaycount called!"
|
||||
|
||||
# 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:
|
||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||
movie = None
|
||||
|
@ -456,7 +474,8 @@ class LibrarySync():
|
|||
self.updateProperty(KodiItem,"runtime",duration,"movie")
|
||||
self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"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:
|
||||
self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"movie")
|
||||
|
@ -748,7 +767,8 @@ class LibrarySync():
|
|||
root = Element(rootelement)
|
||||
SubElement(root, "id").text = item["Id"]
|
||||
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, "fanart").text = API().getArtwork(item, "Backdrop")
|
||||
|
@ -888,7 +908,7 @@ class LibrarySync():
|
|||
kodiItem = self.getKodiMovie(id)
|
||||
utils.logMsg("deleting movie from Kodi library",id)
|
||||
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)
|
||||
xbmcvfs.rmdir(path)
|
||||
|
@ -908,7 +928,7 @@ class LibrarySync():
|
|||
kodiItem = self.getKodiTVShow(id)
|
||||
utils.logMsg("deleting tvshow from Kodi library",id)
|
||||
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)
|
||||
xbmcvfs.rmdir(path)
|
||||
|
||||
|
@ -991,7 +1011,7 @@ class LibrarySync():
|
|||
|
||||
|
||||
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'))
|
||||
movie = None
|
||||
|
||||
|
@ -1004,7 +1024,7 @@ class LibrarySync():
|
|||
return movie
|
||||
|
||||
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'))
|
||||
tvshow = None
|
||||
if(jsonobject.has_key('result')):
|
||||
|
@ -1016,7 +1036,7 @@ class LibrarySync():
|
|||
|
||||
def getKodiEpisodes(self, id):
|
||||
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'))
|
||||
tvshow = None
|
||||
if(jsonobject.has_key('result')):
|
||||
|
@ -1025,7 +1045,7 @@ class LibrarySync():
|
|||
tvshows = result['tvshows']
|
||||
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'))
|
||||
episodes = None
|
||||
if(jsonobject.has_key('result')):
|
||||
|
@ -1035,7 +1055,7 @@ class LibrarySync():
|
|||
return episodes
|
||||
|
||||
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'))
|
||||
episode = None
|
||||
if(jsonobject.has_key('result')):
|
||||
|
@ -1045,7 +1065,7 @@ class LibrarySync():
|
|||
tvshow = tvshows[0]
|
||||
|
||||
# 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'))
|
||||
episodes = None
|
||||
if(jsonobject.has_key('result')):
|
||||
|
|
|
@ -26,7 +26,7 @@ language = addonSettings.getLocalizedString
|
|||
def logMsg(title, msg, level = 1):
|
||||
|
||||
#todo --> get this from a setting
|
||||
logLevel = 0
|
||||
logLevel = 1
|
||||
|
||||
if(logLevel >= level):
|
||||
if(logLevel == 1):
|
||||
|
|
Loading…
Reference in a new issue