This commit is contained in:
lolcat committed 2026-11-07 02:09:26 -05:00
1 parent c0324d7d61
commit 6bbb37d86e
1 file changed
+19 -58
+19 -58
View File
@@ -205,13 +205,6 @@ class yep{
"zh-tw" => "Chinese (Traditional)", "zh-tw" => "Chinese (Traditional)",
"zu" => "Zulu" "zu" => "Zulu"
] ]
],
"nsfw" => [
"display" => "NSFW",
"option" => [
"yes" => "Yes",
"no" => "No"
]
] ]
]; ];
} }
@@ -317,20 +310,23 @@ class yep{
// parse filters // parse filters
$filters = [ $filters = [
"limit" => 100, // wwwwwwwwwwwwwww "q" => $search,
"query" => $search, "limit" => 10 // no fun allowed
]; ];
if($get["nsfw"] == "no"){ $filters["safeSearch"] = "moderate"; } if($get["lang"] != "any"){
if($get["lang"] != "any"){ $filters["hl"] = $get["lang"]; }
$filters["language"] = $get["lang"];
$filters["lang"] = $get["lang"];
}
try{ try{
// https://api.yep.com/search?limit=20&query=asmr // https://yep.com/web/v1/search?q=asmr&limit=10
$json = $json =
$this->get( $this->get(
$this->backend->get_ip(), $this->backend->get_ip(),
"https://api.yep.com/search", "https://yep.com/web/v1/search",
$filters $filters
); );
@@ -343,59 +339,27 @@ class yep{
$json = json_decode($json, true); $json = json_decode($json, true);
//$json = json_decode(file_get_contents("scraper/yep.json"), true); //$json = json_decode(file_get_contents("scraper/yep.json"), true);
if($json === null){ if($json === null){
throw new Exception("Failed to decode JSON"); throw new Exception("Failed to decode JSON");
} }
if(isset($json[1]["correction"])){ if(isset($json["code"])){
$out["spelling"] = [ if(isset($json["reason"])){
"type" => "not_many",
"using" => $search, throw new Exception("Yep returned an API error: [{$json["code"]}] {$json["reason"]}");
"correction" => $json[1]["correction"][1]
];
} }
if(isset($json[1]["results"])){ throw new Exception("Yep returned an unknown error");
foreach($json[1]["results"] as $item){
switch(strtolower($item["type"])){
case "organic":
$sublinks = [];
if(isset($item["sitelinks"]["full"])){
foreach($item["sitelinks"]["full"] as $link){
$sublinks[] = [
"title" => $link["title"],
"date" => null,
"description" =>
$this->titledots(
strip_tags(
html_entity_decode(
$link["snippet"]
)
)
),
"url" => $link["url"]
];
}
} }
if(isset($json["results"])){
foreach($json["results"] as $item){
$out["web"][] = [ $out["web"][] = [
"title" => $item["title"], "title" => $item["title"],
"description" => "description" => str_replace("\n", " ", $item["description"]),
$this->titledots(
strip_tags(
html_entity_decode(
$item["snippet"]
)
)
),
"url" => $item["url"], "url" => $item["url"],
"date" => null, "date" => null,
"type" => "web", "type" => "web",
@@ -403,11 +367,9 @@ class yep{
"url" => null, "url" => null,
"ratio" => null "ratio" => null
], ],
"sublink" => $sublinks, "sublink" => [],
"table" => [] "table" => []
]; ];
break;
}
} }
} }
@@ -445,7 +407,6 @@ class yep{
"limit" => 99 // for some reason they dont show anything sometimes at 100 results "limit" => 99 // for some reason they dont show anything sometimes at 100 results
]; ];
if($get["nsfw"] == "no"){ $filters["safe_search"] = true; }
if($get["lang"] != "any"){ $filters["language"] = [ $get["lang"] ]; } if($get["lang"] != "any"){ $filters["language"] = [ $get["lang"] ]; }
// add api key // add api key