e3ds-app-uploader 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of e3ds-app-uploader might be problematic. Click here for more details.
- e3ds_app_uploader-0.1.0/LICENSE +21 -0
- e3ds_app_uploader-0.1.0/PKG-INFO +131 -0
- e3ds_app_uploader-0.1.0/README.md +106 -0
- e3ds_app_uploader-0.1.0/pyproject.toml +44 -0
- e3ds_app_uploader-0.1.0/setup.cfg +4 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader/__init__.py +23 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader/__main__.py +5 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader/_version.py +1 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader/api.py +202 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader/cli.py +110 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader/errors.py +28 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader/progress.py +95 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader/transfer.py +197 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader/uploader.py +278 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader.egg-info/PKG-INFO +131 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader.egg-info/SOURCES.txt +19 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader.egg-info/dependency_links.txt +1 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader.egg-info/entry_points.txt +2 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader.egg-info/requires.txt +6 -0
- e3ds_app_uploader-0.1.0/src/e3ds_app_uploader.egg-info/top_level.txt +1 -0
- e3ds_app_uploader-0.1.0/tests/test_uploader.py +203 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eagle 3D Streaming
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: e3ds-app-uploader
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Upload Unreal Engine app builds (zip) to Eagle 3D Streaming and track upload and stream-test progress.
|
|
5
|
+
Author: Eagle 3D Streaming
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/e3ds/e3ds-app-uploader
|
|
8
|
+
Project-URL: Issues, https://github.com/e3ds/e3ds-app-uploader/issues
|
|
9
|
+
Keywords: eagle3dstreaming,e3ds,pixel streaming,unreal engine,upload
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Requires-Python: >=3.8
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: requests>=2.25
|
|
20
|
+
Requires-Dist: tqdm>=4.60
|
|
21
|
+
Provides-Extra: test
|
|
22
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
23
|
+
Requires-Dist: responses>=0.23; extra == "test"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# e3ds-app-uploader
|
|
27
|
+
|
|
28
|
+
Upload an Unreal Engine app build (a zip) to [Eagle 3D Streaming](https://eagle3dstreaming.com)
|
|
29
|
+
and follow it until it is ready to stream. You get byte-level upload progress and a stage
|
|
30
|
+
event for each step: upload, stream test, and shared-drive sync.
|
|
31
|
+
|
|
32
|
+
It is a Python port of the upload step in the E3DS Unreal automation tool. It covers only
|
|
33
|
+
the part after the zip exists. It does not build or package the project.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install e3ds-app-uploader
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Requires Python 3.8+.
|
|
40
|
+
|
|
41
|
+
## Command line
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
export E3DS_API_KEY="..." # or pass --api-key
|
|
45
|
+
e3ds-upload MyApp.zip --app my_app # streaming app
|
|
46
|
+
e3ds-upload MyServer.zip --app my_server --type dedicatedserver
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
| Option | Meaning |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `--type streamingapp\|dedicatedserver` | App type (default `streamingapp`) |
|
|
52
|
+
| `--concurrency N` | R2 parts uploaded at once (default 4) |
|
|
53
|
+
| `--attempts N` | Whole-upload attempts before giving up (default 3) |
|
|
54
|
+
| `--no-wait` | Don't wait for the stream test to finish |
|
|
55
|
+
| `--timeout S` | Seconds to wait for the stream test (default 600) |
|
|
56
|
+
| `--open` | Open the streaming URL in a browser when the app is ready |
|
|
57
|
+
| `--json` | Print the result as JSON on stdout |
|
|
58
|
+
| `-q` | No progress bar or stage messages |
|
|
59
|
+
|
|
60
|
+
Exit codes: `0` ready, `1` error, `2` not enough storage space, `3` uploaded but the
|
|
61
|
+
stream test did not finish in time.
|
|
62
|
+
|
|
63
|
+
## Python
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from e3ds_app_uploader import AppUploader
|
|
67
|
+
|
|
68
|
+
def on_progress(p):
|
|
69
|
+
print(f"{p.percent:5.1f}% {p.bytes_sent}/{p.total_bytes} {p.speed/1e6:.1f} MB/s eta {p.eta}")
|
|
70
|
+
|
|
71
|
+
def on_event(e):
|
|
72
|
+
print(e.stage, e.message)
|
|
73
|
+
|
|
74
|
+
uploader = AppUploader(api_key, on_progress=on_progress, on_event=on_event)
|
|
75
|
+
result = uploader.upload("MyApp.zip", "my_app", app_type="streamingapp")
|
|
76
|
+
|
|
77
|
+
print(result.version, result.stream_test_status, result.streaming_url)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Or use the one-call helper, `upload_build(api_key, "MyApp.zip", "my_app")`.
|
|
81
|
+
|
|
82
|
+
`on_progress` receives a `ProgressInfo` with `bytes_sent`, `total_bytes`, `percent`,
|
|
83
|
+
`speed` (bytes/s), `elapsed` and `eta` (seconds). It is called from upload threads, at most
|
|
84
|
+
about every 0.2 s.
|
|
85
|
+
|
|
86
|
+
`on_event` receives an `Event(stage, message, data)`. The stages are:
|
|
87
|
+
|
|
88
|
+
| Stage | When |
|
|
89
|
+
| --- | --- |
|
|
90
|
+
| `upload_started` | Storage key known (`data["key"]`; for R2 also `total_parts`) |
|
|
91
|
+
| `part_done` | An R2 part finished (`part`, `total_parts`) |
|
|
92
|
+
| `upload_retry` | The whole upload failed and will start again |
|
|
93
|
+
| `upload_done` | All bytes stored (`key`, `version`, `seconds`) |
|
|
94
|
+
| `stream_test_queued` / `stream_test_retry` | Stream test queued, or queueing is being retried |
|
|
95
|
+
| `stream_test_waiting` | Stream test result not available yet |
|
|
96
|
+
| `stream_test_stage` | Stream test moved to a new stage (`stage_number`, `status`) |
|
|
97
|
+
| `stream_test_passed` | App is tested and ready to stream |
|
|
98
|
+
| `stream_test_timeout` | Stopped waiting (`stream_test_timeout` seconds) |
|
|
99
|
+
| `shared_drive_synced` | Verified app or dedicated server: shared drive told to sync |
|
|
100
|
+
| `done` | Finished (`data["result"]`) |
|
|
101
|
+
|
|
102
|
+
`UploadResult.stream_test_status` is `passed`, `timeout`, `not_waited`, or `skipped` (no
|
|
103
|
+
stream test needed).
|
|
104
|
+
|
|
105
|
+
Errors are all subclasses of `E3DSError`: `InsufficientSpaceError`, `UploadError`,
|
|
106
|
+
`StreamTestError`, `ApiError`.
|
|
107
|
+
|
|
108
|
+
## How the upload works
|
|
109
|
+
|
|
110
|
+
1. Start an R2 multipart upload (`/api/v3/us/r2-initiate-upload`). E3DS returns the storage
|
|
111
|
+
key, upload ID, part size and part count.
|
|
112
|
+
2. Get presigned part URLs (`/api/v3/us/r2-batch-part-urls`). PUT the parts in parallel,
|
|
113
|
+
collecting ETags, then complete it (`/api/v3/us/r2-complete-upload`). Failed parts are
|
|
114
|
+
retried, and an expired part URL (HTTP 403) is refreshed.
|
|
115
|
+
3. The stored name gives the version. `owner/app/uv-3.zip` means version `3`, unverified.
|
|
116
|
+
4. **Unverified streaming app:** queue a stream test (`/api/v3/st/stream-test`), then poll
|
|
117
|
+
`/api/v3/fb/get-streamtest-result` until `uploadSystemFile.isRenamed` is true.
|
|
118
|
+
**Verified app or dedicated server:** ask the shared drive to sync (`/api/v3/sd/download-ext`).
|
|
119
|
+
5. Look up the app's streaming URL (`/api/v3/mmlinker/getStreamingURL`).
|
|
120
|
+
|
|
121
|
+
All calls go to `https://agw.eagle3dstreaming.com`, apart from the presigned R2 part URLs it hands out.
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
pip install -e ".[test]"
|
|
127
|
+
pytest
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Releases go to PyPI from GitHub Actions when a `v*` tag is pushed. To release, bump
|
|
131
|
+
`src/e3ds_app_uploader/_version.py`, then `git tag v0.1.1 && git push --tags`.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# e3ds-app-uploader
|
|
2
|
+
|
|
3
|
+
Upload an Unreal Engine app build (a zip) to [Eagle 3D Streaming](https://eagle3dstreaming.com)
|
|
4
|
+
and follow it until it is ready to stream. You get byte-level upload progress and a stage
|
|
5
|
+
event for each step: upload, stream test, and shared-drive sync.
|
|
6
|
+
|
|
7
|
+
It is a Python port of the upload step in the E3DS Unreal automation tool. It covers only
|
|
8
|
+
the part after the zip exists. It does not build or package the project.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install e3ds-app-uploader
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requires Python 3.8+.
|
|
15
|
+
|
|
16
|
+
## Command line
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
export E3DS_API_KEY="..." # or pass --api-key
|
|
20
|
+
e3ds-upload MyApp.zip --app my_app # streaming app
|
|
21
|
+
e3ds-upload MyServer.zip --app my_server --type dedicatedserver
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| Option | Meaning |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| `--type streamingapp\|dedicatedserver` | App type (default `streamingapp`) |
|
|
27
|
+
| `--concurrency N` | R2 parts uploaded at once (default 4) |
|
|
28
|
+
| `--attempts N` | Whole-upload attempts before giving up (default 3) |
|
|
29
|
+
| `--no-wait` | Don't wait for the stream test to finish |
|
|
30
|
+
| `--timeout S` | Seconds to wait for the stream test (default 600) |
|
|
31
|
+
| `--open` | Open the streaming URL in a browser when the app is ready |
|
|
32
|
+
| `--json` | Print the result as JSON on stdout |
|
|
33
|
+
| `-q` | No progress bar or stage messages |
|
|
34
|
+
|
|
35
|
+
Exit codes: `0` ready, `1` error, `2` not enough storage space, `3` uploaded but the
|
|
36
|
+
stream test did not finish in time.
|
|
37
|
+
|
|
38
|
+
## Python
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from e3ds_app_uploader import AppUploader
|
|
42
|
+
|
|
43
|
+
def on_progress(p):
|
|
44
|
+
print(f"{p.percent:5.1f}% {p.bytes_sent}/{p.total_bytes} {p.speed/1e6:.1f} MB/s eta {p.eta}")
|
|
45
|
+
|
|
46
|
+
def on_event(e):
|
|
47
|
+
print(e.stage, e.message)
|
|
48
|
+
|
|
49
|
+
uploader = AppUploader(api_key, on_progress=on_progress, on_event=on_event)
|
|
50
|
+
result = uploader.upload("MyApp.zip", "my_app", app_type="streamingapp")
|
|
51
|
+
|
|
52
|
+
print(result.version, result.stream_test_status, result.streaming_url)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or use the one-call helper, `upload_build(api_key, "MyApp.zip", "my_app")`.
|
|
56
|
+
|
|
57
|
+
`on_progress` receives a `ProgressInfo` with `bytes_sent`, `total_bytes`, `percent`,
|
|
58
|
+
`speed` (bytes/s), `elapsed` and `eta` (seconds). It is called from upload threads, at most
|
|
59
|
+
about every 0.2 s.
|
|
60
|
+
|
|
61
|
+
`on_event` receives an `Event(stage, message, data)`. The stages are:
|
|
62
|
+
|
|
63
|
+
| Stage | When |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `upload_started` | Storage key known (`data["key"]`; for R2 also `total_parts`) |
|
|
66
|
+
| `part_done` | An R2 part finished (`part`, `total_parts`) |
|
|
67
|
+
| `upload_retry` | The whole upload failed and will start again |
|
|
68
|
+
| `upload_done` | All bytes stored (`key`, `version`, `seconds`) |
|
|
69
|
+
| `stream_test_queued` / `stream_test_retry` | Stream test queued, or queueing is being retried |
|
|
70
|
+
| `stream_test_waiting` | Stream test result not available yet |
|
|
71
|
+
| `stream_test_stage` | Stream test moved to a new stage (`stage_number`, `status`) |
|
|
72
|
+
| `stream_test_passed` | App is tested and ready to stream |
|
|
73
|
+
| `stream_test_timeout` | Stopped waiting (`stream_test_timeout` seconds) |
|
|
74
|
+
| `shared_drive_synced` | Verified app or dedicated server: shared drive told to sync |
|
|
75
|
+
| `done` | Finished (`data["result"]`) |
|
|
76
|
+
|
|
77
|
+
`UploadResult.stream_test_status` is `passed`, `timeout`, `not_waited`, or `skipped` (no
|
|
78
|
+
stream test needed).
|
|
79
|
+
|
|
80
|
+
Errors are all subclasses of `E3DSError`: `InsufficientSpaceError`, `UploadError`,
|
|
81
|
+
`StreamTestError`, `ApiError`.
|
|
82
|
+
|
|
83
|
+
## How the upload works
|
|
84
|
+
|
|
85
|
+
1. Start an R2 multipart upload (`/api/v3/us/r2-initiate-upload`). E3DS returns the storage
|
|
86
|
+
key, upload ID, part size and part count.
|
|
87
|
+
2. Get presigned part URLs (`/api/v3/us/r2-batch-part-urls`). PUT the parts in parallel,
|
|
88
|
+
collecting ETags, then complete it (`/api/v3/us/r2-complete-upload`). Failed parts are
|
|
89
|
+
retried, and an expired part URL (HTTP 403) is refreshed.
|
|
90
|
+
3. The stored name gives the version. `owner/app/uv-3.zip` means version `3`, unverified.
|
|
91
|
+
4. **Unverified streaming app:** queue a stream test (`/api/v3/st/stream-test`), then poll
|
|
92
|
+
`/api/v3/fb/get-streamtest-result` until `uploadSystemFile.isRenamed` is true.
|
|
93
|
+
**Verified app or dedicated server:** ask the shared drive to sync (`/api/v3/sd/download-ext`).
|
|
94
|
+
5. Look up the app's streaming URL (`/api/v3/mmlinker/getStreamingURL`).
|
|
95
|
+
|
|
96
|
+
All calls go to `https://agw.eagle3dstreaming.com`, apart from the presigned R2 part URLs it hands out.
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install -e ".[test]"
|
|
102
|
+
pytest
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Releases go to PyPI from GitHub Actions when a `v*` tag is pushed. To release, bump
|
|
106
|
+
`src/e3ds_app_uploader/_version.py`, then `git tag v0.1.1 && git push --tags`.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "e3ds-app-uploader"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Upload Unreal Engine app builds (zip) to Eagle 3D Streaming and track upload and stream-test progress."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Eagle 3D Streaming" }]
|
|
13
|
+
keywords = ["eagle3dstreaming", "e3ds", "pixel streaming", "unreal engine", "upload"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Environment :: Console",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"requests>=2.25",
|
|
24
|
+
"tqdm>=4.60",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
test = ["pytest>=7", "responses>=0.23"]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/e3ds/e3ds-app-uploader"
|
|
32
|
+
Issues = "https://github.com/e3ds/e3ds-app-uploader/issues"
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
e3ds-upload = "e3ds_app_uploader.cli:main"
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.dynamic]
|
|
38
|
+
version = { attr = "e3ds_app_uploader._version.__version__" }
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.packages.find]
|
|
41
|
+
where = ["src"]
|
|
42
|
+
|
|
43
|
+
[tool.pytest.ini_options]
|
|
44
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Upload app build zips to Eagle 3D Streaming and track their progress."""
|
|
2
|
+
|
|
3
|
+
from ._version import __version__
|
|
4
|
+
from .api import E3DSClient
|
|
5
|
+
from .errors import ApiError, E3DSError, InsufficientSpaceError, StreamTestError, UploadError
|
|
6
|
+
from .progress import ProgressInfo
|
|
7
|
+
from .uploader import AppUploader, Event, UploadResult, parse_storage_key, upload_build
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"__version__",
|
|
11
|
+
"AppUploader",
|
|
12
|
+
"upload_build",
|
|
13
|
+
"UploadResult",
|
|
14
|
+
"Event",
|
|
15
|
+
"ProgressInfo",
|
|
16
|
+
"E3DSClient",
|
|
17
|
+
"parse_storage_key",
|
|
18
|
+
"E3DSError",
|
|
19
|
+
"ApiError",
|
|
20
|
+
"InsufficientSpaceError",
|
|
21
|
+
"UploadError",
|
|
22
|
+
"StreamTestError",
|
|
23
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""Thin client for the Eagle 3D Streaming endpoints used by the upload flow.
|
|
2
|
+
|
|
3
|
+
Each method maps to one HTTP endpoint and returns the useful part of the
|
|
4
|
+
response body. Transient failures (connection errors, timeouts, 429 and 5xx)
|
|
5
|
+
are retried with exponential backoff; other HTTP errors raise :class:`ApiError`.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import time
|
|
9
|
+
from typing import Any, Dict, List, Optional
|
|
10
|
+
|
|
11
|
+
import requests
|
|
12
|
+
|
|
13
|
+
from ._version import __version__
|
|
14
|
+
from .errors import ApiError, InsufficientSpaceError
|
|
15
|
+
|
|
16
|
+
DEFAULT_API_BASE = "https://agw.eagle3dstreaming.com"
|
|
17
|
+
|
|
18
|
+
APP_TYPES = ("streamingapp", "dedicatedserver")
|
|
19
|
+
|
|
20
|
+
_RETRY_STATUS = {429, 500, 502, 503, 504}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _dig(body: Any, *keys: str) -> Any:
|
|
24
|
+
"""Return body[k1][k2]... or None if any level is missing."""
|
|
25
|
+
cur = body
|
|
26
|
+
for key in keys:
|
|
27
|
+
if not isinstance(cur, dict) or key not in cur:
|
|
28
|
+
return None
|
|
29
|
+
cur = cur[key]
|
|
30
|
+
return cur
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class E3DSClient:
|
|
34
|
+
"""HTTP client for the E3DS (agw) upload, stream-test and shared-drive APIs."""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
api_key: str,
|
|
39
|
+
api_base: str = DEFAULT_API_BASE,
|
|
40
|
+
session: Optional[requests.Session] = None,
|
|
41
|
+
timeout: float = 60.0,
|
|
42
|
+
retries: int = 3,
|
|
43
|
+
backoff: float = 2.0,
|
|
44
|
+
):
|
|
45
|
+
if not api_key:
|
|
46
|
+
raise ValueError("api_key is required")
|
|
47
|
+
self.api_key = api_key
|
|
48
|
+
self.api_base = api_base.rstrip("/")
|
|
49
|
+
self.session = session or requests.Session()
|
|
50
|
+
self.session.headers.setdefault("User-Agent", "e3ds-app-uploader/" + __version__)
|
|
51
|
+
self.timeout = timeout
|
|
52
|
+
self.retries = retries
|
|
53
|
+
self.backoff = backoff
|
|
54
|
+
|
|
55
|
+
# ------------------------------------------------------------------ core
|
|
56
|
+
|
|
57
|
+
def _request(
|
|
58
|
+
self,
|
|
59
|
+
method: str,
|
|
60
|
+
url: str,
|
|
61
|
+
json: Optional[Dict[str, Any]] = None,
|
|
62
|
+
auth_header: bool = True,
|
|
63
|
+
retries: Optional[int] = None,
|
|
64
|
+
ok_statuses: tuple = (),
|
|
65
|
+
) -> requests.Response:
|
|
66
|
+
url = self.api_base + url
|
|
67
|
+
headers = {"apiKey": self.api_key} if auth_header else {}
|
|
68
|
+
attempts = (self.retries if retries is None else retries) + 1
|
|
69
|
+
last_exc = None # type: Optional[Exception]
|
|
70
|
+
for attempt in range(attempts):
|
|
71
|
+
try:
|
|
72
|
+
resp = self.session.request(
|
|
73
|
+
method, url, json=json, headers=headers, timeout=self.timeout
|
|
74
|
+
)
|
|
75
|
+
except (requests.ConnectionError, requests.Timeout) as exc:
|
|
76
|
+
last_exc = exc
|
|
77
|
+
else:
|
|
78
|
+
if resp.status_code < 400 or resp.status_code in ok_statuses:
|
|
79
|
+
return resp
|
|
80
|
+
if resp.status_code not in _RETRY_STATUS:
|
|
81
|
+
raise ApiError(
|
|
82
|
+
"%s %s failed with HTTP %d: %s"
|
|
83
|
+
% (method, url, resp.status_code, resp.text[:500]),
|
|
84
|
+
status_code=resp.status_code,
|
|
85
|
+
body=_safe_json(resp),
|
|
86
|
+
)
|
|
87
|
+
last_exc = ApiError(
|
|
88
|
+
"%s %s failed with HTTP %d" % (method, url, resp.status_code),
|
|
89
|
+
status_code=resp.status_code,
|
|
90
|
+
body=_safe_json(resp),
|
|
91
|
+
)
|
|
92
|
+
if attempt + 1 < attempts:
|
|
93
|
+
time.sleep(self.backoff * (2 ** attempt))
|
|
94
|
+
if isinstance(last_exc, ApiError):
|
|
95
|
+
raise last_exc
|
|
96
|
+
raise ApiError("%s %s failed: %s" % (method, url, last_exc))
|
|
97
|
+
|
|
98
|
+
def _json(self, method: str, url: str, **kwargs: Any) -> Any:
|
|
99
|
+
resp = self._request(method, url, **kwargs)
|
|
100
|
+
body = _safe_json(resp)
|
|
101
|
+
if body is None:
|
|
102
|
+
raise ApiError("%s %s returned a non-JSON body" % (method, url), resp.status_code)
|
|
103
|
+
return body
|
|
104
|
+
|
|
105
|
+
# ---------------------------------------------------------------------- r2
|
|
106
|
+
|
|
107
|
+
def r2_initiate_upload(self, app_name: str, file_size: int) -> Dict[str, Any]:
|
|
108
|
+
"""``POST /api/v3/us/r2-initiate-upload``.
|
|
109
|
+
|
|
110
|
+
Returns ``{"uploadId", "key", "chunkSize", "totalParts"}``.
|
|
111
|
+
"""
|
|
112
|
+
body = self._json(
|
|
113
|
+
"POST",
|
|
114
|
+
"/api/v3/us/r2-initiate-upload",
|
|
115
|
+
json={"childFolder": app_name, "fileSize": file_size},
|
|
116
|
+
)
|
|
117
|
+
data = _dig(body, "data", "data")
|
|
118
|
+
if not isinstance(data, dict) or not all(k in data for k in ("uploadId", "key", "chunkSize", "totalParts")):
|
|
119
|
+
message = _dig(body, "data", "message") or _dig(body, "message") or body
|
|
120
|
+
if isinstance(message, str) and message.startswith("File size exceeded the available space"):
|
|
121
|
+
raise InsufficientSpaceError(message, body=body)
|
|
122
|
+
raise ApiError("Could not start the R2 upload: %s" % (message,), body=body)
|
|
123
|
+
return data
|
|
124
|
+
|
|
125
|
+
def r2_part_urls(self, key: str, upload_id: str, part_numbers: List[int]) -> Dict[int, str]:
|
|
126
|
+
"""``POST /api/v3/us/r2-batch-part-urls``. Returns ``{partNumber: url}``."""
|
|
127
|
+
body = self._json(
|
|
128
|
+
"POST",
|
|
129
|
+
"/api/v3/us/r2-batch-part-urls",
|
|
130
|
+
json={"key": key, "uploadId": upload_id, "partNumbers": part_numbers},
|
|
131
|
+
)
|
|
132
|
+
urls = _dig(body, "data", "data", "urls")
|
|
133
|
+
if not isinstance(urls, list):
|
|
134
|
+
raise ApiError("Could not get R2 part URLs: %s" % (body,), body=body)
|
|
135
|
+
return {int(item["partNumber"]): item["url"] for item in urls}
|
|
136
|
+
|
|
137
|
+
def r2_complete_upload(self, key: str, upload_id: str, parts: List[Dict[str, Any]]) -> Any:
|
|
138
|
+
"""``POST /api/v3/us/r2-complete-upload`` with ``[{PartNumber, ETag}]``."""
|
|
139
|
+
return self._json(
|
|
140
|
+
"POST",
|
|
141
|
+
"/api/v3/us/r2-complete-upload",
|
|
142
|
+
json={"key": key, "uploadId": upload_id, "parts": parts},
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
# ------------------------------------------------------------- after upload
|
|
146
|
+
|
|
147
|
+
def queue_stream_test(self, app_name: str, test_version: str) -> Any:
|
|
148
|
+
"""``POST /api/v3/st/stream-test``. Returns the response body."""
|
|
149
|
+
return self._json(
|
|
150
|
+
"POST",
|
|
151
|
+
"/api/v3/st/stream-test",
|
|
152
|
+
json={"apiKey": self.api_key, "appname": app_name, "version": test_version, "isUnverified": "true"},
|
|
153
|
+
auth_header=False,
|
|
154
|
+
retries=0,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
def get_stream_test_result(self, stream_test_version: str) -> Optional[Dict[str, Any]]:
|
|
158
|
+
"""``POST /api/v3/fb/get-streamtest-result``.
|
|
159
|
+
|
|
160
|
+
Returns the ``data`` object, or None while the result does not exist yet (HTTP 404).
|
|
161
|
+
"""
|
|
162
|
+
resp = self._request(
|
|
163
|
+
"POST",
|
|
164
|
+
"/api/v3/fb/get-streamtest-result",
|
|
165
|
+
json={"version": stream_test_version},
|
|
166
|
+
retries=0,
|
|
167
|
+
ok_statuses=(404,),
|
|
168
|
+
)
|
|
169
|
+
if resp.status_code == 404:
|
|
170
|
+
return None
|
|
171
|
+
data = _dig(_safe_json(resp), "data")
|
|
172
|
+
return data if isinstance(data, dict) else None
|
|
173
|
+
|
|
174
|
+
def shared_drive_sync(self, app_name: str, app_type: str, version: str = "latest") -> Any:
|
|
175
|
+
"""``POST /api/v3/sd/download-ext``: tell the shared drive to pull the new version."""
|
|
176
|
+
sd_type = "streamingApp" if app_type == "streamingapp" else "DS"
|
|
177
|
+
return self._json(
|
|
178
|
+
"POST",
|
|
179
|
+
"/api/v3/sd/download-ext",
|
|
180
|
+
json={"appName": app_name, "version": version, "appType": sd_type, "apiKey": self.api_key},
|
|
181
|
+
auth_header=False,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
def get_streaming_url(self, app_name: str, domain: Optional[str] = None,
|
|
185
|
+
version: Optional[str] = None, config_name: Optional[str] = None) -> Optional[str]:
|
|
186
|
+
"""``POST /api/v3/mmlinker/getStreamingURL``. Returns the app's streaming URL."""
|
|
187
|
+
payload = {"appName": app_name, "apiKey": self.api_key} # type: Dict[str, Any]
|
|
188
|
+
if domain:
|
|
189
|
+
payload["domain"] = domain
|
|
190
|
+
if version:
|
|
191
|
+
payload["version"] = version
|
|
192
|
+
if config_name:
|
|
193
|
+
payload["configName"] = config_name
|
|
194
|
+
body = self._json("POST", "/api/v3/mmlinker/getStreamingURL", json=payload)
|
|
195
|
+
return _dig(body, "data", "streamingURL") or None
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _safe_json(resp: requests.Response) -> Any:
|
|
199
|
+
try:
|
|
200
|
+
return resp.json()
|
|
201
|
+
except ValueError:
|
|
202
|
+
return None
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""``e3ds-upload``: upload a build zip from the command line."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
import webbrowser
|
|
8
|
+
from typing import List, Optional
|
|
9
|
+
|
|
10
|
+
from tqdm import tqdm
|
|
11
|
+
|
|
12
|
+
from ._version import __version__
|
|
13
|
+
from .errors import E3DSError, InsufficientSpaceError
|
|
14
|
+
from .progress import ProgressInfo
|
|
15
|
+
from .uploader import AppUploader, Event
|
|
16
|
+
|
|
17
|
+
EXIT_OK = 0
|
|
18
|
+
EXIT_ERROR = 1
|
|
19
|
+
EXIT_NO_SPACE = 2
|
|
20
|
+
EXIT_STREAM_TEST_TIMEOUT = 3
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _parser() -> argparse.ArgumentParser:
|
|
24
|
+
p = argparse.ArgumentParser(
|
|
25
|
+
prog="e3ds-upload",
|
|
26
|
+
description="Upload an app build zip to Eagle 3D Streaming and track it until it is ready.",
|
|
27
|
+
)
|
|
28
|
+
p.add_argument("file", help="path to the build zip")
|
|
29
|
+
p.add_argument("--app", required=True, help="E3DS app name")
|
|
30
|
+
p.add_argument("--type", dest="app_type", default="streamingapp",
|
|
31
|
+
choices=["streamingapp", "dedicatedserver"], help="app type (default: streamingapp)")
|
|
32
|
+
p.add_argument("--api-key", default=os.environ.get("E3DS_API_KEY"),
|
|
33
|
+
help="E3DS API key (default: $E3DS_API_KEY)")
|
|
34
|
+
p.add_argument("--concurrency", type=int, default=4, help="R2 parts uploaded at once (default: 4)")
|
|
35
|
+
p.add_argument("--attempts", type=int, default=3, help="whole-upload attempts (default: 3)")
|
|
36
|
+
p.add_argument("--no-wait", action="store_true", help="do not wait for the stream test result")
|
|
37
|
+
p.add_argument("--timeout", type=float, default=600, help="seconds to wait for the stream test (default: 600)")
|
|
38
|
+
p.add_argument("--open", action="store_true", help="open the streaming URL in a browser when ready")
|
|
39
|
+
p.add_argument("--json", action="store_true", help="print the result as JSON on stdout")
|
|
40
|
+
p.add_argument("-q", "--quiet", action="store_true", help="no progress bar or stage messages")
|
|
41
|
+
p.add_argument("--version", action="version", version="%(prog)s " + __version__)
|
|
42
|
+
return p
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main(argv: Optional[List[str]] = None) -> int:
|
|
46
|
+
args = _parser().parse_args(argv)
|
|
47
|
+
if not args.api_key:
|
|
48
|
+
print("error: an API key is required (--api-key or E3DS_API_KEY)", file=sys.stderr)
|
|
49
|
+
return EXIT_ERROR
|
|
50
|
+
|
|
51
|
+
bar = None # type: Optional[tqdm]
|
|
52
|
+
|
|
53
|
+
def on_progress(info: ProgressInfo) -> None:
|
|
54
|
+
nonlocal bar
|
|
55
|
+
if args.quiet:
|
|
56
|
+
return
|
|
57
|
+
if bar is None:
|
|
58
|
+
bar = tqdm(total=info.total_bytes, unit="B", unit_scale=True, unit_divisor=1024,
|
|
59
|
+
desc=args.app, file=sys.stderr, dynamic_ncols=True)
|
|
60
|
+
bar.update(info.bytes_sent - bar.n)
|
|
61
|
+
|
|
62
|
+
def on_event(event: Event) -> None:
|
|
63
|
+
nonlocal bar
|
|
64
|
+
if event.stage in ("upload_done", "upload_retry") and bar is not None:
|
|
65
|
+
bar.close()
|
|
66
|
+
bar = None
|
|
67
|
+
if args.quiet or event.stage == "part_done":
|
|
68
|
+
return
|
|
69
|
+
if bar is not None:
|
|
70
|
+
bar.write("[%s] %s" % (event.stage, event.message), file=sys.stderr)
|
|
71
|
+
else:
|
|
72
|
+
print("[%s] %s" % (event.stage, event.message), file=sys.stderr)
|
|
73
|
+
|
|
74
|
+
uploader = AppUploader(
|
|
75
|
+
args.api_key, on_progress=on_progress, on_event=on_event,
|
|
76
|
+
concurrency=args.concurrency, upload_attempts=args.attempts, stream_test_timeout=args.timeout,
|
|
77
|
+
)
|
|
78
|
+
try:
|
|
79
|
+
result = uploader.upload(
|
|
80
|
+
args.file, args.app, args.app_type,
|
|
81
|
+
wait_for_stream_test=not args.no_wait,
|
|
82
|
+
)
|
|
83
|
+
except InsufficientSpaceError as exc:
|
|
84
|
+
print("error: %s" % exc, file=sys.stderr)
|
|
85
|
+
return EXIT_NO_SPACE
|
|
86
|
+
except (E3DSError, OSError, ValueError) as exc:
|
|
87
|
+
print("error: %s" % exc, file=sys.stderr)
|
|
88
|
+
return EXIT_ERROR
|
|
89
|
+
except KeyboardInterrupt:
|
|
90
|
+
print("\ncancelled", file=sys.stderr)
|
|
91
|
+
return 130
|
|
92
|
+
finally:
|
|
93
|
+
if bar is not None:
|
|
94
|
+
bar.close()
|
|
95
|
+
|
|
96
|
+
if args.json:
|
|
97
|
+
print(json.dumps(result.to_dict(), indent=2))
|
|
98
|
+
elif not args.quiet:
|
|
99
|
+
print("Uploaded %s v%s (%s)" % (result.app_name, result.version, result.stream_test_status), file=sys.stderr)
|
|
100
|
+
if result.streaming_url:
|
|
101
|
+
print("Streaming URL: %s" % result.streaming_url, file=sys.stderr)
|
|
102
|
+
|
|
103
|
+
if args.open and result.streaming_url and result.stream_test_status in ("passed", "skipped"):
|
|
104
|
+
webbrowser.open(result.streaming_url)
|
|
105
|
+
|
|
106
|
+
return EXIT_STREAM_TEST_TIMEOUT if result.stream_test_status == "timeout" else EXIT_OK
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
sys.exit(main())
|