1
1
# pylint: disable=too-few-public-methods, missing-module-docstring, broad-exception-caught,invalid-name
2
2
3
3
from enum import Enum
4
- from typing import Optional , Dict , Any , Union , Literal
4
+ from typing import Optional , Dict , Any , Union , Literal , List
5
5
from dataclasses import dataclass , field
6
6
from .version import VERSION
7
7
10
10
11
11
RenderType = Union [Literal ["video-or-audio" ], Literal ["still" ]]
12
12
13
+
13
14
class ValidStillImageFormats (str , Enum ):
14
15
"""
15
16
Enumeration of valid image formats for still images.
@@ -20,6 +21,7 @@ class ValidStillImageFormats(str, Enum):
20
21
PDF: Represents the PDF format for images.
21
22
WEBP: Represents the WEBP image format.
22
23
"""
24
+
23
25
PNG = 'png'
24
26
JPEG = 'jpeg'
25
27
PDF = 'pdf'
@@ -34,6 +36,7 @@ class Privacy(str, Enum):
34
36
PUBLIC: Indicates a public setting.
35
37
PRIVATE: Indicates a private setting.
36
38
"""
39
+
37
40
PUBLIC = 'public'
38
41
PRIVATE = 'private'
39
42
NO_ACL = 'no-acl'
@@ -49,6 +52,7 @@ class LogLevel(str, Enum):
49
52
WARN: Warning logging level.
50
53
ERROR: Error logging level.
51
54
"""
55
+
52
56
VERBOSE = 'verbose'
53
57
INFO = 'info'
54
58
WARN = 'warn'
@@ -66,6 +70,7 @@ class OpenGlRenderer(str, Enum):
66
70
SWIFTSHADER: Represents the SWIFTSHADER OpenGL renderer.
67
71
VULKAN: Represents the VULKAN OpenGL renderer.
68
72
"""
73
+
69
74
SWANGLE = 'swangle'
70
75
ANGLE = 'angle'
71
76
EGL = 'egl'
@@ -84,9 +89,10 @@ class ChromiumOptions:
84
89
gl (Optional[OpenGlRenderer]): Specifies the OpenGL renderer to use.
85
90
headless (Optional[bool]): If True, runs Chromium in headless mode.
86
91
user_agent (Optional[str]): Specifies a custom user agent.
87
- enable_multi_process_on_linux (Optional[bool]):
92
+ enable_multi_process_on_linux (Optional[bool]):
88
93
If True, enables multi-process mode on Linux.
89
94
"""
95
+
90
96
ignore_certificate_errors : Optional [bool ] = None
91
97
disable_web_security : Optional [bool ] = None
92
98
gl : Optional [OpenGlRenderer ] = None
@@ -103,18 +109,20 @@ class CustomCredentialsWithoutSensitiveData:
103
109
Attributes:
104
110
endpoint (str): The endpoint associated with the credentials.
105
111
"""
112
+
106
113
endpoint : str
107
114
108
115
109
116
@dataclass
110
117
class CustomCredentials (CustomCredentialsWithoutSensitiveData ):
111
118
"""
112
- Represents custom credentials, extending credentials without sensitive data.
119
+ Represents custom credentials, extending credentials without sensitive data.
120
+
121
+ Attributes:
122
+ access_key_id (Optional[str]): The access key ID.
123
+ secret_access_key (Optional[str]): The secret access key.
124
+ """
113
125
114
- Attributes:
115
- access_key_id (Optional[str]): The access key ID.
116
- secret_access_key (Optional[str]): The secret access key.
117
- """
118
126
access_key_id : Optional [str ] = None
119
127
secret_access_key : Optional [str ] = None
120
128
region : Optional [str ] = None
@@ -143,6 +151,7 @@ class OutNameInputObject:
143
151
s3_output_provider (Optional[CustomCredentials]):
144
152
Optional custom credentials for the S3 output provider.
145
153
"""
154
+
146
155
bucketName : str
147
156
key : str
148
157
s3_output_provider : Optional [CustomCredentials ] = None
@@ -158,6 +167,7 @@ class DeleteAfter(Enum):
158
167
SEVEN_DAYS: Represents deletion after seven days.
159
168
THIRTY_DAYS: Represents deletion after thirty days.
160
169
"""
170
+
161
171
ONE_DAY = '1-day'
162
172
THREE_DAYS = '3-days'
163
173
SEVEN_DAYS = '7-days'
@@ -169,6 +179,7 @@ class RenderMediaResponse:
169
179
"""
170
180
Response data after rendering.
171
181
"""
182
+
172
183
bucket_name : str
173
184
render_id : str
174
185
@@ -222,6 +233,7 @@ class CostsInfo:
222
233
currency (str): The type of currency used for the costs, e.g., 'USD', 'EUR'.
223
234
disclaimer (str): Any disclaimer or additional information related to the costs.
224
235
"""
236
+
225
237
accrued_so_far : float
226
238
display_cost : str
227
239
currency : str
@@ -233,6 +245,7 @@ class PlayInBrowser:
233
245
"""
234
246
The video should play in the browser when the link is clicked.
235
247
"""
248
+
236
249
type : Literal ['play-in-browser' ]
237
250
# You can define additional fields as needed
238
251
@@ -242,6 +255,7 @@ class ShouldDownload:
242
255
"""
243
256
The video should download when the link is clicked.
244
257
"""
258
+
245
259
type : Literal ['download' ]
246
260
fileName : str # Additional fields for this type
247
261
@@ -251,6 +265,7 @@ class Webhook:
251
265
"""
252
266
Represents a webhook.
253
267
"""
268
+
254
269
secret : str
255
270
url : str
256
271
customData : Optional [Dict ] = None
@@ -261,6 +276,7 @@ class RenderMediaParams:
261
276
"""
262
277
Parameters for video rendering.
263
278
"""
279
+
264
280
input_props : Optional [Dict [str , Any ]] = None
265
281
bucket_name : Optional [str ] = None
266
282
region : Optional [str ] = None
@@ -290,7 +306,8 @@ class RenderMediaParams:
290
306
concurrency_per_lambda : Optional [int ] = 1
291
307
concurrency : Optional [int ] = None
292
308
download_behavior : Optional [Union [PlayInBrowser , ShouldDownload ]] = field (
293
- default_factory = lambda : PlayInBrowser (type = 'play-in-browser' ))
309
+ default_factory = lambda : PlayInBrowser (type = 'play-in-browser' )
310
+ )
294
311
muted : bool = False
295
312
overwrite : bool = False
296
313
force_path_style : Optional [bool ] = None
@@ -337,7 +354,9 @@ def serialize_params(self) -> Dict:
337
354
'outName' : self .out_name ,
338
355
'preferLossless' : self .prefer_lossless ,
339
356
'timeoutInMilliseconds' : self .timeout_in_milliseconds ,
340
- 'chromiumOptions' : self .chromium_options if self .chromium_options is not None else {},
357
+ 'chromiumOptions' : (
358
+ self .chromium_options if self .chromium_options is not None else {}
359
+ ),
341
360
'scale' : self .scale ,
342
361
'everyNthFrame' : self .every_nth_frame ,
343
362
'numberOfGifLoops' : self .number_of_gif_loops ,
@@ -360,7 +379,7 @@ def serialize_params(self) -> Dict:
360
379
'deleteAfter' : self .delete_after ,
361
380
'encodingBufferSize' : self .encoding_buffer_size ,
362
381
'encodingMaxRate' : self .encoding_max_rate ,
363
- 'type' : 'start'
382
+ 'type' : 'start' ,
364
383
}
365
384
366
385
if self .crf is not None :
@@ -399,6 +418,7 @@ class RenderStillParams:
399
418
"""
400
419
Parameters for video rendering.
401
420
"""
421
+
402
422
composition : str
403
423
serve_url : str = ""
404
424
input_props : Optional [Dict [str , Any ]] = None
@@ -415,7 +435,9 @@ class RenderStillParams:
415
435
timeout_in_milliseconds : Optional [int ] = 30000
416
436
chromium_options : Optional [ChromiumOptions ] = None
417
437
scale : Optional [float ] = 1
418
- download_behavior : Dict = field (default_factory = lambda : PlayInBrowser (type = 'play-in-browser' ))
438
+ download_behavior : Union [PlayInBrowser , ShouldDownload ] = field (
439
+ default_factory = lambda : PlayInBrowser (type = 'play-in-browser' )
440
+ )
419
441
force_width : Optional [int ] = None
420
442
api_key : Optional [int ] = None
421
443
storage_class : Optional [str ] = None
@@ -430,21 +452,21 @@ class RenderStillParams:
430
452
431
453
def serialize_params (self ) -> Dict :
432
454
"""
433
- Serializes the parameters of the current object into a dictionary.
455
+ Serializes the parameters of the current object into a dictionary.
434
456
435
- This method consolidates both mandatory and optional attributes of the object
436
- into a single dictionary. Mandatory attributes include region, functionName,
437
- serveUrl, composition, inputProps, imageFormat, and privacy. Optional attributes
438
- are added to the dictionary only if they are not None.
457
+ This method consolidates both mandatory and optional attributes of the object
458
+ into a single dictionary. Mandatory attributes include region, functionName,
459
+ serveUrl, composition, inputProps, imageFormat, and privacy. Optional attributes
460
+ are added to the dictionary only if they are not None.
439
461
440
- The optional attributes include maxRetries, envVariables, jpegQuality, frame,
441
- logLevel, outName, timeoutInMilliseconds, chromiumOptions, scale, downloadBehavior,
442
- forceWidth, forceHeight, forceBucketName, and deleteAfter.
443
- Default values are provided for 'inputProps' (empty dictionary) and 'downloadBehavior'
444
- ('type': 'play-in-browser') if they are not explicitly set.
462
+ The optional attributes include maxRetries, envVariables, jpegQuality, frame,
463
+ logLevel, outName, timeoutInMilliseconds, chromiumOptions, scale, downloadBehavior,
464
+ forceWidth, forceHeight, forceBucketName, and deleteAfter.
465
+ Default values are provided for 'inputProps' (empty dictionary) and 'downloadBehavior'
466
+ ('type': 'play-in-browser') if they are not explicitly set.
445
467
446
- Returns:
447
- Dict: A dictionary containing all the serialized parameters of the object.
468
+ Returns:
469
+ Dict: A dictionary containing all the serialized parameters of the object.
448
470
"""
449
471
parameters = {
450
472
'type' : 'still' ,
@@ -456,15 +478,20 @@ def serialize_params(self) -> Dict:
456
478
'version' : VERSION ,
457
479
'timeoutInMilliseconds' : self .timeout_in_milliseconds ,
458
480
'maxRetries' : self .max_retries ,
459
- 'envVariables' : self .env_variables if self .env_variables is not None else {},
481
+ 'envVariables' : (
482
+ self .env_variables if self .env_variables is not None else {}
483
+ ),
460
484
'jpegQuality' : self .jpeg_quality ,
461
485
'storageClass' : self .storage_class ,
462
486
'frame' : self .frame ,
463
487
'logLevel' : self .log_level ,
464
488
'outName' : self .out_name ,
465
- 'chromiumOptions' : self .chromium_options if self .chromium_options is not None else {},
489
+ 'chromiumOptions' : (
490
+ self .chromium_options if self .chromium_options is not None else {}
491
+ ),
466
492
'scale' : self .scale ,
467
- 'downloadBehavior' : self .download_behavior or PlayInBrowser (type = 'play-in-browser' ),
493
+ 'downloadBehavior' : self .download_behavior
494
+ or PlayInBrowser (type = 'play-in-browser' ),
468
495
'forceWidth' : self .force_width ,
469
496
'apiKey' : self .api_key ,
470
497
'forceHeight' : self .force_height ,
@@ -490,14 +517,15 @@ class RenderStillResponse:
490
517
Represents the output information of a rendering operation performed on AWS Lambda.
491
518
492
519
Attributes:
493
- estimated_price (CostsInfo):
520
+ estimated_price (CostsInfo):
494
521
An object containing detailed cost information related to the rendering.
495
522
url (str): The URL where the rendered image is stored or can be accessed.
496
523
size_in_bytes (int): The size of the rendered image file in bytes.
497
524
bucket_name (str): The name of the S3 bucket where the rendered image is stored.
498
525
render_id (str): A unique identifier for the rendering operation.
499
526
cloud_watch_logs (str): The CloudWatch logs associated with the rendering operation.
500
527
"""
528
+
501
529
estimated_price : CostsInfo
502
530
url : str
503
531
size_in_bytes : int
@@ -506,26 +534,26 @@ class RenderStillResponse:
506
534
outKey : str
507
535
508
536
537
+ @dataclass
509
538
class RenderMediaProgress :
510
539
"""
511
540
Progress of video rendering.
512
541
"""
513
542
514
- def __init__ (self ):
515
- self .overallProgress = float ()
516
- self .chunks = int ()
517
- self .done = bool ()
518
- self .encodingStatus = None
519
- self .costs = None
520
- self .renderId = str ()
521
- self .renderMetadata = None
522
- self .outputFile = None
523
- self .outKey = None
524
- self .timeToFinish = None
525
- self .errors = []
526
- self .fatalErrorEncountered = bool ()
527
- self .currentTime = int ()
528
- self .renderSize = int ()
529
- self .outputSizeInBytes = None
530
- self .lambdasInvoked = int ()
531
- self .framesRendered = None
543
+ overallProgress : float = 0.0
544
+ chunks : int = 0
545
+ done : bool = False
546
+ encodingStatus : Optional [Any ] = None
547
+ costs : Optional [Any ] = None
548
+ renderId : str = ""
549
+ renderMetadata : Optional [Any ] = None
550
+ outputFile : Optional [Any ] = None
551
+ outKey : Optional [str ] = None
552
+ timeToFinish : Optional [float ] = None
553
+ errors : List [Any ] = field (default_factory = list )
554
+ fatalErrorEncountered : bool = False
555
+ currentTime : int = 0
556
+ renderSize : int = 0
557
+ outputSizeInBytes : Optional [int ] = None
558
+ lambdasInvoked : int = 0
559
+ framesRendered : Optional [int ] = None
0 commit comments