php获取youku视频最终地址的方法

php中文网
发布: 2016-07-25 08:56:20
原创
2075人浏览过
  1. /**

  2. * 取得youku视频的最终地址
  3. * edit by bbs.it-home.org
  4. * at: 2013-10-2
  5. */
  6. class youkuflv{
  7. static private $error = "";
  8. static private $result = array();
  9. static public function getyoukuflv($url){
  10. //从url获取youkuid
  11. if(! $id = self::getyoukuid($url)){
  12. return false;
  13. }
  14. //获取youku视频详细信息
  15. $content = self::get_curl_contents( "http://v.youku.com/player/getplaylist/videoids/".$id );
  16. $data = json_decode($content);
  17. if(!isset($data->data[0]->streamfileids)){
  18. self::$error = "cannot find this video";
  19. return false;
  20. }
  21. foreach($data->data[0]->streamfileids as $k=>$v){
  22. if($k == 'flv' || $k == 'mp4'){
  23. //sid
  24. $sid= self::getsid();
  25. //fileid
  26. $fileid = self::getfileid($v,$data->data[0]->seed);
  27. $one=($data->data[0]->segs->$k);
  28. self::$result[$k] = "http://f.youku.com/player/getflvpath/sid/{$sid}_00/st/{$k}/fileid/{$fileid}?k={$one[0]->k}";
  29. }
  30. }
  31. if(empty(self::$result)){
  32. self::$error = "this viod is not in mp4 or flv format";
  33. return false;
  34. }else{
  35. return true;
  36. }
  37. }
  38. static public function error(){
  39. return self::$error;
  40. }
  41. static public function result(){
  42. return self::$result;
  43. }
  44. static private function getyoukuid($url){
  45. //url 不能为空
  46. if($url == "" || substr($url , 0 , 29) != "http://v.youku.com/v_show/id_"){
  47. self::$error = "url is error";
  48. return false;
  49. }
  50. return substr($url , 29 , -5);
  51. }
  52. static private function get_curl_contents($url, $second = 5){
  53. if(!function_exists('curl_init')) die('php.ini未开启php_curl.dll');
  54. $c = curl_init();
  55. curl_setopt($c,curlopt_url,$url);
  56. $useragent=$_server['http_user_agent'];
  57. curl_setopt($c,curlopt_useragent,$useragent);
  58. curl_setopt($c,curlopt_header,0);
  59. curl_setopt($c,curlopt_timeout,$second);
  60. curl_setopt($c,curlopt_returntransfer, true);
  61. $cnt = curl_exec($c);
  62. curl_close($c);
  63. return $cnt;
  64. }
  65. static private function getsid() {
  66. $sid = time().(rand(0,9000)+10000);
  67. return $sid;
  68. }
  69. static private function getfileid($fileid,$seed) {
  70. $mixed = self::getmixstring($seed);
  71. $ids = explode("*",$fileid);
  72. unset($ids[count($ids)-1]);
  73. $realid = "";
  74. for ($i=0;$i $idx = $ids[$i];
  75. $realid .= substr($mixed,$idx,1);
  76. }
  77. return $realid;
  78. }
  79. static private function getmixstring($seed) {
  80. $mixed = "";
  81. $source = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz/\:._-1234567890";
  82. $len = strlen($source);
  83. for($i=0;$i $seed = ($seed * 211 + 30031) % 65536;
  84. $index = ($seed / 65536 * strlen($source));
  85. $c = substr($source,$index,1);
  86. $mixed .= $c;
  87. $source = str_replace($c, "",$source);
  88. }
  89. return $mixed;
  90. }
  91. }
  92. if(youkuflv::getyoukuflv("http://v.youku.com/v_show/id_xnjeyote4ntey_ev_1.html")){
  93. print_r( youkuflv::result() );
  94. }else{
  95. echo youkuflv::error();
  96. }
  97. ?>

复制代码

另外一种调用方法: http://player.youku.com/player.php/sid/XMjI0MDIwNDc2/v.swf http://player.youku.com/player.php/sid/{$id}/v.swf



PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号