more brave fixes

This commit is contained in:
lolcat 2023-09-09 21:45:07 -04:00
parent bcbf5dd06b
commit 9964cdaf81
1 changed files with 199 additions and 33 deletions

View File

@ -414,8 +414,6 @@ class brave{
return $out; return $out;
} }
//$has_so_answer = false;
foreach($data["web"]["results"] as $result){ foreach($data["web"]["results"] as $result){
if( if(
@ -435,6 +433,7 @@ class brave{
]; ];
} }
// get sublinks
$sublink = []; $sublink = [];
if( if(
isset($result["cluster"]) && isset($result["cluster"]) &&
@ -458,10 +457,50 @@ class brave{
} }
} }
// more sublinks
if(
isset($result["deep_results"]) &&
is_array($result["deep_results"])
){
foreach($result["deep_results"]["buttons"] as $r){
$sublink[] = [
"title" => $this->titledots($r["title"]),
"description" => null,
"url" => $r["url"],
"date" => null
];
}
}
// parse table elements // parse table elements
$table = []; $table = [];
/*
[locations] => void 0 Done
[video] => void 0 Done
[movie] => void 0 Done
[faq] => void 0
[recipe] => void 0
[qa] => void 0 Not needed
[book] => void 0
[rating] => void 0
[article] => void 0
[product] => void 0 Done
[product_cluster] => void 0
[cluster_type] => void 0
[cluster] => void 0 Done
[creative_work] => void 0 Done
[music_recording] => void 0
[review] => void 0 Done
[software] => void 0 Done
[content_type] => void 0
[descriptionLength] => 271
*/
// product // product
// creative_work
$ref = null; $ref = null;
if(isset($result["product"])){ if(isset($result["product"])){
@ -535,6 +574,8 @@ class brave{
} }
} }
echo "test";
if($rating !== null){ if($rating !== null){
$table["Rating"] = $rating; $table["Rating"] = $rating;
@ -542,6 +583,75 @@ class brave{
} }
} }
// review
if(
isset($result["review"]) &&
is_array($result["review"])
){
if(isset($result["review"]["rating"]["ratingValue"])){
$table["Rating"] =
$result["review"]["rating"]["ratingValue"] . "/" .
$result["review"]["rating"]["bestRating"];
}
}
// software
if(
isset($result["software"]) &&
is_array($result["software"])
){
if(isset($result["software"]["author"])){
$table["Author"] = $result["software"]["author"];
}
if(isset($result["software"]["stars"])){
$table["Stars"] = number_format($result["software"]["stars"]);
}
if(isset($result["software"]["forks"])){
$table["Forks"] = number_format($result["software"]["forks"]);
}
if(isset($result["software"]["programmingLanguage"])){
$table["Programming languages"] = $result["software"]["programmingLanguage"];
}
}
// location
if(
isset($result["location"]) &&
is_array($result["location"])
){
if(isset($result["location"]["postal_address"]["displayAddress"])){
$table["Address"] = $result["location"]["postal_address"]["displayAddress"];
}
if(isset($result["location"]["rating"])){
$table["Rating"] =
$result["location"]["rating"]["ratingValue"] . "/" .
$result["location"]["rating"]["bestRating"] . " (" .
number_format($result["location"]["rating"]["reviewCount"]) . " votes)";
}
if(isset($result["location"]["contact"]["telephone"])){
$table["Phone number"] =
$result["location"]["contact"]["telephone"];
}
if(isset($result["location"]["price_range"])){
$table["Price"] =
$result["location"]["price_range"];
}
}
// video // video
if( if(
isset($result["video"]) && isset($result["video"]) &&
@ -559,40 +669,86 @@ class brave{
} }
} }
/* // movie
Get StackOverflow answers
*/
// commented out since it also returns alot of garbage
/*
if( if(
$has_so_answer === false && isset($result["video"]) &&
isset($result["qa"]) is_array($result["movie"])
){ ){
$has_so_answer = true; if(isset($result["movie"]["release"])){
$answer = $this->stackoverflow_parse($result["qa"]["answer"]["text"]);
if(isset($result["qa"]["answer"]["author"])){
$answer[] = [ $table["Release date"] = $result["movie"]["release"];
"type" => "quote",
"value" => "Answer from " . $result["qa"]["answer"]["author"]
];
} }
$out["answer"][] = [ if(isset($result["movie"]["directors"])){
"title" =>
$this->fuckhtml $directors = [];
->getTextContent(
$result["qa"]["question"] foreach($result["movie"]["directors"] as $director){
),
"description" => $answer, $directors[] = $director["name"];
"url" => $result["url"], }
"thumb" => null,
"table" => [], if(count($directors) !== 0){
"sublink" => []
]; $table["Directors"] = implode(", ", $directors);
}*/ }
}
if(isset($result["movie"]["actors"])){
$actors = [];
foreach($result["movie"]["actors"] as $actor){
$actors[] = $actor["name"];
}
if(count($actors) !== 0){
$table["Actors"] = implode(", ", $actors);
}
}
if(isset($result["movie"]["rating"])){
$table["Rating"] =
$result["movie"]["rating"]["ratingValue"] . "/" .
$result["movie"]["rating"]["bestRating"] . " (" .
number_format($result["movie"]["rating"]["reviewCount"]) . " votes)";
}
if(isset($result["movie"]["duration"])){
$table["Duration"] =
$result["movie"]["duration"];
}
if(isset($result["movie"]["genre"])){
$genres = [];
foreach($result["movie"]["genre"] as $genre){
$genres[] = $genre;
}
if(count($genres) !== 0){
$table["Genre"] = implode(", ", $genres);
}
}
}
if(
isset($result["age"]) &&
$result["age"] != "void 0" &&
$result["age"] != ""
){
$date = strtotime($result["age"]);
}else{
$date = null;
}
$out["web"][] = [ $out["web"][] = [
"title" => "title" =>
@ -600,6 +756,10 @@ class brave{
$result["title"] $result["title"]
), ),
"description" => "description" =>
isset($result["review"]["description"]) ?
$this->limitstrlen(
$result["review"]["description"]
) :
$this->titledots( $this->titledots(
$this->fuckhtml $this->fuckhtml
->getTextContent( ->getTextContent(
@ -607,7 +767,7 @@ class brave{
) )
), ),
"url" => $result["url"], "url" => $result["url"],
"date" => (isset($result["age"]) && $result["age"] != "void 0") ? strtotime($result["age"]) : null, "date" => $date,
"type" => "web", "type" => "web",
"thumb" => $thumb, "thumb" => $thumb,
"sublink" => $sublink, "sublink" => $sublink,
@ -622,10 +782,16 @@ class brave{
isset($data["query"]["bo_altered_diff"][0][0]) && isset($data["query"]["bo_altered_diff"][0][0]) &&
$data["query"]["bo_altered_diff"][0][0] == "true" $data["query"]["bo_altered_diff"][0][0] == "true"
){ ){
$using = [];
foreach($data["query"]["bo_altered_diff"] as $diff){
$using[] = $diff[1];
}
$out["spelling"] = [ $out["spelling"] = [
"type" => "including", "type" => "including",
"using" => $data["query"]["bo_altered_diff"][0][1], "using" => implode(" ", $using),
"correction" => $get["s"] "correction" => $get["s"]
]; ];
} }
@ -1189,7 +1355,7 @@ class brave{
"title" => $result["title"], "title" => $result["title"],
"description" => $result["description"] == "null" ? null : $this->titledots($result["description"]), "description" => $result["description"] == "null" ? null : $this->titledots($result["description"]),
"author" => $author, "author" => $author,
"date" => $result["age"] == "null" ? null : strtotime($result["age"]), "date" => ($result["age"] == "null" || $result["age"] == "void 0") ? null : strtotime($result["age"]),
"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,