由于最近项目开发中遇到视频分享的功能,以下简单的使用了,还不完善,不过可以用:
01 | /* |
02 | * 根据用户提交的(swf/html)地址,获取优酷,土豆的swf播放地址 |
03 | * */ |
04 | private function _getSwf ( $url = '' ) { |
05 | if (isset( $url ) && ! empty ( $url )){ |
06 | preg_match_all( '/http:\/\/(.*?)?\.(.*?)?\.com\/(.*)/' , $url , $types ); |
07 | } else { |
08 | return false; |
09 | } |
10 | $type = $types [2][0]; |
11 | $domain = $types [1][0]; |
12 | $isswf = strpos ( $types [3][0], 'v.swf' ) === false ? false : true; |
13 | $method = substr ( $types [3][0],0,1); |
14 | switch ( $type ){ |
15 | case 'youku' : |
16 | if ( $domain == 'player' ) { |
17 | $swf = $url ; |
18 | } else if ( $domain == 'v' ) { |
19 | preg_match_all( '/http:\/\/v\.youku\.com\/v_show\/id_(.*)?\.html/' , $url , $url_array ); |
20 | $swf = 'http://player.youku.com/player.php/sid/' . str_replace ( '/' , '' , $url_array [1][0]). '/v.swf' ; |
21 | } else { |
22 | $swf = $url ; |
23 | } |
24 | break ; |
25 | case 'tudou' : |
26 | if ( $isswf ){ |
27 | $swf = $url ; |
28 | } else { |
29 | $method = $method == 'p' ? 'v' : $method ; |
30 | preg_match_all( '/http:\/\/www.tudou\.com\/(.*)?\/(.*)?/' , $url , $url_array ); |
31 | $str_arr = explode ( '/' , $url_array [1][0]); |
32 | $count = count ( $str_arr ); |
33 | if ( $count == 1) { |
34 | $id = explode ( '.' , $url_array [2][0])[0]; |
35 | } else if ( $count == 2){ |
36 | $id = $str_arr [1]; |
37 | } else if ( $count == 3){ |
38 | $id = $str_arr [2]; |
39 | } |
40 | $swf = 'http://www.tudou.com/' . $method . '/' . $id . '/v.swf' ; |
41 | } |
42 | break ; |
43 | default : |
44 | $swf = $url ; |
45 | break ; |
46 | } |
47 | return $swf ; |
48 | } |
49 | |