From 769b7410605037273feceff1b0083c10271ffbc3 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Wed, 16 Mar 2016 12:49:55 +0100 Subject: [PATCH] Fix direct play monitoring --- resources/lib/kodimonitor.py | 23 +++++------------------ resources/lib/playbackutils.py | 1 - 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 8c558daa..842eeb7a 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -68,7 +68,6 @@ class KodiMonitor(xbmc.Monitor): if data: data = json.loads(data,'utf-8') - if method == "Player.OnPlay": # Set up report progress for emby playback item = data.get('item') @@ -81,19 +80,15 @@ class KodiMonitor(xbmc.Monitor): if ((utils.settings('useDirectPaths') == "1" and not type == "song") or (type == "song" and utils.settings('enableMusic') == "true")): # Set up properties for player - embyconn = utils.kodiSQL('emby') - embycursor = embyconn.cursor() - emby_db = embydb.Embydb_Functions(embycursor) - emby_dbitem = emby_db.getItem_byKodiId(kodiid, type) + with embydb.GetEmbyDB() as emby_db: + emby_dbitem = emby_db.getItem_byKodiId(kodiid, type) try: itemid = emby_dbitem[0] except TypeError: self.logMsg("No kodiid returned.", 1) else: - url = "{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid + url = "{server}/library/metadata/%s" % itemid result = doUtils.downloadUrl(url) - self.logMsg("Item: %s" % result, 2) - playurl = None count = 0 while not playurl and count < 2: @@ -114,8 +109,6 @@ class KodiMonitor(xbmc.Monitor): value="DirectPlay") # Set properties for player.py playback.setProperties(playurl, listItem) - finally: - embycursor.close() elif method == "VideoLibrary.OnUpdate": # Manually marking as watched/unwatched @@ -128,10 +121,8 @@ class KodiMonitor(xbmc.Monitor): self.logMsg("Item is invalid for playstate update.", 1) else: # Send notification to the server. - embyconn = utils.kodiSQL('emby') - embycursor = embyconn.cursor() - emby_db = embydb.Embydb_Functions(embycursor) - emby_dbitem = emby_db.getItem_byKodiId(kodiid, type) + with embydb.GetEmbyDB() as emby_db: + emby_dbitem = emby_db.getItem_byKodiId(kodiid, type) try: itemid = emby_dbitem[0] except TypeError: @@ -148,10 +139,6 @@ class KodiMonitor(xbmc.Monitor): else: scrobble(itemid, 'unwatched') - finally: - embycursor.close() - - elif method == "VideoLibrary.OnRemove": # Removed function, because with plugin paths + clean library, it will wipe # entire library if user has permissions. Instead, use the emby context menu available diff --git a/resources/lib/playbackutils.py b/resources/lib/playbackutils.py index 402e3b44..b5ed9174 100644 --- a/resources/lib/playbackutils.py +++ b/resources/lib/playbackutils.py @@ -251,7 +251,6 @@ class PlaybackUtils(): return True def setProperties(self, playurl, listitem): - window = utils.window # Set all properties necessary for plugin path playback itemid = self.API.getRatingKey()