Skip to content

Commit c3ab8a3

Browse files
committed
add video-pulp
1 parent 2144bf5 commit c3ab8a3

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

examples/pulpvideo.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../autoload.php';
4+
5+
use Qiniu\Auth;
6+
use Qiniu\Http\Client;
7+
8+
$accessKey = getenv('QINIU_ACCESS_KEY');
9+
$secretKey = getenv('QINIU_SECRET_KEY');
10+
$auth = new Auth($accessKey, $secretKey);
11+
$config = new \Qiniu\Config();
12+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
13+
14+
$reqBody = array();
15+
$reqBody['uri'] = "xxxxxxxx";
16+
$ops = array();
17+
$ops = array(
18+
array(
19+
'op' => 'pulp',
20+
),
21+
);
22+
23+
$vid = "xxxx";
24+
list($ret, $err) = $bucketManager->pulpVideo($reqBody, $ops, $vid);
25+
26+
if ($err !== null) {
27+
var_dump($err);
28+
} else {
29+
var_dump($ret);
30+
}

src/Qiniu/Config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final class Config
1212
const RS_HOST = 'rs.qiniu.com'; //RS Host
1313
const UC_HOST = 'https://api.qiniu.com'; //UC Host
1414
const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
15+
const ARGUS_HOST = 'argus.atlab.ai';
1516
const RTCAPI_VERSION = 'v3';
1617

1718
// Zone 空间对应的机房

src/Qiniu/Storage/BucketManager.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,30 @@ public function move($from_bucket, $from_key, $to_bucket, $to_key, $force = fals
187187
return $error;
188188
}
189189

190+
/**
191+
* 将资源从一个空间到另一个空间
192+
*
193+
* @param $reqBody 待操作资源所在空间
194+
* @param $from_key 待操作资源文件名
195+
* @param $to_bucket 目标资源空间名
196+
* @param $to_key 目标资源文件名
197+
*
198+
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
199+
* @link https://developer.qiniu.com/dora/manual/4258/video-pulp
200+
*/
201+
public function pulpVideo($reqBody, $ops, $vid, $params = null)
202+
{
203+
$path = '/v1/video/' . $vid;
204+
$req = array();
205+
$req['data'] = $reqBody;
206+
$req['ops'] = $ops;
207+
if (isset($params)) {
208+
$req['params'] = $params;
209+
}
210+
$body = json_encode($req);
211+
return $this->arPost($path, $body);
212+
}
213+
190214
/**
191215
* 主动修改指定资源的文件类型
192216
*
@@ -359,6 +383,15 @@ private function getRsHost()
359383
return $scheme . Config::RS_HOST;
360384
}
361385

386+
private function getArHost()
387+
{
388+
$scheme = "http://";
389+
if ($this->config->useHTTPS == true) {
390+
$scheme = "https://";
391+
}
392+
return $scheme . Config::ARGUS_HOST;
393+
}
394+
362395
private function getApiHost()
363396
{
364397
$scheme = "http://";
@@ -386,6 +419,12 @@ private function rsGet($path)
386419
return $this->get($url);
387420
}
388421

422+
private function arPost($path, $body = null)
423+
{
424+
$url = $this->getArHost() . $path;
425+
return $this->pluPost($url, 'POST', $body);
426+
}
427+
389428
private function get($url)
390429
{
391430
$headers = $this->auth->authorization($url);
@@ -407,6 +446,19 @@ private function post($url, $body)
407446
return array($r, null);
408447
}
409448

449+
private function pluPost($url, $method, $body)
450+
{
451+
$headers = $this->auth->authorizationV2($url, $method, $body, 'application/json');
452+
$headers['Content-Type']='application/json';
453+
$ret = Client::post($url, $body, $headers);
454+
if (!$ret->ok()) {
455+
print($ret->statusCode);
456+
return array(null, new Error($url, $ret));
457+
}
458+
$r = ($ret->body === null) ? array() : $ret->json();
459+
return array($r, null);
460+
}
461+
410462
public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket, $force)
411463
{
412464
return self::twoKeyBatch('/copy', $source_bucket, $key_pairs, $target_bucket, $force);

0 commit comments

Comments
 (0)