最近在开发视频收藏功能时候,需要根据视频网站如优酷、酷6、土豆网的一个视频链接,能自动获取该视频的真实链接和相对应视频的截图。类似与校内的分享视频的功能~~~~

下面以优酷为例:
假设我们给任意一个优酷视频网址:http://v.youku.com/v_show/id_XMTA0NTM2MzI4.html
要注意一点:优酷网上的视频地址较早些的是:http://v.youku.com/v_show/id_XNTM3MDg2ODA=.html
注意上面的一点点区别,最后有个“=”。
通过分析优酷视频网站的页面内容特点,利用php结合正则表达式,过滤获取我们想要的信息。具体参见下面功能函数。

//优酷视频地址,如http://v.youku.com/v_show/id_XMTA0NTM2MzI4.html
$link = ’http://v.youku.com/v_show/id_XMTA0NTM2MzI4.html‘;
$host = 'youku.com';
function getVideoInfo($link, $host) {
	$return = array();
	if('youku.com' == $host) {
		//分析视频网址,获取视频编码号
		preg_match_all("/id\_(\w+)[\=|.html]/", $link, $matches);
		if(!empty($matches[1][0])) {
			$return['flashvar'] = $matches[1][0];
		}
                //获取视频页面内容,存与$text中
		$text=file_get_contents($link);
                //获取视频标题
		preg_match("/<title>(.*?) - (.*)<\/title>/",  $text, $title);
                //获取优酷网上某一视频对应的视频截图,经分析,视频的截图的图片地址在该视频页面html代码里以<li class="download"></li>标记里的最后一个http://vimg....
例如http://vimg20.yoqoo.com/0100641F4649B9D27344B00131FBB6AFDF5175-7D35-930B-E43C-99C59F918E00
		preg_match_all("/<li class=\"download\"(.*)<\/li>/",$text,$match2);
		preg_match("/http:\/\/vimg(.*)\|\"\>/",$match2[1][0],$imageurl);
		if (!empty($imageurl[1])) {
			$return['imageurl'] = 'http://vimg'.$imageurl[1];
		}
		if (!empty($title)) {
			$return['title'] = $title[1];
		}
	} elseif('ku6.com' == $host) {
		// http://v.ku6.com/show/bjbJKPEex097wVtC.html
		// http://v.ku6.com/special/index_3628020.html
               //对于酷6网,末尾以index_开头的地址需要另外分析其视频编码
		$text=file_get_contents($link);
		preg_match_all("/\/([\w\-]+)\.html/", $link, $matches);
		if(1 > preg_match("/\/index_([\w\-]+)\.html/", $link) && !empty($matches[1][0])) {
			$return['flashvar'] = $matches[1][0];
		}else{
			preg_match_all("/refer\/(.*)\/v.swf/",$text,$videourl);
			$return['flashvar'] = $videourl[1][0];
		}	
		preg_match("/<title>(.*?) - (.*)<\/title>/",  $text, $title);
                //经分析,酷六的视频截图地址在视频页面的<span class="s_pic“></span>标签之间
		preg_match_all("/<span class=\"s_pic\">(.*)<\/span>/",$text,$imageurl);
		if (!empty($imageurl[1][0])) {
			$return['imageurl'] = $imageurl[1][0];
		}
		if (!empty($title)) {
			$return['title'] = $title[1];
		}		
	}elseif ('tudou.com' == $host){
		//http://www.tudou.com/programs/view/_ke1lzCnBYw/
		$tudou = file_get_contents($link);  
		preg_match_all("/view\/([\w\-]+)\//", $link, $matches);
		if(!empty($matches[1][0])) {
			$return['flashvar'] = $matches[1][0];
		}		
		preg_match("/<title>(.*?) - (.*)<\/title>/",  $tudou, $title);
		preg_match_all("/<span class=\"s_pic\">(.*)<\/span>/",$tudou,$imageurl);
		if (!empty($imageurl[1][0])) {
			$return['imageurl'] = $imageurl[1][0];
		}		
		if (!empty($title)) {
			$return['title'] = $title[1];
		}			
	}
	return $return;
}