function getVideoUrl($url) { |
$url = str_replace("\/","/",$url); |
$ch = curl_init(); |
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.2.13) ' . |
'Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729)'; |
curl_setopt($ch, CURLOPT_URL, $url); |
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); |
curl_setopt($ch, CURLOPT_HEADER,false); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
curl_setopt($ch, CURLOPT_VERBOSE,1); |
$result = curl_exec($ch); |
curl_close($ch); |
$video_url = ''; |
$hd = Array('240', '360', '480', '720', '1080'); |
preg_match("/var video_host = '([0-9a-z\.\/:]*)'/", $result, $res); |
if (preg_match('/http/', $res[1])) |
$video_url.=$res[1]; |
else { |
$video_url.='http://cs' . $host[1]; |
} |
if (substr($video_url, strlen($video_url) - 1, 1) != '/') |
$video_url.='/'; |
preg_match("/var video_uid = '(\d*)'/", $result, $res); |
$video_url.='u' . $res[1] . '/video/'; |
preg_match("/var video_vtag = '([\da-zA-Z]*)'/", $result, $res); |
$video_url.=$res[1]; |
preg_match("/var video_no_flv = (\d)/", $result, $res); |
if ($res[1] == 0) { |
$video_url .= '.flv'; |
} |
else if($res[1] == 1){ |
preg_match("/var video_max_hd = '(\d)'/", $result, $res); |
$video_url .= '.'.$hd[$res[1]].'.mp4'.$res[1]; |
} |
return $video_url; |
} |