1. 程式人生 > >優酷土豆騰訊視訊html地址轉flash swf地址

優酷土豆騰訊視訊html地址轉flash swf地址

很多使用者不知道如何複製flash地址,只能在程式中幫他們替換了:

  1. <?php
  2. /**
  3. * 支援優酷、土豆、騰訊視訊html到swf轉換
  4. * @link http://www.phpddt.com
  5. */
  6. function convert_html_to_swf($url ='')
  7. {
  8. if(!is_string($url)|| empty($url))return;
  9. if(strpos($url,'swf'))return $url;
  10. preg_match_all('/http:\/\/(.*?)?\.(.*?)?\.com\/(.*)/', $url, $types);
  11. $type = $types
    [2][0];
  12. $domain = $types[1][0];
  13. switch($type){
  14. case'youku':
  15. preg_match_all('/http:\/\/v\.youku\.com\/v_show\/id_(.*)?\.html/', $url, $url_array);
  16. $swf ='http://player.youku.com/player.php/sid/'. str_replace('/','', $url_array[1][0]).'/v.swf';
  17. break;
  18. case'tudou':
  19. $method = substr($types
    [3][0],0,1);
  20. $method = $method =='p'?'v': $method;
  21. preg_match_all('/http:\/\/www.tudou\.com\/(.*)?\/(.*)?/', $url, $url_array);
  22. $str_arr = explode('/', $url_array[1][0]);
  23. $count = count($str_arr);
  24. if($count ==1){
  25. $id = explode('.', $url_array[2][0]);
  26. $id
    = $id[0];
  27. }elseif($count ==2){
  28. $id = $str_arr[1];
  29. }elseif($count ==3){
  30. $id = $str_arr[2];
  31. }
  32. $swf ='http://www.tudou.com/'. $method .'/'. $id .'/v.swf';
  33. break;
  34. case'qq':
  35. $url_array = parse_url($url);
  36. $swf ="http://static.video.qq.com/TPout.swf?{$url_array['query']}&auto=0";
  37. break;
  38. default:
  39. $swf = $url;
  40. break;
  41. }
  42. return $swf;
  43. }
  44. /**
  45. * 優酷視訊轉換測試
  46. * html地址 http://v.youku.com/v_show/id_XNzU4Mzg2NDA4.html?f=22720170&ev=2&from=y1.1-2.10001-0.1-2
  47. * swf地址 http://player.youku.com/player.php/sid/XNzU4Mzg2NDA4/v.swf
  48. */
  49. echo convert_html_to_swf("http://v.youku.com/v_show/id_XNzU4Mzg2NDA4.html?f=22720170&ev=2&from=y1.1-2.10001-0.1-2");
  50. echo "<hr>";
  51. /**
  52. * 騰訊視訊轉換測試
  53. *
  54. * html地址 http://v.qq.com/cover/w/w5lb270k15j7ita.html?vid=v0015mnd5x6
  55. * swf地址 http://static.video.qq.com/TPout.swf?vid=v0015mnd5x6&auto=0
  56. */
  57. echo convert_html_to_swf("http://v.qq.com/cover/w/w5lb270k15j7ita.html?vid=v0015mnd5x6");
  58. echo "<hr>";
  59. /**
  60. * 土豆視訊轉換測試
  61. *
  62. * html地址 http://www.tudou.com/albumplay/hqtp6W5XLN8/Kscjyz4J-RE.html
  63. * swf地址 http://www.tudou.com/a/hqtp6W5XLN8/&iid=132223533&resourceId=0_04_0_99/v.swf
  64. */
  65. echo convert_html_to_swf("http://www.tudou.com/albumplay/hqtp6W5XLN8/Kscjyz4J-RE.html");
  66. echo "<hr>";