0

我正在尝试从优酷获取直接文件下载链接。

示例网址:http: //v.youku.com/v_show/id_XNDU0MTgxNzI0.html

我使用了一个视频下载网站,试图模仿下载路径。我使用了 hxxp://flvcd 。com 来解析链接。(您可以将示例 URL 粘贴到搜索字段中,然后您将得到结果,应该有 4 个链接)。

获得 4 直接链接后,我使用 fiddler2 捕获 HTTP 输出。我能够找到视频的第一部分(根据 flvcd 网站应该有 4 个)

我尝试在页面源中搜索直接下载链接字符串,但找不到任何匹配项。我想实际的直接链接是使用网站 javascript 获取的?

有人可以对此有所了解吗?

4

1 回答 1

0

这是我正在使用的代码;我从 SO 上的另一个答案中找到了它,但我现在找不到它..

<?php

class VideoUrlParser{
    private $video_code;
    private $video_type;
    private $success;

    public function __construct($url = null, $type = null) {
        $this->success = false;

        if(!empty($url) && !empty($type)) {
            $this->video_code = trim($url);
            $this->video_type = trim($type);
            $this->success = true;
            return;
        }

        if(!empty($url)) {
            $urls = parse_url(trim($url));

            //url is http://youtu.be/xxxx
            if($urls['host'] == 'youtu.be'){
                $this->video_code = ltrim($urls['path'],'/');
                $this->video_type = "youtube";
                $this->success = true;
            }
            else if($urls['host'] == 'youtube.com' || $urls['host'] == 'www.youtube.com'){
                $this->video_type = "youtube";

                //url is http://www.youtube.com/embed/xxxx
                if(strpos($urls['path'],'embed') == 1){
                    $this->video_code = end(explode('/',$urls['path']));
                    $this->success = true;
                }
                //http://www.youtube.com/watch?feature=player_embedded&v=m-t4pcO99gI
                //url is http://www.youtube.com/watch?v=xxxx
                else{
                    parse_str($urls['query'],$parts);
                    $this->video_code = $parts['v'];
                    $this->success = true;
                }
            }
            else if(strpos($urls['host'],'youku.com') > 0){
                $this->video_type = "youku";
                $regExp = "#/(?:player.php/sid/|v_show/id_)([a-zA-Z0-9]+)(?:/|\\.)#";

                    if(preg_match($regExp, $urls['path'], $url_parts)){
                        $this->video_code = $url_parts[1];
                        $this->success = true;
                    }
                }
            //url is xxxx only
            else if(strpos($url,'/')===false){
                $this->video_code = $url;
                $this->video_type = "unknown";
            }
            return;
        }
    }

    public function success() {
        return $this->success;
    }
    public function getVideoType() {
        return $this->video_type;
    }
    public function getVideoCode() {
        return $this->video_code;
    }
    public function getVideoURL() {
        if($this->video_type == "youtube") {
            return 'http://www.youtube.com/?v=' . $this->video_code;
        } elseif($this->video_type == "youku") {
            return "http://v.youku.com/v_show/id_" . $this->video_code . ".html";
        }
    }
    public function getEmbedCode($rel, $width, $height) {
        if($this->video_type == "youtube") {
            return '<iframe src="http://www.youtube.com/embed/'.$this->video_code.'?rel='.$rel.'" frameborder="0" width="'.($width?$width:560).'" height="'.($height?$height:349).'"></iframe>';
        } else if($this->video_type == "youku") {
            return '<iframe width="'.($width?$width:560).'" height="'.($height?$height:349).'" src="http://player.youku.com/player.php/sid/'.$this->video_code.'/v.swf"></iframe>';
        } else {
            return "unknown video type in class.video_url_parser";
        }

    }
}
于 2012-10-25T07:49:21.177 回答