From 6f5ae66c548cf2080a0292ef754f9781ce2203b7 Mon Sep 17 00:00:00 2001 From: im85288 Date: Sun, 3 May 2015 13:44:23 +0100 Subject: [PATCH 1/5] added initial box set support --- resources/lib/LibrarySync.py | 37 ++++++++++++++++++++++++ resources/lib/WriteKodiDB.py | 56 ++++++++++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 5 deletions(-) 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/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index 96c42b2d..3cdd8951 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"])) + + + \ No newline at end of file From e91d2ff2a7925b4d4f286aefe2cc43541f72d8cf Mon Sep 17 00:00:00 2001 From: im85288 Date: Sun, 3 May 2015 14:45:13 +0100 Subject: [PATCH 2/5] resolve artwork issue for widgets --- resources/lib/PlaybackUtils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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': From 76691ea687c552eec9d84924a1b5f59e380b1c75 Mon Sep 17 00:00:00 2001 From: xnappo Date: Sun, 3 May 2015 09:42:37 -0500 Subject: [PATCH 3/5] Fixes for user views in case we decide to use them --- resources/lib/ReadEmbyDB.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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): From 7a2d0d2ef78afd2178da40b14ab1fff9a88a11df Mon Sep 17 00:00:00 2001 From: xnappo Date: Sun, 3 May 2015 10:05:26 -0500 Subject: [PATCH 4/5] Add sync on wakeup --- resources/lib/KodiMonitor.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/lib/KodiMonitor.py b/resources/lib/KodiMonitor.py index 42208475..a3be00a5 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,11 @@ 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) + utils.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync),1) + + From 08ea50bdcae2eceebbc686b8048c1346a8f7aaeb Mon Sep 17 00:00:00 2001 From: xnappo Date: Sun, 3 May 2015 10:19:02 -0500 Subject: [PATCH 5/5] Missed a line somehow. --- resources/lib/KodiMonitor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lib/KodiMonitor.py b/resources/lib/KodiMonitor.py index a3be00a5..a2e789aa 100644 --- a/resources/lib/KodiMonitor.py +++ b/resources/lib/KodiMonitor.py @@ -49,6 +49,7 @@ class Kodi_Monitor(xbmc.Monitor): 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)