summaryrefslogtreecommitdiff
path: root/api/v1/ac.php
diff options
context:
space:
mode:
authorlolcat <will@lolcat.ca>2023-11-07 08:04:56 -0500
committerlolcat <will@lolcat.ca>2023-11-07 08:04:56 -0500
commit785452873f0ee0a27fc157b482b7551560f0282d (patch)
tree4c70e240031ed3868425ca683c83ebfd378a9159 /api/v1/ac.php
parent64b090ee058953aed2246967332c7f0b6623cd8f (diff)
fix typo
Diffstat (limited to 'api/v1/ac.php')
-rw-r--r--api/v1/ac.php91
1 files changed, 53 insertions, 38 deletions
diff --git a/api/v1/ac.php b/api/v1/ac.php
index 3ee1481..b1ec7dd 100644
--- a/api/v1/ac.php
+++ b/api/v1/ac.php
@@ -1,5 +1,6 @@
<?php
+include "../../data/config.php";
new autocomplete();
class autocomplete{
@@ -17,7 +18,7 @@ class autocomplete{
"yep" => "https://api.yep.com/ac/?query={searchTerms}",
"marginalia" => "https://search.marginalia.nu/suggest/?partial={searchTerms}",
"yt" => "https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&q={searchTerms}",
- "sc" => "https://api-v2.soundcloud.com/search/queries?q={searchTerms}&client_id=ArYppSEotE3YiXCO4Nsgid2LLqJutiww&limit=10&offset=0&linked_partitioning=1&app_version=1693487844&app_locale=en"
+ "sc" => "https://api-v2.soundcloud.com/search/queries?q={searchTerms}&client_id=" . config::SC_CLIENT_TOKEN . "&limit=10&offset=0&linked_partitioning=1&app_version=1693487844&app_locale=en"
];
/*
@@ -107,7 +108,8 @@ class autocomplete{
[
$_GET["s"],
$json
- ]
+ ],
+ JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
break;
@@ -132,7 +134,8 @@ class autocomplete{
[
$_GET["s"],
$json
- ]
+ ],
+ JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
break;
@@ -150,7 +153,8 @@ class autocomplete{
[
$_GET["s"],
$json
- ]
+ ],
+ JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
break;
@@ -162,7 +166,8 @@ class autocomplete{
[
$_GET["s"],
$json[1] // ensure it contains valid key 0
- ]
+ ],
+ JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
break;
}
@@ -170,45 +175,54 @@ class autocomplete{
private function get($url, $query){
- $curlproc = curl_init();
-
- $url = str_replace("{searchTerms}", urlencode($query), $url);
-
- curl_setopt($curlproc, CURLOPT_URL, $url);
-
- curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
- curl_setopt($curlproc, CURLOPT_HTTPHEADER,
- ["User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0",
- "Accept: application/json, text/javascript, */*; q=0.01",
- "Accept-Language: en-US,en;q=0.5",
- "Accept-Encoding: gzip",
- "DNT: 1",
- "Connection: keep-alive",
- "Sec-Fetch-Dest: empty",
- "Sec-Fetch-Mode: cors",
- "Sec-Fetch-Site: same-site"]
- );
-
- 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);
-
- $data = curl_exec($curlproc);
+ try{
+ $curlproc = curl_init();
+
+ $url = str_replace("{searchTerms}", urlencode($query), $url);
+
+ curl_setopt($curlproc, CURLOPT_URL, $url);
+
+ curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
+ curl_setopt($curlproc, CURLOPT_HTTPHEADER,
+ ["User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0",
+ "Accept: application/json, text/javascript, */*; q=0.01",
+ "Accept-Language: en-US,en;q=0.5",
+ "Accept-Encoding: gzip",
+ "DNT: 1",
+ "Connection: keep-alive",
+ "Sec-Fetch-Dest: empty",
+ "Sec-Fetch-Mode: cors",
+ "Sec-Fetch-Site: same-site"]
+ );
+
+ 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);
+
+ $data = curl_exec($curlproc);
+
+ if(curl_errno($curlproc)){
+
+ throw new Exception(curl_error($curlproc));
+ }
+
+ curl_close($curlproc);
+ return $data;
- if(curl_errno($curlproc)){
+ }catch(Exception $error){
- throw new Exception(curl_error($curlproc));
+ do404("Curl error: " . $error->getMessage());
}
-
- curl_close($curlproc);
- return $data;
}
private function do404($error){
- echo json_encode(["error" => $error]);
+ echo json_encode(
+ ["error" => $error],
+ JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
+ );
die();
}
@@ -218,7 +232,8 @@ class autocomplete{
[
$_GET["s"],
[]
- ]
+ ],
+ JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
die();
}