Skip to content

Commit 4c4f9b8

Browse files
authored
Merge pull request #277 from ankadada/master
add video pulp demo
2 parents 2144bf5 + 3a9f9d2 commit 4c4f9b8

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

examples/pulpvideo.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
$argusManager = new \Qiniu\Storage\ArgusManager($auth, $config);
13+
14+
$reqBody = array();
15+
$reqBody['uri'] = "xxxx";
16+
17+
$ops = array();
18+
$ops = array(
19+
array(
20+
'op' => 'pulp',
21+
'params' => array(
22+
'labels' => array(
23+
array(
24+
'label' => "1",
25+
'select' => 1,
26+
'score' => 2,
27+
),
28+
)
29+
)
30+
),
31+
);
32+
33+
$params = array();
34+
$params = array(
35+
'async' => false,
36+
'vframe' => array(
37+
'mode' => 1,
38+
'interval' => 8,
39+
)
40+
);
41+
42+
$req = array();
43+
$req['data'] = $reqBody;
44+
$req['ops'] = $ops;
45+
$req['params'] = $params;
46+
$body = json_encode($req);
47+
48+
$vid = "xxxx";
49+
list($ret, $err) = $argusManager->pulpVideo($body, $vid);
50+
51+
if ($err !== null) {
52+
var_dump($err);
53+
} else {
54+
var_dump($ret);
55+
}

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/ArgusManager.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
namespace Qiniu\Storage;
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Config;
6+
use Qiniu\Zone;
7+
use Qiniu\Http\Client;
8+
use Qiniu\Http\Error;
9+
10+
/**
11+
* 主要涉及了鉴黄接口的实现,具体的接口规格可以参考
12+
*
13+
* @link https://developer.qiniu.com/dora/manual/3674/kodo-product-introduction
14+
*/
15+
final class ArgusManager
16+
{
17+
private $auth;
18+
private $config;
19+
20+
public function __construct(Auth $auth, Config $config = null)
21+
{
22+
$this->auth = $auth;
23+
if ($config == null) {
24+
$this->config = new Config();
25+
} else {
26+
$this->config = $config;
27+
}
28+
}
29+
30+
/**
31+
* 视频鉴黄
32+
*
33+
* @param $body body信息
34+
* @param $vid videoID
35+
*
36+
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
37+
* @link https://developer.qiniu.com/dora/manual/4258/video-pulp
38+
*/
39+
public function pulpVideo($body, $vid)
40+
{
41+
$path = '/v1/video/' . $vid;
42+
43+
return $this->arPost($path, $body);
44+
}
45+
46+
private function getArHost()
47+
{
48+
$scheme = "http://";
49+
if ($this->config->useHTTPS == true) {
50+
$scheme = "https://";
51+
}
52+
return $scheme . Config::ARGUS_HOST;
53+
}
54+
55+
private function arPost($path, $body = null)
56+
{
57+
$url = $this->getArHost() . $path;
58+
return $this->post($url, $body);
59+
}
60+
61+
private function post($url, $body)
62+
{
63+
$headers = $this->auth->authorizationV2($url, 'POST', $body, 'application/json');
64+
$headers['Content-Type']='application/json';
65+
$ret = Client::post($url, $body, $headers);
66+
if (!$ret->ok()) {
67+
print($ret->statusCode);
68+
return array(null, new Error($url, $ret));
69+
}
70+
$r = ($ret->body === null) ? array() : $ret->json();
71+
return array($r, null);
72+
}
73+
}

0 commit comments

Comments
 (0)