nerdstack-ark 1.0.2__tar.gz → 1.0.3__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.
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/PKG-INFO +22 -1
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/README.md +21 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/pyproject.toml +1 -1
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/src/ark_py/__init__.py +10 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/src/ark_py/async_client.py +101 -1
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/src/ark_py/errors.py +16 -5
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/src/ark_py/models.py +55 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/src/ark_py/sync.py +101 -1
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/tests/test_async.py +30 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/tests/test_sync.py +47 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/.gitignore +0 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/LICENSE +0 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/examples/django/apps.py +0 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/examples/django/views.py +0 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/examples/fastapi/app.py +0 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/examples/flask/app.py +0 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/src/ark_py/_shared.py +0 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/src/ark_py/py.typed +0 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/src/ark_py/s3.py +0 -0
- {nerdstack_ark-1.0.2 → nerdstack_ark-1.0.3}/tests/conftest.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: nerdstack-ark
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Official Python SDK for Ark storage, with sync, async, and S3-compatible access.
|
|
5
5
|
Project-URL: Homepage, https://ark.nerdstackgrp.com
|
|
6
6
|
Project-URL: Documentation, https://github.com/joshhumphrey02/ark-sdk/tree/master/packages/ark-py#readme
|
|
@@ -130,6 +130,27 @@ session = ark.create_client_session(ttl_seconds=900)
|
|
|
130
130
|
# Hand session.token to @nerdstackgrp/ark-client in the browser.
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
## Ark Streams
|
|
134
|
+
|
|
135
|
+
Both synchronous and asynchronous clients expose the Ark Streams control
|
|
136
|
+
plane. Creating a video returns a TUS endpoint for the client that owns the
|
|
137
|
+
video bytes. A remote import is fetched directly by Ark's video provider.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
creation = ark.streams.create("Product launch", size_bytes, app_id=app_id)
|
|
141
|
+
print(creation.stream.id, creation.upload.endpoint)
|
|
142
|
+
|
|
143
|
+
ark.streams.import_from_url("Remote video", source_url, app_id=app_id)
|
|
144
|
+
page = ark.streams.list(app_id=app_id, limit=50)
|
|
145
|
+
stream = ark.streams.get(creation.stream.id, app_id=app_id)
|
|
146
|
+
ark.streams.refresh_upload_url(stream.id, app_id=app_id)
|
|
147
|
+
ark.streams.delete(stream.id, app_id=app_id)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The same methods on `AsyncArk.streams` are awaitable. Poll `get` while a video
|
|
151
|
+
is uploading or encoding; `hls_url` and `embed_url` are populated when its
|
|
152
|
+
status becomes `ready`.
|
|
153
|
+
|
|
133
154
|
## S3-compatible access
|
|
134
155
|
|
|
135
156
|
```python
|
|
@@ -87,6 +87,27 @@ session = ark.create_client_session(ttl_seconds=900)
|
|
|
87
87
|
# Hand session.token to @nerdstackgrp/ark-client in the browser.
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
## Ark Streams
|
|
91
|
+
|
|
92
|
+
Both synchronous and asynchronous clients expose the Ark Streams control
|
|
93
|
+
plane. Creating a video returns a TUS endpoint for the client that owns the
|
|
94
|
+
video bytes. A remote import is fetched directly by Ark's video provider.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
creation = ark.streams.create("Product launch", size_bytes, app_id=app_id)
|
|
98
|
+
print(creation.stream.id, creation.upload.endpoint)
|
|
99
|
+
|
|
100
|
+
ark.streams.import_from_url("Remote video", source_url, app_id=app_id)
|
|
101
|
+
page = ark.streams.list(app_id=app_id, limit=50)
|
|
102
|
+
stream = ark.streams.get(creation.stream.id, app_id=app_id)
|
|
103
|
+
ark.streams.refresh_upload_url(stream.id, app_id=app_id)
|
|
104
|
+
ark.streams.delete(stream.id, app_id=app_id)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The same methods on `AsyncArk.streams` are awaitable. Poll `get` while a video
|
|
108
|
+
is uploading or encoding; `hls_url` and `embed_url` are populated when its
|
|
109
|
+
status becomes `ready`.
|
|
110
|
+
|
|
90
111
|
## S3-compatible access
|
|
91
112
|
|
|
92
113
|
```python
|
|
@@ -5,11 +5,16 @@ from .errors import ArkError
|
|
|
5
5
|
from .models import (
|
|
6
6
|
ArkFile,
|
|
7
7
|
ArkFolder,
|
|
8
|
+
ArkStream,
|
|
8
9
|
ArkUsage,
|
|
9
10
|
ClientSession,
|
|
10
11
|
FilePage,
|
|
11
12
|
ImageOptions,
|
|
12
13
|
StorageUsage,
|
|
14
|
+
StreamCreation,
|
|
15
|
+
StreamPage,
|
|
16
|
+
StreamStatus,
|
|
17
|
+
StreamUploadTicket,
|
|
13
18
|
)
|
|
14
19
|
from .s3 import create_s3_client
|
|
15
20
|
from .sync import Ark
|
|
@@ -19,12 +24,17 @@ __all__ = [
|
|
|
19
24
|
"ArkError",
|
|
20
25
|
"ArkFile",
|
|
21
26
|
"ArkFolder",
|
|
27
|
+
"ArkStream",
|
|
22
28
|
"ArkUsage",
|
|
23
29
|
"AsyncArk",
|
|
24
30
|
"ClientSession",
|
|
25
31
|
"FilePage",
|
|
26
32
|
"ImageOptions",
|
|
27
33
|
"StorageUsage",
|
|
34
|
+
"StreamCreation",
|
|
35
|
+
"StreamPage",
|
|
36
|
+
"StreamStatus",
|
|
37
|
+
"StreamUploadTicket",
|
|
28
38
|
"create_s3_client",
|
|
29
39
|
]
|
|
30
40
|
|
|
@@ -27,7 +27,18 @@ from ._shared import (
|
|
|
27
27
|
validate_size,
|
|
28
28
|
)
|
|
29
29
|
from .errors import ArkError, error_from_response, invalid_argument, network_error, upload_error
|
|
30
|
-
from .models import
|
|
30
|
+
from .models import (
|
|
31
|
+
ArkFile,
|
|
32
|
+
ArkFolder,
|
|
33
|
+
ArkStream,
|
|
34
|
+
ArkUsage,
|
|
35
|
+
ClientSession,
|
|
36
|
+
FilePage,
|
|
37
|
+
ImageOptions,
|
|
38
|
+
StreamCreation,
|
|
39
|
+
StreamPage,
|
|
40
|
+
StreamUploadTicket,
|
|
41
|
+
)
|
|
31
42
|
|
|
32
43
|
T = TypeVar("T")
|
|
33
44
|
AsyncSource = str | os.PathLike[str] | BinaryIO | AsyncIterable[bytes]
|
|
@@ -56,6 +67,7 @@ class AsyncArk:
|
|
|
56
67
|
self.folders = AsyncFolders(self)
|
|
57
68
|
self.images = AsyncImages(self)
|
|
58
69
|
self.imports = AsyncImports(self)
|
|
70
|
+
self.streams = AsyncStreams(self)
|
|
59
71
|
|
|
60
72
|
async def __aenter__(self) -> AsyncArk:
|
|
61
73
|
return self
|
|
@@ -426,6 +438,94 @@ class AsyncImports:
|
|
|
426
438
|
return bool(value.get("cancelled"))
|
|
427
439
|
|
|
428
440
|
|
|
441
|
+
class AsyncStreams:
|
|
442
|
+
"""Asynchronous Ark Streams video control-plane APIs."""
|
|
443
|
+
|
|
444
|
+
def __init__(self, ark: AsyncArk) -> None:
|
|
445
|
+
self._ark = ark
|
|
446
|
+
|
|
447
|
+
async def create(
|
|
448
|
+
self,
|
|
449
|
+
title: str,
|
|
450
|
+
size_bytes: int,
|
|
451
|
+
*,
|
|
452
|
+
app_id: str | None = None,
|
|
453
|
+
collection_id: str | None = None,
|
|
454
|
+
) -> StreamCreation:
|
|
455
|
+
payload: dict[str, Any] = {"title": title, "sizeBytes": size_bytes}
|
|
456
|
+
if app_id is not None:
|
|
457
|
+
payload["appId"] = app_id
|
|
458
|
+
if collection_id is not None:
|
|
459
|
+
payload["collectionId"] = collection_id
|
|
460
|
+
value = await self._ark._request("POST", "/streams", json=payload)
|
|
461
|
+
stream = value.get("stream")
|
|
462
|
+
upload = value.get("upload")
|
|
463
|
+
if not isinstance(stream, Mapping) or not isinstance(upload, Mapping):
|
|
464
|
+
raise ArkError("INTERNAL_ERROR", "Ark returned an invalid stream creation response")
|
|
465
|
+
return StreamCreation(
|
|
466
|
+
ArkStream.from_dict(stream),
|
|
467
|
+
StreamUploadTicket(str(upload["endpoint"])),
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
async def import_from_url(
|
|
471
|
+
self,
|
|
472
|
+
title: str,
|
|
473
|
+
url: str,
|
|
474
|
+
*,
|
|
475
|
+
app_id: str | None = None,
|
|
476
|
+
access_token: str | None = None,
|
|
477
|
+
size_bytes: int | None = None,
|
|
478
|
+
) -> ArkStream:
|
|
479
|
+
payload: dict[str, Any] = {"title": title, "url": url}
|
|
480
|
+
if app_id is not None:
|
|
481
|
+
payload["appId"] = app_id
|
|
482
|
+
if access_token is not None:
|
|
483
|
+
payload["accessToken"] = access_token
|
|
484
|
+
if size_bytes is not None:
|
|
485
|
+
payload["sizeBytes"] = size_bytes
|
|
486
|
+
value = await self._ark._request("POST", "/streams/fetch", json=payload)
|
|
487
|
+
return ArkStream.from_dict(value)
|
|
488
|
+
|
|
489
|
+
async def list(
|
|
490
|
+
self,
|
|
491
|
+
*,
|
|
492
|
+
app_id: str | None = None,
|
|
493
|
+
limit: int | None = None,
|
|
494
|
+
cursor: str | None = None,
|
|
495
|
+
) -> StreamPage:
|
|
496
|
+
suffix = query_string({"appId": app_id, "limit": limit, "cursor": cursor})
|
|
497
|
+
value = await self._ark._request("GET", f"/streams{suffix}")
|
|
498
|
+
raw_streams = value.get("streams")
|
|
499
|
+
streams = tuple(
|
|
500
|
+
ArkStream.from_dict(item)
|
|
501
|
+
for item in (raw_streams if isinstance(raw_streams, list) else [])
|
|
502
|
+
if isinstance(item, Mapping)
|
|
503
|
+
)
|
|
504
|
+
next_cursor = value.get("nextCursor")
|
|
505
|
+
return StreamPage(streams, next_cursor if isinstance(next_cursor, str) else None)
|
|
506
|
+
|
|
507
|
+
async def get(self, stream_id: str, *, app_id: str | None = None) -> ArkStream:
|
|
508
|
+
suffix = query_string({"appId": app_id})
|
|
509
|
+
value = await self._ark._request("GET", f"/streams/{segment(stream_id)}{suffix}")
|
|
510
|
+
return ArkStream.from_dict(value)
|
|
511
|
+
|
|
512
|
+
async def refresh_upload_url(
|
|
513
|
+
self,
|
|
514
|
+
stream_id: str,
|
|
515
|
+
*,
|
|
516
|
+
app_id: str | None = None,
|
|
517
|
+
) -> StreamUploadTicket:
|
|
518
|
+
suffix = query_string({"appId": app_id})
|
|
519
|
+
value = await self._ark._request(
|
|
520
|
+
"POST", f"/streams/{segment(stream_id)}/upload-url{suffix}", json={}
|
|
521
|
+
)
|
|
522
|
+
return StreamUploadTicket(str(value["endpoint"]))
|
|
523
|
+
|
|
524
|
+
async def delete(self, stream_id: str, *, app_id: str | None = None) -> None:
|
|
525
|
+
suffix = query_string({"appId": app_id})
|
|
526
|
+
await self._ark._request("DELETE", f"/streams/{segment(stream_id)}{suffix}")
|
|
527
|
+
|
|
528
|
+
|
|
429
529
|
def _as_async_iterable(source: AsyncSource) -> AsyncIterator[bytes] | None:
|
|
430
530
|
method = getattr(source, "__aiter__", None)
|
|
431
531
|
if method is None:
|
|
@@ -35,12 +35,23 @@ def error_from_response(response: httpx.Response) -> ArkError:
|
|
|
35
35
|
body = response.json()
|
|
36
36
|
except ValueError:
|
|
37
37
|
body = {}
|
|
38
|
-
|
|
39
|
-
if
|
|
40
|
-
|
|
38
|
+
raw_error = body.get("error") if isinstance(body, dict) else None
|
|
39
|
+
envelope = raw_error if isinstance(raw_error, dict) else {}
|
|
40
|
+
status_codes = {
|
|
41
|
+
400: "INVALID_ARGUMENT",
|
|
42
|
+
401: "UNAUTHORIZED",
|
|
43
|
+
402: "QUOTA_EXCEEDED",
|
|
44
|
+
403: "INSUFFICIENT_SCOPE",
|
|
45
|
+
404: "NOT_FOUND",
|
|
46
|
+
429: "RATE_LIMITED",
|
|
47
|
+
}
|
|
41
48
|
return ArkError(
|
|
42
|
-
str(envelope.get("code") or "INTERNAL_ERROR"),
|
|
43
|
-
str(
|
|
49
|
+
str(envelope.get("code") or status_codes.get(response.status_code, "INTERNAL_ERROR")),
|
|
50
|
+
str(
|
|
51
|
+
envelope.get("message")
|
|
52
|
+
or (raw_error if isinstance(raw_error, str) else None)
|
|
53
|
+
or f"Request failed with status {response.status_code}"
|
|
54
|
+
),
|
|
44
55
|
status=response.status_code,
|
|
45
56
|
request_id=_optional_string(envelope.get("requestId")),
|
|
46
57
|
details=envelope.get("details") if isinstance(envelope.get("details"), dict) else None,
|
|
@@ -96,6 +96,61 @@ class FilePage:
|
|
|
96
96
|
next_cursor: str | None
|
|
97
97
|
|
|
98
98
|
|
|
99
|
+
StreamStatus = Literal["created", "uploading", "processing", "ready", "failed"]
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dataclass(frozen=True, slots=True)
|
|
103
|
+
class ArkStream:
|
|
104
|
+
"""A video managed by Ark Streams. Playback URLs are None until it is ready."""
|
|
105
|
+
|
|
106
|
+
id: str
|
|
107
|
+
title: str
|
|
108
|
+
status: StreamStatus | str
|
|
109
|
+
encode_progress: int
|
|
110
|
+
duration_seconds: int
|
|
111
|
+
width: int
|
|
112
|
+
height: int
|
|
113
|
+
size: int
|
|
114
|
+
thumbnail_url: str | None
|
|
115
|
+
hls_url: str | None
|
|
116
|
+
embed_url: str | None
|
|
117
|
+
created_at: str
|
|
118
|
+
|
|
119
|
+
@classmethod
|
|
120
|
+
def from_dict(cls, value: Mapping[str, Any]) -> ArkStream:
|
|
121
|
+
return cls(
|
|
122
|
+
id=str(value["id"]),
|
|
123
|
+
title=str(value["title"]),
|
|
124
|
+
status=str(value.get("status") or "created"),
|
|
125
|
+
encode_progress=int(value.get("encodeProgress") or 0),
|
|
126
|
+
duration_seconds=int(value.get("durationSeconds") or 0),
|
|
127
|
+
width=int(value.get("width") or 0),
|
|
128
|
+
height=int(value.get("height") or 0),
|
|
129
|
+
size=int(value.get("size") or 0),
|
|
130
|
+
thumbnail_url=_optional_string(value.get("thumbnailUrl")),
|
|
131
|
+
hls_url=_optional_string(value.get("hlsUrl")),
|
|
132
|
+
embed_url=_optional_string(value.get("embedUrl")),
|
|
133
|
+
created_at=str(value.get("createdAt") or ""),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@dataclass(frozen=True, slots=True)
|
|
138
|
+
class StreamUploadTicket:
|
|
139
|
+
endpoint: str
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@dataclass(frozen=True, slots=True)
|
|
143
|
+
class StreamCreation:
|
|
144
|
+
stream: ArkStream
|
|
145
|
+
upload: StreamUploadTicket
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@dataclass(frozen=True, slots=True)
|
|
149
|
+
class StreamPage:
|
|
150
|
+
streams: tuple[ArkStream, ...]
|
|
151
|
+
next_cursor: str | None
|
|
152
|
+
|
|
153
|
+
|
|
99
154
|
@dataclass(frozen=True, slots=True)
|
|
100
155
|
class ClientSession:
|
|
101
156
|
token: str
|
|
@@ -27,7 +27,18 @@ from ._shared import (
|
|
|
27
27
|
upload_payload,
|
|
28
28
|
)
|
|
29
29
|
from .errors import ArkError, error_from_response, network_error, upload_error
|
|
30
|
-
from .models import
|
|
30
|
+
from .models import (
|
|
31
|
+
ArkFile,
|
|
32
|
+
ArkFolder,
|
|
33
|
+
ArkStream,
|
|
34
|
+
ArkUsage,
|
|
35
|
+
ClientSession,
|
|
36
|
+
FilePage,
|
|
37
|
+
ImageOptions,
|
|
38
|
+
StreamCreation,
|
|
39
|
+
StreamPage,
|
|
40
|
+
StreamUploadTicket,
|
|
41
|
+
)
|
|
31
42
|
|
|
32
43
|
T = TypeVar("T")
|
|
33
44
|
|
|
@@ -55,6 +66,7 @@ class Ark:
|
|
|
55
66
|
self.folders = Folders(self)
|
|
56
67
|
self.images = Images(self)
|
|
57
68
|
self.imports = Imports(self)
|
|
69
|
+
self.streams = Streams(self)
|
|
58
70
|
|
|
59
71
|
def __enter__(self) -> Ark:
|
|
60
72
|
return self
|
|
@@ -379,3 +391,91 @@ class Imports:
|
|
|
379
391
|
def cancel(self, import_id: str) -> bool:
|
|
380
392
|
value = self._ark._request("POST", f"/imports/{segment(import_id)}/cancel", json={})
|
|
381
393
|
return bool(value.get("cancelled"))
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
class Streams:
|
|
397
|
+
"""Ark Streams video creation, import, playback metadata, and lifecycle APIs."""
|
|
398
|
+
|
|
399
|
+
def __init__(self, ark: Ark) -> None:
|
|
400
|
+
self._ark = ark
|
|
401
|
+
|
|
402
|
+
def create(
|
|
403
|
+
self,
|
|
404
|
+
title: str,
|
|
405
|
+
size_bytes: int,
|
|
406
|
+
*,
|
|
407
|
+
app_id: str | None = None,
|
|
408
|
+
collection_id: str | None = None,
|
|
409
|
+
) -> StreamCreation:
|
|
410
|
+
payload: dict[str, Any] = {"title": title, "sizeBytes": size_bytes}
|
|
411
|
+
if app_id is not None:
|
|
412
|
+
payload["appId"] = app_id
|
|
413
|
+
if collection_id is not None:
|
|
414
|
+
payload["collectionId"] = collection_id
|
|
415
|
+
value = self._ark._request("POST", "/streams", json=payload)
|
|
416
|
+
stream = value.get("stream")
|
|
417
|
+
upload = value.get("upload")
|
|
418
|
+
if not isinstance(stream, Mapping) or not isinstance(upload, Mapping):
|
|
419
|
+
raise ArkError("INTERNAL_ERROR", "Ark returned an invalid stream creation response")
|
|
420
|
+
return StreamCreation(
|
|
421
|
+
ArkStream.from_dict(stream),
|
|
422
|
+
StreamUploadTicket(str(upload["endpoint"])),
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
def import_from_url(
|
|
426
|
+
self,
|
|
427
|
+
title: str,
|
|
428
|
+
url: str,
|
|
429
|
+
*,
|
|
430
|
+
app_id: str | None = None,
|
|
431
|
+
access_token: str | None = None,
|
|
432
|
+
size_bytes: int | None = None,
|
|
433
|
+
) -> ArkStream:
|
|
434
|
+
payload: dict[str, Any] = {"title": title, "url": url}
|
|
435
|
+
if app_id is not None:
|
|
436
|
+
payload["appId"] = app_id
|
|
437
|
+
if access_token is not None:
|
|
438
|
+
payload["accessToken"] = access_token
|
|
439
|
+
if size_bytes is not None:
|
|
440
|
+
payload["sizeBytes"] = size_bytes
|
|
441
|
+
return ArkStream.from_dict(self._ark._request("POST", "/streams/fetch", json=payload))
|
|
442
|
+
|
|
443
|
+
def list(
|
|
444
|
+
self,
|
|
445
|
+
*,
|
|
446
|
+
app_id: str | None = None,
|
|
447
|
+
limit: int | None = None,
|
|
448
|
+
cursor: str | None = None,
|
|
449
|
+
) -> StreamPage:
|
|
450
|
+
suffix = query_string({"appId": app_id, "limit": limit, "cursor": cursor})
|
|
451
|
+
value = self._ark._request("GET", f"/streams{suffix}")
|
|
452
|
+
raw_streams = value.get("streams")
|
|
453
|
+
streams = tuple(
|
|
454
|
+
ArkStream.from_dict(item)
|
|
455
|
+
for item in (raw_streams if isinstance(raw_streams, list) else [])
|
|
456
|
+
if isinstance(item, Mapping)
|
|
457
|
+
)
|
|
458
|
+
next_cursor = value.get("nextCursor")
|
|
459
|
+
return StreamPage(streams, next_cursor if isinstance(next_cursor, str) else None)
|
|
460
|
+
|
|
461
|
+
def get(self, stream_id: str, *, app_id: str | None = None) -> ArkStream:
|
|
462
|
+
suffix = query_string({"appId": app_id})
|
|
463
|
+
return ArkStream.from_dict(
|
|
464
|
+
self._ark._request("GET", f"/streams/{segment(stream_id)}{suffix}")
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
def refresh_upload_url(
|
|
468
|
+
self,
|
|
469
|
+
stream_id: str,
|
|
470
|
+
*,
|
|
471
|
+
app_id: str | None = None,
|
|
472
|
+
) -> StreamUploadTicket:
|
|
473
|
+
suffix = query_string({"appId": app_id})
|
|
474
|
+
value = self._ark._request(
|
|
475
|
+
"POST", f"/streams/{segment(stream_id)}/upload-url{suffix}", json={}
|
|
476
|
+
)
|
|
477
|
+
return StreamUploadTicket(str(value["endpoint"]))
|
|
478
|
+
|
|
479
|
+
def delete(self, stream_id: str, *, app_id: str | None = None) -> None:
|
|
480
|
+
suffix = query_string({"appId": app_id})
|
|
481
|
+
self._ark._request("DELETE", f"/streams/{segment(stream_id)}{suffix}")
|
|
@@ -8,6 +8,7 @@ from typing import Any
|
|
|
8
8
|
import httpx
|
|
9
9
|
import pytest
|
|
10
10
|
from conftest import file_response, json_response
|
|
11
|
+
from test_sync import STREAM_RESPONSE
|
|
11
12
|
|
|
12
13
|
from ark_py import ArkError, AsyncArk
|
|
13
14
|
|
|
@@ -42,6 +43,35 @@ async def test_async_resources_and_default_url() -> None:
|
|
|
42
43
|
await client.aclose()
|
|
43
44
|
|
|
44
45
|
|
|
46
|
+
@pytest.mark.asyncio
|
|
47
|
+
async def test_async_streams_control_plane() -> None:
|
|
48
|
+
async def handler(request: httpx.Request) -> httpx.Response:
|
|
49
|
+
if request.url.path.endswith("/streams") and request.method == "POST":
|
|
50
|
+
return json_response(
|
|
51
|
+
{"stream": STREAM_RESPONSE, "upload": {"endpoint": "/streams/stream-1/upload"}},
|
|
52
|
+
201,
|
|
53
|
+
)
|
|
54
|
+
if request.url.path.endswith("/streams/fetch"):
|
|
55
|
+
return json_response(STREAM_RESPONSE, 202)
|
|
56
|
+
if request.url.path.endswith("/upload-url"):
|
|
57
|
+
return json_response({"endpoint": "/streams/stream-1/upload"})
|
|
58
|
+
if request.method == "DELETE":
|
|
59
|
+
return httpx.Response(204)
|
|
60
|
+
if request.url.path.endswith("/stream-1"):
|
|
61
|
+
return json_response(STREAM_RESPONSE)
|
|
62
|
+
return json_response({"streams": [STREAM_RESPONSE], "nextCursor": None})
|
|
63
|
+
|
|
64
|
+
client = async_client_for(handler)
|
|
65
|
+
streams = AsyncArk("token", base_url="https://ark.test", client=client).streams
|
|
66
|
+
assert (await streams.create("Launch", 42)).stream.id == "stream-1"
|
|
67
|
+
assert (await streams.import_from_url("Remote", "https://video.test/a.mp4")).size == 42
|
|
68
|
+
assert len((await streams.list(app_id="app-1")).streams) == 1
|
|
69
|
+
assert (await streams.get("stream-1")).status == "ready"
|
|
70
|
+
assert (await streams.refresh_upload_url("stream-1")).endpoint.endswith("/upload")
|
|
71
|
+
assert await streams.delete("stream-1") is None
|
|
72
|
+
await client.aclose()
|
|
73
|
+
|
|
74
|
+
|
|
45
75
|
@pytest.mark.asyncio
|
|
46
76
|
async def test_async_iterable_multipart_upload_is_bounded() -> None:
|
|
47
77
|
data = bytes(range(10))
|
|
@@ -13,6 +13,21 @@ from conftest import file_response, json_response
|
|
|
13
13
|
|
|
14
14
|
from ark_py import Ark, ArkError, ImageOptions
|
|
15
15
|
|
|
16
|
+
STREAM_RESPONSE = {
|
|
17
|
+
"id": "stream-1",
|
|
18
|
+
"title": "Launch",
|
|
19
|
+
"status": "ready",
|
|
20
|
+
"encodeProgress": 100,
|
|
21
|
+
"durationSeconds": 12,
|
|
22
|
+
"width": 1920,
|
|
23
|
+
"height": 1080,
|
|
24
|
+
"size": 42,
|
|
25
|
+
"thumbnailUrl": "https://cdn.test/thumb.jpg",
|
|
26
|
+
"hlsUrl": "https://cdn.test/playlist.m3u8",
|
|
27
|
+
"embedUrl": "https://player.test/embed",
|
|
28
|
+
"createdAt": "2026-09-03T00:00:00.000Z",
|
|
29
|
+
}
|
|
30
|
+
|
|
16
31
|
|
|
17
32
|
def client_for(handler: Any) -> httpx.Client:
|
|
18
33
|
return httpx.Client(transport=httpx.MockTransport(handler))
|
|
@@ -87,6 +102,38 @@ def test_resources_models_images_and_errors() -> None:
|
|
|
87
102
|
client.close()
|
|
88
103
|
|
|
89
104
|
|
|
105
|
+
def test_streams_control_plane() -> None:
|
|
106
|
+
requests: list[tuple[str, str]] = []
|
|
107
|
+
|
|
108
|
+
def handler(request: httpx.Request) -> httpx.Response:
|
|
109
|
+
requests.append((request.method, str(request.url)))
|
|
110
|
+
if request.url.path.endswith("/streams") and request.method == "POST":
|
|
111
|
+
return json_response(
|
|
112
|
+
{"stream": STREAM_RESPONSE, "upload": {"endpoint": "/streams/stream-1/upload"}},
|
|
113
|
+
201,
|
|
114
|
+
)
|
|
115
|
+
if request.url.path.endswith("/streams/fetch"):
|
|
116
|
+
return json_response(STREAM_RESPONSE, 202)
|
|
117
|
+
if request.url.path.endswith("/upload-url"):
|
|
118
|
+
return json_response({"endpoint": "/streams/stream-1/upload?appId=app-1"})
|
|
119
|
+
if request.method == "DELETE":
|
|
120
|
+
return httpx.Response(204)
|
|
121
|
+
if request.url.path.endswith("/stream-1"):
|
|
122
|
+
return json_response(STREAM_RESPONSE)
|
|
123
|
+
return json_response({"streams": [STREAM_RESPONSE], "nextCursor": "next"})
|
|
124
|
+
|
|
125
|
+
client = client_for(handler)
|
|
126
|
+
streams = Ark("token", base_url="https://ark.test", client=client).streams
|
|
127
|
+
assert streams.create("Launch", 42, app_id="app-1").upload.endpoint.endswith("/upload")
|
|
128
|
+
assert streams.import_from_url("Remote", "https://video.test/a.mp4").id == "stream-1"
|
|
129
|
+
assert streams.list(app_id="app-1", limit=10).next_cursor == "next"
|
|
130
|
+
assert streams.get("stream-1", app_id="app-1").hls_url is not None
|
|
131
|
+
assert streams.refresh_upload_url("stream-1", app_id="app-1").endpoint.endswith("appId=app-1")
|
|
132
|
+
assert streams.delete("stream-1", app_id="app-1") is None
|
|
133
|
+
assert requests[2] == ("GET", "https://ark.test/api/v2/streams?appId=app-1&limit=10")
|
|
134
|
+
client.close()
|
|
135
|
+
|
|
136
|
+
|
|
90
137
|
def test_single_path_upload_streams_and_completes(tmp_path: Path) -> None:
|
|
91
138
|
data = b"streamed from disk"
|
|
92
139
|
path = tmp_path / "photo.jpg"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|