Enable playstate update if Kodi does not give DB id
This commit is contained in:
parent
9dd592b863
commit
0d79ec76b1
2 changed files with 44 additions and 35 deletions
|
@ -780,7 +780,7 @@ class Kodidb_Functions():
|
||||||
"""
|
"""
|
||||||
Returns the Kodi id (e.g. idMovie, idEpisode) from the item's
|
Returns the Kodi id (e.g. idMovie, idEpisode) from the item's
|
||||||
title (c00), if there is exactly ONE found for the itemtype.
|
title (c00), if there is exactly ONE found for the itemtype.
|
||||||
(False otherwise)
|
(None otherwise)
|
||||||
|
|
||||||
itemdetails is the data['item'] response from Kodi
|
itemdetails is the data['item'] response from Kodi
|
||||||
|
|
||||||
|
@ -801,11 +801,11 @@ class Kodidb_Functions():
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
type = itemdetails['type']
|
typus = itemdetails['type']
|
||||||
except:
|
except:
|
||||||
return False
|
return
|
||||||
|
|
||||||
if type == 'movie':
|
if typus == 'movie':
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
"SELECT idMovie",
|
"SELECT idMovie",
|
||||||
"FROM movie",
|
"FROM movie",
|
||||||
|
@ -814,8 +814,8 @@ class Kodidb_Functions():
|
||||||
try:
|
try:
|
||||||
rows = self.cursor.execute(query, (itemdetails['title'],))
|
rows = self.cursor.execute(query, (itemdetails['title'],))
|
||||||
except:
|
except:
|
||||||
return False
|
return
|
||||||
elif type == 'episode':
|
elif typus == 'episode':
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
"SELECT idShow",
|
"SELECT idShow",
|
||||||
"FROM tvshow",
|
"FROM tvshow",
|
||||||
|
@ -824,14 +824,13 @@ class Kodidb_Functions():
|
||||||
try:
|
try:
|
||||||
rows = self.cursor.execute(query, (itemdetails['showtitle'],))
|
rows = self.cursor.execute(query, (itemdetails['showtitle'],))
|
||||||
except:
|
except:
|
||||||
return False
|
return
|
||||||
ids = []
|
ids = []
|
||||||
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
|
# No unique match possible
|
||||||
return False
|
return
|
||||||
showid = ids[0]
|
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
"SELECT idEpisode",
|
"SELECT idEpisode",
|
||||||
|
@ -843,11 +842,11 @@ class Kodidb_Functions():
|
||||||
query,
|
query,
|
||||||
(itemdetails['season'],
|
(itemdetails['season'],
|
||||||
itemdetails['episode'],
|
itemdetails['episode'],
|
||||||
showid))
|
ids[0]))
|
||||||
except:
|
except:
|
||||||
return False
|
return
|
||||||
else:
|
else:
|
||||||
return False
|
return
|
||||||
|
|
||||||
ids = []
|
ids = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
@ -856,7 +855,7 @@ class Kodidb_Functions():
|
||||||
return ids[0]
|
return ids[0]
|
||||||
else:
|
else:
|
||||||
# No unique match possible
|
# No unique match possible
|
||||||
return False
|
return
|
||||||
|
|
||||||
def getUnplayedItems(self):
|
def getUnplayedItems(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -156,6 +156,25 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
log = self.logMsg
|
log = self.logMsg
|
||||||
window = utils.window
|
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
|
# Try to get a Kodi ID
|
||||||
item = data.get('item')
|
item = data.get('item')
|
||||||
try:
|
try:
|
||||||
|
@ -166,8 +185,19 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
try:
|
try:
|
||||||
kodiid = item['id']
|
kodiid = item['id']
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
log("Item is invalid for PMS playstate update.", 0)
|
itemType = window("emby_%s.type" % currentFile)
|
||||||
return
|
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
|
||||||
|
|
||||||
# Get Plex' item id
|
# Get Plex' item id
|
||||||
with embydb.GetEmbyDB() as emby_db:
|
with embydb.GetEmbyDB() as emby_db:
|
||||||
|
@ -179,26 +209,6 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
return
|
return
|
||||||
log("Found Plex id %s for Kodi id %s" % (plexid, kodiid), 1)
|
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
|
# Set some stuff if Kodi initiated playback
|
||||||
if ((utils.settings('useDirectPaths') == "1" and not type == "song") or
|
if ((utils.settings('useDirectPaths') == "1" and not type == "song") or
|
||||||
(type == "song" and utils.settings('enableMusic') == "true")):
|
(type == "song" and utils.settings('enableMusic') == "true")):
|
||||||
|
|
Loading…
Add table
Reference in a new issue