yep fic
This commit is contained in:
1 parent
c0324d7d61
commit
6bbb37d86e
1 file changed
+31
-70
+31
-70
@@ -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,71 +339,37 @@ 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]
|
}
|
||||||
];
|
|
||||||
|
throw new Exception("Yep returned an unknown error");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($json[1]["results"])){
|
if(isset($json["results"])){
|
||||||
foreach($json[1]["results"] as $item){
|
foreach($json["results"] as $item){
|
||||||
|
|
||||||
switch(strtolower($item["type"])){
|
$out["web"][] = [
|
||||||
|
"title" => $item["title"],
|
||||||
case "organic":
|
"description" => str_replace("\n", " ", $item["description"]),
|
||||||
$sublinks = [];
|
"url" => $item["url"],
|
||||||
|
"date" => null,
|
||||||
if(isset($item["sitelinks"]["full"])){
|
"type" => "web",
|
||||||
|
"thumb" => [
|
||||||
foreach($item["sitelinks"]["full"] as $link){
|
"url" => null,
|
||||||
|
"ratio" => null
|
||||||
$sublinks[] = [
|
],
|
||||||
"title" => $link["title"],
|
"sublink" => [],
|
||||||
"date" => null,
|
"table" => []
|
||||||
"description" =>
|
];
|
||||||
$this->titledots(
|
|
||||||
strip_tags(
|
|
||||||
html_entity_decode(
|
|
||||||
$link["snippet"]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
"url" => $link["url"]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$out["web"][] = [
|
|
||||||
"title" => $item["title"],
|
|
||||||
"description" =>
|
|
||||||
$this->titledots(
|
|
||||||
strip_tags(
|
|
||||||
html_entity_decode(
|
|
||||||
$item["snippet"]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
"url" => $item["url"],
|
|
||||||
"date" => null,
|
|
||||||
"type" => "web",
|
|
||||||
"thumb" => [
|
|
||||||
"url" => null,
|
|
||||||
"ratio" => null
|
|
||||||
],
|
|
||||||
"sublink" => $sublinks,
|
|
||||||
"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
|
||||||
|
|||||||
Reference in new issue
Block a user