ini_set('error_reporting', E_ALL); ini_set ('display_errors', 1); $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)'; $login = ''; $password = ''; function curl_gets_exec($ch, $redirects = 0, $curlopt_returntransfer = true, $curlopt_maxredirs = 10, $curlopt_header = false) { curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $header=substr($data,0,curl_getinfo($ch,CURLINFO_HEADER_SIZE)); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $exceeded_max_redirects = $curlopt_maxredirs > $redirects; $exist_more_redirects = false; if ($http_code == 301 || $http_code == 302) { if ($exceeded_max_redirects) { list($header) = explode("\r\n\r\n", $data, 2); $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $url = trim(array_pop($matches)); $url_parsed = parse_url($url); if (isset($url_parsed)) { curl_setopt($ch, CURLOPT_URL, $url); $redirects++; return curl_gets_exec($ch, $redirects, $curlopt_returntransfer, $curlopt_maxredirs, $curlopt_header); } } else { $exist_more_redirects = true; } } if ($data !== false) { if (!$curlopt_header) list(,$data) = explode("\r\n\r\n", $data, 2); if ($exist_more_redirects) return false; if ($curlopt_returntransfer) { return $data; } else { echo $data; if (curl_errno($ch) === 0) return true; else return false; } } else { return false; } } $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch,CURLOPT_REFERER,'http://m.vk.com/login?fast=1&hash=&s=0&to='); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_COOKIEFILE,'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_URL, 'https://login.vk.com/?act=login&from_host=m.vk.com&from_protocol=http&ip_h=&pda=1'); $answer = curl_gets_exec($ch); $post = array( 'email' => $login, 'pass' => $password ); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); $answer = curl_gets_exec($ch); </code> – , , : <source lang="php"> curl_setopt($ch,CURLOPT_REFERER,'http://m.vk.com/login?fast=1&hash=&s=0&to='); // curl_setopt($ch, CURLOPT_COOKIEFILE,'cookie.txt'); // ( 777 , - 'cookie.txt' ) curl_setopt($ch, CURLOPT_URL, 'https://login.vk.com/?act=login&from_host=m.vk.com&from_protocol=http&ip_h=&pda=1'); // curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); // ( – )
$vid=$_GET['vid']; $oid=$_GET['oid'];
$link="http://m.vk.com/video{$vid}_{$oid}";
curl_setopt($ch, CURLOPT_URL, $link); $answer = curl_gets_exec($ch);
include "simplehtmldom/simple_html_dom.php"; $html = new simple_html_dom();
$html->load($answer);
$div_video=$html->find('video',0);
if($div_video->outertext=="")die(“Video not found”);
<video preload="none" controls="controls" poster="http://cs527213.userapi.com/u11174769/video/l_18a03288.jpg"> <source src="http://cs527213.userapi.com/u11174769/videos/dc3277461b.720.mp4" type="video/mp4"></source> <source src="http://cs527213.userapi.com/u11174769/videos/dc3277461b.480.mp4" type="video/mp4"></source> <source src="http://cs527213.userapi.com/u11174769/videos/dc3277461b.360.mp4" type="video/mp4"></source> <source src="http://cs527213.userapi.com/u11174769/videos/dc3277461b.240.mp4" type="video/mp4"></source> <div class="img"><img src="http://cs527213.userapi.com/u11174769/video/l_18a03288.jpg" alt=""></div> <div class="no_pl"> </div> </video>
$sVideo=$div_video->find('source'); // $aBuf=""; $j=0; foreach($sVideo as $post) { /*$aBuf[$j]=$post->outertext; $aBuf[$j]=substr($aBuf[$j],stripos($aBuf[$j],'src="')+5,strlen($aBuf[$j])); $aBuf[$j]=substr($aBuf[$j],0,stripos($aBuf[$j],'" type')); */ $aBuf[$j]=$post->src; $j++; //echo "{$aBuf[$j]} \n |"; }
$link= $aBuf[0]; header('Content-type: content=video/mp4'); header("Content-Disposition: attachment; filename=vPlirex.mpg"); header("Pragma: no-cache"); header("Expires: 0"); $tFile = fopen($link,'r'); while (!feof($tFile)) { echo( fgets($tFile)); } fclose($tFile);
Source: https://habr.com/ru/post/168343/
All Articles