@@ -57,19 +57,8 @@ public function getObject() {
5757
5858
5959class Scene extends Base {
60- protected $ properties = ['comment ' , 'background_color ' , 'duration ' , 'cache ' ];
61-
60+ protected $ properties = ['comment ' , 'background_color ' , 'transition ' , 'duration ' , 'cache ' ];
6261 protected $ object = [];
63-
64- public function setTransition ($ style =null , $ duration =null , $ type =null ) {
65- if ($ style || $ duration || $ type ) {
66- if (!isset ($ this ->object ['transition ' ])) $ this ->object ['transition ' ] = [];
67- if (!is_null ($ style )) $ this ->object ['transition ' ]['style ' ] = $ style ;
68- if (!is_null ($ duration )) $ this ->object ['transition ' ]['duration ' ] = $ duration ;
69- if (!is_null ($ type )) $ this ->object ['transition ' ]['type ' ] = $ type ;
70- }
71- }
72-
7362}
7463
7564class Movie extends Base {
@@ -170,4 +159,39 @@ public function getStatus() {
170159
171160 return false ;
172161 }
162+
163+ public function waitToFinish ($ delay =5 , $ callback =null ) {
164+
165+ $ max_loops = 100 ;
166+ $ loops = 0 ;
167+
168+ while ($ loops <$ max_loops ) {
169+ $ response = $ this ->getStatus ();
170+
171+ if ($ response && ($ response ['success ' ]??false ) && isset ($ response ['movies ' ]) && count ($ response ['movies ' ])==1 ) {
172+ if (isset ($ response ['movies ' ][0 ]['status ' ]) && $ response ['movies ' ][0 ]['status ' ]=='done ' ) {
173+ if (is_callable ($ callback )) $ callback ($ response ['movies ' ][0 ]);
174+ else $ this ->printStatus ($ response ['movies ' ][0 ]);
175+
176+ return $ response ['movies ' ][0 ];
177+ }
178+ }
179+ else {
180+ throw new \Error ('Invalid API response ' );
181+ }
182+
183+ if (is_callable ($ callback )) $ callback ($ response ['movies ' ][0 ]);
184+ else $ this ->printStatus ($ response ['movies ' ][0 ]);
185+
186+ sleep ($ delay );
187+ $ loops ++;
188+ }
189+ }
190+
191+ public function printStatus ($ response ) {
192+ echo 'Status: ' , $ response ['status ' ], ' / ' , $ response ['task ' ], PHP_EOL ;
193+ if ($ response ['status ' ]=='done ' ) {
194+ echo PHP_EOL , 'Movie URL: ' , $ response ['url ' ], PHP_EOL , PHP_EOL ;
195+ }
196+ }
173197}
0 commit comments