more universal way of setting the properties on items
This commit is contained in:
parent
f1e393d0f2
commit
082747fafc
1 changed files with 47 additions and 35 deletions
|
@ -134,7 +134,6 @@ class LibrarySync():
|
||||||
|
|
||||||
def updateMovieToKodiLibrary( self, MBitem, KodiItem ):
|
def updateMovieToKodiLibrary( self, MBitem, KodiItem ):
|
||||||
|
|
||||||
#TODO: only update the info if something is actually changed
|
|
||||||
timeInfo = API().getTimeInfo(MBitem)
|
timeInfo = API().getTimeInfo(MBitem)
|
||||||
userData=API().getUserData(MBitem)
|
userData=API().getUserData(MBitem)
|
||||||
people = API().getPeople(MBitem)
|
people = API().getPeople(MBitem)
|
||||||
|
@ -146,34 +145,20 @@ class LibrarySync():
|
||||||
utils.logMsg("Updating item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Updating item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
|
|
||||||
#update artwork
|
#update artwork
|
||||||
self.updateArtWork(KodiItem,"poster", downloadUtils.getArtwork(MBitem, "poster"))
|
self.updateArtWork(KodiItem,"poster", downloadUtils.getArtwork(MBitem, "poster"),"movie")
|
||||||
self.updateArtWork(KodiItem,"clearlogo", downloadUtils.getArtwork(MBitem, "Logo"))
|
self.updateArtWork(KodiItem,"clearlogo", downloadUtils.getArtwork(MBitem, "Logo"),"movie")
|
||||||
self.updateArtWork(KodiItem,"banner", downloadUtils.getArtwork(MBitem, "Banner"))
|
self.updateArtWork(KodiItem,"banner", downloadUtils.getArtwork(MBitem, "Banner"),"movie")
|
||||||
self.updateArtWork(KodiItem,"landscape", downloadUtils.getArtwork(MBitem, "Thumb"))
|
self.updateArtWork(KodiItem,"landscape", downloadUtils.getArtwork(MBitem, "Thumb"),"movie")
|
||||||
self.updateArtWork(KodiItem,"discart", downloadUtils.getArtwork(MBitem, "Disc"))
|
self.updateArtWork(KodiItem,"discart", downloadUtils.getArtwork(MBitem, "Disc"),"movie")
|
||||||
self.updateArtWork(KodiItem,"fanart", downloadUtils.getArtwork(MBitem, "Backdrop"))
|
self.updateArtWork(KodiItem,"fanart", downloadUtils.getArtwork(MBitem, "Backdrop"),"movie")
|
||||||
|
|
||||||
#update duration
|
#update common properties
|
||||||
duration = (int(timeInfo.get('Duration'))*60)
|
duration = (int(timeInfo.get('Duration'))*60)
|
||||||
if KodiItem['runtime'] != duration:
|
self.updateProperty(KodiItem,"runtime",duration,"movie")
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "runtime": %s}, "id": 1 }' %(KodiItem['movieid'], duration))
|
self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
|
||||||
|
self.updateProperty(KodiItem,"writer",MBitem.get("Writer"),"movie")
|
||||||
#update year
|
self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
|
||||||
if KodiItem['year'] != MBitem.get("ProductionYear") and MBitem.get("ProductionYear") != None:
|
self.updateProperty(KodiItem,"rating",MBitem.get("CommunityRating"),"movie")
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "year": %s}, "id": 1 }' %(KodiItem['movieid'], MBitem.get("ProductionYear")))
|
|
||||||
|
|
||||||
#update writer
|
|
||||||
if KodiItem['writer'] != MBitem.get("Writer") and MBitem.get("Writer") != None:
|
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "writer": "%s"}, "id": 1 }' %(KodiItem['movieid'], MBitem.get("Writer")))
|
|
||||||
|
|
||||||
#update mpaa
|
|
||||||
if KodiItem['mpaa'] != MBitem.get("OfficialRating") and MBitem.get("OfficialRating") != None:
|
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "mpaa": "%s"}, "id": 1 }' %(KodiItem['movieid'], MBitem.get("OfficialRating")))
|
|
||||||
|
|
||||||
#update rating
|
|
||||||
if KodiItem['rating'] != MBitem.get("CommunityRating") and MBitem.get("CommunityRating") != None:
|
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "rating": "%s"}, "id": 1 }' %(KodiItem['movieid'], int(MBitem.get("CommunityRating"))))
|
|
||||||
|
|
||||||
|
|
||||||
#trailer link
|
#trailer link
|
||||||
trailerUrl = None
|
trailerUrl = None
|
||||||
|
@ -182,8 +167,7 @@ class LibrarySync():
|
||||||
jsonData = downloadUtils.downloadUrl(itemTrailerUrl, suppress=True, popup=0 )
|
jsonData = downloadUtils.downloadUrl(itemTrailerUrl, suppress=True, popup=0 )
|
||||||
trailerItem = json.loads(jsonData)
|
trailerItem = json.loads(jsonData)
|
||||||
trailerUrl = "plugin://plugin.video.mb3sync/?id=" + trailerItem[0].get("Id") + '&mode=play'
|
trailerUrl = "plugin://plugin.video.mb3sync/?id=" + trailerItem[0].get("Id") + '&mode=play'
|
||||||
if KodiItem['trailer'] != trailerUrl and trailerUrl != None:
|
self.updateProperty(KodiItem,"trailer",trailerUrl,"movie")
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "trailer": "%s"}, "id": 1 }' %(KodiItem['movieid'], trailerUrl))
|
|
||||||
|
|
||||||
|
|
||||||
#update genre
|
#update genre
|
||||||
|
@ -204,13 +188,41 @@ class LibrarySync():
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "playcount": %i}, "id": 1 }' %(KodiItem['movieid'], int(userData.get("PlayCount"))))
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "playcount": %i}, "id": 1 }' %(KodiItem['movieid'], int(userData.get("PlayCount"))))
|
||||||
|
|
||||||
|
|
||||||
def updateArtWork(self,KodiItem,artWorkName,artworkValue):
|
# adds or updates artwork to the given Kodi file in database
|
||||||
|
def updateArtWork(self,KodiItem,artWorkName,artworkValue, fileType="movie"):
|
||||||
|
if fileType == "tvshow":
|
||||||
|
method = "VideoLibrary.SetTVShowDetails"
|
||||||
|
elif fileType == "episode":
|
||||||
|
method = "VideoLibrary.SetEpisodeDetails"
|
||||||
|
elif fileType == "musicvideo":
|
||||||
|
method = "VideoLibrary.SetMusicVideoDetails"
|
||||||
|
else:
|
||||||
|
method = "VideoLibrary.SetMovieDetails"
|
||||||
|
|
||||||
if KodiItem['art'].has_key(artWorkName):
|
if KodiItem['art'].has_key(artWorkName):
|
||||||
curValue = urllib.unquote(KodiItem['art'][artWorkName]).decode('utf8')
|
curValue = urllib.unquote(KodiItem['art'][artWorkName]).decode('utf8')
|
||||||
if not artworkValue in curValue:
|
if not artworkValue in curValue:
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "art": { "%s": "%s" }}, "id": 1 }' %(KodiItem['movieid'], artWorkName, artworkValue))
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "%s", "params": { "movieid": %i, "art": { "%s": "%s" }}, "id": 1 }' %(method,KodiItem['movieid'], artWorkName, artworkValue))
|
||||||
elif artworkValue != None:
|
elif artworkValue != None:
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "art": { "%s": "%s" }}, "id": 1 }' %(KodiItem['movieid'], artWorkName, artworkValue))
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "%s", "params": { "movieid": %i, "art": { "%s": "%s" }}, "id": 1 }' %(method,KodiItem['movieid'], artWorkName, artworkValue))
|
||||||
|
|
||||||
|
# adds or updates the given property on the videofile in Kodi database
|
||||||
|
def updateProperty(self,KodiItem,propertyName,propertyValue,fileType="movie"):
|
||||||
|
if fileType == "tvshow":
|
||||||
|
method = "VideoLibrary.SetTVShowDetails"
|
||||||
|
elif fileType == "episode":
|
||||||
|
method = "VideoLibrary.SetEpisodeDetails"
|
||||||
|
elif fileType == "musicvideo":
|
||||||
|
method = "VideoLibrary.SetMusicVideoDetails"
|
||||||
|
else:
|
||||||
|
method = "VideoLibrary.SetMovieDetails"
|
||||||
|
|
||||||
|
if not propertyValue in KodiItem[propertyName]:
|
||||||
|
if type(propertyValue) is int:
|
||||||
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "%s", "params": { "movieid": %i, "%s": %i}, "id": 1 }' %(method,KodiItem['movieid'], propertyName, propertyValue))
|
||||||
|
else:
|
||||||
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "%s", "params": { "movieid": %i, "%s": "%s"}, "id": 1 }' %(method,KodiItem['movieid'], propertyName, propertyValue))
|
||||||
|
|
||||||
|
|
||||||
def createSTRM(self,id):
|
def createSTRM(self,id):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue