fixed some errors

This commit is contained in:
Marcel van der Veldt 2015-05-02 12:51:46 +02:00
parent 61c6fedc19
commit 8c6b90923e
2 changed files with 63 additions and 49 deletions

View file

@ -64,6 +64,7 @@ class LibrarySync():
self.MoviesFullSync(connection,cursor,pDialog) self.MoviesFullSync(connection,cursor,pDialog)
#sync Tvshows and episodes #sync Tvshows and episodes
self.TvShowsFullSync(connection,cursor,pDialog) self.TvShowsFullSync(connection,cursor,pDialog)
# set the install done setting # set the install done setting
if(syncInstallRunDone == False and completed): if(syncInstallRunDone == False and completed):
@ -115,7 +116,7 @@ class LibrarySync():
if(pDialog != None): if(pDialog != None):
progressTitle = "Processing " + view.get('title') + " (" + str(count) + " of " + str(total) + ")" progressTitle = "Processing " + view.get('title') + " (" + str(count) + " of " + str(total) + ")"
pDialog.update(0, "Emby for Kodi - Running Sync", progressTitle) pDialog.update(0, "Emby for Kodi - Running Sync", progressTitle)
count = 1 count += 1
kodiMovie = None kodiMovie = None
for kodimovie in allKodiMovies: for kodimovie in allKodiMovies:
@ -128,12 +129,12 @@ class LibrarySync():
if kodiMovie[2] != API().getChecksum(item): if kodiMovie[2] != API().getChecksum(item):
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
#### PROCESS DELETES ##### #### PROCESS DELETES #####
allEmbyMovieIds = set(allEmbyMovieIds) allEmbyMovieIds = set(allEmbyMovieIds)
for kodiId in allKodiMovieIds: for kodiId in allKodiMovieIds:
if not kodiId in allEmbyMovieIds: if not kodiId in allEmbyMovieIds:
WINDOW.setProperty(kodiId,"deleted") WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
def TvShowsFullSync(self,connection,cursor,pDialog): def TvShowsFullSync(self,connection,cursor,pDialog):
@ -164,7 +165,7 @@ class LibrarySync():
if(pDialog != None): if(pDialog != None):
progressTitle = "Processing " + view.get('title') + " (" + str(count) + " of " + str(total) + ")" progressTitle = "Processing " + view.get('title') + " (" + str(count) + " of " + str(total) + ")"
pDialog.update(0, "Emby for Kodi - Running Sync", progressTitle) pDialog.update(0, "Emby for Kodi - Running Sync", progressTitle)
count = 1 count += 1
#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
@ -184,12 +185,12 @@ class LibrarySync():
#### PROCESS EPISODES ###### #### PROCESS EPISODES ######
self.EpisodesFullSync(connection,cursor,item["Id"], kodiId) self.EpisodesFullSync(connection,cursor,item["Id"], kodiId)
#### TVSHOW: PROCESS DELETES ##### #### TVSHOW: PROCESS DELETES #####
allEmbyTvShowIds = set(allEmbyTvShowIds) allEmbyTvShowIds = set(allEmbyTvShowIds)
for kodiId in allKodiTvShowIds: for kodiId in allKodiTvShowIds:
if not kodiId in allEmbyTvShowIds: if not kodiId in allEmbyTvShowIds:
WINDOW.setProperty(kodiId,"deleted") WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
def EpisodesFullSync(self,connection,cursor,embyShowId, kodiShowId): def EpisodesFullSync(self,connection,cursor,embyShowId, kodiShowId):
@ -241,43 +242,46 @@ class LibrarySync():
connection = utils.KodiSQL() connection = utils.KodiSQL()
cursor = connection.cursor() cursor = connection.cursor()
#### PROCESS MOVIES #### try:
views = ReadEmbyDB().getCollections("movies") #### PROCESS MOVIES ####
for view in views: views = ReadEmbyDB().getCollections("movies")
allEmbyMovies = ReadEmbyDB().getMovies(view.get('id'), itemList) for view in views:
for item in allEmbyMovies: allEmbyMovies = ReadEmbyDB().getMovies(view.get('id'), itemList)
for item in allEmbyMovies:
if not item.get('IsFolder'):
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
#### PROCESS TV SHOWS ####
views = ReadEmbyDB().getCollections("tvshows")
for view in views:
allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'),itemList)
for item in allEmbyTvShows:
if item.get('IsFolder') and item.get('RecursiveItemCount') != 0:
kodiId = WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
#### PROCESS EPISODES ######
for item in itemList:
if not item.get('IsFolder'): MBitem = ReadEmbyDB().getItem(item)
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) print MBitem
if MBitem["Type"] == "Episode":
#### PROCESS TV SHOWS #### #get the tv show
views = ReadEmbyDB().getCollections("tvshows") cursor.execute("SELECT kodi_id FROM emby WHERE media_type='tvshow' AND emby_id=?", (MBitem["SeriesId"],))
for view in views: result = cursor.fetchall()
allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'),itemList) if result:
for item in allEmbyTvShows: kodi_show_id = result[0]
if item.get('IsFolder') and item.get('RecursiveItemCount') != 0: else:
kodiId = WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) kodi_show_id = None
print "show id not found!"
#### PROCESS EPISODES ###### if kodi_show_id:
for item in itemList: WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodi_show_id, connection, cursor)
finally:
MBitem = ReadEmbyDB().getItem(item) cursor.close()
if MBitem["Type"] == "Episode":
#get the tv show
cursor.execute("SELECT kodi_id FROM emby WHERE media_type='tvshow' AND emby_id=?", (MBitem["SeriesId"],))
result = cursor.fetchall()
if result:
kodi_show_id = result[0]
else:
kodi_show_id = None
if kodi_show_id:
WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodi_show_id, connection, cursor)
#close the progress dialog
cursor.close()
if(pDialog != None): if(pDialog != None):
pDialog.close() pDialog.close()

View file

@ -147,7 +147,10 @@ class WriteKodiDB():
##### ADD THE MOVIE ############ ##### ADD THE MOVIE ############
if movieid == None: if movieid == None:
utils.logMsg("ADD movie to Kodi library","Id: %s - Title: %s" % (embyId, title))
#create the movie #create the movie
cursor.execute("select coalesce(max(idMovie),0) as movieid from movie") cursor.execute("select coalesce(max(idMovie),0) as movieid from movie")
movieid = cursor.fetchone()[0] movieid = cursor.fetchone()[0]
@ -167,6 +170,7 @@ class WriteKodiDB():
#### UPDATE THE MOVIE ##### #### UPDATE THE MOVIE #####
else: else:
utils.logMsg("UPDATE movie to Kodi library","Id: %s - Title: %s" % (embyId, title))
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))
@ -255,6 +259,8 @@ class WriteKodiDB():
#### ADD THE TV SHOW TO KODI ############## #### ADD THE TV SHOW TO KODI ##############
if showid == None: if showid == None:
utils.logMsg("ADD tvshow to Kodi library","Id: %s - Title: %s" % (embyId, title))
#create the tv show path #create the tv show path
cursor.execute("select coalesce(max(idPath),0) as pathid from path") cursor.execute("select coalesce(max(idPath),0) as pathid from path")
pathid = cursor.fetchone()[0] pathid = cursor.fetchone()[0]
@ -293,6 +299,8 @@ class WriteKodiDB():
#### UPDATE THE TV SHOW ############# #### UPDATE THE TV SHOW #############
else: else:
utils.logMsg("UPDATE tvshow to Kodi library","Id: %s - Title: %s" % (embyId, title))
pathsql="UPDATE tvshow SET c00 = ?, c01 = ?, c04 = ?, c05 = ?, c08 = ?, c09 = ?, c13 = ?, c14 = ?, c15 = ? WHERE idShow = ?" pathsql="UPDATE tvshow SET c00 = ?, c01 = ?, c04 = ?, c05 = ?, c08 = ?, c09 = ?, c13 = ?, c14 = ?, c15 = ? WHERE idShow = ?"
cursor.execute(pathsql, (title, plot, rating, premieredate, title, genre, mpaa, studio, sorttitle, showid)) cursor.execute(pathsql, (title, plot, rating, premieredate, title, genre, mpaa, studio, sorttitle, showid))
@ -496,7 +504,7 @@ class WriteKodiDB():
# ADD EPISODE TO KODI # ADD EPISODE TO KODI
if episodeid == None: if episodeid == None:
utils.logMsg("ADD episode to Kodi library","Id: %s - Title: %s" % (embyId, title))
#create the episode #create the episode
cursor.execute("select coalesce(max(idEpisode),0) as episodeid from episode") cursor.execute("select coalesce(max(idEpisode),0) as episodeid from episode")
episodeid = cursor.fetchone()[0] episodeid = cursor.fetchone()[0]
@ -513,6 +521,8 @@ class WriteKodiDB():
# UPDATE THE EPISODE IN KODI (for now, we just send in all data) # UPDATE THE EPISODE IN KODI (for now, we just send in all data)
else: else:
utils.logMsg("UPDATE episode to Kodi library","Id: %s - Title: %s" % (embyId, title))
pathsql = "UPDATE episode SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ? WHERE idEpisode = ?" pathsql = "UPDATE episode SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ? WHERE idEpisode = ?"
cursor.execute(pathsql, (title, plot, rating, writer, premieredate, runtime, director, season, episode, title, "-1", "-1", episodeid)) cursor.execute(pathsql, (title, plot, rating, writer, premieredate, runtime, director, season, episode, title, "-1", "-1", episodeid))