#NEWLINE# def start( self ) : #NEWLINE# #INDENT# logging . info ( 'Starting LEAP server' ) #NEWLINE# routes = [ ( '/ssdp/device-desc.xml' , DeviceHandler ) , ( '/setup/([^\\/]+)' , SetupHandler ) , ( '/apps' , DeviceHandler ) , ( '/connection' , ServiceChannel ) , ( '/connection/([^\\/]+)' , ChannelFactory ) , ( '/receiver/([^\\/]+)' , ReceiverChannel ) , ( '/session/([^\\/]+)' , ApplicationChannel ) , ( '/system/control' , CastPlatform ) ] #NEWLINE# logging . info ( 'Loading Config-JSON from Google-Server' ) #NEWLINE# app_dict_url = 'https://clients3.google.com/cast/chromecast/device/config' #NEWLINE# resp = requests . get ( url = app_dict_url ) #NEWLINE# logging . info ( 'Parsing Config-JSON' ) #NEWLINE# data = json . loads ( resp . content . replace ( ")]}'" , '' ) ) #NEWLINE# added_apps = [ ] #NEWLINE# if Environment . apps : #NEWLINE# #INDENT# logging . info ( ( 'Reading app file: %s' % Environment . apps ) ) #NEWLINE# try : #NEWLINE# #INDENT# f = open ( Environment . apps ) #NEWLINE# tmp = json . load ( f ) #NEWLINE# f . close ( ) #NEWLINE# for key in tmp : #NEWLINE# #INDENT# if ( key == 'applications' ) : #NEWLINE# #INDENT# data [ key ] += tmp [ key ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data [ key ] = tmp [ key ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logging . error ( ( "Couldn't read app file: %s" % e ) ) #NEWLINE# #UNINDENT# #UNINDENT# for app in data [ 'applications' ] : #NEWLINE# #INDENT# name = app [ 'app_name' ] #NEWLINE# name = name . encode ( 'utf-8' ) #NEWLINE# if ( 'url' not in app ) : #NEWLINE# #INDENT# logging . warn ( ( "Didn't add %s because it has no URL!" % name ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# logging . info ( ( 'Added %s app' % name ) ) #NEWLINE# url = app [ 'url' ] #NEWLINE# url = url . replace ( '${{URL_ENCODED_POST_DATA}}' , '{{ query }}' ) . replace ( '${POST_DATA}' , '{{ query }}' ) #NEWLINE# clazz = type ( name , ( LEAPfactory , ) , { #NEWLINE# #INDENT# 'url' : url , #NEWLINE# #UNINDENT# } ) #NEWLINE# routes . append ( ( ( ( ( ( '(/apps/' + name ) + '|/apps/' ) + name ) + '.*)' ) , clazz ) ) #NEWLINE# added_apps . append ( name ) #NEWLINE# #UNINDENT# for app in LEAPfactory . get_subclasses ( ) : #NEWLINE# #INDENT# name = app . __name__ #NEWLINE# if ( name in added_apps ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# logging . info ( ( 'Added %s app' % name ) ) #NEWLINE# routes . append ( ( ( ( ( ( '(/apps/' + name ) + '|/apps/' ) + name ) + '.*)' ) , app ) ) #NEWLINE# #UNINDENT# self . application = tornado . web . Application ( routes ) #NEWLINE# self . application . listen ( 8008 ) #NEWLINE# tornado . ioloop . IOLoop . instance ( ) . start ( )