Skip to content

Commit 86d4a4f

Browse files
v1.1 and subtitles fix
1 parent bd76cfa commit 86d4a4f

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

src/Classes/TranscodingTask.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,41 @@ public function getLastStatus() {
145145
}
146146

147147
private $subtitles;
148+
private function initSubtitles() {
149+
$this->subtitles = new \stdClass();
150+
$this->subtitles->sources = array();
151+
$this->subtitles->copy = 0;
152+
}
148153

154+
/**
155+
* Adds subtitles to a task
156+
* @param $source Subtitles file URL
157+
* @param $language Subtitles file language
158+
*/
149159
public function addSubtitles($source, $language) {
150160
if ($this->subtitles == null) {
151-
$this->subtitles = array();
161+
$this->initSubtitles();
152162
}
153163
$sub = new \stdClass();
154164
$sub->source = $source;
155165
$sub->language = $language;
156-
$this->subtitles[] = $sub;
166+
$this->subtitles->sources[] = $sub;
167+
}
168+
169+
/**
170+
* Sets subtitles / closed captions copy mode: 0 - disabled (default), 1 - existing eia608 or eia708 closed captions
171+
* are copied to output stream
172+
* @param $value
173+
*/
174+
public function setSubtitlesCopyMode($value) {
175+
if ($this->subtitles == null) {
176+
$this->initSubtitles();
177+
}
178+
if ($value) {
179+
$this->subtitles->copy = 1;
180+
}
181+
else {
182+
$this->subtitles->copy = 0;
183+
}
157184
}
158185
}

src/QencodeApiClient.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class QencodeApiClient
2424

2525
public $url = 'https://api.qencode.com/';
2626
public $version = 'v1';
27+
private $supported_versions = array('v1', 'v1.1');
2728

28-
const USER_AGENT = 'Qencode PHP API SDK 1.0';
29+
const USER_AGENT = 'Qencode PHP API SDK 1.1';
2930

3031
/**
3132
* Maximum amount of time in seconds that is allowed to make the connection to the API server
@@ -42,9 +43,10 @@ class QencodeApiClient
4243
/**
4344
* @param string $key Qencode Project API key
4445
* @param string $url Optional url to any different API endpoint
46+
* @param string $version Optional API version
4547
* @throws \Qencode\Exceptions\QencodeException if the library failed to initialize
4648
*/
47-
public function __construct($key, $url = null)
49+
public function __construct($key, $url = null, $version = null)
4850
{
4951
if (strlen($key) < 12) {
5052
throw new QencodeException('Missing or invalid Qencode project api key!');
@@ -55,10 +57,25 @@ public function __construct($key, $url = null)
5557
}
5658
$this->url = $url;
5759
}
60+
if ($version) {
61+
$version = strtolower($version);
62+
if (in_array($version, $this->supported_versions)) {
63+
$this->version = $version;
64+
if ($version == 'v1.1') {
65+
$this->url = $this->v1_1_get_endpoint();
66+
}
67+
}
68+
else throw new QencodeException('Unsupported API version: '.$version);
69+
}
5870
$this->key = $key;
5971
$this->getAccessToken();
6072
}
6173

74+
private function v1_1_get_endpoint() {
75+
$api_host = file_get_contents($this->url.'/v1.1');
76+
return 'https://'.$api_host;
77+
}
78+
6279
private function getAccessToken() {
6380
$response = $this->post("access_token", array('api_key' => $this->key));
6481
$this->access_token = $response['token'];
@@ -127,7 +144,7 @@ private function request($method, $path, array $params = [])
127144
else {
128145
$url = $this->url . '/' . $this->version . '/' . trim($path, '/');
129146
}
130-
147+
echo "URL: ".$url."\n";
131148
if (!empty($params) & is_array($params)) {
132149
$params = http_build_query($params);
133150
}

0 commit comments

Comments
 (0)