用PHP获取土豆网视频FLV地址

主要代码:
<?php   
// 根据视频地址取内容   
$url = "http://www.tudou.com/programs/view/B6q-LhN9e-0/";   
$txt = file_get_contents($url);   
  
// 取视频ID   
preg_match("/var iid = (\d+)/", $txt$match_id);   
preg_match("/<title>(.*?) - .*<\/title>/", $txt , $match_title);   
$id = $match_id[1];   
$title = $match_title[1];   
  
// 取视频的绝对地址   
$url = "http://v2.tudou.com/v2/cdn?id={$id}&safekey=YouNeverKnowThat&noCatch=4610";   
$context = array(   
    'http' => array (   
        'header'=> 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT']   
    )   
);   
$xcontext = stream_context_create($context);   
$txt = file_get_contents($urlfalse$xcontext);   
  
preg_match_all("/<f.*?>(.*?)<\/f>/", $txt$match);   
if (is_array($match[1]))   
{   
    foreach ($match[1] as $k => $v)   
    {   
        $c = $k + 1;   
        echo "下载地址{$c}:<a href=\"$v\">{$title} ($v)</a>  <br />\n";   
    }   
}   
?>  

posted on 2011-10-26 15:06  relax  阅读(684)  评论(0编辑  收藏  举报