diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index 0eeed2c1..8390a25c 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -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): """ diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 27840faa..768c3b27 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -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,8 +185,19 @@ class KodiMonitor(xbmc.Monitor): try: kodiid = item['id'] except (KeyError, TypeError): - log("Item is invalid for PMS playstate update.", 0) - return + 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 # Get Plex' item id with embydb.GetEmbyDB() as emby_db: @@ -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")):