php获取优酷土豆页面中视频swf播放器地址

  1. 项目用到临时写的。待完善
  2. /*
  3. * 根据用户提交的(swf/html)地址,获取优酷,土豆的swf播放地址
  4. * */
  5. private function _getSwf ($url = '') {
  6. if(isset($url) && !emptyempty($url)){
  7. preg_match_all('/http://(.*?)?.(.*?)?.com/(.*)/',$url,$types);
  8. }else{
  9. return false;
  10. }
  11. $type = $types[2][0];
  12. $domain = $types[1][0];
  13. $isswf = strpos($types[3][0], 'v.swf') === false ? false : true;
  14. $method = substr($types[3][0],0,1);
  15. switch ($type){
  16. case 'youku' :
  17. if( $domain == 'player' ) {
  18. $swf = $url;
  19. }else if( $domain == 'v' ) {
  20. preg_match_all('/http://v.youku.com/v_show/id_(.*)?.html/',$url,$url_array);
  21. $swf = 'http://player.youku.com/player.php/sid/'.str_replace('/','',$url_array[1][0]).'/v.swf';
  22. }else{
  23. $swf = $url;
  24. }
  25. break;
  26. case 'tudou' :
  27. if($isswf){
  28. $swf = $url;
  29. }else{
  30. $method = $method == 'p' ? 'v' : $method ;
  31. preg_match_all('/http://www.tudou.com/(.*)?/(.*)?/',$url,$url_array);
  32. $str_arr = explode('/',$url_array[1][0]);
  33. $count = count($str_arr);
  34. if($count == 1) {
  35. $id = explode('.',$url_array[2][0])[0];
  36. }else if($count == 2){
  37. $id = $str_arr[1];
  38. }else if($count == 3){
  39. $id = $str_arr[2];
  40. }
  41. $swf = 'http://www.tudou.com/'.$method.'/'.$id.'/v.swf';
  42. }
  43. break;
  44. default :
  45. $swf = $url;
  46. break;
  47. }
  48. return $swf;
  49. }