add support for cucked urls

This commit is contained in:
lolcat committed 2026-11-30 17:19:39 -05:00
1 parent e03c582f74
commit ffb1fc00f3
8 files changed
+223 -318

No files matched your search

+35 -244
View File
@@ -642,22 +642,6 @@ class google{
];
}
elseif(
preg_match(
'/https?:\/\/share\.google\/([^"]+)+/',
$url,
$link_regex
) === 1
){
// share.google
$this->urls_to_resolve[] = [
"replace" => $replace,
"slug" => $link_regex[1],
"type" => "share"
];
}
// rest is ignored, since its not a redirect
// always return url
@@ -704,86 +688,6 @@ class google{
return $url;
}
private function urlfuck_shareservice($url, $slug){
$curlproc = curl_init();
curl_setopt($curlproc, CURLOPT_URL, "https://www.google.com/httpservice/retry/SearchApiService/GetShortenedKpSharingUrl?udm=14&reqpld=[[[\"/goto?url%3D" . rawurlencode($slug) . "\"],1,null,null,null,null,35,[\"st\"]]]&msc=gwsrpc");
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, $this->backend->get_ip(null, true));
curl_multi_add_handle($this->proc, $curlproc);
$this->handles[] = [
"replacement" => $url,
"handle" => $curlproc
];
return $url;
}
private function urlfuck_share($url, $slug){
$curlproc = curl_init();
curl_setopt($curlproc, CURLOPT_URL, "https://www.google.com/share.google?q=" . rawurlencode($slug));
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, $this->backend->get_ip(null, true));
curl_multi_add_handle($this->proc, $curlproc);
$this->handles[] = [
"replacement" => $url,
"handle" => $curlproc
];
return $url;
}
private function resolve_gotos(&$scraped_data){
foreach($this->urls_to_resolve as $item){
@@ -861,140 +765,6 @@ class google{
curl_multi_close($this->proc);
}
private function resolve_share(&$scraped_data){
foreach($this->urls_to_resolve as $item){
$this->urlfuck_shareservice($item["replace"], $item["slug"]);
}
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
//
// get the share links
$this->urls_to_resolve = [];
for($i=0; $i<count($this->handles); $i++){
$html = curl_multi_getcontent($this->handles[$i]["handle"]);
if(
preg_match(
'/https?:\/\/share\.google\/(?:[^"]+)/',
$html,
$link_regex
) !== 1
){
// failed to find link, will serve a resolver target as fallback
$fallback = true;
$slug = explode("url=", $this->handles[$i]["replacement"]);
$link = "/resolver?scraper=google&target=" . rawurlencode($slug[1]);
}else{
$fallback = false;
$link = $link_regex[0];
}
if(
(
$fallback === false &&
preg_match(
'/^(https?:|)\/\//',
$link
)
) ||
$fallback === true
){
$this->redirect_add_url($link, $this->handles[$i]["replacement"]);
}
}
// resolve shareable urls
$this->init_multi_curl();
foreach($this->urls_to_resolve as $item){
$this->urlfuck_share($item["replace"], $item["slug"]);
}
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);
// parse downloaded garbage
$keys = [];
$replacements = [];
for($i=0; $i<count($this->handles); $i++){
$html = curl_multi_getcontent($this->handles[$i]["handle"]);
$this->fuckhtml->load($html);
$a =
$this->fuckhtml
->getElementsByTagName(
"a"
);
if(count($a) === 0){
// failed to find link, will serve a resolver target as fallback
$fallback = true;
$slug = explode("url=", $this->handles[$i]["replacement"]);
$link = "/resolver?scraper=google&target=" . rawurlencode($slug[1]);
}else{
$fallback = false;
$link =
$this->fuckhtml
->getTextContent(
$a[0]["attributes"]["href"]
);
}
if(
(
$fallback === false &&
preg_match(
'/^(https?:|)\/\//',
$link
)
) ||
$fallback === true
){
$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){
@@ -1058,7 +828,7 @@ class google{
$params = [
"q" => $get["s"],
"hl" => "en",
"udm" => 14
//"udm" => 14
];
// country
@@ -1334,7 +1104,7 @@ class google{
}
// sometimes the link is an encrypted redirect, handle redirection securely
$notices[] = $this->redirect_add_url($link);
$notices[] = $this->convert_goto_to_resolver($link);
}
}
@@ -1697,14 +1467,14 @@ class google{
$this->fuckhtml
->getTextContent($sublink),
"date" => null,
"url" => $this->redirect_add_url($sublink_url)
"url" => $this->convert_goto_to_resolver($sublink_url)
];
}
$out["web"][] = [
"title" => $title,
"description" => $description,
"url" => $this->redirect_add_url($url),
"url" => $this->convert_goto_to_resolver($url),
"date" => $date,
"type" => "web",
"thumb" => $thumb,
@@ -1713,7 +1483,8 @@ class google{
];
}
$this->resolve_share($out);
// no longer possible
//$this->resolve_gotos($out);
return $out;
}
@@ -1756,8 +1527,8 @@ class google{
$params = [
"q" => $search,
"udm" => "2", // get images
"start" => 0
"tbm" => "isch", // get images
//"start" => 0
];
// country (image search uses cr instead of gl)
@@ -1767,7 +1538,7 @@ class google{
}
// nsfw
$params["safe"] = $nsfw == "yes" ? "off" : "active";
//$params["safe"] = $nsfw == "yes" ? "off" : "active";
// generate tbs
$tbs = [];
@@ -1959,6 +1730,7 @@ class google{
);
}
// somehow still works? gotta keep an eye on it
$this->resolve_gotos($out);
return $out;
@@ -1992,7 +1764,7 @@ class google{
$params = [
"q" => $search,
"udm" => "7",
"hl" => "en"
//"hl" => "en"
];
// country
@@ -2363,11 +2135,12 @@ class google{
"duration" => $duration,
"views" => null,
"thumb" => $thumb,
"url" => $this->redirect_add_url($url)
"url" => $this->convert_goto_to_resolver($url)
];
}
$this->resolve_share($out);
// does not work
//$this->resolve_gotos($out);
return $out;
}
@@ -2407,7 +2180,7 @@ class google{
$params = [
"q" => $search,
"tbm" => "nws",
"hl" => "en"
//"hl" => "en"
];
// country
@@ -2726,14 +2499,15 @@ class google{
"date" => $date,
"thumb" => $thumb,
"url" =>
$this->redirect_add_url(
$this->convert_goto_to_resolver(
$a["attributes"]
["href"]
)
];
}
$this->resolve_share($out);
// does not work
//$this->resolve_gotos($out);
return $out;
}
@@ -3258,6 +3032,23 @@ class google{
return rtrim(strtr(base64_encode($data), "+/", "-_"), "=");
}
private function convert_goto_to_resolver($url){
if(
preg_match(
'/^\/goto\?url=([^&]+)/',
$url,
$slug
) === 1
){
return "/resolver?scraper=google&target={$slug[1]}&sig=" . $this->backend->hmac_sign(4, "google,{$slug[1]}");
}
// we got a normal URL, yay yipee
return $url;
}
private function detect_sorry(){
// detect recaptcha