From ab33ef5848a13bb5b7a8be17a8e390e1c14bcd79 Mon Sep 17 00:00:00 2001 From: sfaulds Date: Fri, 14 Oct 2016 14:35:34 +1100 Subject: [PATCH 1/6] add screen app size to GA only ping GA if playing dont send an app stopped message --- resources/lib/ga_client.py | 8 ++++++++ resources/lib/librarysync.py | 5 ++--- resources/lib/player.py | 3 +++ resources/lib/service_entry.py | 15 ++++++++------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/resources/lib/ga_client.py b/resources/lib/ga_client.py index 037a5ad6..ba582045 100644 --- a/resources/lib/ga_client.py +++ b/resources/lib/ga_client.py @@ -5,6 +5,7 @@ import requests import logging import clientinfo import md5 +import xbmcgui from utils import window, settings, language as lang log = logging.getLogger("EMBY."+__name__) @@ -29,6 +30,10 @@ class GoogleAnalytics(): # use md5 for client and user for analytics self.device_id = md5.new(self.device_id).hexdigest() self.user_name = md5.new(self.user_name).hexdigest() + + # resolution + self.height = xbmcgui.Window(10000).getHeight() + self.width = xbmcgui.Window(10000).getWidth() def formatException(self): exc_type, exc_obj, exc_tb = sys.exc_info() @@ -76,6 +81,9 @@ class GoogleAnalytics(): data['t'] = 'event' # action type data['ec'] = eventCategory # Event Category data['ea'] = eventAction # Event Action + + # add width and height + data['sr'] = str(self.width) + "x" + str(self.height) if(eventLabel != None): data['el'] = eventLabel # Event Label diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 7279b996..27df195d 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -81,9 +81,6 @@ class LibrarySync(threading.Thread): # Run at start up - optional to use the server plugin if settings('SyncInstallRunDone') == "true": - - ga.sendEventData("SyncAction", "FastSync") - # Validate views self.refreshViews() completed = False @@ -97,11 +94,13 @@ class LibrarySync(threading.Thread): if plugin['Name'] == "Emby.Kodi Sync Queue": log.debug("Found server plugin.") self.isFastSync = True + ga.sendEventData("SyncAction", "FastSync") completed = self.fastSync() break if not completed: # Fast sync failed or server plugin is not found + ga.sendEventData("SyncAction", "Sync") completed = ManualSync().sync() else: # Install sync is not completed diff --git a/resources/lib/player.py b/resources/lib/player.py index f7e0c13a..4e4c1fd8 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -476,6 +476,9 @@ class Player(xbmc.Player): xbmcvfs.delete("%s%s" % (path, file)) self.played_info.clear() + + ga = GoogleAnalytics() + ga.sendEventData("PlayAction", "Stopped") def stopPlayback(self, data): diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index ad6ae247..07ff0224 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -140,13 +140,14 @@ class Service(object): # or Kodi is shut down. self._server_online_check() - # ping metrics server to keep sessions alive - # ping every 3 min + # ping metrics server to keep sessions alive while playing + # ping every 5 min timeSinceLastPing = time.time() - self.lastMetricPing - if(timeSinceLastPing > 180): + if(timeSinceLastPing > 300): self.lastMetricPing = time.time() - ga = GoogleAnalytics() - ga.sendEventData("Application", "Ping") + if self.kodi_player.isPlaying(): + ga = GoogleAnalytics() + ga.sendEventData("PlayAction", "PlayPing") if self.monitor.waitForAbort(1): # Abort was requested while waiting. We should exit @@ -297,8 +298,8 @@ class Service(object): def shutdown(self): - ga = GoogleAnalytics() - ga.sendEventData("Application", "Shutdown") + #ga = GoogleAnalytics() + #ga.sendEventData("Application", "Shutdown") if self.userclient_running: self.userclient_thread.stop_client() From e4ba707a59f68461283232e309252726d4ff5130 Mon Sep 17 00:00:00 2001 From: sfaulds Date: Fri, 14 Oct 2016 14:36:19 +1100 Subject: [PATCH 2/6] bump ver --- addon.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 163c02f6..db8e018e 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ From 124b3bdde1e198ea2d1fdfb17e5383c6e96a9afc Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 13 Oct 2016 22:55:43 -0500 Subject: [PATCH 3/6] Catch server discovery error --- resources/lib/connect/connectionmanager.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/resources/lib/connect/connectionmanager.py b/resources/lib/connect/connectionmanager.py index cd9d6026..60dc2fed 100644 --- a/resources/lib/connect/connectionmanager.py +++ b/resources/lib/connect/connectionmanager.py @@ -263,9 +263,15 @@ class ConnectionManager(object): log.debug("MultiGroup : %s" % str(MULTI_GROUP)) log.debug("Sending UDP Data: %s" % MESSAGE) - sock.sendto(MESSAGE, MULTI_GROUP) - + servers = [] + + try: + sock.sendto(MESSAGE, MULTI_GROUP) + except Exception as error: + log.error(error) + return servers + while True: try: data, addr = sock.recvfrom(1024) # buffer size From e2bbf6186691babcb91f1490501584d29b86f5c8 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 13 Oct 2016 23:02:40 -0500 Subject: [PATCH 4/6] Move ping code --- resources/lib/service_entry.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index 07ff0224..2d8acd8e 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -120,6 +120,14 @@ class Service(object): # If an item is playing if self.kodi_player.isPlaying(): + # ping metrics server to keep sessions alive while playing + # ping every 5 min + timeSinceLastPing = time.time() - self.lastMetricPing + if(timeSinceLastPing > 300): + self.lastMetricPing = time.time() + ga = GoogleAnalytics() + ga.sendEventData("PlayAction", "PlayPing") + self._report_progress() elif not self.startup: @@ -139,15 +147,6 @@ class Service(object): # Wait until Emby server is online # or Kodi is shut down. self._server_online_check() - - # ping metrics server to keep sessions alive while playing - # ping every 5 min - timeSinceLastPing = time.time() - self.lastMetricPing - if(timeSinceLastPing > 300): - self.lastMetricPing = time.time() - if self.kodi_player.isPlaying(): - ga = GoogleAnalytics() - ga.sendEventData("PlayAction", "PlayPing") if self.monitor.waitForAbort(1): # Abort was requested while waiting. We should exit From 8086927673fcf3dba2236056094b44b634c02d5c Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 13 Oct 2016 23:05:33 -0500 Subject: [PATCH 5/6] Version bump 2.2.48 --- addon.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index db8e018e..e5c54fbd 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ From 3f3ac45ef5c3f284fbf27c47dea770a7af31cd70 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Fri, 14 Oct 2016 02:04:59 -0500 Subject: [PATCH 6/6] Fix emby connect --- resources/lib/connectmanager.py | 38 ++++++++++++++++++--------------- resources/lib/service_entry.py | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/resources/lib/connectmanager.py b/resources/lib/connectmanager.py index 96a80a48..1376236e 100644 --- a/resources/lib/connectmanager.py +++ b/resources/lib/connectmanager.py @@ -35,35 +35,39 @@ class ConnectManager(object): self.__dict__ = self._shared_state - if not self.state and not window('emby_currUser'): - client_info = clientinfo.ClientInfo() - self.emby = embyserver.Read_EmbyServer() + client_info = clientinfo.ClientInfo() + self.emby = embyserver.Read_EmbyServer() - version = client_info.get_version() - device_name = client_info.get_device_name() - device_id = client_info.get_device_id() - - self._connect = connectionmanager.ConnectionManager(appName="Kodi", - appVersion=version, - deviceName=device_name, - deviceId=device_id) - path = xbmc.translatePath( + version = client_info.get_version() + device_name = client_info.get_device_name() + device_id = client_info.get_device_id() + self._connect = connectionmanager.ConnectionManager(appName="Kodi", + appVersion=version, + deviceName=device_name, + deviceId=device_id) + path = xbmc.translatePath( "special://profile/addon_data/plugin.video.emby/").decode('utf-8') - if not xbmcvfs.exists(path): - xbmcvfs.mkdirs(path) + if not xbmcvfs.exists(path): + xbmcvfs.mkdirs(path) - self._connect.setFilePath(path) + self._connect.setFilePath(path) + + if window('emby_state.json'): + self.state = window('emby_state.json') + + elif not self.state: self.state = self._connect.connect() log.info("Started with: %s", self.state) + window('emby_state.json', value=self.state) def update_state(self): - self.state = self._connect.connect({'updateDateLastAccessed': False}) - return self.state + return self.get_state() def get_state(self): + window('emby_state.json', value=self.state) return self.state def get_server(self, server): diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index 2d8acd8e..191820a2 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -67,7 +67,7 @@ class Service(object): # Reset window props for profile switch properties = [ - "emby_online", "emby_serverStatus", "emby_onWake", + "emby_online", "emby_state.json" "emby_serverStatus", "emby_onWake", "emby_syncRunning", "emby_dbCheck", "emby_kodiScan", "emby_shouldStop", "emby_currUser", "emby_dbScan", "emby_sessionId", "emby_initialScan", "emby_customplaylist", "emby_playbackProps"