使用方法:
复制代码 代码如下:
require_once "VideoUrlParser.class.php";
$url = "http://v.youku.com/v_show/id_XMjkwMzc0Njg4.html";
$info = VedioUrlParser::parse($url);
echo $info;
说明:调用该工具php文件VideoUrlParser.class.php,$url变量后面的字符串为视频页的地址,然后使用echo输出变量$info。
附:info含有的几个值,分别是img(用于视频缩略图),title(视频标题),url(地址),swf(视频swf播放地址)。我只用到了img和swf地址。具体的可以根据自己的需要进行调整。
VideoUrlParser类源码:
复制代码 代码如下:
* @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
*
* Usage
* require_once "VideoUrlParser.class.php";
* $urls[] = "http://v.youku.com/v_show/id_XMjI4MDM4NDc2.html";
* $urls[] = "http://www.tudou.com/playlist/p/l13087099.html";
* $urls[] = "http://www.tudou.com/programs/view/ufg-A3tlcxk/";
* $urls[] = "http://v.ku6.com/special/show_4926690/Klze2mhMeSK6g05X.html";
* $urls[] = "http://www.56.com/u68/v_NjI2NTkxMzc.html";
* $urls[] = "http://www.letv.com/ptv/vplay/1168109.html";
* $urls[] = "http://video.sina.com.cn/v/b/46909166-1290055681.html";
*
* foreach($urls as $url){
* $info = VideoUrlParser::parse($url);
* //var_dump($info);
* echo "{$info['title']}";
* echo "
";
* echo $info['object'];
* echo "
";
* }
*
*
*
* //优酷
* http://v.youku.com/v_show/id_XMjU0NjY4OTEy.html
*
*
* //酷六
* http://v.ku6.com/special/show_3917484/x0BMXAbgZdQS6FqN.html
*
*
* //土豆
* http://www.tudou.com/playlist/p/a65929.html?iid=74905844
*
*
* //56
* http://www.56.com/u98/v_NTkyODY2NTU.html
*
*
* //新浪播客
* http://video.sina.com.cn/v/b/46909166-1290055681.html
*
*
* //乐视
* http://www.letv.com/ptv/vplay/1168109.html
* */
class VideoUrlParser
{
const USER_AGENT = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko)
Chrome/8.0.552.224 Safari/534.10";
const CHECK_URL_VALID = "/(youku\.com|tudou\.com|ku6\.com|56\.com|letv\.com|video\.sina\.com\.cn|(my\.)?tv\.sohu\.com|v\.qq\.com)/";
/**
* parse
*
* @param string $url
* @param mixed $createObject
* @static
* @access public
* @return void
*/
static public function parse($url='', $createObject=true){
$lowerurl = strtolower($url);
preg_match(self::CHECK_URL_VALID, $lowerurl, $matches);
if(!$matches) return false;
switch($matches[1]){
case 'youku.com':
$data = self::_parseYouku($url);
break;
case 'tudou.com':
$data = self::_parseTudou($url);
break;
case 'ku6.com':
$data = self::_parseKu6($url);
break;
case '56.com':
$data = self::_parse56($url);
break;
case 'letv.com':
$data = self::_parseLetv($url);
break;
case 'video.sina.com.cn':
$data = self::_parseSina($url);
break;
case 'my.tv.sohu.com':
case 'tv.sohu.com':
case 'sohu.com':
$data = self::_parseSohu($url);
break;
case 'v.qq.com':
$data = self::_parseQq($url);
break;
default:
$data = false;
}
if($data && $createObject) $data['object'] = "";
return $data;
}
/**
* 腾讯视频
* http://v.qq.com/cover/o/o9tab7nuu0q3esh.html?vid=97abu74o4w3_0
* http://v.qq.com/play/97abu74o4w3.html
* http://v.qq.com/cover/d/dtdqyd8g7xvoj0o.html
* http://v.qq.com/cover/d/dtdqyd8g7xvoj0o/9SfqULsrtSb.html
* http://imgcache.qq.com/tencentvideo_v1/player/TencentPlayer.swf?_v=20110829&vid=97a