parent
3e56bbc23b
commit
3c6e44bd34
2 changed files with 160 additions and 33 deletions
|
|
@ -94,7 +94,7 @@ class google{
|
|||
|
||||
if(
|
||||
preg_match(
|
||||
'/^https?/',
|
||||
'/^(https?:|)\/\//',
|
||||
$link
|
||||
)
|
||||
){
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ class google{
|
|||
|
||||
include "lib/backend.php";
|
||||
$this->backend = new backend("google");
|
||||
|
||||
$this->proc = curl_multi_init();
|
||||
$this->handles = [];
|
||||
}
|
||||
|
||||
public function getfilters($page){
|
||||
|
|
@ -614,6 +617,145 @@ class google{
|
|||
];
|
||||
}
|
||||
|
||||
private function redirect_add_url($url){
|
||||
|
||||
if(
|
||||
preg_match(
|
||||
'/^\/goto\?url=([^&]+)/',
|
||||
$url,
|
||||
$slug
|
||||
) === 0
|
||||
){
|
||||
|
||||
// not a google redirect
|
||||
return $url;
|
||||
}
|
||||
|
||||
$curlproc = curl_init();
|
||||
|
||||
curl_setopt($curlproc, CURLOPT_URL, "https://www.google.com/goto?url=" . urlencode($slug[1]));
|
||||
|
||||
curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
|
||||
curl_setopt($curlproc, CURLOPT_HTTPHEADER,
|
||||
["User-Agent: " . config::USER_AGENT,
|
||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
"Accept-Language: en-US,en;q=0.5",
|
||||
"Accept-Encoding: gzip, deflate, br, zstd",
|
||||
"DNT: 1",
|
||||
"Sec-GPC: 1",
|
||||
"Connection: keep-alive",
|
||||
"Upgrade-Insecure-Requests: 1",
|
||||
"Sec-Fetch-Dest: document",
|
||||
"Sec-Fetch-Mode: navigate",
|
||||
"Sec-Fetch-Site: none",
|
||||
"Sec-Fetch-User: ?1",
|
||||
"Priority: u=0, i"]
|
||||
);
|
||||
|
||||
curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
|
||||
curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
//$this->backend->assign_proxy($curlproc, $proxy);
|
||||
|
||||
curl_multi_add_handle($this->proc, $curlproc);
|
||||
$this->handles[] = [
|
||||
"replacement" => $url,
|
||||
"handle" => $curlproc
|
||||
];
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
private function resolve_urls(&$scraped_data){
|
||||
|
||||
do{
|
||||
do{
|
||||
$status = curl_multi_exec($this->proc, $active);
|
||||
}while($status === CURLM_CALL_MULTI_PERFORM);
|
||||
|
||||
if($active){
|
||||
curl_multi_select($this->proc);
|
||||
}
|
||||
|
||||
}while($active && $status === CURLM_OK);
|
||||
|
||||
//
|
||||
// if we reach this, we're done downloading garbage
|
||||
//
|
||||
|
||||
// parse redirect values & create data shit
|
||||
$keys = [];
|
||||
$replacements = [];
|
||||
|
||||
for($i=0; $i<count($this->handles); $i++){
|
||||
|
||||
$this->fuckhtml->load(
|
||||
curl_multi_getcontent(
|
||||
$this->handles[$i]["handle"]
|
||||
)
|
||||
);
|
||||
|
||||
$a =
|
||||
$this->fuckhtml
|
||||
->getElementsByTagName(
|
||||
"a"
|
||||
);
|
||||
|
||||
if(count($a) === 0){
|
||||
|
||||
throw new Exception("Failed to find link");
|
||||
}
|
||||
|
||||
$link =
|
||||
$this->fuckhtml
|
||||
->getTextContent(
|
||||
$a[0]["attributes"]["href"]
|
||||
);
|
||||
|
||||
if(
|
||||
preg_match(
|
||||
'/^(https?:|)\/\//',
|
||||
$link
|
||||
)
|
||||
){
|
||||
|
||||
$keys[] = $this->handles[$i]["replacement"];
|
||||
$replacements[] = $link;
|
||||
}
|
||||
}
|
||||
|
||||
$this->recursive_replace($keys, $replacements, $scraped_data);
|
||||
|
||||
curl_multi_close($this->proc);
|
||||
}
|
||||
|
||||
private function recursive_replace(&$keys, &$replacements, &$pointer){
|
||||
|
||||
foreach($pointer as $key => &$value){
|
||||
|
||||
if($key == "url"){
|
||||
|
||||
$search =
|
||||
array_search(
|
||||
$value,
|
||||
$keys
|
||||
);
|
||||
|
||||
if($search !== false){
|
||||
|
||||
// replace url
|
||||
$value = $replacements[$search];
|
||||
}
|
||||
|
||||
}elseif(is_array($value)){
|
||||
|
||||
$this->recursive_replace($keys, $replacements, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function web($get){
|
||||
|
||||
|
|
@ -930,20 +1072,7 @@ class google{
|
|||
){
|
||||
|
||||
// sometimes the link is an encrypted redirect, handle redirection securely
|
||||
if(
|
||||
preg_match(
|
||||
'/^\/goto\?url=(.*)/',
|
||||
$link,
|
||||
$payload
|
||||
)
|
||||
){
|
||||
|
||||
$notices[] = "/resolver?scraper=google&target=" . $payload[1];
|
||||
}else{
|
||||
|
||||
// normal link
|
||||
$notices[] = $link;
|
||||
}
|
||||
$notices[] = $this->redirect_add_url($link);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1290,31 +1419,19 @@ class google{
|
|||
$sublink["attributes"]["href"]
|
||||
);
|
||||
|
||||
if(
|
||||
preg_match(
|
||||
'/^\/goto\?url=(.*)/',
|
||||
$sublink_url,
|
||||
$piece_of_shit
|
||||
)
|
||||
){
|
||||
|
||||
// encrypted piece of shit url
|
||||
$sublink_url = "/resolver?scraper=google&target=" . $piece_of_shit[1];
|
||||
}
|
||||
|
||||
$sublinks[] = [
|
||||
"title" =>
|
||||
$this->fuckhtml
|
||||
->getTextContent($sublink),
|
||||
"date" => null,
|
||||
"url" => $sublink_url
|
||||
"url" => $this->redirect_add_url($sublink_url)
|
||||
];
|
||||
}
|
||||
|
||||
$out["web"][] = [
|
||||
"title" => $title,
|
||||
"description" => $description,
|
||||
"url" => $url,
|
||||
"url" => $this->redirect_add_url($url),
|
||||
"date" => $date,
|
||||
"type" => "web",
|
||||
"thumb" => $thumb,
|
||||
|
|
@ -1323,6 +1440,8 @@ class google{
|
|||
];
|
||||
}
|
||||
|
||||
$this->resolve_urls($out);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
|
@ -1533,9 +1652,11 @@ class google{
|
|||
),
|
||||
"source" => $source,
|
||||
"url" =>
|
||||
$this->fuckhtml
|
||||
->getTextContent(
|
||||
$div["attributes"]["data-lpage"]
|
||||
$this->redirect_add_url(
|
||||
$this->fuckhtml
|
||||
->getTextContent(
|
||||
$div["attributes"]["data-lpage"]
|
||||
)
|
||||
)
|
||||
];
|
||||
}
|
||||
|
|
@ -1560,6 +1681,8 @@ class google{
|
|||
);
|
||||
}
|
||||
|
||||
$this->resolve_urls($out);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
|
@ -1962,10 +2085,12 @@ class google{
|
|||
"duration" => $duration,
|
||||
"views" => null,
|
||||
"thumb" => $thumb,
|
||||
"url" => $url
|
||||
"url" => $this->redirect_add_url($url)
|
||||
];
|
||||
}
|
||||
|
||||
$this->resolve_urls($out);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
|
@ -2330,6 +2455,8 @@ class google{
|
|||
];
|
||||
}
|
||||
|
||||
$this->resolve_urls($out);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue