原文地址:http://www.lianyue.org/2013/2497/

  1. <?php
  2. /**
  3. * 解析 视频信息 类
  4. *
  5. * 支持 优酷, 土豆 酷6 56 新浪 qq播客 乐视 乐视
  6. **/
  7.  
  8. $all['url'] = 'parse';
  9. $all['youku'] = 'youku';
  10. $all['tudou'] = 'tudou';
  11. $all['ku6'] = 'ku6';
  12. $all['56'] = '_56';
  13. $all['sina'] = 'sina';
  14. $all['qq'] = 'qq';
  15. $all['letv'] = 'letv';
  16. $all['sohu'] = 'sohu';
  17.  
  18. $value = empty( $_GET['value'] ) ? '' : (string) $_GET['value'];
  19. $type = empty( $_GET['type'] ) || !is_string( $_GET['type'] ) || empty( $all[$_GET['type']] ) ? 'url' : $_GET['type'];
  20. ?>
  21. <!DOCTYPE html>
  22. <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
  23. <head>
  24. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  25. <title>PHP 解析视频信息</title>
  26. </head>
  27. <body>
  28. <?php
  29. $select = '<select name="type">';
  30. foreach ( $all as $k => $v ) {
  31. $selected = $type == $k ? 'selected="selected"' : '';
  32. $select .= '<option value="'. $k .'" '. $selected.'>'. $k .'</option>';
  33. }
  34. $select .= '</select>';
  35. echo '<form method="get">url 或 vid: <input name="value" type="text" value="' . htmlspecialchars( $value, ENT_QUOTES ) . '" />'. $select .'<input type="submit" ></form>';
  36. if ( !$value ) {
  37. die;
  38. }
  39.  
  40. $class_video = new class_video;
  41.  
  42. echo '<pre>';
  43. echo "\n\n\n";
  44. print_r( call_user_func_array( array( $class_video, $all[$type] ), array( $value ) ) );
  45. echo "\n\n\n";
  46.  
  47. ?>
  48. </body>
  49. </html>
  50.  
  51. <?php
  52. /**
  53. * 解析 视频信息 类
  54. *
  55. * 支持 优酷, 土豆 酷6 56 新浪 qq播客 乐视 乐视
  56. **/
  57.  
  58. class class_video{
  59.  
  60. // 超时时间
  61. var $timeout = 5;
  62.  
  63. /**
  64. * 解析视频
  65. *
  66. * 1 参数 url 地址
  67. *
  68. * 返回值 数组 or false
  69. **/
  70. function parse( $url ) {
  71. $arr = parse_url( $url );
  72. if ( empty( $arr['host'] ) ) {
  73. return false;
  74. }
  75. $host = strtolower( preg_replace( '/.*(?:$|\.)(\w+(?:\.(?:com|net|org|co|info)){0,1}\.[a-z]+)$/iU', '$1', $arr['host'] ) );
  76. if ( $host == 'youku.com' ) {
  77. return $this->youku( $url );
  78. }
  79.  
  80. if ( $host == 'tudou.com' ) {
  81. return $this->tudou( $url );
  82. }
  83.  
  84. if ( $host == 'ku6.com' ) {
  85. return $this->ku6( $url );
  86. }
  87.  
  88. if ( $host == '56.com' ) {
  89. return $this->_56( $url );
  90. }
  91.  
  92. if ( $host == 'sina.com.cn' ) {
  93. return $this->sina( $url );
  94. }
  95.  
  96. if ( $host == 'qq.com' ) {
  97. return $this->qq( $url );
  98. }
  99.  
  100. if ( $host == 'letv.com' ) {
  101. return $this->letv( $url );
  102. }
  103.  
  104. if ( $host == 'sohu.com' ) {
  105. return $this->sohu( $url );
  106. }
  107.  
  108. return false;
  109. }
  110.  
  111. /**
  112. * 优酷的
  113. *
  114. * 1 参数 vid or url
  115. *
  116. * 返回值 false array
  117. **/
  118. function youku( $vid ) {
  119. if ( !$vid ) {
  120. return false;
  121. }
  122.  
  123. if ( !preg_match( '/^[0-9a-z_-]+$/i', $vid ) ) {
  124. if ( !preg_match( '/^http\:\/\/v\.youku\.com\/v_show\/id_([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/player\.youku\.com\/player\.php[0-9a-z\/_-]*\/sid\/([0-9a-z_-]+)/i', $vid, $match ) ) {
  125. return false;
  126. }
  127. $vid = $match[1];
  128. }
  129.  
  130. $url = 'http://v.youku.com/player/getPlayList/VideoIDS/' . $vid;
  131. if ( !$json = $this->url( $url ) ) {
  132. return false;
  133. }
  134. if ( !$json = @json_decode( $json, true ) ) {
  135. return false;
  136. }
  137. if ( empty( $json['data'][0] ) ) {
  138. return false;
  139. }
  140. $json = $json['data'][0];
  141.  
  142. $r['vid'] = $json['vidEncoded'];
  143. $r['url'] = 'http://v.youku.com/v_show/id_'. $json['vidEncoded'] .'.html?f=http://www.lianyue.org/';
  144. $r['swf'] = 'http://player.youku.com/player.php/sid/'. $json['vidEncoded'] .'/lianyue.swf';
  145. $r['title'] = $json['title'];
  146. $r['img']['large'] = $json['logo'];
  147. $r['img']['small'] = str_replace( '.com/11', '.com/01', $json['logo'] );
  148. $r['time'] = $json['seconds'];
  149. $r['tag'] = $json['tags'];
  150. return $r;
  151. }
  152.  
  153. /**
  154. * 土豆的
  155. *
  156. * 1 参数 vid or url
  157. *
  158. * 返回值 false array
  159. **/
  160. function tudou( $vid ) {
  161. if ( !$vid ) {
  162. return false;
  163. }
  164. if ( !preg_match( '/^[0-9a-z_-]+$/i', $vid ) ) {
  165. if ( !preg_match( '/^http\:\/\/www\.tudou\.com\/programs\/view\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/www\.tudou\.com\/v\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/www\.tudou\.com\/(?:listplay|albumplay)\/[0-9a-z_-]+\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/www\.tudou\.com\/(?:a|l)\/[0-9a-z_-]+\/.+iid\=(\d+)/i', $vid, $match ) ) {
  166. return false;
  167. }
  168. $vid = $match[1];
  169. }
  170.  
  171. $url = 'http://www.tudou.com/v/'. $vid .'/v.swf';
  172. $this->url( $url, $header );
  173. if( empty( $header['Location'] ) ) {
  174. return false;
  175. }
  176. $parse = parse_url( $header['Location'] );
  177. if ( empty( $parse['query'] ) ) {
  178. return false;
  179. }
  180. $this->parse_str( $parse['query'], $arr );
  181. if ( empty( $arr['snap_pic'] ) ) {
  182. return false;
  183. }
  184. $r['vid'] = $arr['code'];
  185. $r['url'] = 'http://www.tudou.com/programs/view/'. $arr['code'] .'/?FR=http://www.lianyue.org/';
  186. $r['swf'] = 'http://www.tudou.com/v/'. $arr['code'] .'/lianyue.swf';
  187. $r['title'] = $arr['title'];
  188. $r['img']['large'] = $arr['snap_pic'];
  189. $r['img']['small'] = str_replace( array( '/w.jpg', 'ykimg.com/11' ), array( '/p.jpg', 'ykimg.com/01' ), $arr['snap_pic'] );
  190. $r['time'] = $arr['totalTime'] / 1000;
  191. $r['tag'] = empty( $arr['tag'] ) || $arr['tag'] == 'null' ? array() : $this->array_unempty( explode( ',', $arr['tag'] ) );
  192. return $r;
  193. }
  194.  
  195. /**
  196. * 酷 6 的
  197. *
  198. * 1 参数 vid or url
  199. *
  200. * 很老的视频某些 没大图
  201. * 返回值 false array
  202. **/
  203. function ku6( $vid ) {
  204. if ( !$vid ) {
  205. return false;
  206. }
  207. if ( !preg_match( '/^[0-9a-z_-]+\.{0,2}$/i', $vid ) ) {
  208. if ( !preg_match( '/^http\:\/\/v\.ku6\.com\/show\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/player\.ku6\.com\/refer\/([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/v\.ku6\.com\/special\/show_\d+\/([0-9a-z_-]+)/i', $vid, $match ) ) {
  209. return false;
  210. }
  211. $vid = $match[1];
  212. }
  213. $vid = preg_replace( '/^([0-9a-z_-]+)\.*$/i', '$1..', $vid );
  214. if ( !$json = $this->url( 'http://v.ku6.com/fetchVideo4Player/'. $vid .'.html' ) ) {
  215. return false;
  216. }
  217. if ( !$json = @json_decode( $json, true ) ) {
  218. return false;
  219. }
  220. if ( empty( $json['data']['picpath'] ) ) {
  221. return false;
  222. }
  223.  
  224. $json = $json['data'];
  225. $json['vtime'] = explode( ',', $json['vtime'] );
  226. $r['vid'] = $vid;
  227. $r['url'] = 'http://v.ku6.com/show/'. $vid .'.html?ref=http://www.lianyue.org/';
  228. $r['swf'] = 'http://player.ku6.com/refer/'. $vid .'./lianyue.swf';
  229. $r['title'] = $json['t'];
  230. $r['img']['large'] = $json['bigpicpath'];
  231. $r['img']['small'] = $json['picpath'];
  232. $r['time'] = reset( $json['vtime'] );
  233. $r['tag'] = empty( $json['tag'] ) ? array() : $this->array_unempty( explode( ' ', $json['tag'] ) );
  234. return $r;
  235. }
  236.  
  237. /**
  238. * 56 的
  239. *
  240. * 1 参数 vid or url
  241. *
  242. * 很老的视频某些 没大图
  243. * 返回值 false array
  244. **/
  245. function _56( $vid ) {
  246. if ( !$vid ) {
  247. return false;
  248. }
  249. if ( !preg_match( '/^[0-9a-z_-]+$/i', $vid ) ) {
  250. if ( !preg_match( '/^http\:\/\/www\.56\.com\/[0-9a-z]+\/v_([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/player\.56\.com\/v_([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/www\.56\.com\/[0-9a-z]+\/play_album-aid-\d+_vid-([0-9a-z_-]+)/i', $vid, $match ) ) {
  251. return false;
  252. }
  253. $vid = $match[1];
  254. }
  255. if ( !$json = $this->url( 'http://vxml.56.com/json/'. $vid .'/?src=out' ) ) {
  256. return false;
  257. }
  258. if ( !$json = @json_decode( $json, true ) ) {
  259. return false;
  260. }
  261. if ( empty( $json['info']['img'] ) ) {
  262. return false;
  263. }
  264. $json = $json['info'];
  265. $r['vid'] = $json['textid'];
  266. $r['url'] = 'http://www.56.com/u/v_'. $json['textid'] .'.html?ref=lianyue.org';
  267. $r['swf'] = 'http://player.56.com/v_'. $json['textid'] .'.swf?ref=lianyue';
  268. $r['title'] = $json['Subject'];
  269. $r['img']['large'] = $json['bimg'];
  270. $r['img']['small'] = $json['img'];
  271. $r['time'] = $json['duration']/1000;
  272. $r['tag'] = empty( $json['tag'] ) ? array() : $this->array_unempty( explode( ',', $json['tag'] ) );
  273. return $r;
  274. }
  275.  
  276. /**
  277. * sina 的
  278. *
  279. * 1 参数 vid or url
  280. *
  281. * 如果直接使用vid 获取不到 url 地址
  282. *
  283. * 返回值 false array
  284. **/
  285. function sina( $vid ) {
  286. if ( !$vid ) {
  287. return false;
  288. }
  289. $uid = 0;
  290. $url = '';
  291. $token = '';
  292. if ( !preg_match( '/^[0-9]+$/i', $vid ) ) {
  293. if ( preg_match( '/^http\:\/\/video\.sina\.com\.cn\/p\/news\/s\/v\/\d{4}-\d{2}-\d{2}\/\d+\.html/i', $vid, $match ) ) {
  294. if ( !( $html = $this->url( $vid ) ) || !preg_match( '/swfOutsideUrl\s*:\s*\'(.+?)\'\s*,/i', $html, $match ) ) {
  295. return false;
  296. }
  297. $url = $vid;
  298. $vid = $match[1];
  299. }
  300. if ( preg_match( '/^http\:\/\/video\.sina\.com\.cn\/v\/b\/(\d+)-(\d+)/i', $vid, $match ) || preg_match( '/^http\:\/\/you\.video\.sina\.com\.cn\/api\/sinawebApi\/outplayrefer\.php\/vid=(\d+)_(\d+)_([0-9a-zA-Z+%]+)/i', $vid, $match ) ) {
  301. $vid = $match[1];
  302. $uid = $match[2];
  303. $token = empty( $match[3] ) ? '' : $match[3];
  304. if ( $uid != 1 ) {
  305. $url = 'http://video.sina.com.cn/v/b/'. $vid .'-'. $uid .'.html?ref=lianyue.org';
  306. }
  307. } else {
  308. return false;
  309. }
  310. }
  311. if ( !$url && $token ) {
  312. $token = str_replace( '+', '%2B', $token );
  313. if ( $xml = $this->url( 'http://video.sina.com.cn/api/sinaVideoInfo.php?pid=1012&token=' . $token ) ) {
  314. $xml = $this->parse_xml( $xml );
  315. if ( !empty( $xml['url'] ) ) {
  316. $url = $xml['url'];
  317. }
  318. }
  319. }
  320.  
  321. if( !$xml = $this->url( 'http://v.iask.com/v_play.php?vid=' . $vid ) ) {
  322. return false;
  323. }
  324.  
  325. if( !$xml = $this->parse_xml( $xml ) ) {
  326. return false;
  327. }
  328.  
  329. if( !$img = $this->url( 'http://interface.video.sina.com.cn/interface/common/getVideoImage.php?vid=' . $vid ) ) {
  330. return false;
  331. }
  332.  
  333. $this->parse_str( $img, $img );
  334. if ( empty( $img['imgurl'] ) ) {
  335. return false;
  336. }
  337. $r['vid'] = $xml['ext'];
  338.  
  339. $r['url'] = $url;
  340. $r['swf'] = 'http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=' . $xml['ext'] . '_' . $uid . '_' . $token;
  341. $r['title'] = $xml['vname'];
  342. $r['img']['large'] = $img['imgurl'];
  343. $r['img']['small'] = str_replace( '2.jpg', '1.jpg', $img['imgurl'] );
  344. $r['time'] = $xml['timelength'] / 1000;
  345. $r['tag'] = empty( $xml['vtags'] ) ? array() : $this->array_unempty( explode( ' ', $xml['vtags'] ) );
  346. return $r;
  347. }
  348.  
  349. /**
  350. * QQ 的
  351. *
  352. * 1 参数 vid or url
  353. *
  354. * 返回值 false array
  355. **/
  356. function qq( $vid ) {
  357. if ( !$vid ) {
  358. return false;
  359. }
  360.  
  361. if ( !preg_match( '/^[0-9a-z_-]+$/i', $vid ) ) {
  362. if ( !preg_match( '/^http\:\/\/v\.qq\.com\/cover\/[0-9a-z_-]{1}\/[0-9a-z_-]+\.html\?[0-9a-z&=_-]*vid=([0-9a-z_-]+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/v\.qq\.com\/cover\/[0-9a-z_-]{1}\/[0-9a-z_-]+\/([0-9a-z_-]+)\.html/i', $vid, $match ) && !preg_match( '/^http\:\/\/static\.video\.qq\.com\/TPout\.swf\?[0-9a-z&=_-]*vid=(\w+)/i', $vid, $match ) ) {
  363. return false;
  364. }
  365. $vid = $match[1];
  366. }
  367.  
  368. if( !$xml = $this->url( 'http://vv.video.qq.com/getinfo?otype=xml&vids=' . $vid ) ) {
  369. return false;
  370. }
  371. if( !$xml = $this->parse_xml( $xml ) ) {
  372. return false;
  373. }
  374. if ( empty( $xml['vl']['vi'] ) ) {
  375. return false;
  376. }
  377. $xml = $xml['vl']['vi'];
  378.  
  379. $num = 0xFFFFFFFF + 1;
  380. $m = 10000 * 10000;
  381. $res = 0;
  382.  
  383. $i = 0;
  384. while ( $i < strlen ( $vid ) ) {
  385. $temp = ord ( substr ( $vid, $i, 1 ) );
  386. $res = $res * 32 + $res + $temp;
  387. while ( $res >= $num ) {
  388. $res -= $num;
  389. }
  390. $i++;
  391. }
  392. while ( $res >= $m ) {
  393. $res -= $m;
  394. }
  395. $r['vid'] = $xml['vid'];
  396. $r['url'] = 'http://v.qq.com/page/t/u/h/'. $xml['vid'] .'.html?ref=lianyue.org';
  397. $r['swf'] = 'http://static.video.qq.com/TPout.swf?vid='. $xml['vid'] .'&ref=lianyue.org';
  398. $r['title'] = $xml['ti'];
  399. $r['img']['large'] = 'http://vpic.video.qq.com/'. $res .'/'. $xml['vid'] .'.png';
  400. $r['img']['small'] = 'http://vpic.video.qq.com/'. $res .'/'. $xml['vid'] .'_160_90_2.jpg';
  401. $r['time'] = $xml['td'];
  402. $r['tag'] = array();
  403. return $r ;
  404. }
  405.  
  406. /**
  407. * letv 的
  408. *
  409. * 1 参数 vid or url
  410. *
  411. * 返回值 false array
  412. **/
  413. function letv( $vid ) {
  414. if ( !$vid ) {
  415. return false;
  416. }
  417.  
  418. if ( !preg_match( '/^[0-9]+$/i', $vid ) ) {
  419. if ( !preg_match( '/^http\:\/\/www\.letv\.com\/ptv\/vplay\/(\d+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/i\d+\.imgs\.letv\.com\/player\/swfPlayer\.swf\?[0-9a-z&=_-]*id=(\d+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/www\.letv\.com\/player\/x(\d+)/i', $vid, $match ) ) {
  420. return false;
  421. }
  422. $vid = $match[1];
  423. }
  424. if ( !$html = $this->url( 'http://www.letv.com/ptv/vplay/'. $vid .'.html' ) ) {
  425. return false;
  426. }
  427. if ( !preg_match( '/\<script.*?__INFO__\s*\\=\{(.+?)\<\/script\>/is', $html, $match ) ) {
  428. return false;
  429. }
  430.  
  431. $html = $match[1];
  432.  
  433. $r['vid'] = preg_replace( '/.+vid\s*\:\s*(\d+)\s*,.+/is', '$1', $html );
  434. $r['url'] = 'http://www.letv.com/ptv/vplay/' . $r['vid'] . '.html';
  435. $r['swf'] = 'http://i7.imgs.letv.com/player/swfPlayer.swf?id='. $r['vid'];
  436. $r['img']['large'] = '';
  437. $r['img']['small'] = preg_replace( '/^.+pic\s*\:\s*["\'](http.+?)["\']\s*,.+$/is', '$1', $html );
  438. $r['time'] = 0;
  439. $r['tag'] = array();
  440. return $r;
  441. }
  442.  
  443. /**
  444. * sohu 的
  445. *
  446. * 1 参数 vid or url
  447. *
  448. * 返回值 false array
  449. **/
  450. function sohu( $vid ) {
  451. if ( !$vid ) {
  452. return false;
  453. }
  454. if ( !preg_match( '/^[0-9]+$/i', $vid ) ) {
  455. if ( !preg_match( '/^http\:\/\/my\.tv\.sohu\.com\/us\/\d+\/(\d+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/my\.tv\.sohu\.com\/u\/vw\/(\d+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/share\.vrs\.sohu\.com\/my\/v\.swf.*&id=(\d+)/i', $vid, $match ) && !preg_match( '/^http\:\/\/share\.vrs\.sohu\.com\/(\d+)/i', $vid, $match ) ) {
  456. return false;
  457. }
  458. $vid = $match[1];
  459. }
  460. if ( !$json = $this->url( 'http://my.tv.sohu.com/videinfo.jhtml?m=viewnew&vid=' . $vid ) ) {
  461. return false;
  462. }
  463.  
  464. if ( !$json = @json_decode( $json, true ) ) {
  465. return false;
  466. }
  467.  
  468. if ( empty( $json['url'] ) ) {
  469. return false;
  470. }
  471. $r['vid'] = $vid;
  472. $r['url'] = $json['url'] . '?ref=lianyue.org';
  473. $r['swf'] = 'http://share.vrs.sohu.com/my/v.swf&ref=lianyue.org&id=' . $vid;
  474. $r['img']['large'] = $json['data']['coverImg'];
  475. $r['img']['small'] = str_replace( array( 'b.jpg', '_0.jpg' ), array( '.jpg', '_1.jpg' ), $json['data']['coverImg'] );
  476. $r['time'] = $json['data']['totalDuration'];
  477. $r['tag'] = empty( $json['data']['tag'] ) ? array() : explode( ' ', $json['data']['tag'] );
  478. return $r;
  479. }
  480.  
  481. /**
  482. * 打开 url
  483. *
  484. * 1 参数 url 地址
  485. * 2 参数 header 引用
  486. *
  487. * 返回值 字符串
  488. **/
  489. function url( $url = '', &$header = array() ) {
  490. $timeout = $this->timeout;
  491. $accept = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1478.0 Safari/537.36';
  492.  
  493. $content = '';
  494.  
  495. if ( function_exists( 'curl_init' ) ) {
  496. // curl 的
  497. $curl = curl_init( $url );
  498. curl_setopt( $curl, CURLOPT_DNS_CACHE_TIMEOUT, 86400 ) ;
  499. curl_setopt( $curl, CURLOPT_DNS_USE_GLOBAL_CACHE, true ) ;
  500. curl_setopt( $curl, CURLOPT_BINARYTRANSFER, true );
  501. curl_setopt( $curl, CURLOPT_ENCODING, 'gzip,deflate' );
  502. curl_setopt( $curl, CURLOPT_HEADER, true );
  503. curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
  504. curl_setopt( $curl, CURLOPT_USERAGENT, $accept );
  505. curl_setopt( $curl, CURLOPT_TIMEOUT, $timeout );
  506. $content = curl_exec ( $curl );
  507. curl_close( $curl );
  508.  
  509. } elseif ( function_exists( 'file_get_contents' ) ) {
  510.  
  511. // file_get_contents
  512. $head[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  513. $head[] = "User-Agent: $accept";
  514. $head[] = "Accept-Language: zh-CN,zh;q=0.5";
  515. $head = implode( "\r\n", $head ). "\r\n\r\n";
  516.  
  517. $context['http'] = array (
  518. 'method' => "GET" ,
  519. 'header' => $head,
  520. 'timeout' => $timeout,
  521. );
  522.  
  523. $content = @file_get_contents( $url, false , stream_context_create( $context ) );
  524. if ( $gzip = $this->gzip( $content ) ) {
  525. $content = $gzip;
  526. }
  527. $content = implode( "\r\n", $http_response_header ). "\r\n\r\n" . $content;
  528.  
  529. } elseif ( function_exists('fsockopen') || function_exists('pfsockopen') ) {
  530. // fsockopen or pfsockopen
  531. $url = parse_url( $url );
  532. if ( empty( $url['host'] ) ) {
  533. return false;
  534. }
  535. $url['port'] = empty( $url['port'] ) ? 80 : $url['port'];
  536.  
  537. $host = $url['host'];
  538. $host .= $url['port'] == 80 ? '' : ':'. $port;
  539.  
  540. $get = '';
  541. $get .= empty( $url['path'] ) ? '/' : $url['path'];
  542. $get .= empty( $url['query'] ) ? '' : '?'. $url['query'];
  543.  
  544. $head[] = "GET $get HTTP/1.1";
  545. $head[] = "Host: $host";
  546. $head[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  547. $head[] = "User-Agent: $accept";
  548. $head[] = "Accept-Language: zh-CN,zh;q=0.5";
  549. $head[] = "Connection: Close";
  550. $head = implode( "\r\n", $head ). "\r\n\r\n";
  551.  
  552. $function = function_exists('fsockopen') ? 'fsockopen' : 'pfsockopen';
  553. if ( !$fp = @$function( $url['host'], $url['port'], $errno, $errstr, $timeout ) ) {
  554. return false;
  555. }
  556.  
  557. if( !fputs( $fp, $head ) ) {
  558. return false;
  559. }
  560.  
  561. while ( !feof( $fp ) ) {
  562. $content .= fgets( $fp, 1024 );
  563. }
  564. fclose( $fp );
  565.  
  566. if ( $gzip = $this->gzip( $content ) ) {
  567. $content = $gzip;
  568. }
  569.  
  570. $content = str_replace( "\r\n", "\n", $content );
  571. $content = explode( "\n\n", $content, 2 );
  572.  
  573. if ( !empty( $content[1] ) && !strpos( $content[0], "\nContent-Length:" ) ) {
  574. $content[1] = preg_replace( '/^[0-9a-z\r\n]*(.+?)[0-9\r\n]*$/i', '$1', $content[1] );
  575. }
  576. $content = implode( "\n\n", $content );
  577. }
  578.  
  579. // 分割 header body
  580. $content = str_replace( "\r\n", "\n", $content );
  581. $content = explode( "\n\n", $content, 2 );
  582.  
  583. // 解析 header
  584. $header = array();
  585. foreach ( explode( "\n", $content[0] ) as $k => $v ) {
  586. if ( $v ) {
  587. $v = explode( ':', $v, 2 );
  588. if( isset( $v[1] ) ) {
  589. if ( substr( $v[1],0 , 1 ) == ' ' ) {
  590. $v[1] = substr( $v[1], 1 );
  591. }
  592. $header[trim($v[0])] = $v[1];
  593. } elseif ( empty( $r['status'] ) && preg_match( '/^(HTTP|GET|POST)/', $v[0] ) ) {
  594. $header['status'] = $v[0];
  595. } else {
  596. $header[] = $v[0];
  597. }
  598. }
  599. }
  600.  
  601. $body = empty( $content[1] ) ? '' : $content[1];
  602. return $body;
  603. }
  604.  
  605. /**
  606. * gzip 解压缩
  607. *
  608. * 1 参数 data
  609. *
  610. * 返回值 false or string
  611. **/
  612. function gzip( $data ) {
  613. $len = strlen ( $data );
  614. if ($len < 18 || strcmp ( substr ( $data, 0, 2 ), "\x1f\x8b" )) {
  615. return null; // Not GZIP format (See RFC 1952)
  616. }
  617. $method = ord ( substr ( $data, 2, 1 ) ); // Compression method
  618. $flags = ord ( substr ( $data, 3, 1 ) ); // Flags
  619. if ($flags & 31 != $flags) {
  620. // Reserved bits are set -- NOT ALLOWED by RFC 1952
  621. return null;
  622. }
  623. // NOTE: $mtime may be negative (PHP integer limitations)
  624. $mtime = unpack ( "V", substr ( $data, 4, 4 ) );
  625. $mtime = $mtime [1];
  626. $xfl = substr ( $data, 8, 1 );
  627. $os = substr ( $data, 8, 1 );
  628. $headerlen = 10;
  629. $extralen = 0;
  630. $extra = "";
  631. if ($flags & 4) {
  632. // 2-byte length prefixed EXTRA data in header
  633. if ($len - $headerlen - 2 < 8) {
  634. return false; // Invalid format
  635. }
  636. $extralen = unpack ( "v", substr ( $data, 8, 2 ) );
  637. $extralen = $extralen [1];
  638. if ($len - $headerlen - 2 - $extralen < 8) {
  639. return false; // Invalid format
  640. }
  641. $extra = substr ( $data, 10, $extralen );
  642. $headerlen += 2 + $extralen;
  643. }
  644.  
  645. $filenamelen = 0;
  646. $filename = "";
  647. if ($flags & 8) {
  648. // C-style string file NAME data in header
  649. if ($len - $headerlen - 1 < 8) {
  650. return false; // Invalid format
  651. }
  652. $filenamelen = strpos ( substr ( $data, 8 + $extralen ), chr ( 0 ) );
  653. if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
  654. return false; // Invalid format
  655. }
  656. $filename = substr ( $data, $headerlen, $filenamelen );
  657. $headerlen += $filenamelen + 1;
  658. }
  659.  
  660. $commentlen = 0;
  661. $comment = "";
  662. if ($flags & 16) {
  663. // C-style string COMMENT data in header
  664. if ($len - $headerlen - 1 < 8) {
  665. return false; // Invalid format
  666. }
  667. $commentlen = strpos ( substr ( $data, 8 + $extralen + $filenamelen ), chr ( 0 ) );
  668. if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
  669. return false; // Invalid header format
  670. }
  671. $comment = substr ( $data, $headerlen, $commentlen );
  672. $headerlen += $commentlen + 1;
  673. }
  674.  
  675. $headercrc = "";
  676. if ($flags & 1) {
  677. // 2-bytes (lowest order) of CRC32 on header present
  678. if ($len - $headerlen - 2 < 8) {
  679. return false; // Invalid format
  680. }
  681. $calccrc = crc32 ( substr ( $data, 0, $headerlen ) ) & 0xffff;
  682. $headercrc = unpack ( "v", substr ( $data, $headerlen, 2 ) );
  683. $headercrc = $headercrc [1];
  684. if ($headercrc != $calccrc) {
  685. return false; // Bad header CRC
  686. }
  687. $headerlen += 2;
  688. }
  689.  
  690. // GZIP FOOTER - These be negative due to PHP's limitations
  691. $datacrc = unpack ( "V", substr ( $data, - 8, 4 ) );
  692. $datacrc = $datacrc [1];
  693. $isize = unpack ( "V", substr ( $data, - 4 ) );
  694. $isize = $isize [1];
  695.  
  696. // Perform the decompression:
  697. $bodylen = $len - $headerlen - 8;
  698. if ($bodylen < 1) {
  699. // This should never happen - IMPLEMENTATION BUG!
  700. return null;
  701. }
  702. $body = substr ( $data, $headerlen, $bodylen );
  703. $data = "";
  704. if ($bodylen > 0) {
  705. switch ($method) {
  706. case 8 :
  707. // Currently the only supported compression method:
  708. $data = gzinflate ( $body );
  709. break;
  710. default :
  711. // Unknown compression method
  712. return false;
  713. }
  714. } else {
  715. //...
  716. }
  717.  
  718. if ($isize != strlen ( $data ) || crc32 ( $data ) != $datacrc) {
  719. // Bad format! Length or CRC doesn't match!
  720. return false;
  721. }
  722. return $data;
  723. }
  724.  
  725. /**
  726. * 解析数组
  727. *
  728. * 1 参数 str
  729. * 2 参数 arr 引用
  730. *
  731. * 返回值 无
  732. **/
  733. function parse_xml( $xml ) {
  734. if ( preg_match_all("/\<(?<tag>[a-z]+)\>\s*\<\!\[CDATA\s*\[(.*)\]\]\>\s*\<\/\k<tag>\>/iU", $xml, $matches ) ) {
  735. $find = $replace = array();
  736. foreach ( $matches[0] as $k => $v ) {
  737. $find[] = $v;
  738. $replace[] = '<'. $matches['tag'][$k] .'>' .htmlspecialchars( $matches[2][$k] , ENT_QUOTES ). '</' . $matches['tag'][$k].'>';
  739. }
  740.  
  741. $xml = str_replace( $find, $replace, $xml );
  742. }
  743. if( !$xml = @simplexml_load_string( $xml ) ) {
  744. return false;
  745. }
  746. return $this->turn_array( $xml );
  747. }
  748.  
  749. /**
  750. * 解析数组
  751. *
  752. * 1 参数 str
  753. * 2 参数 arr 引用
  754. *
  755. * 返回值 无
  756. **/
  757. function parse_str( $str, &$arr ) {
  758. parse_str( $str, $arr );
  759. if ( get_magic_quotes_gpc() ) {
  760. $arr = $this->stripslashes_array( $arr );
  761. }
  762. }
  763.  
  764. /**
  765. * stripslashes 取消转义 数组
  766. *
  767. * 1 参数 输入数组
  768. *
  769. * 返回值 处理后的数组
  770. **/
  771. function stripslashes_array( $value ) {
  772. if ( is_array( $value ) ) {
  773. $value = array_map( array( $this, __FUNCTION__ ), $value );
  774. } elseif ( is_object( $value ) ) {
  775. $vars = get_object_vars( $value );
  776. foreach ( $vars as $key => $data ) {
  777. $value->{$key} = stripslashes_array( $data );
  778. }
  779. } else {
  780. $value = stripslashes( $value );
  781. }
  782. return $value;
  783. }
  784.  
  785. /**
  786. * 转换成 数组
  787. *
  788. * 1 参数 需要进行处理的 类 或者 数组 支持多维数组
  789. *
  790. * 返回值 处理后的数组
  791. **/
  792. function turn_array( $arr = array() ) {
  793. $arr = (array) $arr;
  794. $r = array();
  795. foreach ( $arr as $k => $v ) {
  796. if( is_object( $v ) || is_array( $v ) ) {
  797. $r[$k] = $this->turn_array( $v );
  798. } else {
  799. $r[$k] = $v;
  800. }
  801. }
  802. return $r;
  803. }
  804.  
  805. /**
  806. * 删除 数组中 的空值
  807. *
  808. * 1 参数 数组
  809. * 2 参数 是否回调删除多维数组
  810. *
  811. * 返回值 数组
  812. **/
  813. function array_unempty( $a = array(), $call = false ) {
  814.  
  815. foreach ( $a as $k => $v ) {
  816. if ( $call && is_array( $a ) && $a ) {
  817. $a[$k] = $this->array_unempty( $a, $call );
  818. }
  819. if ( empty( $v ) ) {
  820. unset( $a[$k] );
  821. }
  822. }
  823. return $a;
  824. }
  825.  
  826. }

php 解析 视频 信息 封面 标题 图片 支持 优酷, 土豆 酷6 56 新浪 qq播客 乐视 乐视的更多相关文章

  1. 视频下载四大神器—如何下载优酷/爱奇艺/腾讯/B站超清无水印视频

      视频下载四大神器—如何下载优酷/爱奇艺/腾讯/B站超清无水印视频  2018-07-11 |  标签»下载, 下载工具, 视频 又是视频下载,老生常谈的话题.阿刚同学已在乐软博客多次与大家分享推荐 ...

  2. 【高清未加密】2015传智播客 最新21期c#asp.net 基础到就业班视频和源码

    [.NET]传智播客第[21]期就业班视频(高清无加密)本套2015年21期传智播客C#ASP.NET win10通用mvc+app开发视频教程附源码,是一套非常不错的asp.net自学视频教程,传智 ...

  3. 主攻互动娱乐和视频自媒体,新浪SHOW是不是桩好生意?

        对互联网互动服务平台而言,近期几年会是空前重要的发展阶段,首先,互联网行业的持续发展.网民数量的持续激增必定带动网络互动朝更普及的方向迈进.其市场规模也必定会呈极数增长.其次,互动娱乐.视频自 ...

  4. 使用JavaCV实现读取视频信息及自动截取封面图

    概述 最近在对之前写的一个 Spring Boot 的视频网站项目做功能完善,需要利用 FFmpeg 实现读取视频信息和自动截图的功能,查阅资料后发现网上这部分的内容非常少,于是就有了这篇文章. 视频 ...

  5. javaCV开发详解之12:视频转apng动态图片实现,支持透明通道,也支持摄像机、桌面屏幕、流媒体等视频源转apng动态图

    wjavaCV系列文章: javacv开发详解之1:调用本机摄像头视频 javaCV开发详解之2:推流器实现,推本地摄像头视频到流媒体服务器以及摄像头录制视频功能实现(基于javaCV-FFMPEG. ...

  6. .NET读取视频信息、视频截图

    在.NET中处理视频是一件痛苦的事情,.NET并没有提供视频处理的类.于是咱们只能找一些第三方的类库或者自己实现,在项目时间比较赶的情况下,自己实现是不可能的了,而且说不定会留下很多坑.所以一般情况下 ...

  7. python爬取豆瓣视频信息代码

    目录 一:代码 二:结果如下(部分例子)   这里是爬取豆瓣视频信息,用pyquery库(jquery的python库). 一:代码 from urllib.request import quote ...

  8. 使用HTML 5捕捉音频与视频信息

    长期以来,音频与视频信息的捕捉一直是Web开发中的一个难点.许多年来,我们一直依赖浏览器插件来实现这个需求. 在HTML 5中,出现了许多可以访问硬件设备的API,例如访问GPS设备的Geolocat ...

  9. 让织梦CMS的后台编辑器支持优酷视频

    最近做了一些视频教程传到优酷网站上,但我想引入这些视频教程到我的网站,在发表时我发现织梦CMS自带的编辑器又不直接支持优酷等视频网站的引用.所以为了方便教程的发布,特意在网站搜索到本篇教程,详细讲解如 ...

随机推荐

  1. spring mvc 和 velocity整合

    java.lang.ClassNotFoundException: org.springframework.ui.velocity.VelocityEngineFactory 考虑是不是没有添加spr ...

  2. bzoj2006 noi2010 超级钢琴 主席树 + 优先队列

    Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 2435  Solved: 1195 Description 小 Z是一个小有名气的钢琴家,最近C博士送 ...

  3. java中string stringbuilder stringbuffer 的区别

    1. String 类 String的值是不可变的,这就导致每次对String的操作都会生成新的String对象,不仅效率低下,而且大量浪费有限的内存空间. String a = "a&qu ...

  4. [PAT]求集合数据的均方差(15)

    #include "stdio.h" #include "malloc.h" #include "math.h" int *getinput ...

  5. vs2010中将c++控制台程序修改成windows应用程序

    报错:无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用 vs2010环境下将Win32控制台应用程序,改为Win32项目 直接将控制台的mian函数改成 _ ...

  6. bash操作小结

    刚开始学写bash脚本,发现有很多需要注意的细节问题,在这里记录一下便于记忆: 1. help test  帮助 2. bash提供的数组数据结构,它是以数字为下标的,和C语言从0开始的下一样  参考 ...

  7. PDF表单域(FormField)在HTML显示与提交数据到服务器

    1.Adobe Arobat Pro等可以编辑表单域,只有几种控件: 2.展示PDF,可用PdfObject.js,Chrome自带? @{ViewBag.Title = @ViewBag.aaa;} ...

  8. struts2 xml中重定向

    <result name="success" type="redirect">ManagePartAction</result> 重定向 ...

  9. python生成中文验证码,带旋转,带干扰噪音线段

    # -*- coding: utf-8 -*- """ Created on Sun Oct 4 15:57:46 2015 @author: keithguofan & ...

  10. Visual Studio 换皮肤

    通过字体和颜色修改 Visual Studio 提供了修改配色的入口,你完全可以根据自己的喜好进行自定义,下面就通过该方法把编辑器背景设置成 “豆沙绿”. 选择 工具 / 选项 / 环境 / 字体和颜 ...