fixed some small issues

This commit is contained in:
Marcel van der Veldt 2015-05-02 03:47:05 +02:00
parent 42c7256f54
commit 6d191fef1d
2 changed files with 27 additions and 21 deletions

View file

@ -49,11 +49,10 @@ class LibrarySync():
connection = utils.KodiSQL() connection = utils.KodiSQL()
cursor = connection.cursor() cursor = connection.cursor()
#TEMP --> add new columns #Add the special emby table
try: if not startupDone:
cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER)") cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER)")
connection.commit() connection.commit()
except: pass
# sync movies # sync movies
self.MoviesSync(connection,cursor,True) self.MoviesSync(connection,cursor,True)
@ -89,6 +88,9 @@ class LibrarySync():
allMB3Movies = ReadEmbyDB().getMovies(view.get('id')) allMB3Movies = ReadEmbyDB().getMovies(view.get('id'))
allKodiMovies = ReadKodiDB().getKodiMovies(connection, cursor) allKodiMovies = ReadKodiDB().getKodiMovies(connection, cursor)
for kodimovie in allKodiMovies:
allKodiMovieIds.append(kodimovie[1])
#### PROCESS ADDS AND UPDATES ### #### PROCESS ADDS AND UPDATES ###
for item in allMB3Movies: for item in allMB3Movies:
@ -98,12 +100,10 @@ class LibrarySync():
kodiMovie = None kodiMovie = None
for kodimovie in allKodiMovies: for kodimovie in allKodiMovies:
allKodiMovieIds.append(kodimovie[1])
if kodimovie[1] == item["Id"]: if kodimovie[1] == item["Id"]:
kodiMovie = kodimovie kodiMovie = kodimovie
if kodiMovie == None: if kodiMovie == None:
allKodiMovieIds.append(item["Id"])
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
else: else:
if kodiMovie[2] != API().getChecksum(item) or item["Id"] in itemList: if kodiMovie[2] != API().getChecksum(item) or item["Id"] in itemList:
@ -128,11 +128,15 @@ class LibrarySync():
allKodiTvShowIds = list() allKodiTvShowIds = list()
allEmbyTvShowIds = list() allEmbyTvShowIds = list()
for view in views: for view in views:
allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id')) allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'))
allKodiTvShows = ReadKodiDB().getKodiTvShows(connection, cursor) allKodiTvShows = ReadKodiDB().getKodiTvShows(connection, cursor)
for kodishow in allKodiTvShows:
allKodiTvShowIds.append(kodishow[1])
#### TVSHOW: PROCESS ADDS AND UPDATES ### #### TVSHOW: PROCESS ADDS AND UPDATES ###
for item in allEmbyTvShows: for item in allEmbyTvShows:
@ -143,13 +147,11 @@ class LibrarySync():
#build a list with all Id's and get the existing entry (if exists) in Kodi DB #build a list with all Id's and get the existing entry (if exists) in Kodi DB
kodiShow = None kodiShow = None
for kodishow in allKodiTvShows: for kodishow in allKodiTvShows:
allKodiTvShowIds.append(kodishow[1])
if kodishow[1] == item["Id"]: if kodishow[1] == item["Id"]:
kodiShow = kodishow kodiShow = kodishow
if kodiShow == None: if kodiShow == None:
# Tv show doesn't exist in Kodi yet so proceed and add it # Tv show doesn't exist in Kodi yet so proceed and add it
allKodiTvShowIds.append(item["Id"])
kodiId = WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) kodiId = WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
else: else:
kodiId = kodishow[0] kodiId = kodishow[0]
@ -180,22 +182,23 @@ class LibrarySync():
allEmbyEpisodes = ReadEmbyDB().getEpisodes(embyShowId) allEmbyEpisodes = ReadEmbyDB().getEpisodes(embyShowId)
allKodiEpisodes = ReadKodiDB().getKodiEpisodes(connection, cursor, kodiShowId) allKodiEpisodes = ReadKodiDB().getKodiEpisodes(connection, cursor, kodiShowId)
for kodiepisode in allKodiEpisodes:
allKodiEpisodeIds.append(kodiepisode[1])
#### EPISODES: PROCESS ADDS AND UPDATES ### #### EPISODES: PROCESS ADDS AND UPDATES ###
for item in allEmbyEpisodes: for item in allEmbyEpisodes:
allEmbyEpisodeIds.append(item["Id"]) allEmbyEpisodeIds.append(item["Id"])
#build a list with all Id's and get the existing entry (if exists) in Kodi DB #get the existing entry (if exists) in Kodi DB
kodiEpisode = None kodiEpisode = None
for kodiepisode in allKodiEpisodes: for kodiepisode in allKodiEpisodes:
allKodiEpisodeIds.append(kodiepisode[1])
if kodiepisode[1] == item["Id"]: if kodiepisode[1] == item["Id"]:
kodiEpisode = kodiepisode kodiEpisode = kodiepisode
if kodiEpisode == None: if kodiEpisode == None:
# Episode doesn't exist in Kodi yet so proceed and add it # Episode doesn't exist in Kodi yet so proceed and add it
allKodiEpisodeIds.append(item["Id"])
WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor) WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor)
else: else:
# If there are changes to the item, perform a full sync of the item # If there are changes to the item, perform a full sync of the item
@ -204,10 +207,8 @@ class LibrarySync():
#### EPISODES: PROCESS DELETES ##### #### EPISODES: PROCESS DELETES #####
allEmbyEpisodeIds = set(allEmbyEpisodeIds) allEmbyEpisodeIds = set(allEmbyEpisodeIds)
print allEmbyEpisodeIds
for kodiId in allKodiEpisodeIds: for kodiId in allKodiEpisodeIds:
print "kodiId-->" + kodiId if (not kodiId in allEmbyEpisodeIds):
if not kodiId in allEmbyEpisodeIds:
WINDOW.setProperty(kodiId,"deleted") WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteEpisodeFromKodiLibrary(kodiId, connection, cursor) WriteKodiDB().deleteEpisodeFromKodiLibrary(kodiId, connection, cursor)

View file

@ -26,17 +26,22 @@ class WriteKodiDB():
def updatePlayCountFromKodi(self, id, type, playcount=0): def updatePlayCountFromKodi(self, id, type, playcount=0):
#when user marks item watched from kodi interface update this in MB3 #when user marks item watched from kodi interface update this in MB3
xbmc.sleep(sleepVal)
utils.logMsg("Emby", "updatePlayCountFromKodi Called")
mb3Id = ReadKodiDB().getEmbyIdByKodiId(id, type) utils.logMsg("Emby", "updatePlayCountFromKodi Called")
connection = utils.KodiSQL()
cursor = connection.cursor()
cursor.execute("SELECT emby_id FROM emby WHERE media_type=? AND kodi_id=?",(type,id))
emby_id = cursor.fetchone()[0]
cursor.close
if(mb3Id != None): if(emby_id != None):
addon = xbmcaddon.Addon(id='plugin.video.emby') addon = xbmcaddon.Addon(id='plugin.video.emby')
downloadUtils = DownloadUtils() downloadUtils = DownloadUtils()
watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % mb3Id #FIXME --> This is no longer working ??!!
watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % emby_id
utils.logMsg("Emby","watchedurl -->" + watchedurl) utils.logMsg("Emby","watchedurl -->" + watchedurl)
if playcount != 0: if playcount != 0:
downloadUtils.downloadUrl(watchedurl, postBody="", type="POST") downloadUtils.downloadUrl(watchedurl, postBody="", type="POST")
@ -162,7 +167,7 @@ class WriteKodiDB():
#### UPDATE THE MOVIE ##### #### UPDATE THE MOVIE #####
else: else:
pathsql="update movie SET c00 = ?, c01 = ?, c02 = ?, c05 = ?, c06 = ?, c07 = ?, c09 = ? c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ? WHERE idMovie = ?" pathsql="update movie SET c00 = ?, c01 = ?, c02 = ?, c05 = ?, c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ? WHERE idMovie = ?"
cursor.execute(pathsql, (title, plot, shortplot, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio, trailerUrl, movieid)) cursor.execute(pathsql, (title, plot, shortplot, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio, trailerUrl, movieid))
#update the checksum in emby table #update the checksum in emby table