用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($url, false, $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";
}
}
?>
// 根据视频地址取内容
$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($url, false, $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";
}
}
?>