def serviceMethod(name, **params): actionId = __registered_services__[name] data = {'data': AddonUtils.encodeData(params)} service_response_obj = None try: containerObj = Container(addon_id=__addon_id__) iconimage = AddonUtils.getCompleteFilePath( baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png') XBMCInterfaceUtils.displayNotification( __service_name__ + ' Service', 'Processing received request...', iconimage=iconimage) containerObj.reloadTurtleRequest(data) containerObj.performAction(actionId) service_response_obj = containerObj.getTurtleResponse( ).get_service_response_obj() except Exception, e: print __service_name__ + ' Service :: ERROR OCCURRED: ' + str(e) ExceptionHandler.handle(e) service_response_obj = { "status": "exception", "message": "an unexpected error occurred, please check your input" } XBMCInterfaceUtils.displayNotification( __service_name__ + ' Service', 'Error while processing your request', time='5000')
def start(addon_id, service_name, context_root, default_port, allowed_port_range): try: global __addon_id__ global __registered_services__ global __context_root__ global __port__ global __port_range__ global __service_name__ __addon_id__ = addon_id __context_root__ = context_root __port__ = default_port __port_range__ = allowed_port_range __service_name__ = service_name containerObj = Container(addon_id=addon_id) iconimage = AddonUtils.getCompleteFilePath( baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png') serviceport = int( containerObj.getAddonContext().addon.getSetting('serviceport')) XBMCInterfaceUtils.setSuppressDialogMsg(True) if serviceport < __port_range__[0] or serviceport > __port_range__[1]: containerObj.getAddonContext().addon.setSetting( 'serviceport', str(__port__)) serviceport = __port__ XBMCInterfaceUtils.displayNotification( __service_name__ + ' Service: Port updated', 'Service port set to default value 8181', iconimage=iconimage) server = JSONRPCServer(context_root=__context_root__, server_port=serviceport) server.registerService('serviceName', serviceMethod) defined_services = containerObj.getAddonContext().getTurtleServices() if len(defined_services) == 0: print __service_name__ + ' Service :: There are no services defined for registration, end this service program now.' return for service in defined_services: server.registerService(service.get_service_name(), serviceMethod) __registered_services__[ service.get_service_name()] = service.get_action_id() print __service_name__ + ' Service :: service registered = %s @ %s' % ( service.get_service_name(), __context_root__) server.start() XBMCInterfaceUtils.displayNotification( __service_name__ + ' Service has started', 'Use safari extension to play video remotely', iconimage=iconimage) while not xbmc.abortRequested: time.sleep(5) print __service_name__ + ' Service :: ABORT request received from XBMC. PlayIt service will stop now.' except Exception, e: print __service_name__ + ' Service :: ERROR OCCURRED: ' + str(e) ExceptionHandler.handle(e)
def start(addon_id): try: global __addon_id__ __addon_id__ = addon_id containerObj = Container(addon_id=addon_id) action_id = containerObj.getTurtleRequest().get_action_id() containerObj.performAction(action_id) except Exception, e: ExceptionHandler.handle(e)
def start(addon_id, service_name, context_root, default_port, allowed_port_range): server = None try: sys.argv = None # To handle the situations where some library expects system arguments. Main change made for t0mm0 urlresolver library. global __addon_id__ global __registered_services__ global __context_root__ global __port__ global __port_range__ global __service_name__ __addon_id__ = addon_id __context_root__ = context_root __port__ = default_port __port_range__ = allowed_port_range __service_name__ = service_name containerObj = Container(addon_id=addon_id) iconimage = AddonUtils.getCompleteFilePath(baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png') serviceport = int(containerObj.getAddonContext().addon.getSetting('serviceport')) XBMCInterfaceUtils.setSuppressDialogMsg(True) if serviceport < __port_range__[0] or serviceport > __port_range__[1] : containerObj.getAddonContext().addon.setSetting('serviceport', str(__port__)) serviceport = __port__ XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service: Port updated', 'Service port set to default value 8181', iconimage=iconimage) server = JSONRPCServer(context_root=__context_root__, server_port=serviceport) server.registerService('serviceName', serviceMethod) defined_services = containerObj.getAddonContext().getTurtleServices() if len(defined_services) == 0: Logger.logError(__service_name__ + ' Service :: There are no services defined for registration, end this service program now.') return for service in defined_services: server.registerService(service.get_service_name(), serviceMethod) __registered_services__[service.get_service_name()] = service.get_action_id() Logger.logInfo(__service_name__ + ' Service :: service registered = %s @ %s' % (service.get_service_name(), __context_root__)) server.start() # XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service has started', 'Use web browser PlayIt extension to play video.', iconimage=iconimage) while not xbmc.abortRequested: time.sleep(1) Logger.logInfo(__service_name__ + ' Service :: ABORT request received from XBMC. PlayIt service will stop now.') except Exception, e: Logger.logFatal(__service_name__ + ' Service :: ERROR OCCURRED: ' + str(e)) ExceptionHandler.handle(e)
def serviceMethod(name, **params): actionId = __registered_services__[name] data = {'data':AddonUtils.encodeData(params)} service_response_obj = None try: containerObj = Container(addon_id=__addon_id__) iconimage = AddonUtils.getCompleteFilePath(baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png') XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service', 'Processing received request...', iconimage=iconimage) containerObj.reloadTurtleRequest(data) containerObj.performAction(actionId) service_response_obj = containerObj.getTurtleResponse().get_service_response_obj() except Exception, e: print __service_name__ + ' Service :: ERROR OCCURRED: ' + str(e) ExceptionHandler.handle(e) service_response_obj = {"status":"exception", "message":"an unexpected error occurred, please check your input"} XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service', 'Error while processing your request', time='5000')
def start(addon_id, service_name, context_root, default_port, allowed_port_range): try: global __addon_id__ global __registered_services__ global __context_root__ global __port__ global __port_range__ global __service_name__ __addon_id__ = addon_id __context_root__ = context_root __port__ = default_port __port_range__ = allowed_port_range __service_name__ = service_name containerObj = Container(addon_id=addon_id) iconimage = AddonUtils.getCompleteFilePath(baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png') serviceport = int(containerObj.getAddonContext().addon.getSetting('serviceport')) XBMCInterfaceUtils.setSuppressDialogMsg(True) if serviceport < __port_range__[0] or serviceport > __port_range__[1] : containerObj.getAddonContext().addon.setSetting('serviceport', str(__port__)) serviceport = __port__ XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service: Port updated', 'Service port set to default value 8181', iconimage=iconimage) server = JSONRPCServer(context_root=__context_root__, server_port=serviceport) server.registerService('serviceName', serviceMethod) defined_services = containerObj.getAddonContext().getTurtleServices() if len(defined_services) == 0: print __service_name__ + ' Service :: There are no services defined for registration, end this service program now.' return for service in defined_services: server.registerService(service.get_service_name(), serviceMethod) __registered_services__[service.get_service_name()] = service.get_action_id() print __service_name__ + ' Service :: service registered = %s @ %s' % (service.get_service_name(), __context_root__) server.start() XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service has started', 'Use safari extension to play video remotely', iconimage=iconimage) while not xbmc.abortRequested: time.sleep(5) print __service_name__ + ' Service :: ABORT request received from XBMC. PlayIt service will stop now.' except Exception, e: print __service_name__ + ' Service :: ERROR OCCURRED: ' + str(e) ExceptionHandler.handle(e)
def start(addon_id, addon_ver=None): try: Logger.logDebug(sys.argv) global __addon_id__ __addon_id__ = addon_id __addon_ver__ = addon_ver containerObj = Container(addon_id=addon_id, addon_ver=addon_ver) action_id = containerObj.getTurtleRequest().get_action_id() containerObj.performAction(action_id) except urllib2.URLError, e: Logger.logFatal(e) XBMCInterfaceUtils.displayDialogMessage('Unable to connect', 'Please choose a different source if available in add-on.', 'Website used in add-on is down, try to access using web browser.', 'Please share logs with developer if problem keeps coming!') except Exception, e: Logger.logFatal(e) ExceptionHandler.handle(e) cleanUp() xbmcplugin.endOfDirectory(int(sys.argv[1])) def cleanUp(): try: containerObj = Container() containerObj.cleanUp() del containerObj httpClient = HttpUtils.HttpClient() httpClient.cleanUp() del httpClient except: pass
__addon_id__ = addon_id __addon_ver__ = addon_ver containerObj = Container(addon_id=addon_id, addon_ver=addon_ver) action_id = containerObj.getTurtleRequest().get_action_id() containerObj.performAction(action_id) except urllib2.URLError, e: Logger.logFatal(e) XBMCInterfaceUtils.displayDialogMessage( 'Unable to connect', 'Please choose a different source if available in add-on.', 'Website used in add-on is down, try to access using web browser.', 'Please share logs with developer if problem keeps coming!') except Exception, e: Logger.logFatal(e) ExceptionHandler.handle(e) cleanUp() xbmcplugin.endOfDirectory(int(sys.argv[1])) def cleanUp(): try: containerObj = Container() containerObj.cleanUp() del containerObj httpClient = HttpUtils.HttpClient() httpClient.cleanUp() del httpClient except: pass