Preparing to multi-account search
This commit is contained in:
@@ -54,8 +54,6 @@ class Vkontakte {
|
||||
'q' => urlencode($this->_query),
|
||||
'sort' =>'2'
|
||||
)));
|
||||
$this->parseHtml();
|
||||
return $this->_files;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +97,8 @@ class Vkontakte {
|
||||
private function auth() {
|
||||
$this->_cookies = array(
|
||||
'remixchk' => 5,
|
||||
'remixsid' => 'c68c4362f62f218a25802bae87201d1bc46fadd0b5c64f71678430c9b63b'
|
||||
'remixsid' => 'cf8bdd79d451422c1d484532a58205d92fc46b79caab663a40624c812e01',
|
||||
'remixlang' => 777
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,12 +62,16 @@ class VkontakteMP3 {
|
||||
* @author chez
|
||||
**/
|
||||
public static function check($files, $artist_name, $track_name, $track_length) {
|
||||
$urls = array();
|
||||
foreach($files as $i => $file) {
|
||||
$urls[$i] = $file['url'];
|
||||
}
|
||||
$headers = RemoteFile::getHeadersMT($urls);
|
||||
foreach ($files as $i => $file) {
|
||||
$headers = RemoteFile::getHeaders($file['url']);
|
||||
if ($headers === false || $headers['http'] != 200) {
|
||||
if (!isset($headers[$i]['http']) || $headers[$i]['http'] != 200) {
|
||||
unset($files[$i]);
|
||||
} else {
|
||||
$files[$i]['size'] = trim($headers['content_length']);
|
||||
$files[$i]['size'] = trim($headers[$i]['content_length']);
|
||||
}
|
||||
}
|
||||
$m = new TrackWeight();
|
||||
|
||||
@@ -118,4 +118,51 @@ class RemoteFile {
|
||||
public static function setHeaders($headers) {
|
||||
self::$_headers = $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Массововое получение заголовков по списку файлов
|
||||
*
|
||||
* @param array $fules Ассоциативный массив id => url
|
||||
* @return array Ассоциативный массив id => headers
|
||||
* @author chez
|
||||
**/
|
||||
public static function getHeadersMT($files) {
|
||||
$mh = curl_multi_init();
|
||||
$headers_all = array();
|
||||
$handlers = array();
|
||||
foreach($files as $i => $url) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_NOBODY, 1);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_multi_add_handle($mh, $ch);
|
||||
$handlers[$i] = $ch;
|
||||
}
|
||||
$running=null;
|
||||
do
|
||||
{
|
||||
curl_multi_exec($mh, $running);
|
||||
usleep (250000);
|
||||
} while ($running > 0);
|
||||
foreach($handlers as $i => $ch) {
|
||||
$content = curl_multi_getcontent($handlers[$i]);
|
||||
curl_multi_remove_handle($mh, $handlers[$i]);
|
||||
$content = explode("\r\n", $content);
|
||||
$headers = array();
|
||||
foreach($content as $header) {
|
||||
if (substr($header, 0, 5) == 'HTTP/') {
|
||||
$header = explode(' ', $header);
|
||||
$headers['http'] = $header[1];
|
||||
} elseif ($header != '') {
|
||||
preg_match('/^([a-z0-9\-]*):\s(.*)$/Ui', $header, $m);
|
||||
$headers[strtolower(str_replace('-', '_', $m[1]))] = $m[2];
|
||||
}
|
||||
}
|
||||
$headers_all[$i] = $headers;
|
||||
}
|
||||
curl_multi_close($mh);
|
||||
return $headers_all;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user