Skip to content

Commit 08c94f1

Browse files
committed
Add waitToFinish() function to Movie
1 parent 3f47a61 commit 08c94f1

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

src/Movie.php

+35
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,39 @@ public function getStatus() {
100100

101101
return false;
102102
}
103+
104+
public function waitToFinish($delay=5, $callback=null) {
105+
106+
$max_loops = 100;
107+
$loops = 0;
108+
109+
while ($loops<$max_loops) {
110+
$response = $this->getStatus();
111+
112+
if ($response && ($response['success']??false) && isset($response['movies']) && count($response['movies'])==1) {
113+
if (isset($response['movies'][0]['status']) && $response['movies'][0]['status']=='done') {
114+
if (is_callable($callback)) $callback($response['movies'][0]);
115+
else $this->printStatus($response['movies'][0]);
116+
117+
return $response['movies'][0];
118+
}
119+
}
120+
else {
121+
throw new \Error('Invalid API response');
122+
}
123+
124+
if (is_callable($callback)) $callback($response['movies'][0]);
125+
else $this->printStatus($response['movies'][0]);
126+
127+
sleep($delay);
128+
$loops++;
129+
}
130+
}
131+
132+
public function printStatus($response) {
133+
echo 'Status: ', $response['status'], ' / ', $response['task'], PHP_EOL;
134+
if ($response['status']=='done') {
135+
echo PHP_EOL, 'Movie URL: ', $response['url'], PHP_EOL, PHP_EOL;
136+
}
137+
}
103138
}

src/Scene.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@
33
namespace JSON2Video;
44

55
class Scene extends Base {
6-
protected $properties = ['comment', 'background_color', 'duration', 'cache'];
7-
6+
protected $properties = ['comment', 'background_color', 'transition', 'duration', 'cache'];
87
protected $object = [];
9-
10-
public function setTransition($style=null, $duration=null, $type=null) {
11-
if ($style || $duration || $type) {
12-
if (!isset($this->object['transition'])) $this->object['transition'] = [];
13-
if (!is_null($style)) $this->object['transition']['style'] = $style;
14-
if (!is_null($duration)) $this->object['transition']['duration'] = $duration;
15-
if (!is_null($type)) $this->object['transition']['type'] = $type;
16-
}
17-
}
18-
198
}

0 commit comments

Comments
 (0)