diff --git a/resources/lib/KodiMonitor.py b/resources/lib/KodiMonitor.py index 42208475..a2e789aa 100644 --- a/resources/lib/KodiMonitor.py +++ b/resources/lib/KodiMonitor.py @@ -11,6 +11,7 @@ import json import Utils as utils from WriteKodiDB import WriteKodiDB from ReadKodiDB import ReadKodiDB +from LibrarySync import LibrarySync from PlayUtils import PlayUtils from DownloadUtils import DownloadUtils from PlaybackUtils import PlaybackUtils @@ -45,6 +46,12 @@ class Kodi_Monitor(xbmc.Monitor): utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2) WriteKodiDB().updatePlayCountFromKodi(item, type, playcount) - + if method == "System.OnWake": + xbmc.sleep(10000) #Allow network to wake up + utils.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Started)",1) + libSync = LibrarySync().FullLibrarySync() + utils.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync),1) + + diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index a453a4b2..5e8cb15e 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -142,6 +142,31 @@ class LibrarySync(): else: if kodiMovie[2] != API().getChecksum(item): WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) + + + + #### PROCESS BOX SETS ##### + if(pDialog != None): + utils.logMsg("Sync Movies", "BoxSet Sync Started", 1) + boxsets = ReadEmbyDB().getBoxSets() + + total = len(boxsets) + 1 + count = 1 + for boxset in boxsets: + progressTitle = "Processing BoxSets"+ " (" + str(count) + " of " + str(total) + ")" + pDialog.update(0, "Emby for Kodi - Running Sync", progressTitle) + count += 1 + if(self.ShouldStop()): + return False + boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"]) + WriteKodiDB().addBoxsetToKodiLibrary(boxset,connection, cursor) + + for boxsetMovie in boxsetMovies: + if(self.ShouldStop()): + return False + WriteKodiDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor) + + utils.logMsg("Sync Movies", "BoxSet Sync Finished", 1) #### PROCESS DELETES ##### allEmbyMovieIds = set(allEmbyMovieIds) @@ -335,7 +360,19 @@ class LibrarySync(): if not item.get('IsFolder'): WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) + + + #### PROCESS BOX SETS ##### + boxsets = ReadEmbyDB().getBoxSets() + + for boxset in boxsets: + boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"]) + WriteKodiDB().addBoxsetToKodiLibrary(boxset,connection, cursor) + + for boxsetMovie in boxsetMovies: + WriteKodiDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor) + #### PROCESS TV SHOWS #### views = ReadEmbyDB().getCollections("tvshows") for view in views: diff --git a/resources/lib/PlaybackUtils.py b/resources/lib/PlaybackUtils.py index 000b5c91..103c4f4f 100644 --- a/resources/lib/PlaybackUtils.py +++ b/resources/lib/PlaybackUtils.py @@ -115,8 +115,9 @@ class PlaybackUtils(): if setup == "service": xbmc.Player().play(playurl,listItem) elif setup == "default": - listItem = xbmcgui.ListItem(path=playurl) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem) + #artwork only works from widgets with both resolvedurl and player command + xbmc.Player().play(playurl,listItem) def setArt(self, list,name,path): if name=='thumb' or name=='fanart_image' or name=='small_poster' or name=='tiny_poster' or name == "medium_landscape" or name=='medium_poster' or name=='small_fanartimage' or name=='medium_fanartimage' or name=='fanart_noindicators': diff --git a/resources/lib/ReadEmbyDB.py b/resources/lib/ReadEmbyDB.py index f436d365..edd24e2f 100644 --- a/resources/lib/ReadEmbyDB.py +++ b/resources/lib/ReadEmbyDB.py @@ -246,13 +246,13 @@ class ReadEmbyDB(): Name = view[u'Name'] total = str(view[u'ChildCount']) - type = view[u'CollectionType'] - if type == None: - type = "None" # User may not have declared the type - if type == type: + itemtype = view[u'CollectionType'] + if itemtype == None: + itemtype = "movies" # User may not have declared the type + if itemtype == type: collections.append( {'title' : Name, - 'type' : type, - 'id' : view[u'Id']}) + 'type' : type, + 'id' : view[u'Id']}) return collections def getBoxSets(self): diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index 825e23af..afce017a 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -992,15 +992,61 @@ class WriteKodiDB(): setssql="INSERT INTO sets (idSet, strSet) values(?, ?)" cursor.execute(setssql, (None,strSet)) #if OK: + cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,)) + result = cursor.fetchone() 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") + + art_types = ['poster','fanart','landscape','clearlogo','clearart','banner','discart'] + 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])) return True - def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset): + def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset, connection, cursor): strSet = boxset["Name"] - kodiMovie = ReadKodiDB().getKodiMovie(boxsetmovie["Id"]) - if kodiMovie != None: - WriteKodiDB().updateProperty(kodiMovie,"set",strSet,"movie",True) - \ No newline at end of file + cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(boxsetmovie["Id"],)) + result = cursor.fetchone() + if result != None: + movieid = result[0] + else: + movieid = None + if movieid != None: + # check if exists + cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,)) + result = cursor.fetchone() + setid = None + if result != None: + setid = result[0] + + pathsql="update movie SET idSet = ? WHERE idMovie = ?" + cursor.execute(pathsql, (setid, movieid)) + + #update the checksum in emby table + cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(boxsetmovie),boxsetmovie["Id"])) + + +