11import io
2+ import sys
23import uuid
34import time
45import asyncio
1415from xcloud_api import XCloudApi
1516from xhomestreaming_api import XHomeStreamingApi
1617
17- APP_CONFIG_FILE = "appconfig.json"
18-
18+ APP_CONFIG_XBOXBETA_FILE = "appconfig.xboxbeta .json"
19+ APP_CONFIG_XBOXGAMEPASS_FILE = "appconfig.xboxgamepass.json"
1920
2021def choose_console (console_list ):
2122 print ('Please choose a console:' )
@@ -94,21 +95,31 @@ async def test_xcloud_streaming(
9495 await xhome_api .session .aclose ()
9596
9697
97- async def main ():
98+ async def main (command : str ):
9899 """
99100 Prepare needed values
100101 """
101102
103+ if command == 'xhome' or command == 'smartglass' :
104+ app_config = APP_CONFIG_XBOXBETA_FILE
105+ xal_params = IOS_XBOXBETA_APP_PARAMS
106+ elif command == 'xcloud' :
107+ app_config = APP_CONFIG_XBOXGAMEPASS_FILE
108+ xal_params = ANDROID_GAMEPASS_BETA_PARAMS
109+ else :
110+ print (':: Unexpected command...' )
111+ return
112+
102113 try :
103- config = AppConfiguration .parse_file (APP_CONFIG_FILE )
114+ config = AppConfiguration .parse_file (app_config )
104115 except Exception as e :
105116 print (f'Failed to parse app configuration! Err: { e } ' )
106117 print ('Initializing new config...' )
107118 config = AppConfiguration (
108119 ClientUUID = uuid .uuid4 (),
109120 SigningKey = RequestSigner ().export_signing_key (),
110121 XalParameters = XalClientParameters .parse_obj (
111- ANDROID_GAMEPASS_BETA_PARAMS # NOTE: XBOXBETA APP -> XHOME, XBOXGAMEPASS BETA -> XCLOUD!
122+ xal_params
112123 )
113124 )
114125
@@ -130,27 +141,38 @@ async def main():
130141 """
131142 Saving app config
132143 """
133- with io .open (APP_CONFIG_FILE , 'wt' ) as f :
144+ with io .open (app_config , 'wt' ) as f :
134145 f .write (config .json (indent = 2 ))
135146
136- """
137- smartglass = SmartglassApi(
138- request_signer,
139- config.Authorization.AuthorizationToken
140- )
147+ if command == 'smartglass' or command == 'xhome' :
148+ smartglass = SmartglassApi (
149+ request_signer ,
150+ config .Authorization .AuthorizationToken
151+ )
141152
142- print(':: Getting console list')
143- console_list = await smartglass.get_console_list()
144- await smartglass.session.aclose()
153+ print (':: Getting console list' )
154+ console_list = await smartglass .get_console_list ()
155+ await smartglass .session .aclose ()
145156
146- console = choose_console(console_list)
147- console_liveid = console.id
148- """
157+ console = choose_console (console_list )
158+ console_liveid = console .id
149159
150- # test_smartglass_api(smartglass, console_liveid)
151- await test_xcloud_streaming (config )
152- # await test_xhome_streaming(config, console_liveid)
160+ if command == 'smartglass' :
161+ await test_smartglass_api (smartglass , console_liveid )
162+ else :
163+ await test_xhome_streaming (config , console_liveid )
164+ elif command == 'xcloud' :
165+ await test_xcloud_streaming (config )
153166
154167
155168if __name__ == '__main__' :
156- asyncio .run (main ())
169+ if len (sys .argv ) < 2 :
170+ print (':: Please provide a command! Choices: smartglass, xhome, xcloud' )
171+ sys .exit (1 )
172+
173+ command = sys .argv [1 ]
174+ if command not in ['smartglass' , 'xhome' , 'xcloud' ]:
175+ print (':: You provided an invalid command!' )
176+ sys .exit (2 )
177+
178+ asyncio .run (main (command ))
0 commit comments