parent
e70ce89c34
commit
be63414893
2 changed files with 44 additions and 101 deletions
|
@ -179,52 +179,6 @@ class Kodidb_Functions():
|
||||||
|
|
||||||
return fileid
|
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):
|
def getFile(self, fileid):
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -891,7 +845,7 @@ class Kodidb_Functions():
|
||||||
for row in rows:
|
for row in rows:
|
||||||
ids.append(row[0])
|
ids.append(row[0])
|
||||||
if len(ids) > 1:
|
if len(ids) > 1:
|
||||||
# No unique match possible
|
self.logMsg('No unique match possible. Rows: %s' % rows, 1)
|
||||||
return
|
return
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
|
@ -188,6 +188,10 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
log("Playing itemtype is: %s" % typus, 1)
|
log("Playing itemtype is: %s" % typus, 1)
|
||||||
|
|
||||||
# Try to get a Kodi ID
|
# 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:
|
try:
|
||||||
playerid = data["player"]["playerid"]
|
playerid = data["player"]["playerid"]
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
|
@ -218,32 +222,17 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
kodiid = result["result"]["item"][key]
|
kodiid = result["result"]["item"][key]
|
||||||
except KeyError:
|
except (TypeError, KeyError):
|
||||||
pass
|
pass
|
||||||
# Kodi might return -1 for last element
|
# Kodi might return -1 for last element
|
||||||
if kodiid in (None, -1):
|
if kodiid in (None, -1) and typus in ('movie', 'episode'):
|
||||||
log('Could not get Kodi id directly. Kodi said: %s' % result, 1)
|
log('Could not get Kodi id directly. Kodi said: %s'
|
||||||
if currentFile.startswith('http'):
|
% result, 1)
|
||||||
# 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'):
|
|
||||||
log('Trying to get Kodi id from the items name', 1)
|
log('Trying to get Kodi id from the items name', 1)
|
||||||
with kodidb.GetKodiDB('video') as kodi_db:
|
with kodidb.GetKodiDB('video') as kodi_db:
|
||||||
kodiid = kodi_db.getIdFromTitle(data.get('item'))
|
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"
|
log("Skip playstate update. No unique Kodi title found"
|
||||||
" for %s" % data.get('item'), 0)
|
" for %s" % data.get('item'), 0)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue