0
# Asset and DVR Management
1
2
Management of media assets and Digital Video Recording (DVR) sessions for creating recordings, clips, and time-shifted viewing experiences from live streams.
3
4
## Asset Management Capabilities
5
6
### Creating Assets
7
8
Creates a new media asset that can be used for slate content, ad insertion, or other overlay purposes in live streams.
9
10
```python { .api }
11
def create_asset(
12
self,
13
request: Union[CreateAssetRequest, dict] = None,
14
*,
15
parent: str = None,
16
asset: Asset = None,
17
asset_id: str = None,
18
retry: OptionalRetry = gapic_v1.method.DEFAULT,
19
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
20
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
21
) -> operation.Operation:
22
"""
23
Creates an asset with the provided unique ID in the specified region.
24
25
Args:
26
request: The request object containing parent, asset_id, asset, and request_id
27
parent: Required. The parent location path (projects/{project}/locations/{location})
28
asset: Required. The asset resource to create
29
asset_id: Required. The ID to use for the asset (must be unique within parent)
30
retry: Retry configuration for the request
31
timeout: Request timeout in seconds
32
metadata: Additional metadata for the request
33
34
Returns:
35
google.api_core.operation.Operation: Long-running operation
36
37
Raises:
38
google.api_core.exceptions.GoogleAPICallError: If the request fails
39
"""
40
```
41
42
### Listing Assets
43
44
Retrieves a list of media assets with pagination and filtering capabilities.
45
46
```python { .api }
47
def list_assets(
48
self,
49
request: Union[ListAssetsRequest, dict] = None,
50
*,
51
parent: str = None,
52
retry: OptionalRetry = gapic_v1.method.DEFAULT,
53
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
54
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
55
) -> pagers.ListAssetsPager:
56
"""
57
Returns a list of all assets in the specified region.
58
59
Args:
60
request: The request object containing parent, page_size, page_token, filter, order_by
61
parent: Required. The parent path (projects/{project}/locations/{location})
62
retry: Retry configuration for the request
63
timeout: Request timeout in seconds
64
metadata: Additional metadata for the request
65
66
Returns:
67
pagers.ListAssetsPager: Pager for iterating over asset results
68
69
Raises:
70
google.api_core.exceptions.GoogleAPICallError: If the request fails
71
"""
72
```
73
74
### Getting Asset Details
75
76
Retrieves detailed information about a specific asset including its content, state, and metadata.
77
78
```python { .api }
79
def get_asset(
80
self,
81
request: Union[GetAssetRequest, dict] = None,
82
*,
83
name: str = None,
84
retry: OptionalRetry = gapic_v1.method.DEFAULT,
85
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
86
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
87
) -> Asset:
88
"""
89
Returns the specified asset.
90
91
Args:
92
request: The request object containing name
93
name: Required. The asset name (projects/{project}/locations/{location}/assets/{asset})
94
retry: Retry configuration for the request
95
timeout: Request timeout in seconds
96
metadata: Additional metadata for the request
97
98
Returns:
99
Asset: The asset resource
100
101
Raises:
102
google.api_core.exceptions.GoogleAPICallError: If the request fails
103
"""
104
```
105
106
### Deleting Assets
107
108
Permanently removes a media asset and all associated data.
109
110
```python { .api }
111
def delete_asset(
112
self,
113
request: Union[DeleteAssetRequest, dict] = None,
114
*,
115
name: str = None,
116
retry: OptionalRetry = gapic_v1.method.DEFAULT,
117
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
118
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
119
) -> operation.Operation:
120
"""
121
Deletes the specified asset.
122
123
Args:
124
request: The request object containing name and request_id
125
name: Required. The asset name (projects/{project}/locations/{location}/assets/{asset})
126
retry: Retry configuration for the request
127
timeout: Request timeout in seconds
128
metadata: Additional metadata for the request
129
130
Returns:
131
google.api_core.operation.Operation: Long-running operation
132
133
Raises:
134
google.api_core.exceptions.GoogleAPICallError: If the request fails
135
"""
136
```
137
138
## DVR Session Management Capabilities
139
140
### Creating DVR Sessions
141
142
Creates a new DVR session for recording live streams with configurable retention and time window settings.
143
144
```python { .api }
145
def create_dvr_session(
146
self,
147
request: Union[CreateDvrSessionRequest, dict] = None,
148
*,
149
parent: str = None,
150
dvr_session: DvrSession = None,
151
dvr_session_id: str = None,
152
retry: OptionalRetry = gapic_v1.method.DEFAULT,
153
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
154
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
155
) -> DvrSession:
156
"""
157
Creates a DVR session with the provided unique ID in the specified channel.
158
159
Args:
160
request: The request object containing parent, dvr_session_id, dvr_session, and request_id
161
parent: Required. The parent channel (projects/{project}/locations/{location}/channels/{channel})
162
dvr_session: Required. The DVR session resource to create
163
dvr_session_id: Required. The ID to use for the DVR session
164
retry: Retry configuration for the request
165
timeout: Request timeout in seconds
166
metadata: Additional metadata for the request
167
168
Returns:
169
DvrSession: The created DVR session resource
170
171
Raises:
172
google.api_core.exceptions.GoogleAPICallError: If the request fails
173
"""
174
```
175
176
### Listing DVR Sessions
177
178
Retrieves a list of DVR sessions with pagination and filtering capabilities.
179
180
```python { .api }
181
def list_dvr_sessions(
182
self,
183
request: Union[ListDvrSessionsRequest, dict] = None,
184
*,
185
parent: str = None,
186
retry: OptionalRetry = gapic_v1.method.DEFAULT,
187
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
188
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
189
) -> pagers.ListDvrSessionsPager:
190
"""
191
Returns a list of all DVR sessions in the specified channel.
192
193
Args:
194
request: The request object containing parent, page_size, page_token, filter, order_by
195
parent: Required. The parent channel (projects/{project}/locations/{location}/channels/{channel})
196
retry: Retry configuration for the request
197
timeout: Request timeout in seconds
198
metadata: Additional metadata for the request
199
200
Returns:
201
pagers.ListDvrSessionsPager: Pager for iterating over DVR session results
202
203
Raises:
204
google.api_core.exceptions.GoogleAPICallError: If the request fails
205
"""
206
```
207
208
### Getting DVR Session Details
209
210
Retrieves detailed information about a specific DVR session including its recording state and available time ranges.
211
212
```python { .api }
213
def get_dvr_session(
214
self,
215
request: Union[GetDvrSessionRequest, dict] = None,
216
*,
217
name: str = None,
218
retry: OptionalRetry = gapic_v1.method.DEFAULT,
219
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
220
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
221
) -> DvrSession:
222
"""
223
Returns the specified DVR session.
224
225
Args:
226
request: The request object containing name
227
name: Required. The DVR session name (projects/{project}/locations/{location}/channels/{channel}/dvrSessions/{dvrSession})
228
retry: Retry configuration for the request
229
timeout: Request timeout in seconds
230
metadata: Additional metadata for the request
231
232
Returns:
233
DvrSession: The DVR session resource
234
235
Raises:
236
google.api_core.exceptions.GoogleAPICallError: If the request fails
237
"""
238
```
239
240
### Updating DVR Sessions
241
242
Updates DVR session configuration including retention settings and time windows.
243
244
```python { .api }
245
def update_dvr_session(
246
self,
247
request: Union[UpdateDvrSessionRequest, dict] = None,
248
*,
249
dvr_session: DvrSession = None,
250
update_mask: field_mask_pb2.FieldMask = None,
251
retry: OptionalRetry = gapic_v1.method.DEFAULT,
252
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
253
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
254
) -> DvrSession:
255
"""
256
Updates the specified DVR session.
257
258
Args:
259
request: The request object containing update_mask, dvr_session, and request_id
260
dvr_session: Required. The DVR session resource with updated fields
261
update_mask: Required. Field mask specifying which fields to update
262
retry: Retry configuration for the request
263
timeout: Request timeout in seconds
264
metadata: Additional metadata for the request
265
266
Returns:
267
DvrSession: The updated DVR session resource
268
269
Raises:
270
google.api_core.exceptions.GoogleAPICallError: If the request fails
271
"""
272
```
273
274
### Deleting DVR Sessions
275
276
Permanently removes a DVR session and all associated recorded content.
277
278
```python { .api }
279
def delete_dvr_session(
280
self,
281
request: Union[DeleteDvrSessionRequest, dict] = None,
282
*,
283
name: str = None,
284
retry: OptionalRetry = gapic_v1.method.DEFAULT,
285
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
286
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
287
) -> None:
288
"""
289
Deletes the specified DVR session.
290
291
Args:
292
request: The request object containing name and request_id
293
name: Required. The DVR session name (projects/{project}/locations/{location}/channels/{channel}/dvrSessions/{dvrSession})
294
retry: Retry configuration for the request
295
timeout: Request timeout in seconds
296
metadata: Additional metadata for the request
297
298
Returns:
299
None
300
301
Raises:
302
google.api_core.exceptions.GoogleAPICallError: If the request fails
303
"""
304
```
305
306
## Asset and DVR Types
307
308
### Asset Resource
309
310
```python { .api }
311
class Asset:
312
"""
313
Asset resource represents media content that can be used in live streams.
314
315
Attributes:
316
name (str): Asset resource name
317
create_time (google.protobuf.timestamp_pb2.Timestamp): Creation timestamp
318
update_time (google.protobuf.timestamp_pb2.Timestamp): Last update timestamp
319
labels (MutableMapping[str, str]): User-defined labels
320
video (VideoAsset): Video asset configuration
321
crc32c (str): CRC32C checksum of the asset
322
state (State): Current asset state
323
error (google.rpc.status_pb2.Status): Any processing errors
324
"""
325
326
class State(proto.Enum):
327
"""Asset state enumeration."""
328
STATE_UNSPECIFIED = 0
329
CREATING = 1
330
ACTIVE = 2
331
DELETING = 3
332
ERROR = 4
333
334
class VideoAsset:
335
"""Video asset configuration."""
336
uri (str): Cloud Storage URI of the video file
337
```
338
339
### DVR Session Resource
340
341
```python { .api }
342
class DvrSession:
343
"""
344
DVR session resource for recording live streams.
345
346
Attributes:
347
name (str): DVR session resource name
348
create_time (google.protobuf.timestamp_pb2.Timestamp): Creation timestamp
349
update_time (google.protobuf.timestamp_pb2.Timestamp): Last update timestamp
350
labels (MutableMapping[str, str]): User-defined labels
351
start_time (google.protobuf.timestamp_pb2.Timestamp): Recording start time
352
end_time (google.protobuf.timestamp_pb2.Timestamp): Recording end time
353
retention_config (RetentionConfig): Data retention configuration
354
dvr_end_time (google.protobuf.timestamp_pb2.Timestamp): Actual DVR end time
355
state (State): Current DVR session state
356
error (google.rpc.status_pb2.Status): Any recording errors
357
"""
358
359
class State(proto.Enum):
360
"""DVR session state enumeration."""
361
STATE_UNSPECIFIED = 0
362
CREATING = 1
363
ACTIVE = 2
364
STOPPED = 3
365
ERROR = 4
366
```
367
368
### Retention Configuration
369
370
```python { .api }
371
class RetentionConfig:
372
"""
373
Data retention configuration for DVR sessions.
374
375
Attributes:
376
retention_window_duration (google.protobuf.duration_pb2.Duration): How long to retain data
377
"""
378
```
379
380
## Usage Examples
381
382
### Creating Video Asset
383
384
```python
385
from google.cloud.video import live_stream_v1
386
387
client = live_stream_v1.LivestreamServiceClient()
388
389
# Create asset from Cloud Storage video file
390
asset = live_stream_v1.Asset(
391
video=live_stream_v1.Asset.VideoAsset(
392
uri="gs://my-bucket/videos/slate.mp4"
393
)
394
)
395
396
request = live_stream_v1.CreateAssetRequest(
397
parent="projects/my-project/locations/us-central1",
398
asset_id="slate-video",
399
asset=asset
400
)
401
402
operation = client.create_asset(request=request)
403
asset_result = operation.result()
404
print(f"Created asset: {asset_result.name}")
405
```
406
407
### Creating DVR Session
408
409
```python
410
from google.protobuf import timestamp_pb2, duration_pb2
411
import datetime
412
413
# Create DVR session for 2-hour window
414
start_time = datetime.datetime.now()
415
end_time = start_time + datetime.timedelta(hours=2)
416
417
start_timestamp = timestamp_pb2.Timestamp()
418
end_timestamp = timestamp_pb2.Timestamp()
419
start_timestamp.FromDatetime(start_time)
420
end_timestamp.FromDatetime(end_time)
421
422
# Retain data for 24 hours
423
retention_duration = duration_pb2.Duration(seconds=24*60*60)
424
425
dvr_session = live_stream_v1.DvrSession(
426
start_time=start_timestamp,
427
end_time=end_timestamp,
428
retention_config=live_stream_v1.RetentionConfig(
429
retention_window_duration=retention_duration
430
)
431
)
432
433
request = live_stream_v1.CreateDvrSessionRequest(
434
parent="projects/my-project/locations/us-central1/channels/my-channel",
435
dvr_session_id="recording-session-1",
436
dvr_session=dvr_session
437
)
438
439
dvr_result = client.create_dvr_session(request=request)
440
print(f"Created DVR session: {dvr_result.name}")
441
```
442
443
### Managing Asset Lifecycle
444
445
```python
446
# List all assets
447
list_request = live_stream_v1.ListAssetsRequest(
448
parent="projects/my-project/locations/us-central1"
449
)
450
451
for asset in client.list_assets(request=list_request):
452
print(f"Asset: {asset.name}, State: {asset.state}")
453
454
# Check if asset is ready
455
if asset.state == live_stream_v1.Asset.State.ACTIVE:
456
print(f"Asset {asset.name} is ready for use")
457
elif asset.state == live_stream_v1.Asset.State.ERROR:
458
print(f"Asset {asset.name} failed: {asset.error.message}")
459
460
# Get specific asset details
461
get_request = live_stream_v1.GetAssetRequest(
462
name="projects/my-project/locations/us-central1/assets/my-asset"
463
)
464
asset = client.get_asset(request=get_request)
465
print(f"Asset URI: {asset.video.uri}")
466
print(f"Asset checksum: {asset.crc32c}")
467
```
468
469
### Managing DVR Sessions
470
471
```python
472
from google.protobuf import field_mask_pb2
473
474
# Update DVR session retention
475
updated_dvr = live_stream_v1.DvrSession(
476
name="projects/my-project/locations/us-central1/channels/my-channel/dvrSessions/my-session",
477
retention_config=live_stream_v1.RetentionConfig(
478
retention_window_duration=duration_pb2.Duration(seconds=48*60*60) # 48 hours
479
)
480
)
481
482
update_mask = field_mask_pb2.FieldMask(
483
paths=["retention_config.retention_window_duration"]
484
)
485
486
update_request = live_stream_v1.UpdateDvrSessionRequest(
487
dvr_session=updated_dvr,
488
update_mask=update_mask
489
)
490
491
updated_session = client.update_dvr_session(request=update_request)
492
493
# Monitor DVR session state
494
get_request = live_stream_v1.GetDvrSessionRequest(
495
name="projects/my-project/locations/us-central1/channels/my-channel/dvrSessions/my-session"
496
)
497
498
session = client.get_dvr_session(request=get_request)
499
print(f"DVR session state: {session.state}")
500
print(f"Recording from {session.start_time} to {session.end_time}")
501
```