From 8dee81c6a2ca7641a63b8b06fbef60513da0e2be Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Thu, 17 Mar 2016 16:03:02 +0100 Subject: [PATCH] Fix potential time sync problems --- resources/lib/embydb_functions.py | 28 ++++++++++++++++++++++++---- resources/lib/librarysync.py | 15 ++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/resources/lib/embydb_functions.py b/resources/lib/embydb_functions.py index 079cb869..ee4cf558 100644 --- a/resources/lib/embydb_functions.py +++ b/resources/lib/embydb_functions.py @@ -152,17 +152,37 @@ class Embydb_Functions(): )) self.embycursor.execute(query, (viewid,)) - def getItem_byFileId(self, fileId): + def getItem_byFileId(self, fileId, kodiType): """ - Returns the Plex itemId by using the Kodi fileId + Returns the Plex itemId by using the Kodi fileId. VIDEO ONLY + + kodiType: 'movie', 'episode', ... """ query = ' '.join(( "SELECT emby_id", "FROM emby", - "WHERE kodi_fileid = ?" + "WHERE kodi_fileid = ? AND media_type = ?" )) try: - self.embycursor.execute(query, (fileId,)) + self.embycursor.execute(query, (fileId, kodiType)) + item = self.embycursor.fetchone()[0] + return item + except: + return None + + def getMusicItem_byFileId(self, fileId, kodiType): + """ + Returns the Plex itemId by using the Kodi fileId. MUSIC ONLY + + kodiType: 'song' + """ + query = ' '.join(( + "SELECT emby_id", + "FROM emby", + "WHERE kodi_id = ? AND media_type = ?" + )) + try: + self.embycursor.execute(query, (fileId, kodiType)) item = self.embycursor.fetchone()[0] return item except: diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 3734582d..27c017c1 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -293,10 +293,15 @@ class LibrarySync(Thread): self.logMsg('Found kodiId: %s' % kodiId, 1) # Get Plex ID using the Kodi ID with embydb.GetEmbyDB() as emby_db: - plexId = emby_db.getItem_byFileId(kodiId) - if plexId: - self.logMsg('Found plexId: %s' % plexId, 1) - break + plexId = emby_db.getItem_byFileId(kodiId, 'movie') + if plexId: + self.logMsg('Found movie plexId: %s' % plexId, 1) + break + else: + plexId = emby_db.getItem_byFileId(kodiId, 'episode') + if plexId: + self.logMsg('Found episode plexId: %s' % plexId, 1) + break # Try getting a music item if we did not find a video item if not plexId: @@ -310,7 +315,7 @@ class LibrarySync(Thread): self.logMsg('Found kodiId: %s' % kodiId, 1) # Get Plex ID using the Kodi ID with embydb.GetEmbyDB() as emby_db: - plexId = emby_db.getItem_byFileId(kodiId) + plexId = emby_db.getMusicItem_byFileId(kodiId, 'song') if plexId: self.logMsg('Found plexId: %s' % plexId, 1) break