def shutdown(self): LOG.warn("---<[ EXITING ]") window('emby_should_stop.bool', True) properties = [ # TODO: review "emby_state", "emby_serverStatus", "emby_currUser", "emby_play", "emby_online", "emby.connected", "emby.resume", "emby_startup", "emby.updatewidgets", "emby.external", "emby.external_check", "emby_deviceId", "emby_db_check", "emby_pathverified", "emby_sync" ] for prop in properties: window(prop, clear=True) Emby.close_all() if self.library_thread is not None: self.library_thread.stop_client() if self.webservice is not None: self.webservice.stop() if self.monitor is not None: self.monitor.listener.stop() LOG.warn("---<<<[ %s ]", client.get_addon_name())
def shutdown(self): LOG.warn("---<[ EXITING ]") window('emby_should_stop.bool', True) properties = [ "emby.play", "emby.play.widget", "emby.autoplay", "emby_online", "emby.connected", "emby.resume", "emby.updatewidgets", "emby.external", "emby.external_check", "emby_deviceId", "emby_pathverified", "emby_sync", "emby.restart", "emby.sync.pause", "emby.playlist.clear", "emby.server.state", "emby.server.states" ] for server in window('emby.server.states.json') or []: properties.append("emby.server.%s.state" % server) for prop in properties: window(prop, clear=True) WEBSERVICE.stop() Emby.close_all() if self['library'] is not None: self['library'].stop_client() if self['monitor'] is not None: self['monitor'].listener.stop() LOG.warn("---<<<[ %s ]", client.get_addon_name())
def onNotification(self, sender, method, data): ''' All notifications are sent via NotifyAll built-in or Kodi. Central hub. ''' if sender.lower() not in ('plugin.video.emby', 'xbmc'): return if sender == 'plugin.video.emby': method = method.split('.')[1] if method not in ('ServerUnreachable', 'ServerShuttingDown', 'UserDataChanged', 'ServerConnect', 'LibraryChanged', 'ServerOnline', 'SyncLibrary', 'RepairLibrary', 'RemoveLibrary', 'EmbyConnect', 'SyncLibrarySelection', 'RepairLibrarySelection', 'AddServer', 'Unauthorized', 'UpdateServer', 'UserConfigurationUpdated', 'ServerRestarting', 'RemoveServer', 'AddLibrarySelection', 'CheckUpdate', 'RemoveLibrarySelection', 'PatchMusic'): return data = json.loads(data)[0] else: if method not in ('System.OnQuit', 'System.OnSleep', 'System.OnWake'): return data = json.loads(data) LOG.debug("[ onNotification/%s/%s ]", sender, method) LOG.debug("[ %s: %s ] %s", sender, method, json.dumps(data, indent=4)) if method == 'ServerOnline': if data.get('ServerId') is None: window('emby_online.bool', True) self.settings['auth_check'] = True self.warn = True if settings('connectMsg.bool'): users = [ user for user in (settings('additionalUsers') or "" ).decode('utf-8').split(',') if user ] users.insert(0, settings('username').decode('utf-8')) dialog("notification", heading="{emby}", message="%s %s" % (_(33000), ", ".join(users)), icon="{emby}", time=1500, sound=False) if self.webservice is None: self.webservice = webservice.WebService() self.webservice.start() if self.library_thread is None: self.library_thread = library.Library(self) self.library_thread.start() elif method in ('ServerUnreachable', 'ServerShuttingDown'): if self.warn or data.get('ServerId'): self.warn = data.get('ServerId') is not None dialog("notification", heading="{emby}", message=_(33146) if data.get('ServerId') is None else _(33149), icon=xbmcgui.NOTIFICATION_ERROR) if data.get('ServerId') is None: self.stop_default() if self.waitForAbort(20): return self.start_default() elif method == 'Unauthorized': dialog("notification", heading="{emby}", message=_(33147) if data['ServerId'] is None else _(33148), icon=xbmcgui.NOTIFICATION_ERROR) if data.get('ServerId') is None and self.settings['auth_check']: self.settings['auth_check'] = False self.stop_default() if self.waitForAbort(5): return self.start_default() elif method == 'ServerRestarting': if data.get('ServerId'): return if settings('restartMsg.bool'): dialog("notification", heading="{emby}", message=_(33006), icon="{emby}") self.stop_default() if self.waitForAbort(15): return self.start_default() elif method == 'ServerConnect': self.connect.register(data['Id']) xbmc.executebuiltin("Container.Refresh") elif method == 'EmbyConnect': self.connect.setup_login_connect() elif method == 'AddServer': self.connect.setup_manual_server() xbmc.executebuiltin("Container.Refresh") elif method == 'RemoveServer': self.connect.remove_server(data['Id']) xbmc.executebuiltin("Container.Refresh") elif method == 'UpdateServer': dialog("ok", heading="{emby}", line1=_(33151)) self.connect.setup_manual_server() elif method == 'UserDataChanged' and self.library_thread: if data.get('ServerId') or not window('emby_startup.bool'): return LOG.info("[ UserDataChanged ] %s", data) self.library_thread.userdata(data['UserDataList']) elif method == 'LibraryChanged' and self.library_thread: if data.get('ServerId') or not window('emby_startup.bool'): return LOG.info("[ LibraryChanged ] %s", data) self.library_thread.updated(data['ItemsUpdated'] + data['ItemsAdded']) self.library_thread.removed(data['ItemsRemoved']) elif method == 'System.OnQuit': window('emby_should_stop.bool', True) self.running = False elif method in ('SyncLibrarySelection', 'RepairLibrarySelection', 'AddLibrarySelection', 'RemoveLibrarySelection'): self.library_thread.select_libraries(method) elif method == 'SyncLibrary': if not data.get('Id'): return self.library_thread.add_library(data['Id'], data.get('Update', False)) xbmc.executebuiltin("Container.Refresh") elif method == 'RepairLibrary': if not data.get('Id'): return libraries = data['Id'].split(',') for lib in libraries: if not self.library_thread.remove_library(lib): return self.library_thread.add_library(data['Id']) xbmc.executebuiltin("Container.Refresh") elif method == 'RemoveLibrary': libraries = data['Id'].split(',') for lib in libraries: if not self.library_thread.remove_library(lib): return xbmc.executebuiltin("Container.Refresh") elif method == 'System.OnSleep': LOG.info("-->[ sleep ]") window('emby_should_stop.bool', True) if self.library_thread is not None: self.library_thread.stop_client() self.library_thread = None Emby.close_all() self.monitor.server = [] self.monitor.sleep = True elif method == 'System.OnWake': if not self.monitor.sleep: LOG.warn("System.OnSleep was never called, skip System.OnWake") return LOG.info("--<[ sleep ]") xbmc.sleep(10000) # Allow network to wake up self.monitor.sleep = False window('emby_should_stop', clear=True) try: self.connect.register() except Exception as error: LOG.error(error) elif method == 'GUI.OnScreensaverDeactivated': LOG.info("--<[ screensaver ]") xbmc.sleep(5000) if self.library_thread is not None: self.library_thread.fast_sync() elif method == 'UserConfigurationUpdated': if data.get('ServerId') is None: Views().get_views() elif method == 'CheckUpdate': if not self.patch.check_update(True): dialog("notification", heading="{emby}", message=_(21341), icon="{emby}", sound=False) else: dialog("notification", heading="{emby}", message=_(33181), icon="{emby}", sound=False) window('emby.restart.bool', True) elif method == 'PatchMusic': self.library_thread.run_library_task( method, data.get('Notification', True))