2015-03-17 19:02:42 +00:00
|
|
|
#################################################################################################
|
|
|
|
# WriteKodiDB
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcaddon
|
|
|
|
import xbmcvfs
|
|
|
|
import json
|
|
|
|
import urllib
|
|
|
|
import sqlite3
|
|
|
|
import os
|
|
|
|
|
|
|
|
from DownloadUtils import DownloadUtils
|
|
|
|
from CreateFiles import CreateFiles
|
2015-03-17 20:18:27 +00:00
|
|
|
from ReadKodiDB import ReadKodiDB
|
2015-03-20 15:58:46 +00:00
|
|
|
from ReadEmbyDB import ReadEmbyDB
|
2015-03-17 19:02:42 +00:00
|
|
|
from API import API
|
|
|
|
import Utils as utils
|
|
|
|
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
|
|
|
|
dataPath = os.path.join(addondir,"library")
|
|
|
|
movieLibrary = os.path.join(dataPath,'movies')
|
|
|
|
tvLibrary = os.path.join(dataPath,'tvshows')
|
2015-03-19 10:13:49 +00:00
|
|
|
|
|
|
|
sleepVal = 20
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-18 02:45:15 +00:00
|
|
|
class WriteKodiDB():
|
|
|
|
|
|
|
|
def updatePlayCountFromKodi(self, id, type, playcount=0):
|
|
|
|
#when user marks item watched from kodi interface update this in MB3
|
2015-03-19 10:13:49 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-18 02:45:15 +00:00
|
|
|
xbmc.log("WriteKodiDB -> updatePlayCountFromKodi Called")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-18 02:45:15 +00:00
|
|
|
mb3Id = None
|
|
|
|
if(type == "movie"):
|
|
|
|
mb3Id = None
|
|
|
|
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'))
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('moviedetails')):
|
|
|
|
moviedetails = result['moviedetails']
|
|
|
|
filename = moviedetails.get("file").rpartition('\\')[2]
|
|
|
|
mb3Id = filename.replace(".strm","")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-18 02:45:15 +00:00
|
|
|
elif(type == "episode"):
|
|
|
|
mb3Id = None
|
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": { "episodeid": ' + str(id) + ', "properties" : ["playcount", "file"] }, "id": "1"}')
|
|
|
|
if json_response != None:
|
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('episodedetails')):
|
|
|
|
episodedetails = result['episodedetails']
|
|
|
|
filename = episodedetails.get("file").rpartition('\\')[2]
|
|
|
|
mb3Id = filename[-38:-6]
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-18 02:45:15 +00:00
|
|
|
if(mb3Id != None):
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
userid = downloadUtils.getUserId()
|
|
|
|
|
|
|
|
watchedurl = 'http://' + server + '/mediabrowser/Users/' + userid + '/PlayedItems/' + mb3Id
|
|
|
|
utils.logMsg("MB3 Sync","watchedurl -->" + watchedurl)
|
|
|
|
if playcount != 0:
|
|
|
|
downloadUtils.downloadUrl(watchedurl, postBody="", type="POST")
|
|
|
|
else:
|
|
|
|
downloadUtils.downloadUrl(watchedurl, type="DELETE")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
def updateMovieToKodiLibrary( self, MBitem, KodiItem ):
|
|
|
|
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
userid = downloadUtils.getUserId()
|
|
|
|
|
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
people = API().getPeople(MBitem)
|
|
|
|
genre = API().getGenre(MBitem)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
mediaStreams=API().getMediaStreams(MBitem)
|
|
|
|
|
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
|
|
|
|
|
|
|
changes = False
|
|
|
|
|
2015-03-20 11:39:26 +00:00
|
|
|
#update/check all artwork
|
|
|
|
changes |= self.updateArtWork(KodiItem,MBitem)
|
2015-03-19 23:48:59 +00:00
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
#update common properties
|
|
|
|
duration = (int(timeInfo.get('Duration'))*60)
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"runtime",duration,"movie")
|
|
|
|
changes |= self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
|
|
|
|
changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
|
|
|
|
|
|
|
|
changes |= self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
if MBitem.get("CriticRating") != None:
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"movie")
|
|
|
|
|
|
|
|
changes |= self.updateProperty(KodiItem,"plotoutline",MBitem.get("ShortOverview"),"movie")
|
|
|
|
changes |= self.updateProperty(KodiItem,"set",MBitem.get("TmdbCollectionName"),"movie")
|
|
|
|
changes |= self.updateProperty(KodiItem,"sorttitle",MBitem.get("SortName"),"movie")
|
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
if MBitem.get("ProviderIds") != None:
|
|
|
|
if MBitem.get("ProviderIds").get("Imdb") != None:
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"movie")
|
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
# FIXME --> Taglines not returned by MB3 server !?
|
|
|
|
if MBitem.get("TagLines") != None:
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"tagline",MBitem.get("TagLines")[0],"movie")
|
2015-03-18 05:05:21 +00:00
|
|
|
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"movie")
|
|
|
|
changes |= self.updatePropertyArray(KodiItem,"director",people.get("Director"),"movie")
|
|
|
|
changes |= self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"movie")
|
|
|
|
|
2015-03-18 05:05:21 +00:00
|
|
|
if(studios != None):
|
|
|
|
for x in range(0, len(studios)):
|
|
|
|
studios[x] = studios[x].replace("/", "&")
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"studio",studios,"movie")
|
2015-03-18 05:05:21 +00:00
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
# FIXME --> ProductionLocations not returned by MB3 server !?
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"movie")
|
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
#trailer link
|
|
|
|
trailerUrl = None
|
|
|
|
if MBitem.get("LocalTrailerCount") != None and MBitem.get("LocalTrailerCount") > 0:
|
|
|
|
itemTrailerUrl = "http://" + server + "/mediabrowser/Users/" + userid + "/Items/" + MBitem.get("Id") + "/LocalTrailers?format=json"
|
|
|
|
jsonData = downloadUtils.downloadUrl(itemTrailerUrl, suppress=True, popup=0 )
|
|
|
|
if(jsonData != ""):
|
|
|
|
trailerItem = json.loads(jsonData)
|
|
|
|
trailerUrl = "plugin://plugin.video.mb3sync/?id=" + trailerItem[0].get("Id") + '&mode=play'
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"trailer",trailerUrl,"movie")
|
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
#add actors
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"movie")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
CreateFiles().createSTRM(MBitem)
|
|
|
|
CreateFiles().createNFO(MBitem)
|
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
|
|
|
|
|
|
|
def updateTVShowToKodiLibrary( self, MBitem, KodiItem ):
|
|
|
|
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
|
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
people = API().getPeople(MBitem)
|
|
|
|
genre = API().getGenre(MBitem)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
mediaStreams=API().getMediaStreams(MBitem)
|
|
|
|
|
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
|
|
|
|
|
|
|
changes = False
|
|
|
|
|
2015-03-20 11:39:26 +00:00
|
|
|
#update/check all artwork
|
|
|
|
changes |= self.updateArtWork(KodiItem,MBitem)
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
#update common properties
|
|
|
|
if MBitem.get("PremiereDate") != None:
|
|
|
|
premieredatelist = (MBitem.get("PremiereDate")).split("T")
|
|
|
|
premieredate = premieredatelist[0]
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"premiered",premieredate,"tvshow")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"tvshow")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
if MBitem.get("CriticRating") != None:
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"tvshow")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"sorttitle",MBitem.get("SortName"),"tvshow")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
if MBitem.get("ProviderIds") != None:
|
|
|
|
if MBitem.get("ProviderIds").get("Imdb") != None:
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"tvshow")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"tvshow")
|
2015-03-18 05:05:21 +00:00
|
|
|
|
|
|
|
if(studios != None):
|
|
|
|
for x in range(0, len(studios)):
|
|
|
|
studios[x] = studios[x].replace("/", "&")
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"studio",studios,"tvshow")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
# FIXME --> ProductionLocations not returned by MB3 server !?
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"tvshow")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
#add actors
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"tvshow")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-20 15:58:46 +00:00
|
|
|
#update season artwork
|
|
|
|
self.updateSeasonArtwork(MBitem, KodiItem)
|
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
CreateFiles().createNFO(MBitem)
|
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
2015-03-20 11:39:26 +00:00
|
|
|
|
2015-03-19 08:44:25 +00:00
|
|
|
def updateEpisodeToKodiLibrary( self, MBitem, KodiItem ):
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
userid = downloadUtils.getUserId()
|
|
|
|
|
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
people = API().getPeople(MBitem)
|
|
|
|
genre = API().getGenre(MBitem)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
mediaStreams=API().getMediaStreams(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
|
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
|
|
|
|
|
|
|
changes = False
|
|
|
|
|
2015-03-20 11:39:26 +00:00
|
|
|
#update/check all artwork
|
|
|
|
changes |= self.updateArtWork(KodiItem,MBitem)
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
#update common properties
|
|
|
|
duration = (int(timeInfo.get('Duration'))*60)
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"runtime",duration,"episode")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
if MBitem.get("PremiereDate") != None:
|
|
|
|
premieredatelist = (MBitem.get("PremiereDate")).split("T")
|
|
|
|
premieredate = premieredatelist[0]
|
|
|
|
premieretime = premieredatelist[1].split(".")[0]
|
|
|
|
firstaired = premieredate + " " + premieretime
|
|
|
|
# for Helix we use the whole time string, for kodi 15 we have to change to only the datestring
|
|
|
|
# see: http://forum.kodi.tv/showthread.php?tid=218743
|
|
|
|
if KodiItem["firstaired"] != premieredate:
|
|
|
|
self.updateProperty(KodiItem,"firstaired",firstaired,"episode")
|
|
|
|
|
|
|
|
if MBitem.get("CriticRating") != None:
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"episode")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"episode")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
#add actors
|
2015-03-20 00:21:43 +00:00
|
|
|
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"episode")
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-19 08:44:25 +00:00
|
|
|
CreateFiles().createNFO(MBitem)
|
|
|
|
CreateFiles().createSTRM(MBitem)
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
|
|
|
|
|
|
|
# adds or updates artwork to the given Kodi file in database
|
2015-03-20 11:39:26 +00:00
|
|
|
def updateArtWork(self,KodiItem,MBitem):
|
|
|
|
|
|
|
|
item_type=str(MBitem.get("Type"))
|
|
|
|
|
|
|
|
if item_type == "Series":
|
2015-03-17 19:02:42 +00:00
|
|
|
id = KodiItem['tvshowid']
|
2015-03-20 11:39:26 +00:00
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "art": %s}, "id": 1 }'
|
|
|
|
elif item_type == "Episode":
|
2015-03-20 13:37:34 +00:00
|
|
|
# episodes don't have any artwork - they derrive this from the tv show
|
|
|
|
return False
|
2015-03-20 11:39:26 +00:00
|
|
|
elif item_type == "MusicVideo":
|
2015-03-17 19:02:42 +00:00
|
|
|
id = KodiItem['musicvideoid']
|
2015-03-20 11:39:26 +00:00
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { musicvideoid": %i, "art": %s}, "id": 1 }'
|
|
|
|
elif item_type == "Movie":
|
2015-03-17 19:02:42 +00:00
|
|
|
id = KodiItem['movieid']
|
2015-03-20 11:39:26 +00:00
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "art": %s}, "id": 1 }'
|
2015-03-20 11:53:02 +00:00
|
|
|
|
2015-03-20 11:39:26 +00:00
|
|
|
#update artwork
|
2015-03-17 19:02:42 +00:00
|
|
|
changes = False
|
2015-03-20 11:39:26 +00:00
|
|
|
|
|
|
|
artwork = {}
|
|
|
|
artwork["poster"] = API().getArtwork(MBitem, "Primary")
|
2015-03-20 15:16:39 +00:00
|
|
|
artwork["banner"] = API().getArtwork(MBitem, "Banner")
|
2015-03-20 11:39:26 +00:00
|
|
|
artwork["clearlogo"] = API().getArtwork(MBitem, "Logo")
|
|
|
|
artwork["clearart"] = API().getArtwork(MBitem, "Art")
|
|
|
|
artwork["landscape"] = API().getArtwork(MBitem, "Thumb")
|
|
|
|
artwork["discart"] = API().getArtwork(MBitem, "Disc")
|
|
|
|
artwork["fanart"] = API().getArtwork(MBitem, "Backdrop")
|
|
|
|
|
|
|
|
for art in artwork:
|
2015-03-20 11:53:02 +00:00
|
|
|
if artwork.get(art) != "":
|
2015-03-20 11:39:26 +00:00
|
|
|
if KodiItem["art"].has_key(art):
|
2015-03-20 11:53:02 +00:00
|
|
|
curValue = urllib.unquote(KodiItem['art'][art]).decode('utf8')
|
|
|
|
if not artwork.get(art) in curValue:
|
2015-03-20 11:39:26 +00:00
|
|
|
KodiItem["art"][art] = artwork.get(art)
|
|
|
|
changes = True
|
|
|
|
else:
|
|
|
|
KodiItem["art"][art] = artwork.get(art)
|
|
|
|
changes = True
|
|
|
|
|
|
|
|
if len(KodiItem["art"]) == 0:
|
|
|
|
changes = False
|
|
|
|
|
|
|
|
if changes:
|
|
|
|
json_array = json.dumps(KodiItem["art"])
|
|
|
|
result = xbmc.executeJSONRPC(jsoncommand %(id, json_array))
|
2015-03-17 19:02:42 +00:00
|
|
|
return changes
|
|
|
|
|
|
|
|
# adds or updates the given property on the videofile in Kodi database
|
2015-03-19 23:24:29 +00:00
|
|
|
def updateProperty(self,KodiItem,propertyName,propertyValue,fileType,forced=False):
|
2015-03-17 19:02:42 +00:00
|
|
|
if fileType == "tvshow":
|
|
|
|
id = KodiItem['tvshowid']
|
|
|
|
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "%s": %i}, "id": 1 }'
|
|
|
|
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "%s": "%s"}, "id": 1 }'
|
|
|
|
elif fileType == "episode":
|
|
|
|
id = KodiItem['episodeid']
|
|
|
|
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "%s": %i}, "id": 1 }'
|
|
|
|
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "%s": "%s"}, "id": 1 }'
|
|
|
|
elif fileType == "musicvideo":
|
|
|
|
id = KodiItem['musicvideoid']
|
|
|
|
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, "%s": %i}, "id": 1 }'
|
|
|
|
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, "%s": "%s"}, "id": 1 }'
|
|
|
|
elif fileType == "movie":
|
|
|
|
id = KodiItem['movieid']
|
|
|
|
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": %i}, "id": 1 }'
|
|
|
|
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": "%s"}, "id": 1 }'
|
|
|
|
|
|
|
|
changes = False
|
2015-03-19 23:24:29 +00:00
|
|
|
if ((propertyValue != KodiItem[propertyName]) or forced):
|
2015-03-17 19:02:42 +00:00
|
|
|
if propertyValue != None:
|
|
|
|
if type(propertyValue) is int:
|
|
|
|
xbmc.sleep(sleepVal)
|
|
|
|
utils.logMsg("MB3 Sync","updating property..." + str(propertyName))
|
|
|
|
utils.logMsg("MB3 Sync","kodi value:" + str(KodiItem[propertyName]) + " MB value: " + str(propertyValue))
|
|
|
|
xbmc.executeJSONRPC(jsoncommand_i %(id, propertyName, propertyValue))
|
|
|
|
changes = True
|
|
|
|
else:
|
|
|
|
xbmc.sleep(sleepVal)
|
|
|
|
utils.logMsg("MB3 Sync","updating property..." + str(propertyName))
|
|
|
|
utils.logMsg("MB3 Sync","kodi value:" + KodiItem[propertyName] + " MB value: " + propertyValue)
|
|
|
|
xbmc.executeJSONRPC(jsoncommand_s %(id, propertyName, propertyValue.encode('utf-8')))
|
|
|
|
changes = True
|
|
|
|
|
|
|
|
return changes
|
|
|
|
|
|
|
|
# adds or updates the property-array on the videofile in Kodi database
|
|
|
|
def updatePropertyArray(self,KodiItem,propertyName,propertyCollection,fileType):
|
|
|
|
if fileType == "tvshow":
|
|
|
|
id = KodiItem['tvshowid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "%s": %s}, "id": 1 }'
|
|
|
|
elif fileType == "episode":
|
|
|
|
id = KodiItem['episodeid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "%s": %s}, "id": 1 }'
|
|
|
|
elif fileType == "musicvideo":
|
|
|
|
id = KodiItem['musicvideoid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, "%s": %s}, "id": 1 }'
|
|
|
|
elif fileType == "movie":
|
|
|
|
id = KodiItem['movieid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": %s}, "id": 1 }'
|
2015-03-18 05:05:21 +00:00
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
pendingChanges = False
|
2015-03-18 05:05:21 +00:00
|
|
|
if propertyCollection != None:
|
2015-03-17 19:02:42 +00:00
|
|
|
currentvalues = set(KodiItem[propertyName])
|
|
|
|
for item in propertyCollection:
|
|
|
|
if not item in currentvalues:
|
|
|
|
pendingChanges = True
|
|
|
|
json_array = json.dumps(propertyCollection)
|
|
|
|
|
|
|
|
if pendingChanges:
|
|
|
|
xbmc.sleep(sleepVal)
|
|
|
|
utils.logMsg("MB3 Sync","updating propertyarray... Name:" + str(propertyName) + " Current:" + str(currentvalues) + " New:" + str(json_array))
|
|
|
|
xbmc.executeJSONRPC(jsoncommand %(id,propertyName,json_array))
|
|
|
|
|
|
|
|
return pendingChanges
|
|
|
|
|
|
|
|
def addMovieToKodiLibrary( self, item ):
|
|
|
|
itemPath = os.path.join(movieLibrary,item["Id"])
|
|
|
|
strmFile = os.path.join(itemPath,item["Id"] + ".strm")
|
|
|
|
|
|
|
|
changes = False
|
|
|
|
|
|
|
|
#create path if not exists
|
|
|
|
if not xbmcvfs.exists(itemPath + os.sep):
|
|
|
|
xbmcvfs.mkdir(itemPath)
|
|
|
|
|
|
|
|
#create nfo file
|
|
|
|
changes = CreateFiles().createNFO(item)
|
|
|
|
|
|
|
|
# create strm file
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= CreateFiles().createSTRM(item)
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("MB3 Sync","Added movie to Kodi Library",item["Id"] + " - " + item["Name"])
|
|
|
|
|
2015-03-19 08:44:25 +00:00
|
|
|
def addEpisodeToKodiLibrary(self, item):
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
changes = False
|
|
|
|
|
|
|
|
#create nfo file
|
2015-03-19 08:44:25 +00:00
|
|
|
changes = CreateFiles().createNFO(item)
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
# create strm file
|
2015-03-19 23:48:59 +00:00
|
|
|
changes |= CreateFiles().createSTRM(item)
|
2015-03-17 19:02:42 +00:00
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("MB3 Sync","Added episode to Kodi Library",item["Id"] + " - " + item["Name"])
|
|
|
|
|
|
|
|
def deleteMovieFromKodiLibrary(self, id ):
|
|
|
|
kodiItem = ReadKodiDB().getKodiMovie(id)
|
|
|
|
utils.logMsg("deleting movie from Kodi library",id)
|
|
|
|
if kodiItem != None:
|
|
|
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveMovie", "params": { "movieid": %i}, "id": 1 }' %(kodiItem["movieid"]))
|
|
|
|
|
|
|
|
path = os.path.join(movieLibrary,id)
|
|
|
|
xbmcvfs.rmdir(path)
|
2015-03-20 19:26:37 +00:00
|
|
|
|
|
|
|
def deleteEpisodeFromKodiLibrary(self, episodeid ):
|
|
|
|
utils.logMsg("deleting movie from Kodi library",id)
|
2015-03-17 19:02:42 +00:00
|
|
|
|
2015-03-20 19:26:37 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": { "episodeid": %i}, "properties" : ["file","episodeid"] }, "id": "libTvShows"}' %(int(episodeid)))
|
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
|
|
|
|
print jsonobject
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('episodedetails')):
|
|
|
|
episodedetails = result['episodedetails']
|
|
|
|
|
|
|
|
strmfile = episodedetails["file"]
|
|
|
|
nfofile = strmfile.replace(".strm",".nfo")
|
|
|
|
|
|
|
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveEpisode", "params": { "episodeid": %i}, "id": 1 }' %(int(episodeid)))
|
|
|
|
|
|
|
|
xbmcvfs.delete(strmfile)
|
|
|
|
xbmcvfs.delete(nfofile)
|
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
def addTVShowToKodiLibrary( self, item ):
|
|
|
|
itemPath = os.path.join(tvLibrary,item["Id"])
|
|
|
|
|
|
|
|
changes = False
|
|
|
|
|
|
|
|
#create path if not exists
|
|
|
|
if not xbmcvfs.exists(itemPath + os.sep):
|
|
|
|
xbmcvfs.mkdir(itemPath)
|
|
|
|
|
|
|
|
#create nfo file
|
|
|
|
changes = CreateFiles().createNFO(item)
|
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("Added TV Show to Kodi Library ",item["Id"] + " - " + item["Name"])
|
|
|
|
|
|
|
|
def deleteTVShowFromKodiLibrary(self, id ):
|
2015-03-19 10:13:49 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-17 19:02:42 +00:00
|
|
|
kodiItem = ReadKodiDB().getKodiTVShow(id)
|
|
|
|
utils.logMsg("deleting tvshow from Kodi library",id)
|
|
|
|
if kodiItem != None:
|
|
|
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveTVShow", "params": { "tvshowid": %i}, "id": 1 }' %(kodiItem["tvshowid"]))
|
|
|
|
path = os.path.join(tvLibrary,id)
|
|
|
|
xbmcvfs.rmdir(path)
|
|
|
|
|
2015-03-20 15:16:39 +00:00
|
|
|
|
2015-03-20 15:58:46 +00:00
|
|
|
def updateSeasonArtwork(self,MBitem, KodiItem):
|
|
|
|
#use sqlite to set the season artwork because no method in API available for this
|
|
|
|
#season poster and banner are set by the nfo. landscape image is filled by this method
|
|
|
|
#if wanted this feature can be extended to also update the other artwork
|
|
|
|
tvshowid = KodiItem["tvshowid"]
|
|
|
|
|
|
|
|
dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db")
|
|
|
|
connection = sqlite3.connect(dbPath)
|
|
|
|
cursor = connection.cursor( )
|
2015-03-20 15:16:39 +00:00
|
|
|
|
2015-03-20 15:58:46 +00:00
|
|
|
seasonData = ReadEmbyDB().getTVShowSeasons(MBitem["Id"])
|
|
|
|
if seasonData != None:
|
|
|
|
for season in seasonData:
|
|
|
|
if season.has_key("IndexNumber"):
|
|
|
|
MB3landscape = API().getArtwork(season, "Thumb")
|
|
|
|
if MB3landscape != "":
|
|
|
|
cursor.execute("SELECT idSeason as seasonid FROM seasons WHERE idShow = ? and season = ?",(tvshowid,season["IndexNumber"]))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
seasonid = result[0]
|
|
|
|
cursor.execute("SELECT art_id as art_id FROM art WHERE media_id = ? and media_type = ? and type = ?",(seasonid,"season","landscape"))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result == None:
|
|
|
|
sql="INSERT into art(media_id, media_type, type, url) values(?, ?, ?, ?)"
|
|
|
|
cursor.execute(sql, (seasonid,"season","landscape",MB3landscape))
|
|
|
|
|
|
|
|
connection.commit()
|
|
|
|
cursor.close()
|
2015-03-20 15:16:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
def setKodiResumePoint(self, id, resume_seconds, total_seconds, fileType):
|
|
|
|
#use sqlite to set the resume point while json api doesn't support this yet
|
|
|
|
#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))
|
2015-03-19 10:13:49 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-17 19:02:42 +00:00
|
|
|
dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db")
|
|
|
|
connection = sqlite3.connect(dbPath)
|
|
|
|
cursor = connection.cursor( )
|
|
|
|
|
|
|
|
if fileType == "episode":
|
|
|
|
cursor.execute("SELECT idFile as fileidid FROM episode WHERE idEpisode = ?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
fileid = result[0]
|
|
|
|
if fileType == "movie":
|
|
|
|
cursor.execute("SELECT idFile as fileidid FROM movie WHERE idMovie = ?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
fileid = result[0]
|
|
|
|
|
|
|
|
cursor.execute("delete FROM bookmark WHERE idFile = ?", (fileid,))
|
|
|
|
cursor.execute("select coalesce(max(idBookmark),0) as bookmarkId from bookmark")
|
|
|
|
bookmarkId = cursor.fetchone()[0]
|
|
|
|
bookmarkId = bookmarkId + 1
|
|
|
|
bookmarksql="insert into bookmark(idBookmark, idFile, timeInSeconds, totalTimeInSeconds, thumbNailImage, player, playerState, type) values(?, ?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(bookmarksql, (bookmarkId,fileid,resume_seconds,total_seconds,None,"DVDPlayer",None,1))
|
|
|
|
connection.commit()
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
def AddActorsToMedia(self, KodiItem, people, mediatype):
|
|
|
|
#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
|
2015-03-20 00:21:43 +00:00
|
|
|
|
2015-03-17 19:02:42 +00:00
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
if mediatype == "movie":
|
|
|
|
id = KodiItem["movieid"]
|
|
|
|
if mediatype == "tvshow":
|
|
|
|
id = KodiItem["tvshowid"]
|
|
|
|
if mediatype == "episode":
|
|
|
|
id = KodiItem["episodeid"]
|
|
|
|
|
|
|
|
currentcast = list()
|
|
|
|
if KodiItem["cast"] != None:
|
|
|
|
for cast in KodiItem["cast"]:
|
|
|
|
currentcast.append(cast["name"])
|
2015-03-19 23:48:59 +00:00
|
|
|
|
2015-03-20 00:21:43 +00:00
|
|
|
needsUpdate = False
|
2015-03-17 19:02:42 +00:00
|
|
|
if(people != None):
|
|
|
|
for person in people:
|
|
|
|
if(person.get("Type") == "Actor"):
|
|
|
|
if person.get("Name") not in currentcast:
|
2015-03-20 00:21:43 +00:00
|
|
|
needsUpdate = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if(needsUpdate == False):
|
|
|
|
return False
|
|
|
|
|
|
|
|
utils.logMsg("AddActorsToMedia", "List needs updating")
|
|
|
|
|
|
|
|
xbmc.sleep(sleepVal)
|
|
|
|
|
|
|
|
dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db")
|
|
|
|
connection = sqlite3.connect(dbPath)
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
if(people != None):
|
|
|
|
for person in people:
|
|
|
|
if(person.get("Type") == "Actor"):
|
|
|
|
if person.get("Name") not in currentcast:
|
|
|
|
utils.logMsg("AddActorsToMedia", "Processing : " + person.get("Name"))
|
2015-03-17 19:02:42 +00:00
|
|
|
Name = person.get("Name")
|
|
|
|
Role = person.get("Role")
|
|
|
|
actorid = None
|
|
|
|
Thumb = downloadUtils.imageUrl(person.get("Id"), "Primary", 0, 400, 400)
|
|
|
|
cursor.execute("SELECT idActor as actorid FROM actors WHERE strActor = ?",(Name,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
actorid = result[0]
|
|
|
|
if actorid == None:
|
|
|
|
cursor.execute("select coalesce(max(idActor),0) as actorid from actors")
|
|
|
|
actorid = cursor.fetchone()[0]
|
|
|
|
actorid = actorid + 1
|
|
|
|
peoplesql="insert into actors(idActor, strActor, strThumb) values(?, ?, ?)"
|
|
|
|
cursor.execute(peoplesql, (actorid,Name,Thumb))
|
|
|
|
|
|
|
|
if mediatype == "movie":
|
|
|
|
peoplesql="INSERT OR REPLACE into actorlinkmovie(idActor, idMovie, strRole, iOrder) values(?, ?, ?, ?)"
|
|
|
|
if mediatype == "tvshow":
|
|
|
|
peoplesql="INSERT OR REPLACE into actorlinktvshow(idActor, idShow, strRole, iOrder) values(?, ?, ?, ?)"
|
|
|
|
if mediatype == "episode":
|
|
|
|
peoplesql="INSERT OR REPLACE into actorlinkepisode(idActor, idEpisode, strRole, iOrder) values(?, ?, ?, ?)"
|
|
|
|
cursor.execute(peoplesql, (actorid,id,Role,None))
|
|
|
|
|
|
|
|
connection.commit()
|
|
|
|
cursor.close()
|
2015-03-20 00:21:43 +00:00
|
|
|
|
|
|
|
return True
|