Be smarter when trying to tell what Kodi plays

- Fixes #67
This commit is contained in:
tomkat83 2016-06-25 12:25:01 +02:00
parent e70ce89c34
commit be63414893
2 changed files with 44 additions and 101 deletions

View file

@ -179,52 +179,6 @@ class Kodidb_Functions():
return fileid
def getIdFromFilename(self, filename):
"""
Returns None if not found OR if several entries found
"""
query = ' '.join((
"SELECT idFile",
"FROM files",
"WHERE strFilename = ?"
))
self.cursor.execute(query, (filename,))
try:
idFile = self.cursor.fetchone()[0]
except TypeError:
idFile = None
else:
# Try to fetch again - if successful, we got >1 result
if self.cursor.fetchone() is not None:
self.logMsg('We found several items with the same filename', 1)
idFile = None
if idFile is None:
return
# Try movies first
itemId = None
query = ' '.join((
"SELECT idMovie",
"FROM movie",
"WHERE idFile = ?"
))
self.cursor.execute(query, (idFile,))
try:
itemId = self.cursor.fetchone()[0]
except TypeError:
# Try tv shows next
query = ' '.join((
"SELECT idEpisode",
"FROM episode",
"WHERE idFile = ?"
))
self.cursor.execute(query, (idFile,))
try:
itemId = self.cursor.fetchone()[0]
except TypeError:
pass
return itemId
def getFile(self, fileid):
query = ' '.join((
@ -891,7 +845,7 @@ class Kodidb_Functions():
for row in rows:
ids.append(row[0])
if len(ids) > 1:
# No unique match possible
self.logMsg('No unique match possible. Rows: %s' % rows, 1)
return
query = ' '.join((

View file

@ -188,6 +188,10 @@ class KodiMonitor(xbmc.Monitor):
log("Playing itemtype is: %s" % typus, 1)
# Try to get a Kodi ID
try:
kodiid = data['item']['id']
except (TypeError, KeyError):
log('Could not get Kodi id directly, trying jsonrpc', 1)
try:
playerid = data["player"]["playerid"]
except (TypeError, KeyError):
@ -218,32 +222,17 @@ class KodiMonitor(xbmc.Monitor):
return
try:
kodiid = result["result"]["item"][key]
except KeyError:
except (TypeError, KeyError):
pass
# Kodi might return -1 for last element
if kodiid in (None, -1):
log('Could not get Kodi id directly. Kodi said: %s' % result, 1)
if currentFile.startswith('http'):
# Native paths - should have launched directly via PKC
log('Trying to get Kodi id from window properties', 1)
kodiid = utils.window('emby_%s.itemid' % currentFile)
elif typus in ('movie', 'episode'):
try:
filename = currentFile.rsplit('/', 1)[1]
except IndexError:
filename = currentFile.rsplit('\\', 1)[1]
log('Trying to get Kodi id from filename: %s'
% utils.tryDecode(filename), 1)
with kodidb.GetKodiDB('video') as kodi_db:
kodiid = kodi_db.getIdFromFilename(
utils.tryDecode(filename))
if not kodiid and typus in ('movie', 'episode'):
if kodiid in (None, -1) and typus in ('movie', 'episode'):
log('Could not get Kodi id directly. Kodi said: %s'
% result, 1)
log('Trying to get Kodi id from the items name', 1)
with kodidb.GetKodiDB('video') as kodi_db:
kodiid = kodi_db.getIdFromTitle(data.get('item'))
if kodiid is None:
if kodiid in (None, -1):
log("Skip playstate update. No unique Kodi title found"
" for %s" % data.get('item'), 0)
return