Fix potential time sync problems

This commit is contained in:
tomkat83 2016-03-17 16:03:02 +01:00
parent 2c0312a035
commit 8dee81c6a2
2 changed files with 34 additions and 9 deletions

View file

@ -152,17 +152,37 @@ class Embydb_Functions():
)) ))
self.embycursor.execute(query, (viewid,)) 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(( query = ' '.join((
"SELECT emby_id", "SELECT emby_id",
"FROM emby", "FROM emby",
"WHERE kodi_fileid = ?" "WHERE kodi_fileid = ? AND media_type = ?"
)) ))
try: 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] item = self.embycursor.fetchone()[0]
return item return item
except: except:

View file

@ -293,9 +293,14 @@ class LibrarySync(Thread):
self.logMsg('Found kodiId: %s' % kodiId, 1) self.logMsg('Found kodiId: %s' % kodiId, 1)
# Get Plex ID using the Kodi ID # Get Plex ID using the Kodi ID
with embydb.GetEmbyDB() as emby_db: with embydb.GetEmbyDB() as emby_db:
plexId = emby_db.getItem_byFileId(kodiId) plexId = emby_db.getItem_byFileId(kodiId, 'movie')
if plexId: if plexId:
self.logMsg('Found plexId: %s' % plexId, 1) 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 break
# Try getting a music item if we did not find a video item # Try getting a music item if we did not find a video item
@ -310,7 +315,7 @@ class LibrarySync(Thread):
self.logMsg('Found kodiId: %s' % kodiId, 1) self.logMsg('Found kodiId: %s' % kodiId, 1)
# Get Plex ID using the Kodi ID # Get Plex ID using the Kodi ID
with embydb.GetEmbyDB() as emby_db: with embydb.GetEmbyDB() as emby_db:
plexId = emby_db.getItem_byFileId(kodiId) plexId = emby_db.getMusicItem_byFileId(kodiId, 'song')
if plexId: if plexId:
self.logMsg('Found plexId: %s' % plexId, 1) self.logMsg('Found plexId: %s' % plexId, 1)
break break