PHP实现使用优酷土豆视频地址获取swf播放器分享地址

所属分类: 网络编程 / PHP编程 阅读数: 558
收藏 0 赞 0 分享

项目用到临时写的。待完善:

复制代码 代码如下:
/*
     * 根据用户提交的(swf/html)地址,获取优酷,土豆的swf播放地址
     * */
    private function _getSwf ($url = '') {
        if(isset($url) && !empty($url)){
            preg_match_all('/http:\/\/(.*?)?\.(.*?)?\.com\/(.*)/',$url,$types);
        }else{
            return false;
        }
        $type = $types[2][0];
        $domain = $types[1][0];
        $isswf = strpos($types[3][0], 'v.swf') === false ? false : true;
        $method = substr($types[3][0],0,1);

        switch ($type){
            case 'youku' :
                if( $domain == 'player' ) {
                    $swf = $url;
                }else if( $domain == 'v' ) {
                    preg_match_all('/http:\/\/v\.youku\.com\/v_show\/id_(.*)?\.html/',$url,$url_array);
                    $swf = 'http://player.youku.com/player.php/sid/'.str_replace('/','',$url_array[1][0]).'/v.swf';
                }else{
                    $swf = $url;
                }
                break;
            case 'tudou' :
                if($isswf){
                    $swf = $url;
                }else{
                    $method = $method == 'p' ? 'v' : $method ;
                    preg_match_all('/http:\/\/www.tudou\.com\/(.*)?\/(.*)?/',$url,$url_array);
                    $str_arr = explode('/',$url_array[1][0]);
                    $count = count($str_arr);
                    if($count == 1) {
                        $id = explode('.',$url_array[2][0])[0];
                    }else if($count == 2){
                        $id = $str_arr[1];
                    }else if($count == 3){
                        $id = $str_arr[2];
                    }
                    $swf = 'http://www.tudou.com/'.$method.'/'.$id.'/v.swf';
                }
                break;
            default :
                $swf = $url;
                break;
        }
        return $swf;
    }
   

更多精彩内容其他人还在看

PHP.MVC的模板标签系统(四)

PHP.MVC的模板标签系统(四)
收藏 0 赞 0 分享

PHP.MVC的模板标签系统(五)

PHP.MVC的模板标签系统(五)
收藏 0 赞 0 分享

Windows下的PHP5.0安装配制详解

Windows下的PHP5.0安装配制详解
收藏 0 赞 0 分享

最令PHP初学者头痛的十四个问题

最令PHP初学者头痛的十四个问题
收藏 0 赞 0 分享

PHP中的串行化变量和序列化对象

PHP中的串行化变量和序列化对象
收藏 0 赞 0 分享

PHP 5.0对象模型深度探索之绑定

PHP 5.0对象模型深度探索之绑定
收藏 0 赞 0 分享

PHP5.0对象模型探索之抽象方法和抽象类

PHP5.0对象模型探索之抽象方法和抽象类
收藏 0 赞 0 分享

PHP在XP下IIS和Apache2服务器上的安装

PHP在XP下IIS和Apache2服务器上的安装
收藏 0 赞 0 分享

初学者入门:细述PHP4的核心Zend

初学者入门:细述PHP4的核心Zend
收藏 0 赞 0 分享

PHP环境搭建最新方法

PHP环境搭建最新方法
收藏 0 赞 0 分享
查看更多