Playback updates if an item is resumed

This commit is contained in:
tomkat83 2016-03-22 16:17:06 +01:00
parent 98554dbe26
commit b20308d68f
2 changed files with 96 additions and 3 deletions

View file

@ -755,6 +755,88 @@ class Kodidb_Functions():
ids.append(row[0])
return ids
def getIdFromTitle(self, itemdetails):
"""
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)
itemdetails is the data['item'] response from Kodi
itemdetails for movies:
{
"title":"Kung Fu Panda",
"type":"movie",
"year":2008
}
itemdetails for episodes:
{
"episode":5
"season":5,
"showtitle":"Girls",
"title":"Queen for Two Days",
"type":"episode"
}
"""
try:
type = itemdetails['type']
except:
return False
if type == 'movie':
query = ' '.join((
"SELECT idMovie",
"FROM movie",
"WHERE c00 = ?"
))
try:
rows = self.cursor.execute(query, (itemdetails['title'],))
except:
return False
elif type == 'episode':
query = ' '.join((
"SELECT idShow",
"FROM tvshow",
"WHERE c00 = ?"
))
try:
rows = self.cursor.execute(query, (itemdetails['showtitle'],))
except:
return False
ids = []
for row in rows:
ids.append(row[0])
if len(ids) > 1:
# No unique match possible
return False
showid = ids[0]
query = ' '.join((
"SELECT idEpisode",
"FROM episode",
"WHERE c12 = ? AND c13 = ? AND idShow = ?"
))
try:
rows = self.cursor.execute(
query,
(itemdetails['season'],
itemdetails['episode'],
showid))
except:
return False
else:
return False
ids = []
for row in rows:
ids.append(row[0])
if len(ids) > 1:
# No unique match possible
return False
else:
return ids[0]
def getUnplayedItems(self):
"""
VIDEOS

View file

@ -10,6 +10,7 @@ import xbmcgui
import downloadutils
import embydb_functions as embydb
import kodidb_functions as kodidb
import playbackutils as pbutils
import utils
from PlexFunctions import scrobble
@ -154,10 +155,20 @@ class KodiMonitor(xbmc.Monitor):
# Try to get a Kodi ID
item = data.get('item')
try:
kodiid = item['id']
type = item['type']
except:
log("Item is invalid for PMS playstate update.", 0)
return
try:
kodiid = item['id']
except (KeyError, TypeError):
log("Item is invalid for Plex playstate update.", 0)
log('Kodi did not give us a Kodi item id, trying to get from item '
'title', 0)
# Try to get itemid with the element's title
with kodidb.GetKodiDB('video') as kodi_db:
kodiid = kodi_db.getIdFromTitle(item)
if kodiid is False:
log("Item is invalid for PMS playstate update.", 0)
return
# Get Plex' item id