add support for cucked urls
This commit is contained in:
1 parent
e03c582f74
commit
ffb1fc00f3
8 files changed
+223
-318
No files matched your search
@@ -334,4 +334,89 @@ class backend{
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// SIGNATURES
|
||||||
|
//
|
||||||
|
public function hmac_sign(int $purpose, string $payload){
|
||||||
|
|
||||||
|
if(config::HMAC_SECRET === null){
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$header = pack("CN", $purpose, intdiv(time(), 60));
|
||||||
|
|
||||||
|
$hash = hash_hmac("sha256", $header . $payload, config::HMAC_SECRET, true);
|
||||||
|
|
||||||
|
return rtrim(strtr(base64_encode(
|
||||||
|
$header . $hash
|
||||||
|
), "+/", "-_"), "=");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hmac_verify(int $expected_purpose, string $payload, string $signature){
|
||||||
|
|
||||||
|
if(config::HMAC_SECRET === null){
|
||||||
|
|
||||||
|
return [
|
||||||
|
"valid" => true
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$decoded = base64_decode(strtr($signature, "-_", "+/"));
|
||||||
|
|
||||||
|
if(strlen($decoded) !== 37){
|
||||||
|
|
||||||
|
return [
|
||||||
|
"valid" => false,
|
||||||
|
"reason" => "Invalid signature size"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// extract bullshit
|
||||||
|
$purpose = unpack("C", $decoded)[1];
|
||||||
|
$timestamp = unpack("N", substr($decoded, 1, 4))[1];
|
||||||
|
$signature = substr($decoded, 5);
|
||||||
|
|
||||||
|
// check purpose
|
||||||
|
if($purpose !== $expected_purpose){
|
||||||
|
|
||||||
|
return [
|
||||||
|
"valid" => false,
|
||||||
|
"reason" => "This signature is used for something else"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// check expiration
|
||||||
|
$now = intdiv(time(), 60);
|
||||||
|
|
||||||
|
if(
|
||||||
|
$timestamp > $now ||
|
||||||
|
$now > $timestamp + config::HMAC_TTL
|
||||||
|
){
|
||||||
|
|
||||||
|
return [
|
||||||
|
"valid" => false,
|
||||||
|
"reason" => "Signature expired"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// check hmac
|
||||||
|
$r_header = pack("CN", $expected_purpose, $timestamp);
|
||||||
|
$r_hash = hash_hmac("sha256", $r_header . $payload, config::HMAC_SECRET, true);
|
||||||
|
|
||||||
|
if(!hash_equals($signature, $r_hash)){
|
||||||
|
|
||||||
|
return [
|
||||||
|
"valid" => false,
|
||||||
|
"reason" => "Signature mismatch"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
"valid" => true,
|
||||||
|
"timestamp" => $timestamp,
|
||||||
|
"signature" => $signature
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+4
-5
@@ -1148,7 +1148,7 @@ class frontend{
|
|||||||
"ddg" => "DuckDuckGo",
|
"ddg" => "DuckDuckGo",
|
||||||
"yandex" => "Yandex",
|
"yandex" => "Yandex",
|
||||||
"brave" => "Brave",
|
"brave" => "Brave",
|
||||||
"google" => "Google",
|
//"google" => "Google",
|
||||||
"google_api" => "Google API",
|
"google_api" => "Google API",
|
||||||
"google_cse" => "Google CSE",
|
"google_cse" => "Google CSE",
|
||||||
"yahoo_japan" => "Yahoo! JAPAN",
|
"yahoo_japan" => "Yahoo! JAPAN",
|
||||||
@@ -1183,7 +1183,7 @@ class frontend{
|
|||||||
"ddg" => "DuckDuckGo",
|
"ddg" => "DuckDuckGo",
|
||||||
"brave" => "Brave",
|
"brave" => "Brave",
|
||||||
"yandex" => "Yandex",
|
"yandex" => "Yandex",
|
||||||
"google" => "Google",
|
//"google" => "Google",
|
||||||
"yahoo_japan" => "Yahoo! JAPAN",
|
"yahoo_japan" => "Yahoo! JAPAN",
|
||||||
"startpage" => "Startpage",
|
"startpage" => "Startpage",
|
||||||
"naver" => "Naver",
|
"naver" => "Naver",
|
||||||
@@ -1201,7 +1201,7 @@ class frontend{
|
|||||||
"option" => [
|
"option" => [
|
||||||
"ddg" => "DuckDuckGo",
|
"ddg" => "DuckDuckGo",
|
||||||
"brave" => "Brave",
|
"brave" => "Brave",
|
||||||
"google" => "Google",
|
//"google" => "Google",
|
||||||
"yahoo_japan" => "Yahoo! JAPAN",
|
"yahoo_japan" => "Yahoo! JAPAN",
|
||||||
"startpage" => "Startpage",
|
"startpage" => "Startpage",
|
||||||
//"mojeek" => "Mojeek",
|
//"mojeek" => "Mojeek",
|
||||||
@@ -1214,8 +1214,7 @@ class frontend{
|
|||||||
$filters["scraper"] = [
|
$filters["scraper"] = [
|
||||||
"display" => "Scraper",
|
"display" => "Scraper",
|
||||||
"option" => [
|
"option" => [
|
||||||
"sc" => "SoundCloud",
|
"sc" => "SoundCloud"
|
||||||
"swisscows" => "Swisscows (SoundCloud)"
|
|
||||||
//"spotify" => "Spotify"
|
//"spotify" => "Spotify"
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class sc{
|
class brave{
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
|
|
||||||
include "lib/backend.php";
|
include "lib/backend.php";
|
||||||
$this->backend = new backend("sc");
|
$this->backend = new backend("brave");
|
||||||
|
|
||||||
include "lib/fuckhtml.php";
|
include "lib/fuckhtml.php";
|
||||||
$this->fuckhtml = new fuckhtml();
|
$this->fuckhtml = new fuckhtml();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get($proxy, $url, $get = []){
|
private function get(/*$proxy, */$url, $get = []){
|
||||||
|
|
||||||
$curlproc = curl_init();
|
$curlproc = curl_init();
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ class sc{
|
|||||||
["User-Agent: " . config::USER_AGENT,
|
["User-Agent: " . config::USER_AGENT,
|
||||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||||
"Accept-Language: en-US,en;q=0.5",
|
"Accept-Language: en-US,en;q=0.5",
|
||||||
"Accept-Encoding: gzip",
|
"Accept-Encoding: gzip, deflate, br, zstd",
|
||||||
"DNT: 1",
|
"DNT: 1",
|
||||||
"Sec-GPC: 1",
|
"Sec-GPC: 1",
|
||||||
"Connection: keep-alive",
|
"Connection: keep-alive",
|
||||||
@@ -40,7 +40,8 @@ class sc{
|
|||||||
"Sec-Fetch-User: ?1",
|
"Sec-Fetch-User: ?1",
|
||||||
"Priority: u=0, i"];
|
"Priority: u=0, i"];
|
||||||
|
|
||||||
$this->backend->assign_proxy($curlproc, $proxy);
|
// i dont think proxies are necessary here...
|
||||||
|
//$this->backend->assign_proxy($curlproc, $proxy);
|
||||||
|
|
||||||
curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
|
curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
|
||||||
curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
|
||||||
@@ -61,57 +62,51 @@ class sc{
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolve($id){
|
function resolve($id, $signature){
|
||||||
|
|
||||||
if(
|
$sig_status = $this->backend->hmac_verify(4, "brave,{$id}", $signature);
|
||||||
!preg_match(
|
|
||||||
'/^(t|p)[0-9]+$/',
|
|
||||||
$id
|
|
||||||
)
|
|
||||||
){
|
|
||||||
|
|
||||||
throw new Exception("ID is invalid");
|
if($sig_status["valid"] === false){
|
||||||
|
|
||||||
|
throw new Exception("[Signature] " . $sig_status["reason"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = $id[0] == "t" ? "track" : "playlist";
|
$html =
|
||||||
$id = substr($id, 1);
|
$this->get(
|
||||||
|
//$this->backend->get_ip(),
|
||||||
try{
|
"https://search.brave.com/go/v1/{$id}",
|
||||||
$html =
|
);
|
||||||
$this->get(
|
|
||||||
$this->backend->get_ip(),
|
|
||||||
"https://w.soundcloud.com/player/",
|
|
||||||
[
|
|
||||||
"url" => "http://api.soundcloud.com/{$type}s/{$id}",
|
|
||||||
"show_artwork" => "true"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}catch(Exception $error){
|
|
||||||
|
|
||||||
throw new Exception("Failed to fetch song embed page");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fuckhtml->load($html);
|
$this->fuckhtml->load($html);
|
||||||
|
|
||||||
$link =
|
$a =
|
||||||
$this->fuckhtml
|
$this->fuckhtml
|
||||||
->getElementsByAttributeValue(
|
->getElementsByClassName(
|
||||||
"rel",
|
"destination",
|
||||||
"canonical",
|
"a"
|
||||||
"link"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if(count($link) === 0){
|
if(count($a) === 0){
|
||||||
|
|
||||||
throw new Exception("Soundcloud could not resolve the song ID to an URL");
|
throw new Exception("Failed to find link");
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
$link =
|
||||||
$this->fuckhtml
|
$this->fuckhtml
|
||||||
->getTextContent(
|
->getTextContent(
|
||||||
$link[0]
|
$a[0]["attributes"]["href"]
|
||||||
["attributes"]
|
|
||||||
["href"]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(
|
||||||
|
preg_match(
|
||||||
|
'/^(https?:|)\/\//',
|
||||||
|
$link
|
||||||
|
)
|
||||||
|
){
|
||||||
|
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception("Got malformed link: " . $link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-1
@@ -62,7 +62,14 @@ class google{
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolve($id){
|
function resolve($id, $signature){
|
||||||
|
|
||||||
|
$sig_status = $this->backend->hmac_verify(4, "google,{$id}", $signature);
|
||||||
|
|
||||||
|
if($sig_status["valid"] === false){
|
||||||
|
|
||||||
|
throw new Exception("[Signature] " . $sig_status["reason"]);
|
||||||
|
}
|
||||||
|
|
||||||
$html =
|
$html =
|
||||||
$this->get(
|
$this->get(
|
||||||
|
|||||||
+18
-5
@@ -5,8 +5,8 @@ $resolver = new resolver();
|
|||||||
class resolver{
|
class resolver{
|
||||||
|
|
||||||
public const resolvers = [
|
public const resolvers = [
|
||||||
"sc",
|
"google",
|
||||||
"google"
|
"brave"
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
@@ -20,7 +20,6 @@ class resolver{
|
|||||||
){
|
){
|
||||||
|
|
||||||
$this->do400("Missing or invalid scraper");
|
$this->do400("Missing or invalid scraper");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(
|
if(
|
||||||
@@ -29,25 +28,37 @@ class resolver{
|
|||||||
){
|
){
|
||||||
|
|
||||||
$this->do400("Missing or invalid target");
|
$this->do400("Missing or invalid target");
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
if(
|
||||||
|
!isset($_GET["sig"]) ||
|
||||||
|
!is_string($_GET["sig"])
|
||||||
|
){
|
||||||
|
|
||||||
|
$this->do400("Missing or malformed signature");
|
||||||
}
|
}
|
||||||
|
|
||||||
$scraper = $_GET["scraper"];
|
$scraper = $_GET["scraper"];
|
||||||
$target = $_GET["target"];
|
$target = $_GET["target"];
|
||||||
|
$signature = $_GET["sig"];
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
include "resolve/{$scraper}.php";
|
include "resolve/{$scraper}.php";
|
||||||
$resolver = new $scraper();
|
$resolver = new $scraper();
|
||||||
$link = $resolver->resolve($target);
|
$link = $resolver->resolve($target, $signature);
|
||||||
|
|
||||||
if(
|
if(
|
||||||
is_string($link) &&
|
is_string($link) &&
|
||||||
!empty($link)
|
!empty($link)
|
||||||
){
|
){
|
||||||
|
|
||||||
|
http_response_code(302);
|
||||||
header("Location: {$link}");
|
header("Location: {$link}");
|
||||||
echo 'If your ass is not getting redirected, <a href="' . htmlspecialchars($link) . '">click here</a>.';
|
echo 'If your ass is not getting redirected, <a href="' . htmlspecialchars($link) . '">click here</a>.';
|
||||||
|
}else{
|
||||||
|
|
||||||
|
$this->do404("Fuck! Failed to resolve URL: Scraper returned no URL");
|
||||||
}
|
}
|
||||||
}catch(Exception $error){
|
}catch(Exception $error){
|
||||||
|
|
||||||
@@ -60,6 +71,7 @@ class resolver{
|
|||||||
header("Content-Type: text/plain");
|
header("Content-Type: text/plain");
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
echo htmlspecialchars($message);
|
echo htmlspecialchars($message);
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function do404($message){
|
public function do404($message){
|
||||||
@@ -67,5 +79,6 @@ class resolver{
|
|||||||
header("Content-Type: text/plain");
|
header("Content-Type: text/plain");
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
echo htmlspecialchars($message);
|
echo htmlspecialchars($message);
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+31
-12
@@ -537,7 +537,7 @@ class brave{
|
|||||||
$cluster["description"]
|
$cluster["description"]
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
"url" => $cluster["url"],
|
"url" => $this->convert_goto_to_resolver($cluster["url"]),
|
||||||
"date" => null
|
"date" => null
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -554,7 +554,7 @@ class brave{
|
|||||||
$sublink[] = [
|
$sublink[] = [
|
||||||
"title" => $this->titledots($r["title"]),
|
"title" => $this->titledots($r["title"]),
|
||||||
"description" => null,
|
"description" => null,
|
||||||
"url" => $r["url"],
|
"url" => $this->convert_goto_to_resolver($r["url"]),
|
||||||
"date" => null
|
"date" => null
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -864,7 +864,7 @@ class brave{
|
|||||||
$result["description"]
|
$result["description"]
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
"url" => $result["url"],
|
"url" => $this->convert_goto_to_resolver($result["url"]),
|
||||||
"date" => $date,
|
"date" => $date,
|
||||||
"type" => "web",
|
"type" => "web",
|
||||||
"thumb" => $thumb,
|
"thumb" => $thumb,
|
||||||
@@ -954,7 +954,7 @@ class brave{
|
|||||||
|
|
||||||
$description[] = [
|
$description[] = [
|
||||||
"type" => "link",
|
"type" => "link",
|
||||||
"url" => $rating["profile"]["url"],
|
"url" => $this->convert_goto_to_resolver($rating["profile"]["url"]),
|
||||||
"value" => $rating["profile"]["name"]
|
"value" => $rating["profile"]["name"]
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -1006,7 +1006,9 @@ class brave{
|
|||||||
$sublink[
|
$sublink[
|
||||||
$this->fuckhtml->getTextContent($name)
|
$this->fuckhtml->getTextContent($name)
|
||||||
] =
|
] =
|
||||||
$this->fuckhtml->getTextContent($row["url"]);
|
$this->fuckhtml->getTextContent(
|
||||||
|
$this->convert_goto_to_resolver($row["url"])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1025,7 +1027,7 @@ class brave{
|
|||||||
$out["answer"][] = [
|
$out["answer"][] = [
|
||||||
"title" => $this->fuckhtml->getTextContent($info["title"]),
|
"title" => $this->fuckhtml->getTextContent($info["title"]),
|
||||||
"description" => $description,
|
"description" => $description,
|
||||||
"url" => $info["url"],
|
"url" => $this->convert_goto_to_resolver($info["url"]),
|
||||||
"thumb" => $thumb,
|
"thumb" => $thumb,
|
||||||
"table" => $table,
|
"table" => $table,
|
||||||
"sublink" => $sublink
|
"sublink" => $sublink
|
||||||
@@ -1077,7 +1079,7 @@ class brave{
|
|||||||
"ratio" => null,
|
"ratio" => null,
|
||||||
"url" => null
|
"url" => null
|
||||||
],
|
],
|
||||||
"url" => $video["url"]
|
"url" => $this->convert_goto_to_resolver($video["url"])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1103,7 +1105,7 @@ class brave{
|
|||||||
"ratio" => null,
|
"ratio" => null,
|
||||||
"url" => null
|
"url" => null
|
||||||
],
|
],
|
||||||
"url" => $news["url"]
|
"url" => $this->convert_goto_to_resolver($news["url"])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1143,7 +1145,7 @@ class brave{
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
"url" => $disc["url"],
|
"url" => $this->convert_goto_to_resolver($disc["url"]),
|
||||||
"date" => isset($disc["age"]) ? strtotime($disc["age"]) : null,
|
"date" => isset($disc["age"]) ? strtotime($disc["age"]) : null,
|
||||||
"type" => "web",
|
"type" => "web",
|
||||||
"thumb" => [
|
"thumb" => [
|
||||||
@@ -1254,7 +1256,7 @@ class brave{
|
|||||||
"height" => (int)$result["thumbnail"]["height"]
|
"height" => (int)$result["thumbnail"]["height"]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"url" => $result["url"]
|
"url" => $this->convert_goto_to_resolver($result["url"])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1425,7 +1427,7 @@ class brave{
|
|||||||
"duration" => $result["video"]["duration"] == "null" ? null : $this->hms2int($result["video"]["duration"]),
|
"duration" => $result["video"]["duration"] == "null" ? null : $this->hms2int($result["video"]["duration"]),
|
||||||
"views" => $result["video"]["views"] == "null" ? null : (int)$result["video"]["views"],
|
"views" => $result["video"]["views"] == "null" ? null : (int)$result["video"]["views"],
|
||||||
"thumb" => $thumb,
|
"thumb" => $thumb,
|
||||||
"url" => $result["url"]
|
"url" => $this->convert_goto_to_resolver($result["url"])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1571,7 +1573,7 @@ class brave{
|
|||||||
"description" => $news["description"],
|
"description" => $news["description"],
|
||||||
"date" => !isset($news["age"]) || $news["age"] == "void 0" || $news["age"] == "null" ? null : strtotime($news["age"]),
|
"date" => !isset($news["age"]) || $news["age"] == "void 0" || $news["age"] == "null" ? null : strtotime($news["age"]),
|
||||||
"thumb" => $thumb,
|
"thumb" => $thumb,
|
||||||
"url" => $news["url"]
|
"url" => $this->convert_goto_to_resolver($news["url"])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2802,6 +2804,23 @@ class brave{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function convert_goto_to_resolver($url){
|
||||||
|
|
||||||
|
if(
|
||||||
|
preg_match(
|
||||||
|
'/^\/go\/v1\/([^\/?&]+)/',
|
||||||
|
$url,
|
||||||
|
$slug
|
||||||
|
) === 1
|
||||||
|
){
|
||||||
|
|
||||||
|
return "/resolver?scraper=brave&target={$slug[1]}&sig=" . $this->backend->hmac_sign(4, "brave,{$slug[1]}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// we got a normal URL, yay yipee
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
private function detect_captcha(){
|
private function detect_captcha(){
|
||||||
|
|
||||||
$title =
|
$title =
|
||||||
|
|||||||
+35
-244
@@ -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
|
// rest is ignored, since its not a redirect
|
||||||
|
|
||||||
// always return url
|
// always return url
|
||||||
@@ -704,86 +688,6 @@ class google{
|
|||||||
return $url;
|
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){
|
private function resolve_gotos(&$scraped_data){
|
||||||
|
|
||||||
foreach($this->urls_to_resolve as $item){
|
foreach($this->urls_to_resolve as $item){
|
||||||
@@ -861,140 +765,6 @@ class google{
|
|||||||
curl_multi_close($this->proc);
|
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){
|
private function recursive_replace(&$keys, &$replacements, &$pointer){
|
||||||
|
|
||||||
foreach($pointer as $key => &$value){
|
foreach($pointer as $key => &$value){
|
||||||
@@ -1058,7 +828,7 @@ class google{
|
|||||||
$params = [
|
$params = [
|
||||||
"q" => $get["s"],
|
"q" => $get["s"],
|
||||||
"hl" => "en",
|
"hl" => "en",
|
||||||
"udm" => 14
|
//"udm" => 14
|
||||||
];
|
];
|
||||||
|
|
||||||
// country
|
// country
|
||||||
@@ -1334,7 +1104,7 @@ class google{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sometimes the link is an encrypted redirect, handle redirection securely
|
// 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
|
$this->fuckhtml
|
||||||
->getTextContent($sublink),
|
->getTextContent($sublink),
|
||||||
"date" => null,
|
"date" => null,
|
||||||
"url" => $this->redirect_add_url($sublink_url)
|
"url" => $this->convert_goto_to_resolver($sublink_url)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$out["web"][] = [
|
$out["web"][] = [
|
||||||
"title" => $title,
|
"title" => $title,
|
||||||
"description" => $description,
|
"description" => $description,
|
||||||
"url" => $this->redirect_add_url($url),
|
"url" => $this->convert_goto_to_resolver($url),
|
||||||
"date" => $date,
|
"date" => $date,
|
||||||
"type" => "web",
|
"type" => "web",
|
||||||
"thumb" => $thumb,
|
"thumb" => $thumb,
|
||||||
@@ -1713,7 +1483,8 @@ class google{
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->resolve_share($out);
|
// no longer possible
|
||||||
|
//$this->resolve_gotos($out);
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
@@ -1756,8 +1527,8 @@ class google{
|
|||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
"q" => $search,
|
"q" => $search,
|
||||||
"udm" => "2", // get images
|
"tbm" => "isch", // get images
|
||||||
"start" => 0
|
//"start" => 0
|
||||||
];
|
];
|
||||||
|
|
||||||
// country (image search uses cr instead of gl)
|
// country (image search uses cr instead of gl)
|
||||||
@@ -1767,7 +1538,7 @@ class google{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nsfw
|
// nsfw
|
||||||
$params["safe"] = $nsfw == "yes" ? "off" : "active";
|
//$params["safe"] = $nsfw == "yes" ? "off" : "active";
|
||||||
|
|
||||||
// generate tbs
|
// generate tbs
|
||||||
$tbs = [];
|
$tbs = [];
|
||||||
@@ -1959,6 +1730,7 @@ class google{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// somehow still works? gotta keep an eye on it
|
||||||
$this->resolve_gotos($out);
|
$this->resolve_gotos($out);
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
@@ -1992,7 +1764,7 @@ class google{
|
|||||||
$params = [
|
$params = [
|
||||||
"q" => $search,
|
"q" => $search,
|
||||||
"udm" => "7",
|
"udm" => "7",
|
||||||
"hl" => "en"
|
//"hl" => "en"
|
||||||
];
|
];
|
||||||
|
|
||||||
// country
|
// country
|
||||||
@@ -2363,11 +2135,12 @@ class google{
|
|||||||
"duration" => $duration,
|
"duration" => $duration,
|
||||||
"views" => null,
|
"views" => null,
|
||||||
"thumb" => $thumb,
|
"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;
|
return $out;
|
||||||
}
|
}
|
||||||
@@ -2407,7 +2180,7 @@ class google{
|
|||||||
$params = [
|
$params = [
|
||||||
"q" => $search,
|
"q" => $search,
|
||||||
"tbm" => "nws",
|
"tbm" => "nws",
|
||||||
"hl" => "en"
|
//"hl" => "en"
|
||||||
];
|
];
|
||||||
|
|
||||||
// country
|
// country
|
||||||
@@ -2726,14 +2499,15 @@ class google{
|
|||||||
"date" => $date,
|
"date" => $date,
|
||||||
"thumb" => $thumb,
|
"thumb" => $thumb,
|
||||||
"url" =>
|
"url" =>
|
||||||
$this->redirect_add_url(
|
$this->convert_goto_to_resolver(
|
||||||
$a["attributes"]
|
$a["attributes"]
|
||||||
["href"]
|
["href"]
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->resolve_share($out);
|
// does not work
|
||||||
|
//$this->resolve_gotos($out);
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
@@ -3258,6 +3032,23 @@ class google{
|
|||||||
return rtrim(strtr(base64_encode($data), "+/", "-_"), "=");
|
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(){
|
private function detect_sorry(){
|
||||||
|
|
||||||
// detect recaptcha
|
// detect recaptcha
|
||||||
|
|||||||
+6
-10
@@ -223,10 +223,10 @@ $settings = [
|
|||||||
"value" => "brave",
|
"value" => "brave",
|
||||||
"text" => "Brave"
|
"text" => "Brave"
|
||||||
],
|
],
|
||||||
[
|
/*[
|
||||||
"value" => "google",
|
"value" => "google",
|
||||||
"text" => "Google"
|
"text" => "Google"
|
||||||
],
|
],*/
|
||||||
[
|
[
|
||||||
"value" => "google_api",
|
"value" => "google_api",
|
||||||
"text" => "Google API"
|
"text" => "Google API"
|
||||||
@@ -321,10 +321,10 @@ $settings = [
|
|||||||
"value" => "yandex",
|
"value" => "yandex",
|
||||||
"text" => "Yandex"
|
"text" => "Yandex"
|
||||||
],
|
],
|
||||||
[
|
/*[
|
||||||
"value" => "google",
|
"value" => "google",
|
||||||
"text" => "Google"
|
"text" => "Google"
|
||||||
],
|
],*/
|
||||||
[
|
[
|
||||||
"value" => "yahoo_japan",
|
"value" => "yahoo_japan",
|
||||||
"text" => "Yahoo! JAPAN",
|
"text" => "Yahoo! JAPAN",
|
||||||
@@ -367,10 +367,10 @@ $settings = [
|
|||||||
"value" => "brave",
|
"value" => "brave",
|
||||||
"text" => "Brave"
|
"text" => "Brave"
|
||||||
],
|
],
|
||||||
[
|
/*[
|
||||||
"value" => "google",
|
"value" => "google",
|
||||||
"text" => "Google"
|
"text" => "Google"
|
||||||
],
|
],*/
|
||||||
[
|
[
|
||||||
"value" => "yahoo_japan",
|
"value" => "yahoo_japan",
|
||||||
"text" => "Yahoo! JAPAN",
|
"text" => "Yahoo! JAPAN",
|
||||||
@@ -396,10 +396,6 @@ $settings = [
|
|||||||
[
|
[
|
||||||
"value" => "sc",
|
"value" => "sc",
|
||||||
"text" => "SoundCloud"
|
"text" => "SoundCloud"
|
||||||
],
|
|
||||||
[
|
|
||||||
"value" => "swisscows",
|
|
||||||
"text" => "Swisscows"
|
|
||||||
]
|
]
|
||||||
/*[
|
/*[
|
||||||
"value" => "spotify",
|
"value" => "spotify",
|
||||||
|
|||||||
Reference in new issue
Block a user