# 按标签查找视频

### 接口URL

```
http://api.polyv.net/v2/video/{userid}/search
```

### 接口说明

```
按视频标签查找视频列表
```

### 支持格式

```
XML/JSON
```

### 请求方式

```
POST,GET
```

### 请求数限制

```
TRUE
```

### 请求参数

| 参数名        | 必选    | 类型及范围  | 说明                                                                                   |
| ---------- | ----- | ------ | ------------------------------------------------------------------------------------ |
| userid     | true  | string | POLYV用户ID，<http://api.polyv.net/v2/video/{userid}/search> 中的{userid}需要替换为POLYV用户ID的值 |
| format     | false | string | 默认返回json格式，如果format=xml返回xml格式                                                       |
| jsonp      | false | string | 例如，正常情况{error:0,data:””}，加 jsonp=a后返回a({error:0,data:””})                            |
| numPerPage | false | int    | 页数                                                                                   |
| pageNum    | false | int    | 页码                                                                                   |
| ptime      | true  | string | 当前时间的毫秒级时间戳（13位），3分钟内有效                                                              |
| tag        | false | string | 视频标签                                                                                 |
| sign       | true  | string | 签名，为40位大写的SHA1值                                                                      |

#### PHP示例代码

```php
<?php
$userid="9f1e0689e1";//必选
$format="";
$jsonp="";
$numPerPage=100;
$pageNum=1;
$ptime=time()*1000;//必选
$tag="刘诗昆";
$secretkey="AkDipaULWw";
$post_data = array (
    "format" => $format,
    "jsonp" => $jsonp,
    "numPerPage" => $numPerPage,
    "pageNum" => $pageNum,
    "ptime" => $ptime,
    "tag" => $tag
);
$str="";
foreach ($post_data as $key => $value){
    if (!empty($value)) {
        $str.=$key."=".$value."&";
    }else{
        unset($post_data[$key]); 
    }
}
$str=substr($str, 0,strlen($str)-1);
$str.=$secretkey;
// echo $str;
// die();
$hash=strtoupper(sha1($str));
$post_data["sign"] = $hash;
// var_dump($post_data);
// exit();
$url="http://api.polyv.net/v2/video/{$userid}/search";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
?>
```

### 返回结果

```xml
<xml>
	<code>200</code>
	<status>success</status>
	<message>success</message>
	<data>
		<tag>刘诗昆,110435</tag>
		<mp4>http://mpv.videocc.net/9f1e0689e1/6/9f1e0689e1a156fc6b373eab9195b0c6_1.mp4</mp4>
		<title>刘诗昆钢琴教程4</title>
		<df>1</df>
		<times>68</times>
		<vid>9f1e0689e1a156fc6b373eab9195b0c6_9</vid>
		<mp4_1>http://mpv.videocc.net/9f1e0689e1/6/9f1e0689e1a156fc6b373eab9195b0c6_1.mp4</mp4_1>
		<cataid>1470122811372</cataid>
		<swf_link>http://player.polyv.net/videos/9f1e0689e1a156fc6b373eab9195b0c6_9.swf</swf_link>
		<status>60</status>
		<seed>0</seed>
		<playerwidth>600</playerwidth>
		<duration>00:35:52</duration>
		<first_image>http://img.videocc.net/uimage/9/9f1e0689e1/6/9f1e0689e1a156fc6b373eab9195b0c6_5.jpg</first_image>
		<original_definition>384x294</original_definition>
		<context></context>
		<playerheight>458</playerheight>
		<ptime>2016-04-28 12:11:10</ptime>
		<source_filesize>65153042</source_filesize>
		<filesize>69789952</filesize>
		<md5checksum>b6dc8cd9ac9f189e5e2efeba8fd62d9b</md5checksum>
		<hls>http://hls.videocc.net/9f1e0689e1/9/9f1e0689e1a156fc6b373eab9195b0c6_1.m3u8</hls>
	</data>
</xml>
```

### JSON示例

```json
{
  "code": 200,
  "status": "success",
  "message": "success",
  "data": [
    {
      "tag": "刘诗昆,110435",
      "mp4": "http://mpv.videocc.net/9f1e0689e1/6/9f1e0689e1a156fc6b373eab9195b0c6_1.mp4",
      "title": "刘诗昆钢琴教程4",
      "df": 1,
      "times": "68",
      "vid": "9f1e0689e1a156fc6b373eab9195b0c6_9",
      "mp4_1": "http://mpv.videocc.net/9f1e0689e1/6/9f1e0689e1a156fc6b373eab9195b0c6_1.mp4",
      "cataid": "1470122811372",
      "swf_link": "http://player.polyv.net/videos/9f1e0689e1a156fc6b373eab9195b0c6_9.swf",
      "status": "60",
      "seed": 0,
      "playerwidth": "600",
      "duration": "00:35:52",
      "first_image": "http://img.videocc.net/uimage/9/9f1e0689e1/6/9f1e0689e1a156fc6b373eab9195b0c6_5.jpg",
      "original_definition": "384x294",
      "context": "",
      "playerheight": "458",
      "ptime": "2016-04-28 12:11:10",
      "source_filesize": 65153042,
      "filesize": [
        69789952
      ],
      "md5checksum": "b6dc8cd9ac9f189e5e2efeba8fd62d9b",
      "hls": [
        "http://hls.videocc.net/9f1e0689e1/9/9f1e0689e1a156fc6b373eab9195b0c6_1.m3u8"
      ]
    }
  ]
}
```

### 字段说明

| 字段                   | 说明                       |
| -------------------- | ------------------------ |
| code                 | 返回码                      |
| status               | 返回状态                     |
| message              | 返回信息                     |
| total                | 总数                       |
| tag                  | 标签                       |
| mp4                  | mp4格式视频地址                |
| title                | 标题                       |
| df                   | 视频码率数                    |
| times                | 播放次数                     |
| vid                  | 视频id                     |
| mp4\_1               | 流畅码率mp4格式视频地址            |
| cataid               | 分类id， 如1为根目录             |
| swf\_link            | 返回flash链接                |
| status               | 视频状态                     |
| seed                 | 加密视频为1，非加密为0             |
| playerwidth          | 视频宽度                     |
| duration             | 时长                       |
| first\_image         | 视频首图                     |
| original\_definition | 最佳分辨率                    |
| context              | 视频描述                     |
| playerheight         | 视频高度                     |
| ptime                | 视频上传日期                   |
| source\_filesize     | 源文件大小                    |
| filesize             | 编码后各个清晰度视频的文件大小，类型为array |
| md5checksum          | md5校验码                   |
| hls                  | m3u8地址                   |

### sign的生成规则

format=参数\&jsonp=参数\&numPerPage=参数\&pageNum=参数\&ptime=参数\&tag=参数secureKey经过SHA-1加密再经过大写化 (注意：参数为空时，则在生成sign的时候不需要添加此字段。例如如果这里没有t，则不需要拼接\&t=参数)
