added lastplayed field to sync

This commit is contained in:
Marcel van der Veldt 2015-03-24 21:03:07 +01:00
parent 7a905d4ec2
commit 95a3e76671
5 changed files with 35 additions and 13 deletions

View file

@ -139,6 +139,14 @@ class API():
UnplayedItemCount = userData.get('UnplayedItemCount') UnplayedItemCount = userData.get('UnplayedItemCount')
else: else:
UnplayedItemCount = "0" UnplayedItemCount = "0"
if userData.get('LastPlayedDate') != None:
#TODO--> is there some other way to do this ?
datestring = userData.get('LastPlayedDate').split('T')[0]
timestring = userData.get('LastPlayedDate').split('T')[1]
timestring = timestring.split('.')[0]
LastPlayedDate = datestring + " " + timestring
else:
LastPlayedDate = None
if userData.get('PlaybackPositionTicks') != None: if userData.get('PlaybackPositionTicks') != None:
PlaybackPositionTicks = userData.get('PlaybackPositionTicks') PlaybackPositionTicks = userData.get('PlaybackPositionTicks')
else: else:
@ -146,6 +154,7 @@ class API():
return {'Watched' : watched, return {'Watched' : watched,
'Favorite' : favorite, 'Favorite' : favorite,
'PlayCount': playcount, 'PlayCount': playcount,
'LastPlayedDate': LastPlayedDate,
'UnplayedItemCount' : UnplayedItemCount, 'UnplayedItemCount' : UnplayedItemCount,
'PlaybackPositionTicks' : str(PlaybackPositionTicks) 'PlaybackPositionTicks' : str(PlaybackPositionTicks)
} }

View file

@ -136,6 +136,11 @@ class CreateFiles():
SubElement(root, "originaltitle").text = utils.convertEncoding(item["Name"]) SubElement(root, "originaltitle").text = utils.convertEncoding(item["Name"])
SubElement(root, "sorttitle").text = utils.convertEncoding(item["SortName"]) SubElement(root, "sorttitle").text = utils.convertEncoding(item["SortName"])
if userData.get("LastPlayedDate") != None:
SubElement(root, "lastplayed").text = userData.get("LastPlayedDate")
else:
SubElement(root, "lastplayed").text = ""
if item.has_key("Album"): if item.has_key("Album"):
SubElement(root, "album").text = item["Album"] SubElement(root, "album").text = item["Album"]

View file

@ -817,6 +817,7 @@ class LibrarySync():
if kodiItem != None: if kodiItem != None:
updated = WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")), "movie") updated = WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")), "movie")
updated = WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "movie")
if(updated): if(updated):
totalCountsUpdated += 1 totalCountsUpdated += 1
kodiresume = int(round(kodiItem['resume'].get("position"))) kodiresume = int(round(kodiItem['resume'].get("position")))
@ -880,6 +881,7 @@ class LibrarySync():
WINDOW.setProperty("episodeid" + str(kodiItem['episodeid']), episode.get('Name') + ";;" + episode.get('Id')) WINDOW.setProperty("episodeid" + str(kodiItem['episodeid']), episode.get('Name') + ";;" + episode.get('Id'))
if kodiItem['playcount'] != int(userData.get("PlayCount")): if kodiItem['playcount'] != int(userData.get("PlayCount")):
updated = WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode") updated = WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode")
updated = WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "episode")
if(updated): if(updated):
totalCountsUpdated += 1 totalCountsUpdated += 1
kodiresume = int(round(kodiItem['resume'].get("position"))) kodiresume = int(round(kodiItem['resume'].get("position")))
@ -957,6 +959,7 @@ class LibrarySync():
WriteKodiDB().setKodiResumePoint(kodiItem['movieid'],resume,total,"movie") WriteKodiDB().setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
#write property forced will refresh the item in the list so playcount change is immediately visible #write property forced will refresh the item in the list so playcount change is immediately visible
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie",True) WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie",True)
WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "movie")
if(self.ShouldStop(None)): if(self.ShouldStop(None)):
return True return True
@ -977,7 +980,8 @@ class LibrarySync():
if kodiresume != resume: if kodiresume != resume:
WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode") WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
#write property forced will refresh the item in the list so playcount change is immediately visible #write property forced will refresh the item in the list so playcount change is immediately visible
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode",True) WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode",True)
WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "episode")
if(self.ShouldStop(None)): if(self.ShouldStop(None)):
return True return True

View file

@ -23,7 +23,7 @@ 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) 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", "lastplayed", "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
@ -39,9 +39,9 @@ class ReadKodiDB():
#returns all movies in Kodi db inserted by MB #returns all movies in Kodi db inserted by MB
xbmc.sleep(sleepVal) 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", "lastplayed", "studio", "set", "imdbnumber", "mpaa", "tagline", "plotoutline","plot", "sorttitle", "director", "writer", "playcount", "tag", "file"] }, "id": "libMovies"}')
else: else:
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties" : ["resume", "playcount", "file"] }, "id": "libMovies"}') json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties" : ["resume", "playcount", "lastplayed", "file"] }, "id": "libMovies"}')
jsonobject = json.loads(json_response.decode('utf-8','replace')) jsonobject = json.loads(json_response.decode('utf-8','replace'))
movies = None movies = None
@ -99,9 +99,9 @@ class ReadKodiDB():
#returns all tvshows in Kodi db inserted by MB #returns all tvshows in Kodi db inserted by MB
xbmc.sleep(sleepVal) 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", "lastplayed", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
else: else:
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties": ["sorttitle", "title", "playcount", "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": "plugin.video.mb3sync"}, "properties": ["sorttitle", "title", "playcount", "lastplayed", "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'))
tvshows = None tvshows = None
@ -125,7 +125,7 @@ class ReadKodiDB():
def getKodiTVShow(self, id): def getKodiTVShow(self, id):
xbmc.sleep(sleepVal) 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", "lastplayed", "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
if(jsonobject.has_key('result')): if(jsonobject.has_key('result')):
@ -173,7 +173,7 @@ class ReadKodiDB():
tvshow = self.getKodiTVShow(tvshowid) tvshow = self.getKodiTVShow(tvshowid)
if tvshow != None: if tvshow != None:
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": ' + str(tvshow['tvshowid']) + ', "properties": ["playcount","season", "resume", "episode", "uniqueid", "file"], "sort": {"method": "episode"}}, "id": 1}') json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": ' + str(tvshow['tvshowid']) + ', "properties": ["playcount","season", "resume", "episode", "lastplayed", "uniqueid", "file"], "sort": {"method": "episode"}}, "id": 1}')
jsonobject = json.loads(json_response.decode('utf-8','replace')) jsonobject = json.loads(json_response.decode('utf-8','replace'))
if(jsonobject.has_key('result')): if(jsonobject.has_key('result')):
result = jsonobject['result'] result = jsonobject['result']
@ -189,7 +189,7 @@ class ReadKodiDB():
def getKodiMusicVideo(self, id): def getKodiMusicVideo(self, id):
#returns a single musicvideo from Kodi db selected on MB item ID #returns a single musicvideo from Kodi db selected on MB item ID
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties" : ["art", "thumbnail", "resume", "runtime", "year", "genre", "studio", "artist", "album", "track","plot", "director", "playcount", "tag", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMusicVideos"}') json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties" : ["art", "thumbnail", "resume", "runtime", "year", "genre", "studio", "artist", "album", "track","plot", "director", "playcount", "lastplayed", "tag", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMusicVideos"}')
print json_response print json_response
jsonobject = json.loads(json_response.decode('utf-8','replace')) jsonobject = json.loads(json_response.decode('utf-8','replace'))
musicvideo = None musicvideo = None
@ -206,9 +206,9 @@ class ReadKodiDB():
#returns all musicvideos in Kodi db inserted by MB #returns all musicvideos in Kodi db inserted by MB
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
if fullInfo: if fullInfo:
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties" : ["art", "thumbnail", "resume", "runtime", "year", "genre", "studio", "artist", "album", "track","plot", "director", "playcount", "tag", "file"] }, "id": "libMusicVideos"}') json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties" : ["art", "thumbnail", "resume", "runtime", "year", "genre", "studio", "artist", "album", "track", "lastplayed", "plot", "director", "playcount", "tag", "file"] }, "id": "libMusicVideos"}')
else: else:
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties" : ["resume", "playcount", "file"] }, "id": "libMusicVideos"}') json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties" : ["resume", "playcount", "lastplayed", "file"] }, "id": "libMusicVideos"}')
jsonobject = json.loads(json_response.decode('utf-8','replace')) jsonobject = json.loads(json_response.decode('utf-8','replace'))
musicvideos = None musicvideos = None
if(jsonobject.has_key('result')): if(jsonobject.has_key('result')):

View file

@ -101,6 +101,7 @@ class WriteKodiDB():
self.getPropertyParam_Batched(KodiItem, "runtime", duration, params) self.getPropertyParam_Batched(KodiItem, "runtime", duration, params)
self.getPropertyParam_Batched(KodiItem, "year", MBitem.get("ProductionYear"), params) self.getPropertyParam_Batched(KodiItem, "year", MBitem.get("ProductionYear"), params)
self.getPropertyParam_Batched(KodiItem, "mpaa", MBitem.get("OfficialRating"), params) self.getPropertyParam_Batched(KodiItem, "mpaa", MBitem.get("OfficialRating"), params)
self.getPropertyParam_Batched(KodiItem, "lastplayed", userData.get("LastPlayedDate"), params)
self.getPropertyParamArray_Batched(KodiItem, "tag", MBitem.get("Tag"), params) self.getPropertyParamArray_Batched(KodiItem, "tag", MBitem.get("Tag"), params)
@ -201,6 +202,7 @@ class WriteKodiDB():
self.getPropertyParamArray_Batched(KodiItem, "genre", MBitem.get("Genres"), params) self.getPropertyParamArray_Batched(KodiItem, "genre", MBitem.get("Genres"), params)
self.getPropertyParamArray_Batched(KodiItem, "artist", MBitem.get("Artist"), params) self.getPropertyParamArray_Batched(KodiItem, "artist", MBitem.get("Artist"), params)
self.getPropertyParamArray_Batched(KodiItem, "album", MBitem.get("Album"), params) self.getPropertyParamArray_Batched(KodiItem, "album", MBitem.get("Album"), params)
self.getPropertyParam_Batched(KodiItem, "lastplayed", userData.get("LastPlayedDate"), params)
if(studios != None): if(studios != None):
for x in range(0, len(studios)): for x in range(0, len(studios)):
@ -259,7 +261,7 @@ class WriteKodiDB():
changes |= self.updateProperty(KodiItem,"runtime",duration,"movie") changes |= self.updateProperty(KodiItem,"runtime",duration,"movie")
changes |= self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie") changes |= self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie") changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
changes |= self.updateProperty(KodiItem,"lastplayed",MBitem.get("LastPlayedDate"),"movie")
changes |= self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie") changes |= self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie")
if MBitem.get("CriticRating") != None: if MBitem.get("CriticRating") != None:
@ -337,6 +339,7 @@ class WriteKodiDB():
changes |= self.updateProperty(KodiItem,"premiered",premieredate,"tvshow") changes |= self.updateProperty(KodiItem,"premiered",premieredate,"tvshow")
changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"tvshow") changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"tvshow")
changes |= self.updateProperty(KodiItem,"lastplayed",MBitem.get("LastPlayedDate"),"tvshow")
if MBitem.get("CriticRating") != None: if MBitem.get("CriticRating") != None:
changes |= self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"tvshow") changes |= self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"tvshow")
@ -397,7 +400,8 @@ class WriteKodiDB():
#update common properties #update common properties
duration = (int(timeInfo.get('Duration'))*60) duration = (int(timeInfo.get('Duration'))*60)
changes |= self.updateProperty(KodiItem,"runtime",duration,"episode") changes |= self.updateProperty(KodiItem,"runtime",duration,"episode")
changes |= self.updateProperty(KodiItem,"lastplayed",userData.get("LastPlayedDate"),"episode")
if MBitem.get("PremiereDate") != None: if MBitem.get("PremiereDate") != None:
premieredatelist = (MBitem.get("PremiereDate")).split("T") premieredatelist = (MBitem.get("PremiereDate")).split("T")
premieredate = premieredatelist[0] premieredate = premieredatelist[0]