Skip to content

Commit 52c2cd9

Browse files
committed
Handle different testing setups via cmdline arguments
1 parent e4c2cc1 commit 52c2cd9

File tree

3 files changed

+69
-22
lines changed

3 files changed

+69
-22
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ __pycache__
77
.idea/
88
venv/
99

10-
appconfig.json
10+
appconfig*

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# XCloud, XHome and SmartGlass
2+
3+
## Preparation
4+
5+
As usual, create a python venv
6+
7+
```sh
8+
python -m venv venv
9+
source venv/bin/activate
10+
```
11+
12+
And install the dependencies
13+
```sh
14+
pip install -r requirements.txt
15+
```
16+
17+
## Usage
18+
19+
You can invoke 3 different parts of the script
20+
21+
```
22+
python -m main smartglass
23+
python -m main xhome
24+
python -m main xcloud
25+
```

main.py

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import sys
23
import uuid
34
import time
45
import asyncio
@@ -14,8 +15,8 @@
1415
from xcloud_api import XCloudApi
1516
from 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

2021
def 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

155168
if __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

Comments
 (0)