2015-03-18 06:02:42 +11:00
|
|
|
#################################################################################################
|
|
|
|
# WriteKodiDB
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcaddon
|
|
|
|
import xbmcvfs
|
|
|
|
import json
|
|
|
|
import urllib
|
|
|
|
import sqlite3
|
|
|
|
import os
|
|
|
|
|
|
|
|
from DownloadUtils import DownloadUtils
|
2015-03-29 03:42:38 +11:00
|
|
|
from PlayUtils import PlayUtils
|
2015-03-18 07:18:27 +11:00
|
|
|
from ReadKodiDB import ReadKodiDB
|
2015-03-21 02:58:46 +11:00
|
|
|
from ReadEmbyDB import ReadEmbyDB
|
2015-03-18 06:02:42 +11:00
|
|
|
from API import API
|
|
|
|
import Utils as utils
|
|
|
|
|
2015-03-19 21:13:49 +11:00
|
|
|
sleepVal = 20
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-18 13:45:15 +11: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 21:13:49 +11:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby", "updatePlayCountFromKodi Called")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-29 13:34:59 +11:00
|
|
|
mb3Id = ReadKodiDB().getEmbyIdByKodiId(id, type)
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-18 13:45:15 +11:00
|
|
|
if(mb3Id != None):
|
2015-03-26 04:37:21 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
2015-03-18 13:45:15 +11:00
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
userid = downloadUtils.getUserId()
|
|
|
|
|
|
|
|
watchedurl = 'http://' + server + '/mediabrowser/Users/' + userid + '/PlayedItems/' + mb3Id
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","watchedurl -->" + watchedurl)
|
2015-03-18 13:45:15 +11:00
|
|
|
if playcount != 0:
|
|
|
|
downloadUtils.downloadUrl(watchedurl, postBody="", type="POST")
|
|
|
|
else:
|
|
|
|
downloadUtils.downloadUrl(watchedurl, type="DELETE")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-21 10:33:04 +11:00
|
|
|
def updateMovieToKodiLibrary_Batched(self, MBitem, KodiItem):
|
2015-03-26 04:37:21 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
2015-03-21 10:33:04 +11:00
|
|
|
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")
|
|
|
|
|
|
|
|
params = list()
|
|
|
|
|
|
|
|
self.getArtworkParam_Batched(KodiItem, MBitem, params)
|
2015-03-29 03:42:38 +11:00
|
|
|
|
|
|
|
#set Filename
|
|
|
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
2015-04-02 06:07:29 +11:00
|
|
|
self.setKodiFilename(KodiItem["movieid"], KodiItem["file"], playurl, "movie", MBitem["Id"])
|
2015-03-29 03:42:38 +11:00
|
|
|
|
2015-03-21 10:33:04 +11:00
|
|
|
#update common properties
|
2015-04-02 06:07:29 +11:00
|
|
|
if KodiItem["runtime"] == 0:
|
|
|
|
self.getPropertyParam_Batched(KodiItem, "runtime", (int(timeInfo.get('Duration'))*60), params)
|
2015-03-21 10:33:04 +11:00
|
|
|
self.getPropertyParam_Batched(KodiItem, "year", MBitem.get("ProductionYear"), params)
|
|
|
|
self.getPropertyParam_Batched(KodiItem, "mpaa", MBitem.get("OfficialRating"), params)
|
2015-03-25 07:03:07 +11:00
|
|
|
self.getPropertyParam_Batched(KodiItem, "lastplayed", userData.get("LastPlayedDate"), params)
|
2015-03-21 10:33:04 +11:00
|
|
|
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "tag", MBitem.get("Tag"), params)
|
|
|
|
|
|
|
|
if MBitem.get("CriticRating") != None:
|
|
|
|
self.getPropertyParam_Batched(KodiItem, "rating", int(MBitem.get("CriticRating"))/10, params)
|
|
|
|
|
|
|
|
self.getPropertyParam_Batched(KodiItem, "plotoutline", MBitem.get("ShortOverview"), params)
|
|
|
|
self.getPropertyParam_Batched(KodiItem, "set", MBitem.get("TmdbCollectionName"), params)
|
|
|
|
self.getPropertyParam_Batched(KodiItem, "sorttitle", MBitem.get("SortName"), params)
|
|
|
|
|
|
|
|
if MBitem.get("ProviderIds") != None:
|
|
|
|
if MBitem.get("ProviderIds").get("Imdb") != None:
|
|
|
|
self.getPropertyParam_Batched(KodiItem, "imdbnumber", MBitem.get("ProviderIds").get("Imdb"), params)
|
|
|
|
|
|
|
|
# FIXME --> Taglines not returned by MB3 server !?
|
|
|
|
if MBitem.get("TagLines") != None:
|
|
|
|
self.getPropertyParam_Batched(KodiItem, "tagline", MBitem.get("TagLines")[0], params)
|
|
|
|
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "writer", people.get("Writer"), params)
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "director", people.get("Director"), params)
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "genre", MBitem.get("Genres"), params)
|
|
|
|
|
|
|
|
if(studios != None):
|
|
|
|
for x in range(0, len(studios)):
|
|
|
|
studios[x] = studios[x].replace("/", "&")
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "studio", studios, params)
|
|
|
|
|
|
|
|
# FIXME --> ProductionLocations not returned by MB3 server !?
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "country", MBitem.get("ProductionLocations"), params)
|
|
|
|
|
|
|
|
#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"
|
2015-03-25 23:48:29 +11:00
|
|
|
jsonData = downloadUtils.downloadUrl(itemTrailerUrl, suppress=False, popup=0 )
|
2015-03-21 10:33:04 +11:00
|
|
|
if(jsonData != ""):
|
|
|
|
trailerItem = json.loads(jsonData)
|
2015-03-23 01:51:03 +11:00
|
|
|
if trailerItem[0].get("LocationType") == "FileSystem":
|
2015-04-02 06:07:29 +11:00
|
|
|
trailerUrl = PlayUtils().getPlayUrl(server, trailerItem[0].get("Id"), trailerItem[0])
|
2015-04-02 21:47:29 +11:00
|
|
|
trailerUrl = utils.convertEncoding(trailerUrl)
|
2015-03-23 01:51:03 +11:00
|
|
|
self.getPropertyParam_Batched(KodiItem, "trailer", trailerUrl, params)
|
|
|
|
|
2015-03-21 10:33:04 +11:00
|
|
|
|
|
|
|
changes = False
|
|
|
|
# if there were movies changes then send the update via JSONRPC
|
|
|
|
if(len(params) > 0):
|
|
|
|
changes |= True
|
2015-03-21 14:15:34 +11:00
|
|
|
utils.logMsg("UpdateMovieParams", str(params), level = 2)
|
2015-03-21 10:33:04 +11:00
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, %s}, "id": 1 }'
|
|
|
|
paramString = ""
|
|
|
|
paramLen = len(params)
|
|
|
|
for x in range(0, paramLen):
|
|
|
|
param = params[x]
|
|
|
|
paramString += param
|
|
|
|
if(x < paramLen-1):
|
|
|
|
paramString += ", "
|
|
|
|
jsoncommand = jsoncommand %(KodiItem['movieid'], paramString)
|
2015-03-21 14:15:34 +11:00
|
|
|
utils.logMsg("executeJSONRPC : ", jsoncommand, level = 2)
|
2015-03-21 10:33:04 +11:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-01 14:17:46 +11:00
|
|
|
result = xbmc.executeJSONRPC(jsoncommand.encode("utf-8"))
|
2015-03-21 10:33:04 +11:00
|
|
|
|
|
|
|
#add actors
|
|
|
|
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"), "movie")
|
|
|
|
|
|
|
|
if(changes):
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"], level=0)
|
|
|
|
|
2015-03-23 14:54:07 +11:00
|
|
|
return changes
|
|
|
|
|
2015-03-22 00:31:30 +11:00
|
|
|
def updateMusicVideoToKodiLibrary_Batched(self, MBitem, KodiItem):
|
2015-03-26 04:37:21 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
2015-03-22 00:31:30 +11:00
|
|
|
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")
|
2015-03-21 10:33:04 +11:00
|
|
|
|
2015-03-22 00:31:30 +11:00
|
|
|
params = list()
|
|
|
|
|
|
|
|
self.getArtworkParam_Batched(KodiItem, MBitem, params)
|
|
|
|
|
|
|
|
#update common properties
|
2015-04-02 06:07:29 +11:00
|
|
|
if KodiItem["runtime"] == None:
|
|
|
|
self.getPropertyParam_Batched(KodiItem, "runtime", (int(timeInfo.get('Duration'))*60), params)
|
2015-03-22 00:31:30 +11:00
|
|
|
self.getPropertyParam_Batched(KodiItem, "year", MBitem.get("ProductionYear"), params)
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "director", people.get("Director"), params)
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "genre", MBitem.get("Genres"), params)
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "artist", MBitem.get("Artist"), params)
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "album", MBitem.get("Album"), params)
|
2015-03-25 07:03:07 +11:00
|
|
|
self.getPropertyParam_Batched(KodiItem, "lastplayed", userData.get("LastPlayedDate"), params)
|
2015-03-22 00:31:30 +11:00
|
|
|
|
|
|
|
if(studios != None):
|
|
|
|
for x in range(0, len(studios)):
|
|
|
|
studios[x] = studios[x].replace("/", "&")
|
|
|
|
self.getPropertyParamArray_Batched(KodiItem, "studio", studios, params)
|
|
|
|
|
|
|
|
changes = False
|
|
|
|
# if there were movies changes then send the update via JSONRPC
|
|
|
|
if(len(params) > 0):
|
|
|
|
changes |= True
|
|
|
|
utils.logMsg("UpdateMovieParams", str(params), level = 2)
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, %s}, "id": 1 }'
|
|
|
|
paramString = ""
|
|
|
|
paramLen = len(params)
|
|
|
|
for x in range(0, paramLen):
|
|
|
|
param = params[x]
|
|
|
|
paramString += param
|
|
|
|
if(x < paramLen-1):
|
|
|
|
paramString += ", "
|
|
|
|
jsoncommand = jsoncommand %(KodiItem['musicvideoid'], paramString)
|
|
|
|
utils.logMsg("executeJSONRPC : ", jsoncommand, level = 2)
|
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-01 14:17:46 +11:00
|
|
|
result = xbmc.executeJSONRPC(jsoncommand.encode("utf-8"))
|
2015-03-22 00:31:30 +11:00
|
|
|
|
|
|
|
if(changes):
|
|
|
|
utils.logMsg("Updated musicvideo to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"], level=0)
|
|
|
|
|
2015-03-21 10:33:04 +11:00
|
|
|
def updateMovieToKodiLibrary(self, MBitem, KodiItem):
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-26 04:37:21 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
2015-03-18 06:02:42 +11:00
|
|
|
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 22:39:26 +11:00
|
|
|
#update/check all artwork
|
|
|
|
changes |= self.updateArtWork(KodiItem,MBitem)
|
2015-03-20 10:48:59 +11:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
#update common properties
|
2015-03-20 10:48:59 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
|
|
|
|
changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
|
2015-03-25 07:03:07 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"lastplayed",MBitem.get("LastPlayedDate"),"movie")
|
2015-03-20 10:48:59 +11:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
if MBitem.get("CriticRating") != None:
|
2015-03-20 10:48:59 +11: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-18 06:02:42 +11:00
|
|
|
if MBitem.get("ProviderIds") != None:
|
|
|
|
if MBitem.get("ProviderIds").get("Imdb") != None:
|
2015-03-20 10:48:59 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"movie")
|
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
# FIXME --> Taglines not returned by MB3 server !?
|
|
|
|
if MBitem.get("TagLines") != None:
|
2015-03-20 10:48:59 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"tagline",MBitem.get("TagLines")[0],"movie")
|
2015-03-18 16:05:21 +11:00
|
|
|
|
2015-03-20 10:48:59 +11: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 16:05:21 +11:00
|
|
|
if(studios != None):
|
|
|
|
for x in range(0, len(studios)):
|
|
|
|
studios[x] = studios[x].replace("/", "&")
|
2015-03-20 10:48:59 +11:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"studio",studios,"movie")
|
2015-03-18 16:05:21 +11:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
# FIXME --> ProductionLocations not returned by MB3 server !?
|
2015-03-20 10:48:59 +11:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"movie")
|
|
|
|
|
2015-03-18 06:02:42 +11: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"
|
2015-03-25 23:48:29 +11:00
|
|
|
jsonData = downloadUtils.downloadUrl(itemTrailerUrl, suppress=False, popup=0 )
|
2015-03-18 06:02:42 +11:00
|
|
|
if(jsonData != ""):
|
|
|
|
trailerItem = json.loads(jsonData)
|
2015-04-02 06:07:29 +11:00
|
|
|
trailerUrl = PlayUtils().getPlayUrl(server, trailerItem[0].get("Id"), MBitem)
|
2015-04-02 21:47:29 +11:00
|
|
|
trailerUrl = utils.convertEncoding(trailerUrl)
|
2015-03-20 10:48:59 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"trailer",trailerUrl,"movie")
|
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
#add actors
|
2015-03-20 10:48:59 +11:00
|
|
|
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"movie")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-29 03:42:38 +11:00
|
|
|
#set Filename
|
|
|
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
2015-03-30 03:20:02 +11:00
|
|
|
self.setKodiFilename(KodiItem["movieid"], KodiItem["file"], playurl, "movie")
|
2015-03-29 03:42:38 +11:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
if changes:
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
|
|
|
|
|
|
|
def updateTVShowToKodiLibrary( self, MBitem, KodiItem ):
|
|
|
|
|
2015-03-26 04:37:21 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
2015-03-18 06:02:42 +11:00
|
|
|
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-04-02 08:28:19 +11:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-30 03:20:02 +11:00
|
|
|
#set Filename
|
|
|
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
|
|
|
#make sure that the path always ends with a slash
|
|
|
|
playurl = playurl + "/"
|
2015-04-02 06:07:29 +11:00
|
|
|
self.setKodiFilename(KodiItem["tvshowid"], KodiItem["file"], playurl, "tvshow", MBitem["Id"])
|
|
|
|
|
2015-03-20 22:39:26 +11:00
|
|
|
#update/check all artwork
|
|
|
|
changes |= self.updateArtWork(KodiItem,MBitem)
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
#update common properties
|
|
|
|
if MBitem.get("PremiereDate") != None:
|
|
|
|
premieredatelist = (MBitem.get("PremiereDate")).split("T")
|
|
|
|
premieredate = premieredatelist[0]
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"premiered",premieredate,"tvshow")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"tvshow")
|
2015-03-25 07:03:07 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"lastplayed",MBitem.get("LastPlayedDate"),"tvshow")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
if MBitem.get("CriticRating") != None:
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"tvshow")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"sorttitle",MBitem.get("SortName"),"tvshow")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
if MBitem.get("ProviderIds") != None:
|
|
|
|
if MBitem.get("ProviderIds").get("Imdb") != None:
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"tvshow")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"tvshow")
|
2015-03-18 16:05:21 +11:00
|
|
|
|
|
|
|
if(studios != None):
|
|
|
|
for x in range(0, len(studios)):
|
|
|
|
studios[x] = studios[x].replace("/", "&")
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"studio",studios,"tvshow")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
# FIXME --> ProductionLocations not returned by MB3 server !?
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"tvshow")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
#add actors
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"tvshow")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
#update season details
|
|
|
|
self.updateSeasons(MBitem, KodiItem)
|
2015-03-26 01:00:08 +11:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
if changes:
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
2015-03-23 14:54:07 +11:00
|
|
|
|
|
|
|
return changes
|
2015-03-20 22:39:26 +11:00
|
|
|
|
2015-03-19 19:44:25 +11:00
|
|
|
def updateEpisodeToKodiLibrary( self, MBitem, KodiItem ):
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-26 04:37:21 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
2015-03-18 06:02:42 +11:00
|
|
|
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 22:39:26 +11:00
|
|
|
#update/check all artwork
|
|
|
|
changes |= self.updateArtWork(KodiItem,MBitem)
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
#set Filename (will update the filename in db if changed)
|
2015-03-29 03:42:38 +11:00
|
|
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
2015-04-02 06:07:29 +11:00
|
|
|
docleanup = self.setKodiFilename(KodiItem["episodeid"], KodiItem["file"], playurl, "episode", MBitem["Id"])
|
2015-04-01 08:21:51 +11:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
#update common properties
|
2015-04-02 06:07:29 +11:00
|
|
|
if KodiItem["runtime"] == 0:
|
|
|
|
changes |= self.updateProperty(KodiItem,"runtime",(int(timeInfo.get('Duration'))*60),"episode")
|
2015-03-25 07:03:07 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"lastplayed",userData.get("LastPlayedDate"),"episode")
|
|
|
|
|
2015-03-18 06:02:42 +11: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 11:21:43 +11:00
|
|
|
changes |= self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"episode")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"episode")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
#add actors
|
2015-03-20 11:21:43 +11:00
|
|
|
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"episode")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
|
|
|
|
2015-03-23 14:54:07 +11:00
|
|
|
return changes
|
|
|
|
|
2015-03-21 10:33:04 +11:00
|
|
|
def getArtworkParam_Batched(self, KodiItem, MBitem, params):
|
|
|
|
|
|
|
|
'''
|
|
|
|
item_type=str(MBitem.get("Type"))
|
|
|
|
if item_type == "Series":
|
|
|
|
id = KodiItem['tvshowid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "art": %s}, "id": 1 }'
|
|
|
|
elif item_type == "Episode":
|
|
|
|
# episodes don't have any artwork - they derrive this from the tv show
|
|
|
|
return False
|
|
|
|
elif item_type == "MusicVideo":
|
|
|
|
id = KodiItem['musicvideoid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { musicvideoid": %i, "art": %s}, "id": 1 }'
|
|
|
|
elif item_type == "Movie":
|
|
|
|
id = KodiItem['movieid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "art": %s}, "id": 1 }'
|
|
|
|
'''
|
|
|
|
|
|
|
|
#update artwork
|
|
|
|
changes = False
|
|
|
|
|
|
|
|
artwork = {}
|
|
|
|
artwork["poster"] = API().getArtwork(MBitem, "Primary")
|
|
|
|
artwork["banner"] = API().getArtwork(MBitem, "Banner")
|
|
|
|
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:
|
|
|
|
if artwork.get(art) != "":
|
|
|
|
if KodiItem["art"].has_key(art):
|
|
|
|
curValue = urllib.unquote(KodiItem['art'][art]).decode('utf8')
|
|
|
|
if not artwork.get(art) in curValue:
|
|
|
|
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"])
|
|
|
|
params.append("\"art\": " + json_array)
|
|
|
|
#result = xbmc.executeJSONRPC(jsoncommand %(id, json_array))
|
|
|
|
return changes
|
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
# adds or updates artwork to the given Kodi file in database
|
2015-03-20 22:39:26 +11:00
|
|
|
def updateArtWork(self,KodiItem,MBitem):
|
|
|
|
|
|
|
|
item_type=str(MBitem.get("Type"))
|
|
|
|
|
|
|
|
if item_type == "Series":
|
2015-03-18 06:02:42 +11:00
|
|
|
id = KodiItem['tvshowid']
|
2015-03-20 22:39:26 +11:00
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "art": %s}, "id": 1 }'
|
|
|
|
elif item_type == "Episode":
|
2015-03-21 00:37:34 +11:00
|
|
|
# episodes don't have any artwork - they derrive this from the tv show
|
|
|
|
return False
|
2015-03-20 22:39:26 +11:00
|
|
|
elif item_type == "MusicVideo":
|
2015-03-18 06:02:42 +11:00
|
|
|
id = KodiItem['musicvideoid']
|
2015-03-20 22:39:26 +11:00
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { musicvideoid": %i, "art": %s}, "id": 1 }'
|
|
|
|
elif item_type == "Movie":
|
2015-03-18 06:02:42 +11:00
|
|
|
id = KodiItem['movieid']
|
2015-03-20 22:39:26 +11:00
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "art": %s}, "id": 1 }'
|
2015-03-20 22:53:02 +11:00
|
|
|
|
2015-03-20 22:39:26 +11:00
|
|
|
#update artwork
|
2015-03-18 06:02:42 +11:00
|
|
|
changes = False
|
2015-03-20 22:39:26 +11:00
|
|
|
|
|
|
|
artwork = {}
|
|
|
|
artwork["poster"] = API().getArtwork(MBitem, "Primary")
|
2015-03-21 02:16:39 +11:00
|
|
|
artwork["banner"] = API().getArtwork(MBitem, "Banner")
|
2015-03-20 22:39:26 +11: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 22:53:02 +11:00
|
|
|
if artwork.get(art) != "":
|
2015-03-20 22:39:26 +11:00
|
|
|
if KodiItem["art"].has_key(art):
|
2015-03-20 22:53:02 +11:00
|
|
|
curValue = urllib.unquote(KodiItem['art'][art]).decode('utf8')
|
|
|
|
if not artwork.get(art) in curValue:
|
2015-03-20 22:39:26 +11: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-18 06:02:42 +11:00
|
|
|
return changes
|
|
|
|
|
2015-03-21 10:33:04 +11:00
|
|
|
def getPropertyParam_Batched(self,KodiItem, propertyName, propertyValue, params, forced = False):
|
|
|
|
|
|
|
|
'''
|
|
|
|
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
|
|
|
|
if ((propertyValue != KodiItem[propertyName]) or forced):
|
|
|
|
if propertyValue != None:
|
|
|
|
if type(propertyValue) is int:
|
|
|
|
#xbmc.sleep(sleepVal)
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","updating property..." + str(propertyName))
|
|
|
|
utils.logMsg("Emby","kodi value:" + str(KodiItem[propertyName]) + " MB value: " + str(propertyValue))
|
2015-03-21 10:33:04 +11:00
|
|
|
params.append("\"" + propertyName + "\": " + str(propertyValue))
|
|
|
|
#xbmc.executeJSONRPC(jsoncommand_i %(id, propertyName, propertyValue))
|
|
|
|
changes = True
|
|
|
|
else:
|
|
|
|
#xbmc.sleep(sleepVal)
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","updating property..." + str(propertyName))
|
|
|
|
utils.logMsg("Emby","kodi value:" + KodiItem[propertyName] + " MB value: " + propertyValue)
|
2015-04-01 14:17:46 +11:00
|
|
|
params.append("\"" + propertyName + "\": \"" + propertyValue + "\"")
|
2015-03-21 10:33:04 +11:00
|
|
|
#xbmc.executeJSONRPC(jsoncommand_s %(id, propertyName, propertyValue.encode('utf-8')))
|
|
|
|
changes = True
|
|
|
|
|
|
|
|
return changes
|
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
# adds or updates the given property on the videofile in Kodi database
|
2015-03-20 10:24:29 +11:00
|
|
|
def updateProperty(self,KodiItem,propertyName,propertyValue,fileType,forced=False):
|
2015-03-18 06:02:42 +11: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-20 10:24:29 +11:00
|
|
|
if ((propertyValue != KodiItem[propertyName]) or forced):
|
2015-03-18 06:02:42 +11:00
|
|
|
if propertyValue != None:
|
|
|
|
if type(propertyValue) is int:
|
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","updating property..." + str(propertyName))
|
|
|
|
utils.logMsg("Emby","kodi value:" + str(KodiItem[propertyName]) + " MB value: " + str(propertyValue))
|
2015-03-18 06:02:42 +11:00
|
|
|
xbmc.executeJSONRPC(jsoncommand_i %(id, propertyName, propertyValue))
|
|
|
|
changes = True
|
|
|
|
else:
|
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","updating property..." + str(propertyName))
|
|
|
|
utils.logMsg("Emby","kodi value:" + KodiItem[propertyName] + " MB value: " + propertyValue)
|
2015-03-18 06:02:42 +11:00
|
|
|
xbmc.executeJSONRPC(jsoncommand_s %(id, propertyName, propertyValue.encode('utf-8')))
|
|
|
|
changes = True
|
|
|
|
|
|
|
|
return changes
|
|
|
|
|
2015-03-21 10:33:04 +11:00
|
|
|
def getPropertyParamArray_Batched(self, KodiItem, propertyName, propertyCollection, params):
|
|
|
|
'''
|
|
|
|
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 }'
|
|
|
|
'''
|
|
|
|
|
|
|
|
pendingChanges = False
|
|
|
|
if propertyCollection != None:
|
|
|
|
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)
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","updating propertyarray... Name:" + str(propertyName) + " Current:" + str(currentvalues) + " New:" + str(json_array))
|
2015-03-21 10:33:04 +11:00
|
|
|
params.append("\"" + propertyName + "\": " + json_array)
|
|
|
|
#xbmc.executeJSONRPC(jsoncommand %(id,propertyName,json_array))
|
|
|
|
|
|
|
|
return pendingChanges
|
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
# 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 16:05:21 +11:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
pendingChanges = False
|
2015-03-18 16:05:21 +11:00
|
|
|
if propertyCollection != None:
|
2015-03-18 06:02:42 +11: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)
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","updating propertyarray... Name:" + str(propertyName) + " Current:" + str(currentvalues) + " New:" + str(json_array))
|
2015-03-18 06:02:42 +11:00
|
|
|
xbmc.executeJSONRPC(jsoncommand %(id,propertyName,json_array))
|
|
|
|
|
|
|
|
return pendingChanges
|
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
def addMovieToKodiLibrary( self, MBitem ):
|
|
|
|
#adds a movie to Kodi by directly inserting it to the DB while there is no addmovie available on the json API
|
|
|
|
#TODO: PR at Kodi team for a addMovie endpoint on their API
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
|
|
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)
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
|
|
|
playurl = utils.convertEncoding(playurl)
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
if MBitem.get("DateCreated") != None:
|
|
|
|
dateadded = MBitem["DateCreated"].replace("T"," ")
|
|
|
|
dateadded = dateadded.replace(".0000000Z","")
|
|
|
|
else:
|
|
|
|
dateadded = None
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
# we need to store both the path and the filename seperately in the kodi db so we split them up
|
|
|
|
if "\\" in playurl:
|
|
|
|
filename = playurl.rsplit("\\",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
elif "/" in playurl:
|
|
|
|
filename = playurl.rsplit("/",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
|
|
|
|
#create the path
|
2015-04-02 10:48:04 +11:00
|
|
|
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
pathid = result[0]
|
|
|
|
else:
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
|
|
pathid = cursor.fetchone()[0]
|
|
|
|
pathid = pathid + 1
|
|
|
|
pathsql = "insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (pathid,path,"movies","metadata.local",1))
|
2015-04-02 06:07:29 +11:00
|
|
|
|
|
|
|
playcount = None
|
|
|
|
if userData.get("PlayCount") == "1":
|
|
|
|
playcount = 1
|
|
|
|
|
|
|
|
#create the file if not exists
|
2015-04-02 10:48:04 +11:00
|
|
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?",(filename,pathid,))
|
2015-04-02 06:07:29 +11:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
fileid = result[0]
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idFile),0) as fileid from files")
|
|
|
|
fileid = cursor.fetchone()[0]
|
|
|
|
fileid = fileid + 1
|
|
|
|
pathsql="insert into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (fileid,pathid,filename,playcount,userData.get("LastPlayedDate"),dateadded))
|
|
|
|
|
|
|
|
runtime = int(timeInfo.get('Duration'))*60
|
|
|
|
plot = utils.convertEncoding(API().getOverview(MBitem))
|
|
|
|
thumb = "<thumb>" + API().getArtwork(MBitem, "Primary") + "</thumb>"
|
|
|
|
fanart = "<fanart>" + API().getArtwork(MBitem, "Backdrop") + "</fanart>"
|
|
|
|
title = utils.convertEncoding(MBitem["Name"])
|
|
|
|
sorttitle = utils.convertEncoding(MBitem["SortName"])
|
|
|
|
year = MBitem.get("ProductionYear")
|
|
|
|
if MBitem.get("CriticRating") != None:
|
|
|
|
rating = int(MBitem.get("CriticRating"))/10
|
|
|
|
else:
|
|
|
|
rating = None
|
|
|
|
if MBitem.get("ShortOverview") != None:
|
|
|
|
shortplot = utils.convertEncoding(MBitem.get("ShortOverview"))
|
|
|
|
else:
|
|
|
|
shortplot = None
|
|
|
|
|
|
|
|
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=False, popup=0 )
|
|
|
|
if(jsonData != ""):
|
|
|
|
trailerItem = json.loads(jsonData)
|
|
|
|
if trailerItem[0].get("LocationType") == "FileSystem":
|
|
|
|
trailerUrl = PlayUtils().getPlayUrl(server, trailerItem[0].get("Id"), trailerItem[0])
|
2015-04-02 21:47:29 +11:00
|
|
|
trailerUrl = utils.convertEncoding(trailerUrl)
|
2015-04-02 06:07:29 +11:00
|
|
|
|
|
|
|
#create the movie
|
|
|
|
cursor.execute("select coalesce(max(idMovie),0) as movieid from movie")
|
|
|
|
movieid = cursor.fetchone()[0]
|
|
|
|
movieid = movieid + 1
|
|
|
|
pathsql="insert into movie(idMovie, idFile, c00, c01, c02, c04, c07, c08, c09, c10, c11, c16, c19, c20) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
2015-04-02 21:47:29 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
cursor.execute(pathsql, (movieid, fileid, title, plot, shortplot, rating, year, thumb, MBitem["Id"], sorttitle, runtime, title, trailerUrl, fanart))
|
|
|
|
|
|
|
|
try:
|
|
|
|
connection.commit()
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","Added movie to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
2015-04-02 06:07:29 +11:00
|
|
|
except:
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","Error adding movie to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
2015-04-02 06:07:29 +11:00
|
|
|
actionPerformed = False
|
|
|
|
finally:
|
|
|
|
cursor.close()
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
def addMusicVideoToKodiLibrary( self, MBitem ):
|
|
|
|
|
|
|
|
#adds a musicvideo to Kodi by directly inserting it to the DB while there is no addMusicVideo available on the json API
|
|
|
|
#TODO: PR at Kodi team for a addMusicVideo endpoint on their API
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
userid = downloadUtils.getUserId()
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
people = API().getPeople(MBitem)
|
|
|
|
genre = API().getGenre(MBitem)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
mediaStreams=API().getMediaStreams(MBitem)
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
|
|
|
playurl = utils.convertEncoding(playurl)
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
if MBitem.get("DateCreated") != None:
|
|
|
|
dateadded = MBitem["DateCreated"].replace("T"," ")
|
|
|
|
dateadded = dateadded.replace(".0000000Z","")
|
|
|
|
else:
|
|
|
|
dateadded = None
|
|
|
|
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
# we need to store both the path and the filename seperately in the kodi db so we split them up
|
|
|
|
if "\\" in playurl:
|
|
|
|
filename = playurl.rsplit("\\",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
elif "/" in playurl:
|
|
|
|
filename = playurl.rsplit("/",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
|
|
|
|
#create the path
|
2015-04-02 10:48:04 +11:00
|
|
|
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
pathid = result[0]
|
|
|
|
else:
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
|
|
pathid = cursor.fetchone()[0]
|
|
|
|
pathid = pathid + 1
|
|
|
|
pathsql = "insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (pathid,path,"movies","metadata.local",1))
|
2015-04-02 06:07:29 +11:00
|
|
|
|
|
|
|
playcount = None
|
|
|
|
if userData.get("PlayCount") == "1":
|
|
|
|
playcount = 1
|
|
|
|
|
|
|
|
#create the file if not exists
|
|
|
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?",(filename,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
fileid = result[0]
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idFile),0) as fileid from files")
|
|
|
|
fileid = cursor.fetchone()[0]
|
|
|
|
fileid = fileid + 1
|
|
|
|
pathsql="insert into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (fileid,pathid,filename,playcount,userData.get("LastPlayedDate"),dateadded))
|
|
|
|
|
|
|
|
runtime = int(timeInfo.get('Duration'))*60
|
|
|
|
plot = utils.convertEncoding(API().getOverview(MBitem))
|
|
|
|
thumb = "<thumb>" + API().getArtwork(MBitem, "Primary") + "</thumb>"
|
|
|
|
title = utils.convertEncoding(MBitem["Name"])
|
|
|
|
|
|
|
|
#create the musicvideo
|
|
|
|
cursor.execute("select coalesce(max(idMVideo),0) as musicvideoid from musicvideo")
|
|
|
|
musicvideoid = cursor.fetchone()[0]
|
|
|
|
musicvideoid = musicvideoid + 1
|
|
|
|
pathsql="insert into musicvideo(idMVideo, idFile, c00, c01, c04, c08, c23) values(?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (musicvideoid, fileid, title, thumb, runtime, plot, MBitem["Id"]))
|
|
|
|
|
|
|
|
try:
|
|
|
|
connection.commit()
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","Added musicvideo to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
2015-04-02 06:07:29 +11:00
|
|
|
except:
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","Error adding musicvideo to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
2015-04-02 06:07:29 +11:00
|
|
|
actionPerformed = False
|
|
|
|
finally:
|
|
|
|
cursor.close()
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
def addEpisodeToKodiLibrary(self, MBitem):
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
#adds a Episode to Kodi by directly inserting it to the DB while there is no addEpisode available on the json API
|
|
|
|
#TODO: PR at Kodi team for a addEpisode endpoint on their API
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
userid = downloadUtils.getUserId()
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
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")
|
|
|
|
|
|
|
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
|
|
|
playurl = utils.convertEncoding(playurl)
|
|
|
|
|
|
|
|
if MBitem.get("DateCreated") != None:
|
|
|
|
dateadded = MBitem["DateCreated"].replace("T"," ")
|
|
|
|
dateadded = dateadded.split(".")[0]
|
|
|
|
else:
|
|
|
|
dateadded = None
|
|
|
|
|
|
|
|
if userData.get("LastPlayedDate") != None:
|
|
|
|
lastplayed = userData.get("LastPlayedDate")
|
|
|
|
else:
|
|
|
|
lastplayed = None
|
|
|
|
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
# we need to store both the path and the filename seperately in the kodi db so we split them up
|
|
|
|
if "\\" in playurl:
|
|
|
|
filename = playurl.rsplit("\\",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
elif "/" in playurl:
|
|
|
|
filename = playurl.rsplit("/",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
|
|
|
|
#create the new path - return id if already exists
|
|
|
|
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
pathid = result[0]
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
|
|
pathid = cursor.fetchone()[0]
|
|
|
|
pathid = pathid + 1
|
|
|
|
pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (pathid,path,None,None,1))
|
|
|
|
|
|
|
|
playcount = None
|
|
|
|
if userData.get("PlayCount") == "1":
|
|
|
|
playcount = 1
|
|
|
|
|
|
|
|
#create the file if not exists
|
2015-04-02 10:48:04 +11:00
|
|
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?",(filename,pathid,))
|
2015-04-02 06:07:29 +11:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
fileid = result[0]
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idFile),0) as fileid from files")
|
|
|
|
fileid = cursor.fetchone()[0]
|
|
|
|
fileid = fileid + 1
|
|
|
|
sql="INSERT OR REPLACE into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(sql, (fileid,pathid,filename,playcount,lastplayed,dateadded))
|
|
|
|
|
|
|
|
#get the showid
|
|
|
|
cursor.execute("SELECT idShow as showid FROM tvshow WHERE c12 = ?",(MBitem["SeriesId"],))
|
|
|
|
showid = cursor.fetchone()[0]
|
|
|
|
|
|
|
|
season = 0
|
|
|
|
if MBitem.get("ParentIndexNumber") != None:
|
|
|
|
season = int(MBitem.get("ParentIndexNumber"))
|
|
|
|
|
|
|
|
episode = 0
|
|
|
|
if MBitem.get("IndexNumber") != None:
|
|
|
|
episode = int(MBitem.get("IndexNumber"))
|
|
|
|
|
|
|
|
runtime = int(timeInfo.get('Duration'))*60
|
|
|
|
plot = utils.convertEncoding(API().getOverview(MBitem))
|
|
|
|
thumb = "<thumb>" + API().getArtwork(MBitem, "Primary") + "</thumb>"
|
|
|
|
title = utils.convertEncoding(MBitem["Name"])
|
|
|
|
if MBitem.get("CriticRating") != None:
|
|
|
|
rating = int(MBitem.get("CriticRating"))/10
|
|
|
|
else:
|
|
|
|
rating = None
|
|
|
|
|
|
|
|
#create the episode
|
|
|
|
cursor.execute("select coalesce(max(idEpisode),0) as episodeid from episode")
|
|
|
|
episodeid = cursor.fetchone()[0]
|
|
|
|
episodeid = episodeid + 1
|
|
|
|
pathsql="INSERT into episode(idEpisode, idFile, c00, c01, c03, c06, c09, c20, c12, c13, c14, idShow) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (episodeid, fileid, title, plot, rating, thumb, runtime, MBitem["Id"], season, episode, title, showid))
|
|
|
|
|
|
|
|
try:
|
|
|
|
connection.commit()
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","Added TV Show to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
2015-04-02 06:07:29 +11:00
|
|
|
except:
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","Error adding tvshow to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
2015-04-02 06:07:29 +11:00
|
|
|
actionPerformed = False
|
|
|
|
finally:
|
|
|
|
cursor.close()
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
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"]))
|
2015-04-01 08:21:51 +11:00
|
|
|
|
2015-03-22 00:31:30 +11:00
|
|
|
def deleteMusicVideoFromKodiLibrary(self, id ):
|
|
|
|
utils.logMsg("deleting musicvideo from Kodi library",id)
|
|
|
|
kodiItem = ReadKodiDB().getKodiMusicVideo(id)
|
|
|
|
if kodiItem != None:
|
|
|
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveMusicVideo", "params": { "musicvideoid": %i}, "id": 1 }' %(kodiItem["musicvideoid"]))
|
|
|
|
|
2015-03-21 22:33:59 +11:00
|
|
|
def deleteEpisodeFromKodiLibrary(self, episodeid, tvshowid ):
|
2015-03-21 06:29:50 +11:00
|
|
|
utils.logMsg("deleting episode from Kodi library",episodeid)
|
2015-03-21 22:33:59 +11:00
|
|
|
episode = ReadKodiDB().getKodiEpisodeByMbItem(episodeid, tvshowid)
|
|
|
|
if episode != None:
|
2015-03-29 03:14:52 +11:00
|
|
|
WINDOW = xbmcgui.Window( 10000 )
|
2015-03-21 22:33:59 +11:00
|
|
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveEpisode", "params": { "episodeid": %i}, "id": 1 }' %(episode["episodeid"]))
|
2015-03-30 08:37:02 +11:00
|
|
|
|
2015-03-30 07:13:11 +11:00
|
|
|
utils.logMsg("episode deleted succesfully!",episodeid)
|
|
|
|
else:
|
2015-03-30 09:43:53 +11:00
|
|
|
utils.logMsg("episode not found in kodi DB",episodeid)
|
2015-03-30 07:13:11 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
def addTVShowToKodiLibrary( self, MBitem ):
|
|
|
|
#adds a Tvshow to Kodi by directly inserting it to the DB while there is no addTvShow available on the json API
|
|
|
|
#TODO: PR at Kodi team for a addTvShow endpoint on their API
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
userid = downloadUtils.getUserId()
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
people = API().getPeople(MBitem)
|
|
|
|
genre = API().getGenre(MBitem)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
mediaStreams=API().getMediaStreams(MBitem)
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
|
|
|
|
|
|
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
|
|
|
#make sure that the path always ends with a slash
|
2015-04-04 08:39:18 +11:00
|
|
|
path = utils.convertEncoding(playurl + "/")
|
2015-04-02 06:07:29 +11:00
|
|
|
|
|
|
|
if MBitem.get("DateCreated") != None:
|
|
|
|
dateadded = MBitem["DateCreated"].replace("T"," ")
|
|
|
|
dateadded = dateadded.replace(".0000000Z","")
|
|
|
|
else:
|
|
|
|
dateadded = None
|
|
|
|
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
2015-04-02 08:28:19 +11:00
|
|
|
#create the tv show path
|
2015-04-02 06:07:29 +11:00
|
|
|
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
|
|
pathid = cursor.fetchone()[0]
|
|
|
|
pathid = pathid + 1
|
|
|
|
pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (pathid,path,None,None,1))
|
|
|
|
|
2015-04-02 08:28:19 +11:00
|
|
|
#create toplevel path as monitored source - needed for things like actors and stuff to work (no clue why)
|
|
|
|
if "\\" in path:
|
|
|
|
toplevelpathstr = path.rsplit("\\",2)[1]
|
|
|
|
toplevelpath = path.replace(toplevelpathstr + "\\","")
|
|
|
|
elif "/" in path:
|
|
|
|
toplevelpathstr = path.rsplit("/",2)[1]
|
|
|
|
toplevelpath = path.replace(toplevelpathstr + "/","")
|
|
|
|
cursor.execute("SELECT idPath as tlpathid FROM path WHERE strPath = ?",(toplevelpath,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as tlpathid from path")
|
|
|
|
tlpathid = cursor.fetchone()[0]
|
|
|
|
tlpathid = pathid + 1
|
|
|
|
pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (tlpathid,toplevelpath,"tvshows","metadata.local",1))
|
|
|
|
|
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
runtime = int(timeInfo.get('Duration'))*60
|
|
|
|
plot = utils.convertEncoding(API().getOverview(MBitem))
|
|
|
|
thumb = "<thumb>" + API().getArtwork(MBitem, "Primary") + "</thumb>"
|
|
|
|
fanart = "<fanart>" + API().getArtwork(MBitem, "Backdrop") + "</fanart>"
|
|
|
|
title = utils.convertEncoding(MBitem["Name"])
|
|
|
|
sorttitle = utils.convertEncoding(MBitem["SortName"])
|
|
|
|
if MBitem.get("CriticRating") != None:
|
|
|
|
rating = int(MBitem.get("CriticRating"))/10
|
|
|
|
else:
|
|
|
|
rating = None
|
|
|
|
|
|
|
|
#create the tvshow
|
|
|
|
cursor.execute("select coalesce(max(idShow),0) as showid from tvshow")
|
|
|
|
showid = cursor.fetchone()[0]
|
|
|
|
showid = pathid + 1
|
|
|
|
pathsql="insert into tvshow(idShow, c00, c01, c04, c06, c09, c11, c12, c15) values(?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (showid, title, plot, rating, thumb, title, fanart, MBitem["Id"], sorttitle))
|
|
|
|
|
|
|
|
#link the path
|
|
|
|
pathsql="insert into tvshowlinkpath(idShow,idPath) values(?, ?)"
|
|
|
|
cursor.execute(pathsql, (showid,pathid))
|
|
|
|
|
|
|
|
try:
|
|
|
|
connection.commit()
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","Added TV Show to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
2015-04-02 06:07:29 +11:00
|
|
|
except:
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","Error adding tvshow to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
2015-04-02 06:07:29 +11:00
|
|
|
actionPerformed = False
|
|
|
|
finally:
|
|
|
|
cursor.close()
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 19:00:58 +11:00
|
|
|
def deleteTVShowFromKodiLibrary(self, id):
|
2015-03-19 21:13:49 +11:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-18 06:02:42 +11:00
|
|
|
kodiItem = ReadKodiDB().getKodiTVShow(id)
|
2015-04-02 19:00:58 +11:00
|
|
|
utils.logMsg("deleting tvshow from Kodi library ", "Emby ID : " + id)
|
2015-03-21 21:32:21 +11:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
if kodiItem != None:
|
2015-04-02 19:00:58 +11:00
|
|
|
utils.logMsg("deleting tvshow from Kodi library ", str(kodiItem))
|
|
|
|
kodiId = kodiItem["tvshowid"]
|
|
|
|
utils.logMsg("deleting tvshow from Kodi library ", "Kodi ID : " + str(kodiId))
|
|
|
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveTVShow", "params": { "tvshowid": %i}, "id": 1 }' %(kodiId))
|
2015-03-21 02:16:39 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
def updateSeasons(self,MBitem, KodiItem):
|
|
|
|
#use sqlite to set the season details because no method in API available for this
|
2015-03-21 02:58:46 +11:00
|
|
|
tvshowid = KodiItem["tvshowid"]
|
2015-03-27 08:35:11 +11:00
|
|
|
|
|
|
|
connection = utils.KodiSQL()
|
2015-04-02 06:07:29 +11:00
|
|
|
cursor = connection.cursor()
|
2015-03-21 02:16:39 +11:00
|
|
|
|
2015-03-21 02:58:46 +11:00
|
|
|
seasonData = ReadEmbyDB().getTVShowSeasons(MBitem["Id"])
|
|
|
|
if seasonData != None:
|
|
|
|
for season in seasonData:
|
|
|
|
if season.has_key("IndexNumber"):
|
2015-04-02 06:07:29 +11:00
|
|
|
cursor.execute("SELECT idSeason as seasonid FROM seasons WHERE idShow = ? and season = ?",(tvshowid,season["IndexNumber"]))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result == None:
|
|
|
|
#create the season
|
|
|
|
cursor.execute("select coalesce(max(idSeason),0) as seasonid from seasons")
|
|
|
|
seasonid = cursor.fetchone()[0]
|
|
|
|
seasonid = seasonid + 1
|
|
|
|
cursor.execute("INSERT into seasons(idSeason, idShow, season) values(?, ?, ?)", (seasonid, tvshowid, season["IndexNumber"]))
|
|
|
|
|
|
|
|
#insert artwork
|
|
|
|
if API().getArtwork(season, "Thumb") != "":
|
|
|
|
cursor.execute("INSERT into art(media_id, media_type, type, url) values(?, ?, ?, ?)", (seasonid,"season","landscape",API().getArtwork(season, "Thumb")))
|
|
|
|
if API().getArtwork(season, "Primary") != "":
|
|
|
|
cursor.execute("INSERT into art(media_id, media_type, type, url) values(?, ?, ?, ?)", (seasonid,"season","poster",API().getArtwork(season, "Primary")))
|
|
|
|
if API().getArtwork(season, "Banner") != "":
|
|
|
|
cursor.execute("INSERT into art(media_id, media_type, type, url) values(?, ?, ?, ?)", (seasonid,"season","banner",API().getArtwork(season, "Banner")))
|
2015-03-21 02:58:46 +11:00
|
|
|
|
|
|
|
connection.commit()
|
2015-03-22 00:31:30 +11:00
|
|
|
cursor.close()
|
2015-03-21 02:16:39 +11:00
|
|
|
|
2015-03-18 06:02:42 +11: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
|
|
|
|
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","setting resume point in kodi db..." + fileType + ": " + str(id))
|
2015-03-19 21:13:49 +11:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-27 08:35:11 +11:00
|
|
|
connection = utils.KodiSQL()
|
2015-03-18 06:02:42 +11:00
|
|
|
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()
|
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
def setKodiFilename(self, id, oldFileName, newFileName, fileType, mbId):
|
2015-03-29 03:42:38 +11:00
|
|
|
#use sqlite to set the filename in DB -- needed to avoid problems with resumepoints etc
|
2015-04-01 08:21:51 +11:00
|
|
|
#return True if any action is performed, False if no action is performed
|
2015-03-29 03:42:38 +11:00
|
|
|
#todo --> submit PR to kodi team to get this added to the jsonrpc api
|
2015-03-29 05:04:32 +11:00
|
|
|
#todo --> extend support for musicvideos
|
2015-03-29 03:42:38 +11:00
|
|
|
|
2015-04-01 08:21:51 +11:00
|
|
|
actionPerformed = False
|
|
|
|
|
2015-03-30 03:20:02 +11:00
|
|
|
oldFileName = utils.convertEncoding(oldFileName)
|
|
|
|
newFileName = utils.convertEncoding(newFileName)
|
2015-03-29 03:42:38 +11:00
|
|
|
|
2015-03-30 03:20:02 +11:00
|
|
|
# only perform changes if the path actually differs
|
|
|
|
if oldFileName != newFileName:
|
|
|
|
|
2015-04-05 00:39:27 +11:00
|
|
|
# xbmc.sleep(sleepVal)
|
2015-04-01 08:21:51 +11:00
|
|
|
connection = utils.KodiSQL()
|
2015-04-02 06:07:29 +11:00
|
|
|
cursor = connection.cursor()
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","setting filename in kodi db..." + fileType + ": " + str(id))
|
|
|
|
utils.logMsg("Emby","old filename -->" + oldFileName)
|
|
|
|
utils.logMsg("Emby","new filename -->" + newFileName)
|
2015-04-01 08:21:51 +11:00
|
|
|
|
2015-04-01 18:28:22 +11:00
|
|
|
######### PROCESS TV SHOW ############
|
2015-04-02 06:32:25 +11:00
|
|
|
if fileType == "tvshow":
|
|
|
|
|
|
|
|
if newFileName.startswith("http"):
|
|
|
|
newFileName = "plugin://plugin.video.emby/"
|
|
|
|
|
2015-04-01 08:21:51 +11:00
|
|
|
#for tvshows we only store the path in DB
|
|
|
|
cursor.execute("SELECT idPath as pathid FROM tvshowlinkpath WHERE idShow = ?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
pathid = result[0]
|
|
|
|
cursor.execute("UPDATE path SET strPath = ?, noUpdate = ?, idParentPath = ? WHERE idPath = ?", (newFileName,1,None,pathid))
|
|
|
|
|
|
|
|
else:
|
|
|
|
# we need to store both the path and the filename seperately in the kodi db so we split them up
|
2015-03-30 03:20:02 +11:00
|
|
|
|
2015-04-01 08:21:51 +11:00
|
|
|
if newFileName.startswith("http"):
|
2015-04-02 06:07:29 +11:00
|
|
|
#transcoding or play from stream
|
|
|
|
path = "plugin://plugin.video.emby/"
|
2015-04-02 06:32:25 +11:00
|
|
|
filename = "plugin://plugin.video.emby/?id=" + mbId + "&mode=play"
|
2015-04-02 06:07:29 +11:00
|
|
|
|
|
|
|
else:
|
|
|
|
# direct play
|
|
|
|
if "\\" in newFileName:
|
|
|
|
filename = newFileName.rsplit("\\",1)[-1]
|
|
|
|
path = newFileName.replace(filename,"")
|
|
|
|
elif "/" in newFileName:
|
|
|
|
filename = newFileName.rsplit("/",1)[-1]
|
|
|
|
path = newFileName.replace(filename,"")
|
|
|
|
|
2015-03-30 03:20:02 +11:00
|
|
|
|
2015-04-01 08:21:51 +11:00
|
|
|
######### PROCESS EPISODE ############
|
|
|
|
if fileType == "episode":
|
2015-03-30 03:20:02 +11:00
|
|
|
|
2015-04-01 18:28:22 +11:00
|
|
|
#get the file and the current path id
|
|
|
|
cursor.execute("SELECT idFile as fileid FROM episode WHERE idEpisode = ?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
fileid = result[0]
|
|
|
|
|
|
|
|
#create the new path - return id if already exists
|
2015-03-30 03:20:02 +11:00
|
|
|
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
pathid = result[0]
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
|
|
pathid = cursor.fetchone()[0]
|
|
|
|
pathid = pathid + 1
|
|
|
|
pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
2015-04-01 08:21:51 +11:00
|
|
|
cursor.execute(pathsql, (pathid,path,None,None,1))
|
2015-04-01 18:28:22 +11:00
|
|
|
|
2015-04-01 08:21:51 +11:00
|
|
|
#set the new path and filename to the episode
|
|
|
|
cursor.execute("UPDATE files SET idPath = ?, strFilename = ? WHERE idFile = ?", (pathid,filename,fileid))
|
2015-03-30 03:20:02 +11:00
|
|
|
|
|
|
|
|
2015-04-01 08:21:51 +11:00
|
|
|
######### PROCESS MOVIE ############
|
|
|
|
if fileType == "movie":
|
|
|
|
cursor.execute("SELECT idFile as fileid FROM movie WHERE idMovie = ?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
fileid = result[0]
|
|
|
|
#write the new filename to the DB
|
2015-03-30 03:20:02 +11:00
|
|
|
cursor.execute("UPDATE files SET strFilename = ? WHERE idFile = ?", (filename,fileid))
|
2015-04-01 08:21:51 +11:00
|
|
|
#set the new path
|
|
|
|
cursor.execute("SELECT idPath as pathid FROM files WHERE idFile = ?",(fileid,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
pathid = result[0]
|
|
|
|
cursor.execute("UPDATE path SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?, idParentPath = ? WHERE idPath = ?", (path, "movies", "metadata.local", 1, None, pathid))
|
2015-03-30 09:43:53 +11:00
|
|
|
|
2015-04-01 08:21:51 +11:00
|
|
|
try:
|
|
|
|
connection.commit()
|
|
|
|
actionPerformed = True
|
|
|
|
except:
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby","Error setting filename in kodi db for: " + fileType + ": " + str(id))
|
2015-04-01 08:21:51 +11:00
|
|
|
actionPerformed = False
|
|
|
|
finally:
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
return actionPerformed
|
2015-03-29 03:42:38 +11:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
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 11:21:43 +11:00
|
|
|
|
2015-03-18 06:02:42 +11: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-20 10:48:59 +11:00
|
|
|
|
2015-03-20 11:21:43 +11:00
|
|
|
needsUpdate = False
|
2015-03-18 06:02:42 +11:00
|
|
|
if(people != None):
|
|
|
|
for person in people:
|
|
|
|
if(person.get("Type") == "Actor"):
|
|
|
|
if person.get("Name") not in currentcast:
|
2015-03-20 11:21:43 +11:00
|
|
|
needsUpdate = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if(needsUpdate == False):
|
|
|
|
return False
|
|
|
|
|
|
|
|
utils.logMsg("AddActorsToMedia", "List needs updating")
|
|
|
|
|
2015-04-05 00:39:27 +11:00
|
|
|
# xbmc.sleep(sleepVal)
|
2015-03-27 08:35:11 +11:00
|
|
|
connection = utils.KodiSQL()
|
2015-03-20 11:21:43 +11:00
|
|
|
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-18 06:02:42 +11:00
|
|
|
Name = person.get("Name")
|
|
|
|
Role = person.get("Role")
|
|
|
|
actorid = None
|
2015-04-03 04:19:29 +11:00
|
|
|
Thumb = downloadUtils.imageUrl(person.get("Id"), "Primary", 0, 400, 400)
|
2015-03-18 06:02:42 +11:00
|
|
|
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 11:21:43 +11:00
|
|
|
|
|
|
|
return True
|
2015-03-25 03:47:26 +11:00
|
|
|
|
|
|
|
def addBoxsetToKodiLibrary(self, boxset):
|
|
|
|
#use sqlite to set add the set
|
2015-03-27 08:35:11 +11:00
|
|
|
connection = utils.KodiSQL()
|
2015-03-25 03:47:26 +11:00
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
strSet = boxset["Name"]
|
|
|
|
# check if exists
|
|
|
|
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
setid = None
|
|
|
|
if result != None:
|
|
|
|
setid = result[0]
|
|
|
|
currentsetartsql = "SELECT type, url FROM art where media_type = ? and media_id = ? and url != ''"
|
|
|
|
cursor.execute(currentsetartsql, ("set", setid))
|
|
|
|
existing_type_map = {}
|
|
|
|
rows = cursor.fetchall()
|
|
|
|
for row in rows:
|
|
|
|
existing_type_map[row[0] ] = row[1]
|
|
|
|
|
|
|
|
artwork = {}
|
|
|
|
artwork["poster"] = API().getArtwork(boxset, "Primary")
|
|
|
|
artwork["banner"] = API().getArtwork(boxset, "Banner")
|
|
|
|
artwork["clearlogo"] = API().getArtwork(boxset, "Logo")
|
|
|
|
artwork["clearart"] = API().getArtwork(boxset, "Art")
|
|
|
|
artwork["landscape"] = API().getArtwork(boxset, "Thumb")
|
|
|
|
artwork["discart"] = API().getArtwork(boxset, "Disc")
|
|
|
|
artwork["fanart"] = API().getArtwork(boxset, "Backdrop")
|
|
|
|
|
2015-03-25 05:58:13 +11:00
|
|
|
art_types = ['poster','fanart','landscape','clearlogo','clearart','banner','discart']
|
2015-03-25 03:47:26 +11:00
|
|
|
for update_type in art_types:
|
|
|
|
if ( update_type in existing_type_map ):
|
|
|
|
if ( existing_type_map[update_type] != artwork[update_type] ) and artwork[update_type] != '':
|
|
|
|
setupdateartsql = "UPDATE art SET url = ? where media_type = ? and media_id = ? and type = ?"
|
|
|
|
cursor.execute(setupdateartsql,(artwork[update_type],"set",setid,update_type))
|
|
|
|
elif artwork[update_type] != '':
|
|
|
|
setartsql = "INSERT INTO art(media_id, media_type, type, url) VALUES(?,?,?,?)"
|
|
|
|
cursor.execute(setartsql,(setid,"set",update_type,artwork[update_type]))
|
|
|
|
|
|
|
|
if setid == None:
|
|
|
|
# insert not exists
|
|
|
|
setssql="INSERT INTO sets (idSet, strSet) values(?, ?)"
|
|
|
|
cursor.execute(setssql, (None,strSet))
|
|
|
|
#if OK:
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
setid = result[0]
|
|
|
|
connection.commit()
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset):
|
|
|
|
strSet = boxset["Name"]
|
|
|
|
kodiMovie = ReadKodiDB().getKodiMovie(boxsetmovie["Id"])
|
2015-03-25 09:39:19 +11:00
|
|
|
if kodiMovie != None:
|
|
|
|
WriteKodiDB().updateProperty(kodiMovie,"set",strSet,"movie",True)
|