33from __future__ import annotations
44
55import logging
6- from typing import TYPE_CHECKING , Any
6+ from typing import TYPE_CHECKING , Any , Literal , cast
77
88from api_types import (
99 GenerateImageRequest ,
1010 GenerateVideoRequest ,
11+ VideoCameraMotion ,
1112)
1213from state .job_queue import QueueJob
1314
@@ -23,11 +24,14 @@ def _str(params: dict[str, Any], key: str, default: str = "") -> str:
2324 return str (v ) if v is not None else default
2425
2526
26- def _bool (params : dict [str , Any ], key : str , default : bool = False ) -> bool :
27- v = params .get (key , default )
28- if isinstance (v , bool ):
29- return v
30- return str (v ).lower () in ("1" , "true" , "yes" , "on" )
27+ def _camera_motion (params : dict [str , Any ]) -> VideoCameraMotion :
28+ """Return the cameraMotion param, defaulting to 'none'. Cast is safe: values come from validated queue jobs."""
29+ return cast (VideoCameraMotion , _str (params , "cameraMotion" , "none" ))
30+
31+
32+ def _aspect_ratio (params : dict [str , Any ]) -> Literal ["16:9" , "9:16" ]:
33+ """Return the aspectRatio param, defaulting to '16:9'. Cast is safe: values come from validated queue jobs."""
34+ return cast (Literal ["16:9" , "9:16" ], _str (params , "aspectRatio" , "16:9" ))
3135
3236
3337def _int (params : dict [str , Any ], key : str , default : int = 0 ) -> int :
@@ -65,8 +69,8 @@ def _execute_video(self, job: QueueJob) -> list[str]:
6569 duration = _str (p , "duration" , "5" ),
6670 fps = _str (p , "fps" , "24" ),
6771 audio = _str (p , "audio" , "false" ),
68- cameraMotion = _str ( p , "cameraMotion" , "none" ),
69- aspectRatio = _str ( p , "aspectRatio" , "16:9" ),
72+ cameraMotion = _camera_motion ( p ),
73+ aspectRatio = _aspect_ratio ( p ),
7074 model = job .model ,
7175 negativePrompt = _str (p , "negativePrompt" ),
7276 )
@@ -123,8 +127,8 @@ def execute(self, job: QueueJob) -> list[str]:
123127 duration = _str (p , "duration" , "5" ),
124128 fps = _str (p , "fps" , "24" ),
125129 audio = _str (p , "audio" , "false" ),
126- cameraMotion = _str ( p , "cameraMotion" , "none" ),
127- aspectRatio = _str ( p , "aspectRatio" , "16:9" ),
130+ cameraMotion = _camera_motion ( p ),
131+ aspectRatio = _aspect_ratio ( p ),
128132 model = job .model ,
129133 negativePrompt = _str (p , "negativePrompt" ),
130134 )
0 commit comments