diff --git a/addon.xml b/addon.xml index 163c02f6..e5c54fbd 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ 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 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/ga_client.py b/resources/lib/ga_client.py index e1ba17f6..266ac1c3 100644 --- a/resources/lib/ga_client.py +++ b/resources/lib/ga_client.py @@ -7,6 +7,7 @@ import clientinfo import md5 import xbmc import platform +import xbmcgui from utils import window, settings, language as lang log = logging.getLogger("EMBY."+__name__) @@ -31,6 +32,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 getUserAgentOS(self): @@ -99,6 +104,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..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" @@ -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,14 +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 - # ping every 3 min - timeSinceLastPing = time.time() - self.lastMetricPing - if(timeSinceLastPing > 180): - self.lastMetricPing = time.time() - ga = GoogleAnalytics() - ga.sendEventData("Application", "Ping") if self.monitor.waitForAbort(1): # Abort was requested while waiting. We should exit @@ -297,8 +297,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()