vedio.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. function fetch_vedio_url($url)
  3. {
  4. $files=file_get_url($url);
  5. $source_url = "";
  6. if(strpos($url,'www.tudou.com')!==false)
  7. {
  8. if(strpos($url,'.html'))
  9. {
  10. preg_match("/,iid: (\w+)/i",$files,$items);
  11. $iid=$items[1];
  12. if(!empty($iid))
  13. {
  14. $source_url="http://www.tudou.com/v/".$iid."/v.swf";
  15. }
  16. }
  17. else
  18. {
  19. preg_match("/,iid: (\w+)/i",$files,$items);
  20. $iid=$items[1];
  21. if(!empty($iid))
  22. {
  23. //$source_url=tudou_get($url);
  24. $source_url="http://www.tudou.com/v/".$iid."/v.swf";
  25. }
  26. else
  27. $source_url=tudou_get($url);
  28. }
  29. }
  30. elseif(strpos($url,'v.ku6.com')!==false)
  31. {
  32. preg_match("/A.VideoInfo(.*)/i",$files,$context);
  33. $context=$context[1];
  34. //匹配网页中的内容\"bigpicpath\" 获取图片
  35. //id:\s*\"([^,]+) 获取 视频ID ,"http://player.ku6.com/refer/$id/v.swf"
  36. preg_match("/\"bigpicpath\":\"([^,]+)\"/i",$context,$items);
  37. //json的UTF8 js编码
  38. $pattner=array('\u003a'=>':','\u002e'=>'.');
  39. $pic=$items[1];
  40. if(!empty($pic))
  41. {
  42. preg_match("/id:\s*\"([^,]+)\"/i",$context,$items);
  43. $id=$items[1];
  44. $source_url="http://player.ku6.com/refer/$id/v.swf";
  45. }
  46. }
  47. elseif(strpos($url,'v.youku.com')!==false)
  48. {
  49. // preg_match("/videoId2=(.*)';/i",$files,$items);
  50. // $videoId2=trim(str_replace('\'','',$items[1]));
  51. // if(!empty($videoId2))
  52. // $source_url="http://player.youku.com/player.php/sid/$videoId2/v.swf";
  53. $source_url=preg_replace("/id_(.*)\.html(.*)/i","http://player.youku.com/embed/\${1}",baseName($url));
  54. }
  55. return $source_url;
  56. }
  57. function file_get_url($url=''){
  58. if(!empty($url)){
  59. $ctx = stream_context_create(array(
  60. 'method'=>'GET',
  61. 'http' => array(
  62. 'timeout' => 1 //设置一个超时时间,单位为秒
  63. )
  64. )
  65. );
  66. $files=file_get_contents($url,false,$ctx);
  67. return $files;
  68. }else{
  69. return false;
  70. }
  71. }
  72. function tudou_get($url){
  73. preg_match('#https?://(?:www\.)?tudou\.com/(?:programs/view|listplay/(?<list_id>[a-z0-9_=\-]+))/(?<video_id>[a-z0-9_=\-]+)#i', $url, $matches );
  74. print_r($matches);die();
  75. return handler_tudou( $matches);
  76. }
  77. function handler_tudou( $matches ) {
  78. $embed = sprintf(
  79. 'http://www.tudou.com/v/%1$s/&resourceId=0_05_05_99&bid=05/v.swf',
  80. $matches['video_id'] );
  81. return $embed;
  82. }
  83. ?>