Enable playstate update if Kodi does not give DB id

This commit is contained in:
tomkat83 2016-04-18 12:09:01 +02:00
parent 9dd592b863
commit 0d79ec76b1
2 changed files with 44 additions and 35 deletions

View file

@ -780,7 +780,7 @@ class Kodidb_Functions():
"""
Returns the Kodi id (e.g. idMovie, idEpisode) from the item's
title (c00), if there is exactly ONE found for the itemtype.
(False otherwise)
(None otherwise)
itemdetails is the data['item'] response from Kodi
@ -801,11 +801,11 @@ class Kodidb_Functions():
}
"""
try:
type = itemdetails['type']
typus = itemdetails['type']
except:
return False
return
if type == 'movie':
if typus == 'movie':
query = ' '.join((
"SELECT idMovie",
"FROM movie",
@ -814,8 +814,8 @@ class Kodidb_Functions():
try:
rows = self.cursor.execute(query, (itemdetails['title'],))
except:
return False
elif type == 'episode':
return
elif typus == 'episode':
query = ' '.join((
"SELECT idShow",
"FROM tvshow",
@ -824,14 +824,13 @@ class Kodidb_Functions():
try:
rows = self.cursor.execute(query, (itemdetails['showtitle'],))
except:
return False
return
ids = []
for row in rows:
ids.append(row[0])
if len(ids) > 1:
# No unique match possible
return False
showid = ids[0]
return
query = ' '.join((
"SELECT idEpisode",
@ -843,11 +842,11 @@ class Kodidb_Functions():
query,
(itemdetails['season'],
itemdetails['episode'],
showid))
ids[0]))
except:
return False
return
else:
return False
return
ids = []
for row in rows:
@ -856,7 +855,7 @@ class Kodidb_Functions():
return ids[0]
else:
# No unique match possible
return False
return
def getUnplayedItems(self):
"""

View file

@ -156,6 +156,25 @@ class KodiMonitor(xbmc.Monitor):
log = self.logMsg
window = utils.window
# Get currently playing file - can take a while. Will be utf-8!
try:
currentFile = self.xbmcplayer.getPlayingFile()
except:
currentFile = None
count = 0
while currentFile is None:
xbmc.sleep(100)
try:
currentFile = self.xbmcplayer.getPlayingFile()
except:
pass
if count == 50:
log("No current File - Cancelling OnPlayBackStart...", -1)
return
else:
count += 1
log("Currently playing file is: %s" % currentFile.decode('utf-8'), 1)
# Try to get a Kodi ID
item = data.get('item')
try:
@ -166,6 +185,17 @@ class KodiMonitor(xbmc.Monitor):
try:
kodiid = item['id']
except (KeyError, TypeError):
itemType = window("emby_%s.type" % currentFile)
log("No kodi id passed. Playing itemtype is: %s" % itemType, 1)
if itemType in ('movie', 'episode'):
# Window was setup by PKC and is NOT a trailer ('clip')
with kodidb.GetKodiDB('video') as kodi_db:
kodiid = kodi_db.getIdFromTitle(data.get('item'))
if kodiid is None:
log("Skip playstate update. No unique Kodi title found"
" for %s" % data.get('item'), 0)
return
else:
log("Item is invalid for PMS playstate update.", 0)
return
@ -179,26 +209,6 @@ class KodiMonitor(xbmc.Monitor):
return
log("Found Plex id %s for Kodi id %s" % (plexid, kodiid), 1)
# Get currently playing file - can take a while. Will be utf-8!
try:
currentFile = self.xbmcplayer.getPlayingFile()
xbmc.sleep(300)
except:
currentFile = ""
count = 0
while not currentFile:
xbmc.sleep(100)
try:
currentFile = self.xbmcplayer.getPlayingFile()
except:
pass
if count == 20:
log("No current File - Cancelling OnPlayBackStart...", -1)
return
else:
count += 1
log("Currently playing file is: %s" % currentFile, 1)
# Set some stuff if Kodi initiated playback
if ((utils.settings('useDirectPaths') == "1" and not type == "song") or
(type == "song" and utils.settings('enableMusic') == "true")):