├── README.md
├── core
├── base.class.php
├── hunantv.class.php
├── ifeng.class.php
├── iqiyi.class.php
├── kankan.class.php
├── ku6.class.php
├── letv.class.php
├── letv.class_2013.php
├── pps.class.php
├── pptv.class.php
├── qq.class.php
├── renren56.class.php
├── sina.class.php
├── sohu.class.php
├── tudou.class.php
├── tv189.class.php
├── youku.class.php
└── youku_2013.class.php
├── getVideo.php
└── parserVideo.class.php
/README.md:
--------------------------------------------------------------------------------
1 | # parseVideo
2 | 解析国内各大视频网站视频 php 2013年
3 |
4 | getVideo.php 是个测试php
5 |
--------------------------------------------------------------------------------
/core/base.class.php:
--------------------------------------------------------------------------------
1 | 0) {
157 | curl_multi_select($queue, 0.5);
158 | }
159 | } while ($active);
160 | curl_multi_close($queue);
161 | return $responses;
162 | }
163 |
164 |
165 | /**
166 | * [get_proxy 获取国内的代理ip和端口]
167 | * @return [type] [description]
168 | */
169 | private static function get_proxy()
170 | {
171 | //http://cn-proxy.com/ 国内代理
172 | $url = "http://cn-proxy.com/feed";
173 | $html = Base::_cget($url, '', false);
174 | preg_match_all('#
([^<]+) | [\r\n]+80 | [\r\n]+高度匿名 | #ms', $html, $proxys);
175 | $rand = mt_rand(0, (count($proxys[1]) - 1)); //随机返回一个ip
176 | return $proxys[1][$rand] . ":80";
177 | }
178 | }
--------------------------------------------------------------------------------
/core/hunantv.class.php:
--------------------------------------------------------------------------------
1 | = 0) {
58 | $_local6 = static::getVRSXORCode(intval($_local3[(($_local4 - $_local5) - 1)], 16), $_local5);
59 | $_local2 = (static::fromCharCode($_local6).$_local2);
60 | $_local5--;
61 | };
62 | return $_local2;
63 | }
64 | private static function getVRSXORCode($_arg1, $_arg2){
65 |
66 | $_local3 = ($_arg2 % 3);
67 | if ($_local3 == 1){
68 | return (($_arg1 ^ 121));
69 | };
70 | if ($_local3 == 2){
71 | return (($_arg1 ^ 72));
72 | };
73 | return (($_arg1 ^ 103));
74 | }
75 |
76 | private static function fromCharCode($codes){
77 | if (is_scalar($codes)) {
78 | $codes = func_get_args();
79 | }
80 | $str = '';
81 | foreach ($codes as $code) {
82 | $str .= chr($code);
83 | }
84 | return $str;
85 | }
86 | /**
87 | * [parseFlv2 解析网站flv格式的视频,第二种方法]
88 | * @param [type] $tvid [description]
89 | * @param [type] $vid [description]
90 | * @return [type] [description]
91 | */
92 | private static function parseFlv2($tvid,$vid){
93 |
94 |
95 | $api_url = "http://cache.video.qiyi.com/vms?key=fvip&src=1702633101b340d8917a69cf8a4b8c7c";
96 | $api_url = $api_url."&tvId=".$tvid."&vid=".$vid."&vinfo=1&tm=".self::$deadpara."&enc=".static::calenc($tvid);
97 |
98 | $video_datas = json_decode(Base::_cget($api_url),true);
99 |
100 |
101 | $vs = $video_datas['data']['vp']['tkl'][0]['vs']; //.data.vp.tkl[0].vs
102 |
103 |
104 | $time_url = "http://data.video.qiyi.com/t?tn=".static::randomFloat();
105 |
106 |
107 | $time_datas = json_decode(Base::_cget($time_url),true);
108 |
109 |
110 | $server_time = $time_datas['t'];
111 |
112 |
113 | $urls_data = $data = array();
114 | if(is_array($vs) && count($vs)>0){
115 | foreach($vs as $val){
116 | //720p 和1080p 的视频地址暂时无法获得。
117 | $data['seconds'] = $val['duration'];
118 | foreach ($val['fs'] as $v){
119 |
120 | $this_link = $v['l'];
121 |
122 |
123 |
124 | if($val['bid'] == 4 || $val['bid'] == 5 || $val['bid'] == 10){
125 | $this_link = static::getVrsEncodeCode($this_link);
126 | }
127 | $sp = explode('/',$this_link);
128 | $sp_length = count($sp);
129 |
130 | $fileId = explode('.',$sp[$sp_length-1])[0];
131 | $this_key = static::calmd($server_time,$fileId);
132 |
133 |
134 |
135 |
136 | $this_link = $this_link.'?ran='.self::$deadpara.'&qyid=08ca8cb480c0384cb5d3db068161f44f&qypid='.$tvid.'_11&retry=1';
137 |
138 | $final_url = "http://data.video.qiyi.com/".$this_key."/videos".$this_link;
139 |
140 | if($val['bid'] == 96)$urls_data['fluent'][] = $final_url;
141 | if($val['bid'] == 1)$urls_data['normal'][] = $final_url;
142 | if($val['bid'] == 2)$urls_data['high'][] = $final_url;
143 | if($val['bid'] == 3)$urls_data['super'][] = $final_url;
144 | if($val['bid'] == 4)$urls_data['SUPER_HIGH'][] = $final_url;
145 | if($val['bid'] == 5)$urls_data['FULL_HD'][] = $final_url;
146 | if($val['bid'] == 10)$urls_data['FOUR_K'][] = $final_url;
147 | }
148 |
149 | }
150 |
151 | if(!empty($urls_data['fluent'])) $data['极速'] = self::getVideoUrl($urls_data['fluent']);
152 | if(!empty($urls_data['normal'])) $data['流畅'] = self::getVideoUrl($urls_data['normal']);
153 | if(!empty($urls_data['high'])) $data['高清'] = self::getVideoUrl($urls_data['high']);
154 | if(!empty($urls_data['super'])) $data['超清'] = self::getVideoUrl($urls_data['super']);
155 | if(!empty($urls_data['SUPER_HIGH'])) $data['720P'] = self::getVideoUrl($urls_data['SUPER_HIGH']);
156 | if(!empty($urls_data['FULL_HD'])) $data['1080P'] = self::getVideoUrl($urls_data['FULL_HD']);
157 | if(!empty($urls_data['FOUR_K'])) $data['4K'] = self::getVideoUrl($urls_data['FOUR_K']);
158 |
159 |
160 |
161 | return $data;
162 | }else{
163 | return false;
164 | }
165 | }
166 |
167 | /**
168 | * [getVideoUrl description]
169 | * @param [type] $url_data [description]
170 | * @return [type] [description]
171 | */
172 | private static function getVideoUrl($url_data){
173 |
174 |
175 | // $url_data = http://data.video.qiyi.com/4739e996fde3348eeef0da8684310ab4/videos/v0/20141221/38/e6/1974401616a8737fa3dd595db0eaefba.f4v
176 | //客户端需要请求这个地址然后返回下面的数据,l是最终的下载地址,因为这个下载地址是有时间限制的,如果无法下载,请再次请求上面那个url,重新返回真正的下载地址
177 |
178 | //视频地址:http://data.video.qiyi.com/4739e996fde3348eeef0da8684310ab4/videos/v0/20141221/38/e6/1974401616a8737fa3dd595db0eaefba.f4v 这个地址也有时间限制,时间长了话,请求服务器会返回405,客户端需要重新向自己的服务器加载
179 |
180 | // {
181 | // "t": "CT|ShangHai-101.81.48.14",
182 | // "s": "1",
183 | // "z": "hengyang3_ct",
184 | // "h": "0",
185 | // "l": "http://220.170.79.37/videos/v0/20141221/38/e6/4be4e1cad4374d3447be144397366ff8.f4v?key=8f5bdcd17a8765c&ran=1000&qyid=08ca8cb480c0384cb5d3db068161f44f&qypid=335764500_11&retry=1&uuid=6551300e-5497c256-36",
186 | // "e": "0"
187 | // }
188 |
189 | $data = self::rolling_curl($url_data);
190 | $urls = array();
191 | foreach($url_data as $val){
192 | //按顺序排列视频 url
193 | if(empty($data[$val]['error'])){
194 |
195 | $urls[] = $data[$val]['results'];
196 | }
197 | // $urls[] = $val;
198 | }
199 |
200 | return $urls;
201 | // return $url_data;
202 | }
203 |
204 | /**
205 | * [rolling_curl curl并发]
206 | * @param [type] $urls [urls数组]
207 | * @return [type] [description]
208 | */
209 | private static function rolling_curl($urls)
210 | {
211 | $queue = curl_multi_init();
212 | $map = array();
213 | foreach ($urls as $url) {
214 | $ch = curl_init();
215 | curl_setopt($ch, CURLOPT_URL, $url);
216 | curl_setopt($ch, CURLOPT_TIMEOUT, 10);
217 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
218 | curl_setopt($ch, CURLOPT_HEADER, 0);
219 | curl_setopt($ch, CURLOPT_USERAGENT, Base::USER_AGENT);
220 | curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
221 | curl_multi_add_handle($queue, $ch);
222 | $map[(string)$ch] = $url;
223 | }
224 | $responses = array();
225 | do {
226 | while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM);
227 | if ($code != CURLM_OK) {
228 | break;
229 | }
230 | // a request was just completed -- find out which one
231 | while ($done = curl_multi_info_read($queue)) {
232 | // get the info and content returned on the request
233 | $info = curl_getinfo($done['handle']);
234 | $error = curl_error($done['handle']);
235 | $results = self::callback_match(curl_multi_getcontent($done['handle']));
236 | $responses[$map[(string)$done['handle']]] = compact('error','results');
237 | // remove the curl handle that just completed
238 | curl_multi_remove_handle($queue, $done['handle']);
239 | curl_close($done['handle']);
240 | }
241 | // Block for data in / output; error handling is done by curl_multi_exec
242 | if ($active > 0) {
243 | curl_multi_select($queue, 0.5);
244 | }
245 | } while ($active);
246 | curl_multi_close($queue);
247 |
248 | return $responses;
249 | }
250 |
251 | /**
252 | * [callback_match 回调获取视频的地址]
253 | * @param [type] $data [description]
254 | * @return [type] [description]
255 | */
256 | private static function callback_match($data){
257 |
258 | preg_match('#"l":"([^"]+)&src=(.*?)"#iU',$data,$matchs);
259 | $url = $matchs[1];
260 |
261 | // return json_decode($data,true);
262 | return $url;
263 | }
264 | }
265 |
--------------------------------------------------------------------------------
/core/kankan.class.php:
--------------------------------------------------------------------------------
1 | 0){
54 | //只选取前四段。
55 | for($i=0;$i<4;$i++){
56 | $data['flv'][self::$sharpness_array[$i]][] = self::getVideoUrl($gcid_array[$i]);
57 | }
58 | }
59 |
60 | return $data;
61 | }
62 |
63 | /**
64 | * [getVideoUrl 根据gcid来获得视频地址]
65 | * @param [type] $gcid [description]
66 | * @return [type] [description]
67 | */
68 | private static function getVideoUrl($gcid,$file_type="flv"){
69 | if($file_type == "mp4"){
70 | $get_url = "http://mp4.cl.kankan.com/getCdnresource_flv?gcid=";
71 | $url = $get_url.strtoupper($gcid);
72 | $video_html = Base::_cget($url); //获得视频地址信息
73 | preg_match('#ip:"([^"]+)?".*path:"([^"]+)?"#',$video_html,$videos);
74 | preg_match("#param1:([\d]+),param2:([\d]+)#",$video_html,$params);
75 | $video_url = "http://".$videos[1]."/".$videos[2]."?key=".md5('xl_mp43651'.$params[1].$params[2])."&key1=".$params[2];
76 | //mp4 格式的key 为 md5('xl_mp43651'.$params[1].$params[2])
77 | }else{
78 | $get_url = "http://p2s.cl.kankan.com/getCdnresource_flv?gcid=";
79 | $url = $get_url.strtoupper($gcid);
80 | $video_html = Base::_cget($url); //获得视频地址信息
81 | preg_match('#ip:"([^"]+)?".*path:"([^"]+)?"#',$video_html,$videos);
82 | $video_url = "http://".$videos[1]."/".$videos[2];
83 | }
84 | return $video_url;
85 |
86 | }
87 |
88 | //获取电视剧的地址列表
89 | public static function getVideoList($movie_id,$subids,$video_names){
90 | $data = array();
91 | if(is_array($subids) && count($subids)>0){
92 | foreach($subids as $k=>$v){
93 | $data[$k]['name'] = iconv("gbk","utf-8",$video_names[$k]); //获得视频的名字
94 | $url = "http://api.movie.kankan.com/vodjs/subdata/".floor($movie_id/1000)."/".$movie_id."/".$v.".js";
95 | $movie_str = Base::_cget($url);
96 | preg_match("#surls:\s*\[([^]]+)\]#",$movie_str,$surls);
97 | eval('$surls_array = array('.$surls[1].');'); //转化为数组
98 | $surls_array = array_filter($surls_array);// 过滤数组
99 | preg_match("#msurls:\s*\[([^]]+)\]#",$movie_str,$msurls);
100 | eval('$msurls_array = array('.$msurls[1].');');
101 | $msurls_array = array_filter($msurls_array);
102 | if(is_array($surls_array)&&count($surls_array)>0){
103 | foreach($surls_array as $key => $val){
104 | $tmp_array = explode('/',$val);
105 | $gcid = $tmp_array[4];
106 | $data[$k]['flv'][self::$sharpness_array[$key]][] = self::getVideoUrl($gcid);
107 | }
108 | }
109 | if(is_array($msurls_array)&&count($msurls_array)>0){
110 | foreach($msurls_array as $key => $val){
111 | $tmp_array = explode('/',$val);
112 | $gcid = $tmp_array[4];
113 | $data[$k]['mp4'][self::$sharpness_array[$key]][] = self::getVideoUrl($gcid,"mp4");
114 | }
115 | }
116 | }
117 | }
118 | return $data;
119 | }
120 | }
--------------------------------------------------------------------------------
/core/ku6.class.php:
--------------------------------------------------------------------------------
1 | $v){
33 | //根据码率 获得相应的 视频地址
34 | $data[$k][] = $val."?strart=0&rate=".$v;
35 | }
36 | }
37 | }
38 | }
39 | }
40 | return $data;
41 |
42 | }else{
43 | return false;
44 | }
45 |
46 |
47 | }
48 |
49 | /**
50 | * [getVideoRate 获得视频的码率数组]
51 | * @param [type] $url [description]
52 | * @return [type] [description]
53 | */
54 | private static function getVideoRate($url){
55 | $sharpness = array();
56 | $video_info = json_decode(Base::_cget($url),true);
57 | $video_rate= explode(";",$video_info["RateInfo"]);
58 | if(is_array($video_rate)&&!empty($video_rate)){
59 | foreach($video_rate as $key => $val){
60 | $tmp_array = explode("@",$val);
61 | if($tmp_array[1] == "流 畅") $sharpness["fluent"] = $tmp_array[0];
62 | if($tmp_array[1] == "标 清") $sharpness["normal"] = $tmp_array[0];
63 | if($tmp_array[1] == "高 清") $sharpness["high"] = $tmp_array[0];
64 | if($tmp_array[1] == "超 清") $sharpness["super"] = $tmp_array[0];
65 | }
66 | }
67 | return $sharpness;
68 | }
69 | }
--------------------------------------------------------------------------------
/core/letv.class.php:
--------------------------------------------------------------------------------
1 | $val){
23 | //加上后面的参数才可以播放
24 | if($key == "350") $data['fluent'][] = Letv::getPlayUrl($val[0]);
25 | if($key == "1000") $data['normal'][] = Letv::getPlayUrl($val[0]);
26 | if($key == "1300") $data['high'][] = Letv::getPlayUrl($val[0]);
27 | if($key == "720p") $data['super'][] = Letv::getPlayUrl($val[0]);
28 | if($key == "1080p") $data['original'][] = Letv::getPlayUrl($val[0]);
29 | }
30 | }
31 | $data['title'] = $video_data['title'];
32 | $data['seconds'] = $video_data['duration'];
33 | return $data;
34 | }else{
35 | return false;
36 | }
37 | }
38 | }
39 |
40 | /**
41 | * [parseXml 解析相关xml]
42 | * @param [type] $url [description]
43 | * @return [type] [description]
44 | */
45 | static public function parseXml($url){
46 | $xml_str = Base::_cget($url);
47 | $xml_obj = @simplexml_load_string($xml_str);
48 | $playurl = $xml_obj->playurl;
49 | if(!empty($playurl)){
50 | $play_str = strval($playurl);
51 | $play_json = json_decode($play_str,true);
52 | if(is_array($play_json)){
53 | return $play_json;
54 | }else{
55 | return false;
56 | }
57 |
58 | }else{
59 | return false;
60 | }
61 | }
62 |
63 | /**
64 | * [getKey 2014 letv tkey值的算法]
65 | * @param [type] $t [时间戳]
66 | * @return [type] [description]
67 | */
68 | static private function getKey($t){
69 | for($e, $s = 0; $s < 8; $s++){
70 | $e = 1 & $t;
71 | $t >>= 1;
72 | $e <<= 31;
73 | $t += $e;
74 | }
75 | return $t^185025305;
76 | }
77 |
78 | /**
79 | * [getPlayUrl 根据前面拿到的url 获得视频地址]
80 | * @param [type] $url [description]
81 | * @return [type] [description]
82 | */
83 | static private function getPlayUrl($url){
84 | $tn = (mt_rand(10000,99999)*865);
85 | $url = $url."&termid=1&format=1&hwtype=un&ostype=Windows8.1&tag=letv&sign=letv&expect=3&tn=0.".$tn."&pay=0&rateid=1000";
86 | $playJson = Base::_cget($url);
87 | $urls = json_decode($playJson,true);
88 | if($urls['location']){
89 | return $urls['location'];
90 | }else{
91 | return false;
92 | }
93 |
94 | }
95 | }
--------------------------------------------------------------------------------
/core/letv.class_2013.php:
--------------------------------------------------------------------------------
1 | $val){
22 | if($key == "350") $data['fluent'][] = $val[0];
23 | if($key == "1000") $data['normal'][] = $val[0];
24 | if($key == "1300") $data['high'][] = $val[0];
25 | if($key == "720p") $data['super'][] = $val[0];
26 | if($key == "1080p") $data['original'][] = $val[0];
27 | }
28 | }
29 | $data['title'] = $video_data['title'];
30 | $data['seconds'] = $video_data['duration'];
31 | return $data;
32 | }else{
33 | return false;
34 | }
35 | }
36 | }
37 |
38 | /**
39 | * [parseXml 解析相关xml]
40 | * @param [type] $url [description]
41 | * @return [type] [description]
42 | */
43 | public static function parseXml($url){
44 | $xml_str = Base::_cget($url);
45 | $xml_obj = @simplexml_load_string($xml_str);
46 | $playurl = $xml_obj->playurl;
47 | if(!empty($playurl)){
48 | $play_str = strval($playurl);
49 | $play_json = json_decode($play_str,true);
50 | if(is_array($play_json)){
51 | return $play_json;
52 | }else{
53 | return false;
54 | }
55 |
56 | }else{
57 | return false;
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/core/pps.class.php:
--------------------------------------------------------------------------------
1 | $val){
58 | //构建视频地址 视频地址不能带 key值
59 | if($key == 0) $data['normal'][]= 'http://'.$val['host'].'/0/'.$val['file'].'?k='.$val['key'].'&type=web.fpp';
60 | if($key == 1) $data['high'][]= 'http://'.$val['host'].'/0/'.$val['file'].'?k='.$val['key'].'&type=web.fpp';
61 | if($key == 2) $data['super'][]= 'http://'.$val['host'].'/0/'.$val['file'].'?k='.$val['key'].'&type=web.fpp';
62 | if($key == 5) $data['fluent'][]= 'http://'.$val['host'].'/0/'.$val['file'].'?k='.$val['key'].'&type=web.fpp';
63 | }
64 | return $data;
65 | }else{
66 | return false;
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/core/qq.class.php:
--------------------------------------------------------------------------------
1 | 10209,"shd"=>10201,"hd"=>10202,"sd"=>10203); //视频清晰度
58 | $data = $datas = $data_videos = array();
59 | if($vi['st'] ==2 && $vi['fst'] == 5 && $infos['s'] == 'o'){
60 | foreach ($video_type as $val){
61 | if(in_array($val['name'],array_keys($sharpness))){
62 | for($i=1;$i<=$counts;$i++){
63 | $fmt = $val['name']; //视频类型
64 | $format = $val['id']; //视频类型id
65 | //$filename = substr($vi['fn'],0,-4).'.1'.substr($vi['fn'],-4); //这个 fn是变化的
66 | $filename = $vid.".p".substr($format,2).".{$i}.mp4";
67 | $br = $vi['br'];
68 | $vt = $vi['ul']['ui']['0']['vt'];
69 | $path = $vi['ul']['ui']['0']['url'];
70 | $datas[] = array('path'=>$path,'vid'=>$vid,'filename'=>$filename,'vt'=>$vt,'format'=>$format,'br'=>$br,'fmt'=>$fmt);
71 | /* 下面的方法 一次只返回一段视频地址 速度太慢
72 | $keyjson = self::getKey($vid,$filename,$vt,$format);
73 | if(!empty($keyjson['key'])){
74 | //echo "获得视频段 {$fmt} {$i} ".date("Y-m-d H:i:s").PHP_EOL;
75 | //videourl = infoData["path"] + infoData["fn"] + "?vkey=" + keyjson.key + "&br=" + infoData["br"] + "&platform=2&fmt=" + s.fmt + "&level=" + keyjson.level + "&sdtfrom=" + getMp4Key();
76 | $videourl = $path.$filename."?vkey=".$keyjson['key']."&br=".$br."&platform=2&fmt=".$fmt."&level=".$keyjson['level']."&sdtfrom=v1000";
77 | $data[$fmt][] = $videourl;
78 | }
79 | */
80 | }
81 | }
82 | }
83 | $url = "http://vv.video.qq.com/getkey";
84 | $data_videos = self::rolling_curl($url,$datas);
85 | $normal = $original = $high = $super = array();
86 | foreach($data_videos as $val){
87 | if(empty($val['error'])){
88 | if($val['results']['fmt'] == 'sd') $normal[$val['results']['id']]= $val['results']['url'];
89 | if($val['results']['fmt'] == 'fhd') $original[$val['results']['id']]= $val['results']['url'];
90 | if($val['results']['fmt'] == 'hd') $high[$val['results']['id']]= $val['results']['url'];
91 | if($val['results']['fmt'] == 'shd') $super[$val['results']['id']]= $val['results']['url'];
92 |
93 | }
94 | }
95 | //视频清晰度判定和视频排序
96 | if(!empty($normal)) ksort($normal); sort($normal); $data['normal'] = $normal;
97 | if(!empty($original)) ksort($original); sort($original); $data['original'] = $original;
98 | if(!empty($high)) ksort($high); sort($high); $data['high'] = $high;
99 | if(!empty($super)) ksort($super); sort($super); $data['super'] = $super;
100 | $data['title'] = $vi['ti'];//标题
101 | $data['seconds'] = $infos['preview'];//时长
102 | return $data;
103 | }
104 | }
105 | /**
106 | * [createGUID 生成随机数]
107 | * @param string $len [description]
108 | * @return [type] [description]
109 | */
110 | private static function createGUID($len='') {
111 | $len = $len?$len:32;
112 | $guid = "";
113 | for ($i = 1; $i <= $len; $i++) {
114 | $n = dechex(floor(mt_rand(0,15)));
115 | $guid .= $n;
116 | }
117 | return $guid;
118 | }
119 |
120 | private static function getSpeed(){
121 | $data = array(
122 | "adspeed"=>"0",
123 | "otype"=>"json",
124 | "history"=>"0,0,".time()
125 | );
126 | $url = "http://vv.video.qq.com/getspeed";
127 | $jsonStr = Base::_cget($url,Base::USER_AGENT,$data,self::REFERER);
128 | $jsonArr = json_decode(substr($jsonStr,strpos($jsonStr, '{'),-1),true);
129 | return $jsonArr;
130 | }
131 | //获得腾讯的 getifo 信息
132 | private static function getInfo($vid){
133 | $data = array(
134 | "ran"=>floatval('0.'.mt_rand(10000000,90000000)),
135 | "charge"=>"0",
136 | "pid"=>self::createGUID(48),
137 | "fp2p"=>"1",
138 | "otype"=>"json",
139 | "platform"=>"11",
140 | "appver"=>"3.2.11.159",
141 | "vids"=>$vid,
142 | "speed"=>"0"
143 | );
144 | $url = "http://vv.video.qq.com/getinfo";
145 | $jsonStr = Base::_cget($url,Base::USER_AGENT,$data,self::REFERER);
146 | $jsonArr = json_decode(substr($jsonStr,strpos($jsonStr, '{'),-1),true);
147 | return $jsonArr;
148 |
149 | }
150 | /**
151 | * [getKey 根据参数获得视频地址参数]
152 | * @param [type] $vid [description]
153 | * @param [type] $filename [description]
154 | * @param [type] $vt [description]
155 | * @param [type] $format [description]
156 | * @return [type] [description]
157 | */
158 | private static function getKey($vid,$filename,$vt,$format){
159 | $url = "http://vv.video.qq.com/getkey";
160 | $data = array(
161 | "otype"=>"json",
162 | "charge"=>"0",
163 | "ran"=>floatval('0.'.mt_rand(10000000,90000000)),
164 | "filename"=>$filename,
165 | "platform"=>"11",
166 | "format"=>$format,
167 | "vid"=>$vid,
168 | "vt"=>$vt,
169 | "defaultfmt"=>"hd"
170 | );
171 | $jsonStr = Base::_cget($url,Base::USER_AGENT,$data,self::REFERER);
172 | $jsonArr = json_decode(substr($jsonStr,strpos($jsonStr, '{'),-1),true);
173 | return $jsonArr;
174 | }
175 |
176 | /**
177 | * [rolling_curl curl并发]
178 | * @param [type] $urls [urls数组]
179 | * @return [type] [description]
180 | */
181 | private static function rolling_curl($url,$datas)
182 | {
183 | $queue = curl_multi_init();
184 | $map = $data = array();
185 | $i = 0;
186 | foreach ($datas as $val) {
187 | $data = array(
188 | "otype"=>"json",
189 | "charge"=>"0",
190 | "ran"=>floatval('0.'.mt_rand(10000000,90000000)),
191 | "filename"=>$val['filename'],
192 | "platform"=>"11",
193 | "format"=>$val['format'],
194 | "vid"=>$val['vid'],
195 | "vt"=>$val['vt'],
196 | "defaultfmt"=>"hd"
197 | );
198 |
199 | $ch = curl_init();
200 | curl_setopt($ch, CURLOPT_URL, $url);
201 | curl_setopt($ch, CURLOPT_TIMEOUT, 10);
202 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
203 | curl_setopt($ch, CURLOPT_HEADER, 0);
204 | curl_setopt($ch, CURLOPT_REFERER,self::REFERER);
205 | curl_setopt($ch, CURLOPT_USERAGENT, Base::USER_AGENT);
206 | curl_setopt($ch, CURLOPT_POST, 1);
207 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
208 | curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
209 | curl_multi_add_handle($queue, $ch);
210 | $map[(string)$ch] = $i;
211 | $i+=1;
212 | }
213 | $responses = array();
214 |
215 | do {
216 | while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM);
217 | if ($code != CURLM_OK) {
218 | break;
219 | }
220 | // a request was just completed -- find out which one
221 | while ($done = curl_multi_info_read($queue)) {
222 | // get the info and content returned on the request
223 | //$info = curl_getinfo($done['handle']);
224 | $error = curl_error($done['handle']);
225 | $results = self::callback_parse(curl_multi_getcontent($done['handle']),$map[(string)$done['handle']],$datas[$map[(string)$done['handle']]]);
226 | $responses[$map[(string)$done['handle']]] = compact('error','results');
227 | // remove the curl handle that just completed
228 | curl_multi_remove_handle($queue, $done['handle']);
229 | curl_close($done['handle']);
230 | }
231 | // Block for data in / output; error handling is done by curl_multi_exec
232 | if ($active > 0) {
233 | curl_multi_select($queue, 0.5);
234 | }
235 | } while ($active);
236 | curl_multi_close($queue);
237 | return $responses;
238 | }
239 |
240 | /**
241 | * [callback_parse 回调拼接视频地址参数]
242 | * @param [type] $json_str [description]
243 | * @param [type] $id [description]
244 | * @param [type] $data [description]
245 | * @return [type] [description]
246 | */
247 | private static function callback_parse($json_str,$id,$data){
248 | $json_arr = json_decode(substr($json_str,strpos($json_str, '{'),-1),true);
249 | $video_url = $data['path'].$data['filename']."?vkey=".$json_arr['key']."&br=".$data['br']."&platform=2&fmt=".$data['fmt']."&level=".$json_arr['level']."&sdtfrom=v1000";
250 | return array('fmt'=>$data['fmt'],'id'=>$id,'url'=>$video_url);
251 | }
252 | }
--------------------------------------------------------------------------------
/core/renren56.class.php:
--------------------------------------------------------------------------------
1 | $val){
24 | if($val['type'] == "normal") $data['normal'][] = $val['url'];
25 | if($val['type'] == "clear") $data['high'][] = $val['url'];
26 | if($val['type'] == "super") $data['super'][] = $val['url'];
27 | }
28 |
29 | return $data;
30 | }else{
31 | return false;
32 | }
33 | }else{
34 | return false;
35 | }
36 |
37 | }
38 | }
--------------------------------------------------------------------------------
/core/sina.class.php:
--------------------------------------------------------------------------------
1 | $vid,
69 | 'uid' => '1',
70 | 'pid' => '1',
71 | 'tid' => '334',
72 | 'plid' => '4001',
73 | 'prid' => 'ja_7_2184731619',
74 | 'referrer' => 'http://video.sina.com.cn',
75 | 'ran' => $ran,
76 | 'r' => 'video.sina.com.cn',
77 | 'v' => '4.1.42.29',
78 | 'p' => 'i',
79 | 'k' => $key,
80 | ));
81 | return $xml_url;
82 | }
83 |
84 | private static function parseXml($url){
85 | $video = $seconds = $title = '';
86 | $video_url = array();
87 | $xml_str = Base::_cget($url);
88 | if(!empty($xml_str)){
89 | $video = @simplexml_load_string($xml_str);
90 | $seconds = intval($video->timelength)/1000; //获得时长
91 | $title = strval($video->vname);
92 | //解析视频地址
93 | $durl = $video->durl;
94 | for($i=0;$i<$durl->count();$i++){
95 | $video_url[] = strval($durl[$i]->url);
96 | }
97 | return array("title"=>$title,"seconds"=>$seconds,'url'=>$video_url);
98 | }else{
99 | return false;
100 | }
101 | }
102 | }
--------------------------------------------------------------------------------
/core/sohu.class.php:
--------------------------------------------------------------------------------
1 | $ip){
31 | $url = "http://{$ip}"; //判断ip是否可以访问
32 | $header_array = array();
33 | $header_array = @get_headers($url);
34 | $is_ok = strpos($header_array[0], "OK");
35 | if(empty($header_array) || $is_ok == false){
36 | unset($sub_ip[$k]);
37 | sort($sub_ip);
38 | }
39 | }
40 | */
41 | $api_url = "http://".$sub_ip[0]."/vrs_flash.action?vid={$vid}&af=1&out=-1&g=8&r=2&t=0.".mt_rand(100,999);
42 | $video_datas = json_decode(Base::_cget($api_url),true);
43 | if(is_array($video_datas)&& !empty($video_datas['data'])){
44 | $video_data = $video_datas['data'];
45 | $data['title'] = $video_data['tvName'];
46 | $data['seconds'] = $video_data['totalDuration'];
47 | //获取不同清晰版本的视频地址
48 | if($video_data['relativeId']) $data['fluent'] = self::parseVideoUrl($video_data['relativeId'],$sub_ip);
49 | if($video_data['norVid']) $data['normal'] = self::parseVideoUrl($video_data['norVid'],$sub_ip);
50 | if($video_data['highVid']) $data['high'] = self::parseVideoUrl($video_data['highVid'],$sub_ip);
51 | if($video_data['superVid']) $data['super'] = self::parseVideoUrl($video_data['superVid'],$sub_ip);
52 | if($video_data['oriVid']) $data['original'] = self::parseVideoUrl($video_data['oriVid'],$sub_ip);
53 | return $data;
54 | }else{
55 | return false;
56 | }
57 | }
58 |
59 | //拼接参数解析视频的方法
60 | private static function parseVideoUrl($vid,$sub_ip){
61 | $api_url = "http://".$sub_ip[0]."/vrs_flash.action?vid={$vid}&out=0&g=8&r=2&t=0.".mt_rand(100,999);
62 | $video_data = json_decode(Base::_cget($api_url),true);
63 | $rands = mt_rand(1,22);
64 | $data = $urls = $data_urls = $params = array();
65 | if(is_array($video_data)&& !empty($video_data)){
66 | foreach($video_data['data']['clipsURL'] as $key => $val){
67 | $su_key = $video_data['data']['su'][$key];
68 | $url = "http://".$video_data['allot']."/?prot=".$video_data['prot']."&file=".ltrim($val,"http://data.vod.itc.cn")."&new=".$su_key;
69 | $urls[$key] = $url;
70 | $params[$key]['su_key'] = $su_key;
71 | $params[$key]['rands'] = $rands;
72 | /* //这里一次只能获取一段视频,速度慢
73 | $param_array = explode("|",Base::_cget($url));
74 | //视频截图地址 http://data.vod.itc.cn/preview?file=/233/52/28FAAL9Tq9UX9kOatm6bj7.mp4&start=28
75 | //相对视频地址 中间多了个thumb http://219.238.10.45/sohu/thumb/1/233/52/28FAAL9Tq9UX9kOatm6bj7.mp4?start=28&key=uGacwCdCKICxxJnliepKI_od5tZlsh3ONPL_ow..&n=13&a=4019&cip=101.39.251.131
76 | $video_url = substr($param_array[0],0,-1).$su_key."?start=&key=" .$param_array[3]."&n=".$rands."&a=4019";
77 | $data[] = $video_url;
78 | */
79 | }
80 | //curl 并发获取视频地址 排序
81 | $data_urls = self::rolling_curl_url($urls,$params);
82 | ksort($data_urls);
83 | $data = $data_urls;
84 | return $data;
85 | }else{
86 | return false;
87 | }
88 | }
89 |
90 | //另外一种解析视频的方法 速度慢
91 | private static function parseVideoUrl2($vid,$sub_ip){
92 | $data = $urls = $data_urls= array();
93 | $api_url = "http://".$sub_ip[0]."/vrs_flash.action?vid={$vid}&out=0&g=8&r=2&t=0.".mt_rand(100,999);
94 | $video_data = json_decode(Base::_cget($api_url),true);
95 | if(is_array($video_data)&& !empty($video_data)){
96 | foreach($video_data['data']['clipsURL'] as $key => $val){
97 | $su_key = $video_data['data']['su'][$key];
98 | $url = "http://data.vod.itc.cn/preview?file=".$su_key;
99 | $urls[] = $url;
100 | /*curl 获取header
101 | $headers = Base::getHeader($url);
102 | preg_match("#Location:\s*(.+)#",$headers,$locations);
103 | $param_array = $locations[1];
104 | */
105 | /* //一次获得一个视频地址的,速度慢
106 | $param_array = get_headers($url,1);
107 | //视频截图地址 http://data.vod.itc.cn/preview?file=/233/52/28FAAL9Tq9UX9kOatm6bj7.mp4&start=28
108 | //相对视频地址 中间多了个thumb http://219.238.10.45/sohu/thumb/1/233/52/28FAAL9Tq9UX9kOatm6bj7.mp4?start=28&key=uGacwCdCKICxxJnliepKI_od5tZlsh3ONPL_ow..&n=13&a=4019&cip=101.39.251.131
109 | $video_url = str_replace('/thumb/', '/',$param_array['Location']); //获得地址转向
110 | $data[] = $video_url;
111 | */
112 | }
113 | $data_urls = self::rolling_curl_url2($urls);
114 | ksort($data_urls); //获得数组根据key值排序
115 | $data = array_values($data_urls);
116 | return $data;
117 | }else{
118 | return false;
119 | }
120 | }
121 |
122 | /**
123 | * [rolling_curl_code curl并发获得ip 的http状态码]
124 | * @param [type] $ips [description]
125 | * @return [type] [description]
126 | */
127 | private static function rolling_curl_code($ips){
128 | $queue = curl_multi_init();
129 | $map = array();
130 | $url = null;
131 | foreach ($ips as $ip) {
132 | $ch = curl_init();
133 | $url = "http://{$ip}";
134 | curl_setopt($ch, CURLOPT_URL, $url);
135 | curl_setopt($ch, CURLOPT_TIMEOUT, 10);
136 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
137 | curl_setopt($ch, CURLOPT_HEADER, 0);
138 | curl_setopt($ch, CURLOPT_USERAGENT, Base::USER_AGENT);
139 | curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
140 | curl_multi_add_handle($queue, $ch);
141 | $map[(string)$ch] = $ip; //将ip当作 数组的value
142 | }
143 | $responses = array();
144 |
145 | do {
146 | while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM);
147 | if ($code != CURLM_OK) {
148 | break;
149 | }
150 | // a request was just completed -- find out which one
151 | while ($done = curl_multi_info_read($queue)) {
152 | // get the info and content returned on the request
153 | $http_code = curl_getinfo($done['handle'],CURLINFO_HTTP_CODE); //获得HTTP 状态码
154 | //$error = curl_error($done['handle']); //获得错误信息
155 | //$results = curl_multi_getcontent($done['handle']); //获得结果
156 | if($http_code != 404){
157 | $responses[$map[(string)$done['handle']]] = compact('http_code');
158 | }
159 | // remove the curl handle that just completed
160 | curl_multi_remove_handle($queue, $done['handle']);
161 | curl_close($done['handle']);
162 | }
163 | // Block for data in / output; error handling is done by curl_multi_exec
164 | if ($active > 0) {
165 | curl_multi_select($queue, 0.5);
166 | }
167 | } while ($active);
168 | curl_multi_close($queue);
169 | return $responses;
170 | }
171 |
172 | /**
173 | * [rolling_curl_url curl并发获取视频地址]
174 | * @param [type] $urls [description]
175 | * @return [type] [description]
176 | */
177 | private static function rolling_curl_url($urls,$params){
178 | $queue = curl_multi_init();
179 | $map = $param_array = array();
180 | $i = 0;
181 | foreach ($urls as $url) {
182 | $ch = curl_init();
183 | curl_setopt($ch, CURLOPT_URL, $url);
184 | curl_setopt($ch, CURLOPT_TIMEOUT, 10);
185 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
186 | curl_setopt($ch, CURLOPT_HEADER, 0);
187 | curl_setopt($ch, CURLOPT_USERAGENT, Base::USER_AGENT);
188 | curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
189 | curl_multi_add_handle($queue, $ch);
190 | $map[(string)$ch] = $i; //将$i当作 数组的value
191 | $i+=1;
192 | }
193 | $responses = array();
194 | $video_url = null;
195 | do {
196 | while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM);
197 | if ($code != CURLM_OK) {
198 | break;
199 | }
200 | // a request was just completed -- find out which one
201 | while ($done = curl_multi_info_read($queue)) {
202 | // get the info and content returned on the request
203 | //$http_code = curl_getinfo($done['handle'],CURLINFO_HTTP_CODE); //获得HTTP 状态码
204 | //$error = curl_error($done['handle']); //获得错误信息
205 | $results = curl_multi_getcontent($done['handle']);//获得请求结果
206 | //拼接视频地址
207 | $param_array = explode("|",$results);
208 | $su_key = $params[$map[(string)$done['handle']]]['su_key'];
209 | $rands = $params[$map[(string)$done['handle']]]['rands'];
210 | $video_url = substr($param_array[0],0,-1).$su_key."?start=&key=" .$param_array[3]."&n=".$rands."&a=4019";
211 | $responses[$map[(string)$done['handle']]] = $video_url; //对结果处理
212 | // remove the curl handle that just completed
213 | curl_multi_remove_handle($queue, $done['handle']);
214 | curl_close($done['handle']);
215 | }
216 | // Block for data in / output; error handling is done by curl_multi_exec
217 | if ($active > 0) {
218 | curl_multi_select($queue, 0.5);
219 | }
220 | } while ($active);
221 | curl_multi_close($queue);
222 | return $responses;
223 | }
224 | /**
225 | * [rolling_curl_url curl并发获取视频地址]
226 | * @param [type] $urls [description]
227 | * @return [type] [description]
228 | */
229 | private static function rolling_curl_url2($urls){
230 | $queue = curl_multi_init();
231 | $map = array();
232 | $i = 0;
233 | foreach ($urls as $url) {
234 | $ch = curl_init();
235 | curl_setopt($ch, CURLOPT_URL, $url);
236 | curl_setopt($ch, CURLOPT_TIMEOUT, 10);
237 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
238 | curl_setopt($ch, CURLOPT_HEADER, 0);
239 | curl_setopt($ch, CURLOPT_USERAGENT, Base::USER_AGENT);
240 | curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
241 | curl_multi_add_handle($queue, $ch);
242 | $map[(string)$ch] = $i; //将$i当作 数组的value
243 | $i+=1;
244 | }
245 | $responses = array();
246 |
247 | do {
248 | while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM);
249 | if ($code != CURLM_OK) {
250 | break;
251 | }
252 | // a request was just completed -- find out which one
253 | while ($done = curl_multi_info_read($queue)) {
254 | // get the info and content returned on the request
255 | //$http_code = curl_getinfo($done['handle'],CURLINFO_HTTP_CODE); //获得HTTP 状态码 重定向为301
256 | //$error = curl_error($done['handle']); //获得错误信息
257 | $redirect_url = curl_getinfo($done['handle'],CURLINFO_REDIRECT_URL);//获得重定向URL;
258 | $responses[$map[(string)$done['handle']]] = str_ireplace('/thumb/', '/',$redirect_url); //对结果替换处理
259 | // remove the curl handle that just completed
260 | curl_multi_remove_handle($queue, $done['handle']);
261 | curl_close($done['handle']);
262 | }
263 | // Block for data in / output; error handling is done by curl_multi_exec
264 | if ($active > 0) {
265 | curl_multi_select($queue, 0.5);
266 | }
267 | } while ($active);
268 | curl_multi_close($queue);
269 | return $responses;
270 | }
271 | }
--------------------------------------------------------------------------------
/core/tudou.class.php:
--------------------------------------------------------------------------------
1 | $val){
38 | foreach ($val as $k =>$v){
39 | $api_url = "http://v2.tudou.com/f?id=".$v['k']."&sid={$areaCode}&hd={$k}&sj=1";
40 | $v_xml = Base::_cget($api_url);
41 | if(empty($v_xml)){
42 | return false;
43 | }
44 | $s_xml = @simplexml_load_string($v_xml);
45 | if($key == 2) $data['normal'][] = strval($s_xml);
46 | if($key == 3) $data['high'][] = strval($s_xml);
47 | if($key == 5) $data['super'][] = strval($s_xml);
48 | if($key == 99) $data['original'][] = strval($s_xml);
49 | }
50 | }
51 | $data['title'] = $title; //土豆网已经变为utf-8编码了无需转码
52 | $data['seconds'] = $time;
53 | return $data;
54 | }else{
55 | return false;
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/core/tv189.class.php:
--------------------------------------------------------------------------------
1 | dt->ct;
24 | $data['title'] = strval($videoObj->tt);
25 | $urls = $videoObj->url;
26 | if($urls->count()>0 && is_object($urls)){
27 | for($i=0;$i<$urls->count();$i++){
28 | foreach($urls[$i]->attributes() as $key=>$val){
29 | //视频地址需要去掉最后的end=300 里的300 否者只能播放300秒 即5分钟
30 | if($key == 'cr' && $val == "450P") $data['normal'][] = rtrim(strval($urls[$i]),'300');
31 | if($key == 'cr' && $val == "720P") $data['high'][] = rtrim(strval($urls[$i]),'300');
32 | if($key == 'cr' && $val == "1080P") $data['super'][] = rtrim(strval($urls[$i]),'300');
33 | if($key == 'tm' && empty($data['seconds'])) $data['seconds'] = strval($val);
34 | }
35 | }
36 | return $data;
37 | }else{
38 | return false;
39 | }
40 | }
41 |
42 | /**
43 | * [getVideoUrl 获得视频真实地址 base64解码]
44 | * @param [type] $url [description]
45 | * @return [type] [description]
46 | */
47 | private static function getVideoUrl($url){
48 | $urlStr = explode('?',$url);
49 | $encodes = ltrim($urlStr[0],"http://vslb.tv189.cn/");
50 | return "http://vslb.tv189.cn".base64_decode($encodes);
51 | }
52 | }
--------------------------------------------------------------------------------
/core/youku.class.php:
--------------------------------------------------------------------------------
1 | > 2);
65 | $c .= static::charAt($str, ($e & 3) << 4);
66 | $c .= '==';
67 | break;
68 | }
69 | $g = static::charCodeAt($a, $b++);
70 | if ($b == $f) {
71 | $c .= static::charAt($str, $e >> 2);
72 | $c .= static::charAt($str, ($e & 3) << 4 | ($g & 240) >> 4);
73 | $c .= static::charAt($str, ($g & 15) << 2);
74 | $c .= '=';
75 | break;
76 | }
77 | $h = static::charCodeAt($a, $b++);
78 | $c .= static::charAt($str, $e >> 2);
79 | $c .= static::charAt($str, ($e & 3) << 4 | ($g & 240) >> 4);
80 | $c .= static::charAt($str, ($g & 15) << 2 | ($h & 192) >> 6);
81 | $c .= static::charAt($str, $h & 63);
82 | }
83 | return $c;
84 | }
85 | private static function yk_na($a){
86 | if (!$a) {
87 | return '';
88 | }
89 | $sz = '-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1';
90 | $h = explode(',', $sz);
91 | $i = strlen($a);
92 | $f = 0;
93 | for ($e = ''; $f < $i;) {
94 | do {
95 | $c = $h[static::charCodeAt($a, $f++) & 255];
96 | } while ($f < $i && -1 == $c);
97 | if (-1 == $c) {
98 | break;
99 | }
100 | do {
101 | $b = $h[static::charCodeAt($a, $f++) & 255];
102 | } while ($f < $i && -1 == $b);
103 | if (-1 == $b) {
104 | break;
105 | }
106 | $e .= static::fromCharCode($c << 2 | ($b & 48) >> 4);
107 | do {
108 | $c = static::charCodeAt($a, $f++) & 255;
109 | if (61 == $c) {
110 | return $e;
111 | }
112 | $c = $h[$c];
113 | } while ($f < $i && -1 == $c);
114 | if (-1 == $c) {
115 | break;
116 | }
117 | $e .= static::fromCharCode(($b & 15) << 4 | ($c & 60) >> 2);
118 | do {
119 | $b = static::charCodeAt($a, $f++) & 255;
120 | if (61 == $b) {
121 | return $e;
122 | }
123 | $b = $h[$b];
124 | } while ($f < $i && -1 == $b);
125 | if (-1 == $b) {
126 | break;
127 | }
128 | $e .= static::fromCharCode(($c & 3) << 6 | $b);
129 | }
130 | return $e;
131 | }
132 | private static function yk_e($a, $c){
133 | for ($f = 0, $i, $e = '', $h = 0; 256 > $h; $h++) {
134 | $b[$h] = $h;
135 | }
136 | for ($h = 0; 256 > $h; $h++) {
137 | $f = (($f + $b[$h]) + static::charCodeAt($a, $h % strlen($a))) % 256;
138 | $i = $b[$h];
139 | $b[$h] = $b[$f];
140 | $b[$f] = $i;
141 | }
142 | for ($q = ($f = ($h = 0)); $q < strlen($c); $q++) {
143 | $h = ($h + 1) % 256;
144 | $f = ($f + $b[$h]) % 256;
145 | $i = $b[$h];
146 | $b[$h] = $b[$f];
147 | $b[$f] = $i;
148 | $e .= static::fromCharCode(static::charCodeAt($c, $q) ^ $b[($b[$h] + $b[$f]) % 256]);
149 | }
150 | return $e;
151 | }
152 |
153 | private static function fromCharCode($codes){
154 | if (is_scalar($codes)) {
155 | $codes = func_get_args();
156 | }
157 | $str = '';
158 | foreach ($codes as $code) {
159 | $str .= chr($code);
160 | }
161 | return $str;
162 | }
163 | private static function charCodeAt($str, $index){
164 | static $charCode = array();
165 | $key = md5($str);
166 | $index = $index + 1;
167 | if (isset($charCode[$key])) {
168 | return $charCode[$key][$index];
169 | }
170 | $charCode[$key] = unpack('C*', $str);
171 | return $charCode[$key][$index];
172 | }
173 |
174 | private static function charAt($str, $index = 0){
175 | return substr($str, $index, 1);
176 | }
177 |
178 |
179 | /**
180 | * [_getYouku description]
181 | * @param [type] $vid [视频id]
182 | * @return [type] [description]
183 | */
184 | public static function _getYouku($vid){
185 | //$link = "http://v.youku.com/player/getPlayList/VideoIDS/{$vid}/Pf/4"; //获取视频信息json 有些视频获取不全(土豆网的 火影忍者)
186 | $base = "http://v.youku.com/player/getPlaylist/VideoIDS/";
187 | $blink = $base.$vid;
188 | $link = $blink."/Pf/4/ctype/12/ev/1";
189 | $retval = Base::_cget($link);
190 | $bretval = Base::_cget($blink);
191 | if ($retval) {
192 | $rs = json_decode($retval, true);
193 | $brs = json_decode($bretval, true);
194 | if(!empty($rs['data'][0]['error'])){
195 | return false; //有错误返回false
196 | }
197 | $data = array();
198 | $streamtypes = $rs['data'][0]['streamtypes']; //可以输出的视频清晰度
199 | $streamfileids = $rs['data'][0]['streamfileids'];
200 | $seed = $rs['data'][0]['seed'];
201 | $segs = $rs['data'][0]['segs'];
202 | $ip = $rs['data'][0]['ip'];
203 | $bsegs = $brs['data'][0]['segs'];
204 | list($sid, $token) = explode('_', static::yk_e('becaf9be', static::yk_na($rs['data'][0]['ep'])));
205 | foreach ($segs as $key=>$val) {
206 | if(in_array($key,$streamtypes)){
207 | foreach($val as $k=> $v){
208 | $no = strtoupper(dechex($v['no'])); //转换为16进制 大写
209 | if(strlen($no) == 1){
210 | $no ="0".$no; //no 为每段视频序号
211 | }
212 | //构建视频地址K值
213 | $_k = $v['k'];
214 | if ((!$_k || $_k == '') || $_k == '-1') {
215 | $_k = $bsegs[$key][$k]['k'];
216 | }
217 | $fileId = static::getFileid($streamfileids[$key],$seed);
218 | $fileId = substr($fileId,0,8).$no.substr($fileId,10);
219 | $ep = urlencode(iconv('gbk', 'UTF-8', static::yk_d(static::yk_e('bf7e5f01', ((($sid . '_') . $fileId) . '_') . $token))));
220 | //判断后缀类型 、获得后缀
221 | $typeArray = array("flv"=>"flv","mp4"=>"mp4","hd2"=>"flv","3gphd"=>"mp4","3gp"=>"flv","hd3"=>"flv");
222 | //判断视频清晰度
223 | $sharpness = array("flv"=>"normal","flvhd"=>"normal","mp4"=>"high","hd2"=>"super","3gphd"=>"high","3gp"=>"normal","hd3"=>"original"); //清晰度 数组
224 | $fileType = $typeArray[$key];
225 | $data[$sharpness[$key]][$k] = "http://k.youku.com/player/getFlvPath/sid/".$sid."_00/st/{$fileType}/fileid/".$fileId."?K=".$_k."&hd=1&myp=0&ts=".((((($v['seconds'].'&ypp=0&ctype=12&ev=1&token=').$token).'&oip=').$ip).'&ep=').$ep;;
226 | }
227 | }
228 | }
229 | //返回 图片 标题 链接 时长 视频地址
230 | $data['img'] = $rs['data'][0]['logo'];
231 | $data['title'] = $rs['data'][0]['title'];
232 | $data['seconds'] = $rs['data'][0]['seconds'];
233 | return $data;
234 | } else {
235 | return false;
236 | }
237 | }
238 | //end 获得优酷视频需要用到的方法
239 | }
--------------------------------------------------------------------------------
/core/youku_2013.class.php:
--------------------------------------------------------------------------------
1 | $val) {
74 | if(in_array($key,$streamtypes)){
75 | foreach($val as $k=> $v){
76 | $no = strtoupper(dechex($v['no'])); //转换为16进制 大写
77 | if(strlen($no) == 1){
78 | $no ="0".$no; //no 为每段视频序号
79 | }
80 | $_k = (!empty($v['k']))? $v['k']:$rs['data'][0]['key2'].$rs['data'][0]['key1']; //构建视频地址K值
81 | $fileId = self::getFileid($streamfileids[$key],$seed);
82 | //判断后缀类型 、获得后缀
83 | $typeArray = array("flv"=>"flv","mp4"=>"mp4","hd2"=>"flv","3gphd"=>"mp4","3gp"=>"flv","hd3"=>"flv");
84 | //判断视频清晰度
85 | $sharpness = array("flv"=>"normal","flvhd"=>"normal","mp4"=>"high","hd2"=>"super","3gphd"=>"high","3gp"=>"normal","hd3"=>"original"); //清晰度 数组
86 | $fileType = $typeArray[$key];
87 | $startId = substr($fileId,0,8); //截取 拼凑 fileid
88 | $endId = substr($fileId,10,strlen($fileId));
89 | $data[$sharpness[$key]][$k] = "http://f.youku.com/player/getFlvPath/sid/".self::getSid()."_{$no}/st/{$fileType}/fileid/".$startId.$no.$endId."?K=".$_k;
90 | }
91 | }
92 | }
93 | //返回 图片 标题 链接 时长 视频地址
94 | $data['img'] = $rs['data'][0]['logo'];
95 | $data['title'] = $rs['data'][0]['title'];
96 | $data['seconds'] = $rs['data'][0]['seconds'];
97 | return $data;
98 | } else {
99 | return false;
100 | }
101 | }
102 | //end 获得优酷视频需要用到的方法
103 | }
--------------------------------------------------------------------------------
/getVideo.php:
--------------------------------------------------------------------------------
1 | ';
8 | print_r($result);
9 | }
10 |
11 | //include_once "../xhprof/xhprof_lib/utils/xhprof_lib.php";
12 | //include_once "../xhprof/xhprof_lib/utils/xhprof_runs.php";
13 |
14 |
15 | // start profiling
16 | //xhprof_enable();
17 | //xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); //同时分析CPU和Mem的开销
18 |
19 | //$url = "http://v.qq.com/cover/y/ypq1qwp0ktzusj9/h00132shwru.html";
20 | $url = "http://v.youku.com/v_show/id_XNzM0MzEyNDY0.html";
21 | //$url = "http://www.iqiyi.com/v_19rrnbyreg.html";
22 | //$url = $_GET['url'];
23 | debug($url);
24 |
25 | /*
26 | // stop profiler
27 | $xhprof_data = xhprof_disable();
28 |
29 | // display raw xhprof data for the profiler run
30 | //echo '';
31 | //print_r($xhprof_data);
32 |
33 |
34 | // save raw data for this profiler run using default
35 | // implementation of iXHProfRuns.
36 | $xhprof_runs = new XHProfRuns_Default();
37 |
38 | // save the run under a namespace "xhprof_foo"
39 | $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
40 |
41 | echo "点击查看消耗时间";
42 |
43 |
44 | //print_r(get_headers("http://data.vod.itc.cn/preview?file=/233/52/28FAAL9Tq9UX9kOatm6bj7.mp4&start=28"));
45 | */
46 |
--------------------------------------------------------------------------------
/parserVideo.class.php:
--------------------------------------------------------------------------------
1 |