brave.php 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  1. <?php
  2. class brave{
  3. public function __construct(){
  4. include "lib/fuckhtml.php";
  5. $this->fuckhtml = new fuckhtml();
  6. include "lib/backend.php";
  7. $this->backend = new backend("brave");
  8. }
  9. public function getfilters($page){
  10. switch($page){
  11. case "web":
  12. return [
  13. "country" => [
  14. "display" => "Country",
  15. "option" => [
  16. "all" => "All Regions",
  17. "ar" => "Argentina",
  18. "au" => "Australia",
  19. "at" => "Austria",
  20. "be" => "Belgium",
  21. "br" => "Brazil",
  22. "ca" => "Canada",
  23. "cl" => "Chile",
  24. "cn" => "China",
  25. "dk" => "Denmark",
  26. "fi" => "Finland",
  27. "fr" => "France",
  28. "de" => "Germany",
  29. "hk" => "Hong Kong",
  30. "in" => "India",
  31. "id" => "Indonesia",
  32. "it" => "Italy",
  33. "jp" => "Japan",
  34. "kr" => "Korea",
  35. "my" => "Malaysia",
  36. "mx" => "Mexico",
  37. "nl" => "Netherlands",
  38. "nz" => "New Zealand",
  39. "no" => "Norway",
  40. "pl" => "Poland",
  41. "pt" => "Portugal",
  42. "ph" => "Philippines",
  43. "ru" => "Russia",
  44. "sa" => "Saudi Arabia",
  45. "za" => "South Africa",
  46. "es" => "Spain",
  47. "se" => "Sweden",
  48. "ch" => "Switzerland",
  49. "tw" => "Taiwan",
  50. "tr" => "Turkey",
  51. "gb" => "United Kingdom",
  52. "us" => "United States"
  53. ]
  54. ],
  55. "nsfw" => [
  56. "display" => "NSFW",
  57. "option" => [
  58. "yes" => "Yes",
  59. "maybe" => "Maybe",
  60. "no" => "No"
  61. ]
  62. ],
  63. "newer" => [
  64. "display" => "Newer than",
  65. "option" => "_DATE"
  66. ],
  67. "older" => [
  68. "display" => "Older than",
  69. "option" => "_DATE"
  70. ],
  71. "spellcheck" => [
  72. "display" => "Spellcheck",
  73. "option" => [
  74. "yes" => "Yes",
  75. "no" => "No"
  76. ]
  77. ]
  78. ];
  79. break;
  80. case "images":
  81. case "videos":
  82. case "news":
  83. return [
  84. "country" => [
  85. "display" => "Country",
  86. "option" => [
  87. "all" => "All regions",
  88. "ar" => "Argentina",
  89. "au" => "Australia",
  90. "at" => "Austria",
  91. "be" => "Belgium",
  92. "br" => "Brazil",
  93. "ca" => "Canada",
  94. "cl" => "Chile",
  95. "cn" => "China",
  96. "dk" => "Denmark",
  97. "fi" => "Finland",
  98. "fr" => "France",
  99. "de" => "Germany",
  100. "hk" => "Hong Kong",
  101. "in" => "India",
  102. "id" => "Indonesia",
  103. "it" => "Italy",
  104. "jp" => "Japan",
  105. "kr" => "Korea",
  106. "my" => "Malaysia",
  107. "mx" => "Mexico",
  108. "nl" => "Netherlands",
  109. "nz" => "New Zealand",
  110. "no" => "Norway",
  111. "pl" => "Poland",
  112. "pt" => "Portugal",
  113. "ph" => "Philippines",
  114. "ru" => "Russia",
  115. "sa" => "Saudi Arabia",
  116. "za" => "South Africa",
  117. "es" => "Spain",
  118. "se" => "Sweden",
  119. "ch" => "Switzerland",
  120. "tw" => "Taiwan",
  121. "tr" => "Turkey",
  122. "gb" => "United Kingdom",
  123. "us" => "United States"
  124. ]
  125. ],
  126. "nsfw" => [
  127. "display" => "NSFW",
  128. "option" => [
  129. "yes" => "Yes",
  130. "maybe" => "Maybe",
  131. "no" => "No"
  132. ]
  133. ],
  134. "spellcheck" => [
  135. "display" => "Spellcheck",
  136. "option" => [
  137. "yes" => "Yes",
  138. "no" => "No"
  139. ]
  140. ]
  141. ];
  142. break;
  143. }
  144. }
  145. private function get($proxy, $url, $get = [], $nsfw, $country){
  146. switch($nsfw){
  147. case "yes": $nsfw = "off"; break;
  148. case "maybe": $nsfw = "moderate"; break;
  149. case "no": $nsfw = "strict"; break;
  150. }
  151. if($country == "any"){
  152. $country = "all";
  153. }
  154. $headers = [
  155. "User-Agent: " . config::USER_AGENT,
  156. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
  157. "Accept-Language: en-US,en;q=0.5",
  158. "Accept-Encoding: gzip",
  159. "Cookie: safesearch={$nsfw}; country={$country}; useLocation=0; summarizer=0",
  160. "DNT: 1",
  161. "Connection: keep-alive",
  162. "Upgrade-Insecure-Requests: 1",
  163. "Sec-Fetch-Dest: document",
  164. "Sec-Fetch-Mode: navigate",
  165. "Sec-Fetch-Site: none",
  166. "Sec-Fetch-User: ?1"
  167. ];
  168. $curlproc = curl_init();
  169. if($get !== []){
  170. $get = http_build_query($get);
  171. $url .= "?" . $get;
  172. }
  173. curl_setopt($curlproc, CURLOPT_URL, $url);
  174. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  175. curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
  176. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  177. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  178. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  179. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  180. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  181. $this->backend->assign_proxy($curlproc, $proxy);
  182. $data = curl_exec($curlproc);
  183. if(curl_errno($curlproc)){
  184. throw new Exception(curl_error($curlproc));
  185. }
  186. curl_close($curlproc);
  187. return $data;
  188. }
  189. public function web($get){
  190. if($get["npt"]){
  191. // get next page data
  192. [$q, $proxy] = $this->backend->get($get["npt"], "web");
  193. $q = json_decode($q, true);
  194. $search = $q["q"];
  195. $q["spellcheck"] = "0";
  196. $nsfw = $q["nsfw"];
  197. unset($q["nsfw"]);
  198. $country = $q["country"];
  199. unset($q["country"]);
  200. }else{
  201. // get _GET data instead
  202. $search = $get["s"];
  203. if(strlen($search) === 0){
  204. throw new Exception("Search term is empty!");
  205. }
  206. if(strlen($search) > 2048){
  207. throw new Exception("Search term is too long!");
  208. }
  209. $proxy = $this->backend->get_ip();
  210. $nsfw = $get["nsfw"];
  211. $country = $get["country"];
  212. $older = $get["older"];
  213. $newer = $get["newer"];
  214. $spellcheck = $get["spellcheck"];
  215. $q = [
  216. "q" => $search
  217. ];
  218. /*
  219. Pass older/newer filters to brave
  220. */
  221. if($newer !== false){
  222. $newer = date("Y-m-d", $newer);
  223. if($older === false){
  224. $older = date("Y-m-d", time());
  225. }
  226. }
  227. if(
  228. is_string($older) === false &&
  229. $older !== false
  230. ){
  231. $older = date("Y-m-d", $older);
  232. if($newer === false){
  233. $newer = "1970-01-02";
  234. }
  235. }
  236. if($older !== false){
  237. $q["tf"] = "{$newer}to{$older}";
  238. }
  239. // spellcheck
  240. if($spellcheck == "no"){
  241. $q["spellcheck"] = "0";
  242. }
  243. }
  244. /*
  245. $handle = fopen("scraper/brave.html", "r");
  246. $html = fread($handle, filesize("scraper/brave.html"));
  247. fclose($handle);
  248. */
  249. try{
  250. $html =
  251. $this->get(
  252. $proxy,
  253. "https://search.brave.com/search",
  254. $q,
  255. $nsfw,
  256. $country
  257. );
  258. }catch(Exception $error){
  259. throw new Exception("Could not fetch search page");
  260. }
  261. $out = [
  262. "status" => "ok",
  263. "spelling" => [
  264. "type" => "no_correction",
  265. "using" => null,
  266. "correction" => null
  267. ],
  268. "npt" => null,
  269. "answer" => [],
  270. "web" => [],
  271. "image" => [],
  272. "video" => [],
  273. "news" => [],
  274. "related" => []
  275. ];
  276. // load html
  277. $this->fuckhtml->load($html);
  278. /*
  279. Get next page "token"
  280. */
  281. $nextpage =
  282. $this->fuckhtml
  283. ->getElementById(
  284. "pagination",
  285. "div"
  286. );
  287. if($nextpage){
  288. $this->fuckhtml->load($nextpage);
  289. $nextpage =
  290. $this->fuckhtml
  291. ->getElementsByClassName("btn", "a");
  292. if(count($nextpage) !== 0){
  293. $nextpage =
  294. $nextpage[count($nextpage) - 1];
  295. if(
  296. strtolower(
  297. $this->fuckhtml
  298. ->getTextContent(
  299. $nextpage
  300. )
  301. ) == "next"
  302. ){
  303. preg_match(
  304. '/offset=([0-9]+)/',
  305. $this->fuckhtml->getTextContent($nextpage["attributes"]["href"]),
  306. $nextpage
  307. );
  308. $q["offset"] = (int)$nextpage[1];
  309. $q["nsfw"] = $nsfw;
  310. $q["country"] = $country;
  311. $out["npt"] =
  312. $this->backend->store(
  313. json_encode($q),
  314. "web",
  315. $proxy
  316. );
  317. }
  318. }
  319. }
  320. $this->fuckhtml->load($html);
  321. $script_disc =
  322. $this->fuckhtml
  323. ->getElementsByTagName(
  324. "script"
  325. );
  326. $grep = [];
  327. foreach($script_disc as $discs){
  328. preg_match(
  329. '/const data ?= ?(\[{.*}]);/',
  330. $discs["innerHTML"],
  331. $grep
  332. );
  333. if(isset($grep[1])){
  334. break;
  335. }
  336. }
  337. if(!isset($grep[1])){
  338. throw new Exception("Could not get data JS");
  339. }
  340. $data =
  341. $this->fuckhtml
  342. ->parseJsObject(
  343. $grep[1]
  344. );
  345. unset($grep);
  346. $data = $data[1]["data"]["body"]["response"];
  347. /*
  348. Get web results
  349. */
  350. if(!isset($data["web"]["results"])){
  351. return $out;
  352. }
  353. foreach($data["web"]["results"] as $result){
  354. if(
  355. isset($result["thumbnail"]) &&
  356. is_array($result["thumbnail"])
  357. ){
  358. $thumb = [
  359. "ratio" => $result["thumbnail"]["logo"] == "false" ? "16:9" : "1:1",
  360. "url" => $result["thumbnail"]["original"]
  361. ];
  362. }else{
  363. $thumb = [
  364. "ratio" => null,
  365. "url" => null
  366. ];
  367. }
  368. // get sublinks
  369. $sublink = [];
  370. if(
  371. isset($result["cluster"]) &&
  372. is_array($result["cluster"])
  373. ){
  374. foreach($result["cluster"] as $cluster){
  375. $sublink[] = [
  376. "title" => $this->titledots($cluster["title"]),
  377. "description" =>
  378. $this->titledots(
  379. $this->fuckhtml
  380. ->getTextContent(
  381. $cluster["description"]
  382. )
  383. ),
  384. "url" => $cluster["url"],
  385. "date" => null
  386. ];
  387. }
  388. }
  389. // more sublinks
  390. if(
  391. isset($result["deep_results"]) &&
  392. is_array($result["deep_results"])
  393. ){
  394. foreach($result["deep_results"]["buttons"] as $r){
  395. $sublink[] = [
  396. "title" => $this->titledots($r["title"]),
  397. "description" => null,
  398. "url" => $r["url"],
  399. "date" => null
  400. ];
  401. }
  402. }
  403. // parse table elements
  404. $table = [];
  405. /*
  406. [locations] => void 0 Done
  407. [video] => void 0 Done
  408. [movie] => void 0 Done
  409. [faq] => void 0
  410. [recipe] => void 0
  411. [qa] => void 0 Not needed
  412. [book] => void 0
  413. [rating] => void 0
  414. [article] => void 0
  415. [product] => void 0 Done
  416. [product_cluster] => void 0
  417. [cluster_type] => void 0
  418. [cluster] => void 0 Done
  419. [creative_work] => void 0 Done
  420. [music_recording] => void 0
  421. [review] => void 0 Done
  422. [software] => void 0 Done
  423. [content_type] => void 0
  424. [descriptionLength] => 271
  425. */
  426. // product
  427. // creative_work
  428. $ref = null;
  429. if(isset($result["product"])){
  430. $ref = &$result["product"];
  431. }elseif(isset($result["creative_work"])){
  432. $ref = &$result["creative_work"];
  433. }
  434. if($ref !== null){
  435. if(isset($ref["offers"])){
  436. foreach($ref["offers"] as $offer){
  437. $price = null;
  438. if(isset($offer["price"])){
  439. if((float)$offer["price"] == 0){
  440. $price = "Free";
  441. }else{
  442. $price = $offer["price"];
  443. }
  444. }
  445. if($price !== "Free"){
  446. if(isset($offer["priceCurrency"])){
  447. $price .= " " . $offer["priceCurrency"];
  448. }
  449. }
  450. if($price !== null){
  451. $table["Price"] = trim($price);
  452. }
  453. }
  454. }
  455. if(isset($ref["rating"])){
  456. $rating = null;
  457. if(isset($ref["rating"]["ratingValue"])){
  458. $rating = $ref["rating"]["ratingValue"];
  459. if(isset($ref["rating"]["bestRating"])){
  460. $rating .= "/" . $ref["rating"]["bestRating"];
  461. }
  462. }
  463. if(isset($ref["rating"]["reviewCount"])){
  464. $isnull = $rating === null ? false : true;
  465. if($isnull){
  466. $rating .= " (";
  467. }
  468. $rating .= number_format($ref["rating"]["reviewCount"]) . " hits";
  469. if($isnull){
  470. $rating .= ")";
  471. }
  472. }
  473. if($rating !== null){
  474. $table["Rating"] = $rating;
  475. }
  476. }
  477. }
  478. // review
  479. if(
  480. isset($result["review"]) &&
  481. is_array($result["review"])
  482. ){
  483. if(isset($result["review"]["rating"]["ratingValue"])){
  484. $table["Rating"] =
  485. $result["review"]["rating"]["ratingValue"] . "/" .
  486. $result["review"]["rating"]["bestRating"];
  487. }
  488. }
  489. // software
  490. if(
  491. isset($result["software"]) &&
  492. is_array($result["software"])
  493. ){
  494. if(isset($result["software"]["author"])){
  495. $table["Author"] = $result["software"]["author"];
  496. }
  497. if(isset($result["software"]["stars"])){
  498. $table["Stars"] = number_format($result["software"]["stars"]);
  499. }
  500. if(isset($result["software"]["forks"])){
  501. $table["Forks"] = number_format($result["software"]["forks"]);
  502. }
  503. if(
  504. isset($result["software"]["programmingLanguage"]) &&
  505. $result["software"]["programmingLanguage"] != ""
  506. ){
  507. $table["Programming languages"] = $result["software"]["programmingLanguage"];
  508. }
  509. }
  510. // location
  511. if(
  512. isset($result["location"]) &&
  513. is_array($result["location"])
  514. ){
  515. if(isset($result["location"]["postal_address"]["displayAddress"])){
  516. $table["Address"] = $result["location"]["postal_address"]["displayAddress"];
  517. }
  518. if(isset($result["location"]["rating"])){
  519. $table["Rating"] =
  520. $result["location"]["rating"]["ratingValue"] . "/" .
  521. $result["location"]["rating"]["bestRating"] . " (" .
  522. number_format($result["location"]["rating"]["reviewCount"]) . " votes)";
  523. }
  524. if(isset($result["location"]["contact"]["telephone"])){
  525. $table["Phone number"] =
  526. $result["location"]["contact"]["telephone"];
  527. }
  528. if(isset($result["location"]["price_range"])){
  529. $table["Price"] =
  530. $result["location"]["price_range"];
  531. }
  532. }
  533. // video
  534. if(
  535. isset($result["video"]) &&
  536. is_array($result["video"])
  537. ){
  538. foreach($result["video"] as $key => $value){
  539. if(is_string($result["video"][$key]) === false){
  540. continue;
  541. }
  542. $table[ucfirst($key)] = $value;
  543. }
  544. }
  545. // movie
  546. if(
  547. isset($result["video"]) &&
  548. is_array($result["movie"])
  549. ){
  550. if(isset($result["movie"]["release"])){
  551. $table["Release date"] = $result["movie"]["release"];
  552. }
  553. if(isset($result["movie"]["directors"])){
  554. $directors = [];
  555. foreach($result["movie"]["directors"] as $director){
  556. $directors[] = $director["name"];
  557. }
  558. if(count($directors) !== 0){
  559. $table["Directors"] = implode(", ", $directors);
  560. }
  561. }
  562. if(isset($result["movie"]["actors"])){
  563. $actors = [];
  564. foreach($result["movie"]["actors"] as $actor){
  565. $actors[] = $actor["name"];
  566. }
  567. if(count($actors) !== 0){
  568. $table["Actors"] = implode(", ", $actors);
  569. }
  570. }
  571. if(isset($result["movie"]["rating"])){
  572. $table["Rating"] =
  573. $result["movie"]["rating"]["ratingValue"] . "/" .
  574. $result["movie"]["rating"]["bestRating"] . " (" .
  575. number_format($result["movie"]["rating"]["reviewCount"]) . " votes)";
  576. }
  577. if(isset($result["movie"]["duration"])){
  578. $table["Duration"] =
  579. $result["movie"]["duration"];
  580. }
  581. if(isset($result["movie"]["genre"])){
  582. $genres = [];
  583. foreach($result["movie"]["genre"] as $genre){
  584. $genres[] = $genre;
  585. }
  586. if(count($genres) !== 0){
  587. $table["Genre"] = implode(", ", $genres);
  588. }
  589. }
  590. }
  591. if(
  592. isset($result["age"]) &&
  593. $result["age"] != "void 0" &&
  594. $result["age"] != ""
  595. ){
  596. $date = strtotime($result["age"]);
  597. }else{
  598. $date = null;
  599. }
  600. $out["web"][] = [
  601. "title" =>
  602. $this->titledots(
  603. $result["title"]
  604. ),
  605. "description" =>
  606. isset($result["review"]["description"]) ?
  607. $this->limitstrlen(
  608. strip_tags(
  609. $result["review"]["description"]
  610. )
  611. ) :
  612. $this->titledots(
  613. $this->fuckhtml
  614. ->getTextContent(
  615. $result["description"]
  616. )
  617. ),
  618. "url" => $result["url"],
  619. "date" => $date,
  620. "type" => "web",
  621. "thumb" => $thumb,
  622. "sublink" => $sublink,
  623. "table" => $table
  624. ];
  625. }
  626. /*
  627. Get spelling autocorrect
  628. */
  629. if(
  630. isset($data["query"]["bo_altered_diff"][0][0]) &&
  631. $data["query"]["bo_altered_diff"][0][0] == "true"
  632. ){
  633. $using = [];
  634. foreach($data["query"]["bo_altered_diff"] as $diff){
  635. $using[] = $diff[1];
  636. }
  637. $out["spelling"] = [
  638. "type" => "including",
  639. "using" => implode(" ", $using),
  640. "correction" => $get["s"]
  641. ];
  642. }
  643. /*
  644. Get wikipedia heads
  645. */
  646. if(isset($data["infobox"]["results"][0])){
  647. foreach($data["infobox"]["results"] as $info){
  648. if($info["subtype"] == "code"){
  649. $description =
  650. $this->stackoverflow_parse($info["data"]["answer"]["text"]);
  651. if(isset($info["data"]["answer"]["author"])){
  652. $description[] = [
  653. "type" => "quote",
  654. "value" => "Answer from " . $info["data"]["answer"]["author"]
  655. ];
  656. }
  657. }else{
  658. $description = [];
  659. if(
  660. isset($info["description"]) &&
  661. $info["description"] != ""
  662. ){
  663. $description[] = [
  664. "type" => "quote",
  665. "value" => $info["description"]
  666. ];
  667. }
  668. if(
  669. isset($info["long_desc"]) &&
  670. $info["long_desc"] != ""
  671. ){
  672. $description[] = [
  673. "type" => "text",
  674. "value" => $this->titledots($info["long_desc"])
  675. ];
  676. }
  677. // parse ratings
  678. if(
  679. isset($info["ratings"]) &&
  680. $info["ratings"] != "void 0"
  681. ){
  682. $description[] = [
  683. "type" => "title",
  684. "value" => "Ratings"
  685. ];
  686. foreach($info["ratings"] as $rating){
  687. $description[] = [
  688. "type" => "link",
  689. "url" => $rating["profile"]["url"],
  690. "value" => $rating["profile"]["name"]
  691. ];
  692. $description[] = [
  693. "type" => "text",
  694. "value" => ": " . $rating["ratingValue"] . "/" . $rating["bestRating"] . "\n"
  695. ];
  696. }
  697. }
  698. }
  699. $table = [];
  700. if(isset($info["attributes"])){
  701. foreach($info["attributes"] as $row){
  702. if(
  703. $row[1] == "null" &&
  704. count($table) !== 0
  705. ){
  706. break;
  707. }
  708. if($row[1] == "null"){
  709. continue;
  710. }
  711. $table[
  712. $this->fuckhtml->getTextContent($row[0])
  713. ] =
  714. $this->fuckhtml->getTextContent($row[1]);
  715. }
  716. }
  717. $sublink = [];
  718. if(isset($info["profiles"])){
  719. foreach($info["profiles"] as $row){
  720. $name = $this->fuckhtml->getTextContent($row["name"]);
  721. if(strtolower($name) == "steampowered"){
  722. $name = "Steam";
  723. }
  724. $sublink[
  725. $this->fuckhtml->getTextContent($name)
  726. ] =
  727. $this->fuckhtml->getTextContent($row["url"]);
  728. }
  729. }
  730. $out["answer"][] = [
  731. "title" => $this->fuckhtml->getTextContent($info["title"]),
  732. "description" => $description,
  733. "url" => $info["url"],
  734. "thumb" => isset($info["images"][0]["original"]) ? $info["images"][0]["original"] : null,
  735. "table" => $table,
  736. "sublink" => $sublink
  737. ];
  738. break; // only iterate once, we get garbage most of the time
  739. }
  740. }
  741. /*
  742. Get videos
  743. */
  744. if(isset($data["videos"]["results"])){
  745. foreach($data["videos"]["results"] as $video){
  746. $out["video"][] = [
  747. "title" => $this->titledots($video["title"]),
  748. "description" => $this->titledots($video["description"]),
  749. "date" => isset($video["age"]) && $video["age"] != "void 0" ? strtotime($video["age"]) : null,
  750. "duration" => isset($video["video"]["duration"]) && $video["video"]["duration"] != "void 0" ? $this->hms2int($video["video"]["duration"]) : null,
  751. "views" => isset($video["video"]["views"]) && $video["video"]["views"] != "void 0" ? (int)$video["video"]["views"] : null,
  752. "thumb" =>
  753. isset($video["thumbnail"]["src"]) ?
  754. [
  755. "ratio" => "16:9",
  756. "url" => $this->unshiturl($video["thumbnail"]["src"])
  757. ] :
  758. [
  759. "ratio" => null,
  760. "url" => null
  761. ],
  762. "url" => $video["url"]
  763. ];
  764. }
  765. }
  766. /*
  767. Get news
  768. */
  769. if(isset($data["news"]["results"])){
  770. foreach($data["news"]["results"] as $news){
  771. $out["news"][] = [
  772. "title" => $this->titledots($news["title"]),
  773. "description" => $this->titledots($news["description"]),
  774. "date" => isset($news["age"]) ? strtotime($news["age"]) : null,
  775. "thumb" =>
  776. isset($video["thumbnail"]["src"]) ?
  777. [
  778. "ratio" => "16:9",
  779. "url" => $this->unshiturl($video["thumbnail"]["src"])
  780. ] :
  781. [
  782. "ratio" => null,
  783. "url" => null
  784. ],
  785. "url" => $news["url"]
  786. ];
  787. }
  788. }
  789. /*
  790. Get discussions
  791. */
  792. $disc_out = [];
  793. if(isset($data["discussions"]["results"])){
  794. foreach($data["discussions"]["results"] as $disc){
  795. $table = [];
  796. if(isset($disc["data"]["num_votes"])){
  797. $table["Votes"] = number_format($disc["data"]["num_votes"]);
  798. }
  799. if(isset($disc["data"]["num_answers"])){
  800. $table["Comments"] = number_format($disc["data"]["num_answers"]);
  801. }
  802. $disc_out[] = [
  803. "title" =>
  804. $this->titledots(
  805. $disc["title"]
  806. ),
  807. "description" =>
  808. $this->limitstrlen(
  809. $this->titledots(
  810. $this->fuckhtml
  811. ->getTextContent(
  812. $disc["description"]
  813. )
  814. )
  815. ),
  816. "url" => $disc["url"],
  817. "date" => isset($disc["age"]) ? strtotime($disc["age"]) : null,
  818. "type" => "web",
  819. "thumb" => [
  820. "ratio" => null,
  821. "url" => null
  822. ],
  823. "sublink" => [],
  824. "table" => $table
  825. ];
  826. }
  827. }
  828. // append discussions at position 2
  829. array_splice($out["web"], 1, 0, $disc_out);
  830. return $out;
  831. }
  832. public function news($get){
  833. if($get["npt"]){
  834. [$req, $proxy] = $this->backend->get($get["npt"], "news");
  835. $req = json_decode($req, true);
  836. $search = $req["q"];
  837. $country = $req["country"];
  838. $nsfw = $req["nsfw"];
  839. $offset = $req["offset"];
  840. $spellcheck = $req["spellcheck"];
  841. try{
  842. $html =
  843. $this->get(
  844. $proxy,
  845. "https://search.brave.com/news",
  846. [
  847. "q" => $search,
  848. "offset" => $offset,
  849. "spellcheck" => $spellcheck
  850. ],
  851. $nsfw,
  852. $country
  853. );
  854. }catch(Exception $error){
  855. throw new Exception("Could not fetch search page");
  856. }
  857. }else{
  858. $search = $get["s"];
  859. if(strlen($search) === 0){
  860. throw new Exception("Search term is empty!");
  861. }
  862. if(strlen($search) > 2048){
  863. throw new Exception("Search term is too long!");
  864. }
  865. $proxy = $this->backend->get_ip();
  866. $nsfw = $get["nsfw"];
  867. $country = $get["country"];
  868. $spellcheck = $get["spellcheck"] == "yes" ? "1" : "0";
  869. /*
  870. $handle = fopen("scraper/brave-news.html", "r");
  871. $html = fread($handle, filesize("scraper/brave-news.html"));
  872. fclose($handle);*/
  873. try{
  874. $html =
  875. $this->get(
  876. $proxy,
  877. "https://search.brave.com/news",
  878. [
  879. "q" => $search,
  880. "spellcheck" => $spellcheck
  881. ],
  882. $nsfw,
  883. $country
  884. );
  885. }catch(Exception $error){
  886. throw new Exception("Could not fetch search page");
  887. }
  888. }
  889. $out = [
  890. "status" => "ok",
  891. "npt" => null,
  892. "news" => []
  893. ];
  894. // load html
  895. $this->fuckhtml->load($html);
  896. // get npt
  897. $out["npt"] =
  898. $this->generatenextpagetoken(
  899. $search,
  900. $nsfw,
  901. $country,
  902. $spellcheck,
  903. "news",
  904. $proxy
  905. );
  906. preg_match(
  907. '/const data ?= ?(\[{.*}]);/',
  908. $html,
  909. $json
  910. );
  911. if(!isset($json[1])){
  912. throw new Exception("Failed to grep javascript object");
  913. }
  914. $json = $this->fuckhtml->parseJsObject($json[1], true);
  915. if($json === null){
  916. throw new Exception("Failed to parse javascript object");
  917. }
  918. foreach(
  919. $json[1]["data"]["body"]["response"]["news"]["results"]
  920. as $news
  921. ){
  922. if(
  923. !isset($news["thumbnail"]["src"]) ||
  924. $news["thumbnail"]["src"] == "void 0"
  925. ){
  926. $thumb = [
  927. "url" => null,
  928. "ratio" => null
  929. ];
  930. }else{
  931. $thumb = [
  932. "url" => $this->unshiturl($news["thumbnail"]["src"]),
  933. "ratio" => "16:9"
  934. ];
  935. }
  936. $out["news"][] = [
  937. "title" => $news["title"],
  938. "author" => null,
  939. "description" => $news["description"],
  940. "date" => !isset($news["age"]) || $news["age"] == "void 0" ? null : strtotime($news["age"]),
  941. "thumb" => $thumb,
  942. "url" => $news["url"]
  943. ];
  944. }
  945. return $out;
  946. }
  947. public function image($get){
  948. $search = $get["s"];
  949. if(strlen($search) === 0){
  950. throw new Exception("Search term is empty!");
  951. }
  952. if(strlen($search) > 2048){
  953. throw new Exception("Search term is too long!");
  954. }
  955. $country = $get["country"];
  956. $nsfw = $get["nsfw"];
  957. $spellcheck = $get["spellcheck"] == "yes" ? "1" : "0";
  958. $out = [
  959. "status" => "ok",
  960. "npt" => null,
  961. "image" => []
  962. ];
  963. try{
  964. $html =
  965. $this->get(
  966. $this->backend->get_ip(), // no nextpage right now, pass proxy directly
  967. "https://search.brave.com/images",
  968. [
  969. "q" => $search,
  970. "spellcheck" => $spellcheck
  971. ],
  972. $nsfw,
  973. $country
  974. );
  975. }catch(Exception $error){
  976. throw new Exception("Could not fetch search page");
  977. }
  978. /*
  979. $handle = fopen("scraper/brave-image.html", "r");
  980. $html = fread($handle, filesize("scraper/brave-image.html"));
  981. fclose($handle);*/
  982. preg_match(
  983. '/const data = (\[{.*}\]);/',
  984. $html,
  985. $json
  986. );
  987. if(!isset($json[1])){
  988. throw new Exception("Failed to get data object");
  989. }
  990. $json =
  991. $this->fuckhtml
  992. ->parseJsObject(
  993. $json[1]
  994. );
  995. foreach(
  996. $json[1]
  997. ["data"]
  998. ["body"]
  999. ["response"]
  1000. ["results"]
  1001. as $result
  1002. ){
  1003. $out["image"][] = [
  1004. "title" => $result["title"],
  1005. "source" => [
  1006. [
  1007. "url" => $result["properties"]["url"],
  1008. "width" => null,
  1009. "height" => null
  1010. ],
  1011. [
  1012. "url" => $result["thumbnail"]["src"],
  1013. "width" => null,
  1014. "height" => null
  1015. ]
  1016. ],
  1017. "url" => $result["url"]
  1018. ];
  1019. }
  1020. return $out;
  1021. }
  1022. public function video($get){
  1023. if($get["npt"]){
  1024. [$npt, $proxy] = $this->backend->get($get["npt"], "videos");
  1025. $npt = json_decode($npt, true);
  1026. $search = $npt["q"];
  1027. $offset = $npt["offset"];
  1028. $spellcheck = $npt["spellcheck"];
  1029. $country = $npt["country"];
  1030. $nsfw = $npt["nsfw"];
  1031. try{
  1032. $html =
  1033. $this->get(
  1034. $proxy,
  1035. "https://search.brave.com/videos",
  1036. [
  1037. "q" => $search,
  1038. "offset" => $offset,
  1039. "spellcheck" => $spellcheck
  1040. ],
  1041. $nsfw,
  1042. $country
  1043. );
  1044. }catch(Exception $error){
  1045. throw new Exception("Could not fetch search page");
  1046. }
  1047. }else{
  1048. $search = $get["s"];
  1049. if(strlen($search) === 0){
  1050. throw new Exception("Search term is empty!");
  1051. }
  1052. if(strlen($search) > 2048){
  1053. throw new Exception("Search term is too long!");
  1054. }
  1055. $country = $get["country"];
  1056. $nsfw = $get["nsfw"];
  1057. $spellcheck = $get["spellcheck"] == "yes" ? "1" : "0";
  1058. $proxy = $this->backend->get_ip();
  1059. try{
  1060. $html =
  1061. $this->get(
  1062. $proxy,
  1063. "https://search.brave.com/videos",
  1064. [
  1065. "q" => $search,
  1066. "spellcheck" => $spellcheck
  1067. ],
  1068. $nsfw,
  1069. $country
  1070. );
  1071. }catch(Exception $error){
  1072. throw new Exception("Could not fetch search page");
  1073. }
  1074. }
  1075. $this->fuckhtml->load($html);
  1076. $out = [
  1077. "status" => "ok",
  1078. "npt" => null,
  1079. "video" => [],
  1080. "author" => [],
  1081. "livestream" => [],
  1082. "playlist" => [],
  1083. "reel" => []
  1084. ];
  1085. // get npt
  1086. $out["npt"] =
  1087. $this->generatenextpagetoken(
  1088. $search,
  1089. $nsfw,
  1090. $country,
  1091. $spellcheck,
  1092. "videos",
  1093. $proxy
  1094. );
  1095. /*
  1096. $handle = fopen("scraper/brave-video.html", "r");
  1097. $html = fread($handle, filesize("scraper/brave-video.html"));
  1098. fclose($handle);*/
  1099. preg_match(
  1100. '/const data = (\[{.*}\]);/',
  1101. $html,
  1102. $json
  1103. );
  1104. if(!isset($json[1])){
  1105. throw new Exception("Failed to get data object");
  1106. }
  1107. $json =
  1108. $this->fuckhtml
  1109. ->parseJsObject(
  1110. $json[1]
  1111. );
  1112. foreach(
  1113. $json
  1114. [1]
  1115. ["data"]
  1116. ["body"]
  1117. ["response"]
  1118. ["results"]
  1119. as $result
  1120. ){
  1121. if($result["video"]["author"] != "null"){
  1122. $author = [
  1123. "name" => $result["video"]["author"]["name"] == "null" ? null : $result["video"]["author"]["name"],
  1124. "url" => $result["video"]["author"]["url"] == "null" ? null : $result["video"]["author"]["url"],
  1125. "avatar" => $result["video"]["author"]["img"] == "null" ? null : $result["video"]["author"]["img"]
  1126. ];
  1127. }else{
  1128. $author = [
  1129. "name" => null,
  1130. "url" => null,
  1131. "avatar" => null
  1132. ];
  1133. }
  1134. if($result["thumbnail"] != "null"){
  1135. $thumb = [
  1136. "url" => $result["thumbnail"]["original"],
  1137. "ratio" => "16:9"
  1138. ];
  1139. }else{
  1140. $thumb = [
  1141. "url" => null,
  1142. "ratio" => null
  1143. ];
  1144. }
  1145. $out["video"][] = [
  1146. "title" => $result["title"],
  1147. "description" => $result["description"] == "null" ? null : $this->titledots($result["description"]),
  1148. "author" => $author,
  1149. "date" => ($result["age"] == "null" || $result["age"] == "void 0") ? null : strtotime($result["age"]),
  1150. "duration" => $result["video"]["duration"] == "null" ? null : $this->hms2int($result["video"]["duration"]),
  1151. "views" => $result["video"]["views"] == "null" ? null : (int)$result["video"]["views"],
  1152. "thumb" => $thumb,
  1153. "url" => $result["url"]
  1154. ];
  1155. }
  1156. return $out;
  1157. }
  1158. private function stackoverflow_parse($html){
  1159. $i = 0;
  1160. $answer = [];
  1161. $this->fuckhtml->load($html);
  1162. foreach(
  1163. $this->fuckhtml->getElementsByTagName("*")
  1164. as $snippet
  1165. ){
  1166. switch($snippet["tagName"]){
  1167. case "p":
  1168. $this->fuckhtml->load($snippet["innerHTML"]);
  1169. $codetags =
  1170. $this->fuckhtml
  1171. ->getElementsByTagName("*");
  1172. $tmphtml = $snippet["innerHTML"];
  1173. foreach($codetags as $tag){
  1174. if(!isset($tag["outerHTML"])){
  1175. continue;
  1176. }
  1177. $tmphtml =
  1178. explode(
  1179. $tag["outerHTML"],
  1180. $tmphtml,
  1181. 2
  1182. );
  1183. $value = $this->fuckhtml->getTextContent($tmphtml[0], false, false);
  1184. $this->appendtext($value, $answer, $i);
  1185. $type = null;
  1186. switch($tag["tagName"]){
  1187. case "code": $type = "inline_code"; break;
  1188. case "em": $type = "italic"; break;
  1189. case "blockquote": $type = "quote"; break;
  1190. default: $type = "text";
  1191. }
  1192. if($type !== null){
  1193. $value = $this->fuckhtml->getTextContent($tag, false, true);
  1194. if(trim($value) != ""){
  1195. if(
  1196. $i !== 0 &&
  1197. $type == "title"
  1198. ){
  1199. $answer[$i - 1]["value"] = rtrim($answer[$i - 1]["value"]);
  1200. }
  1201. $answer[] = [
  1202. "type" => $type,
  1203. "value" => $value
  1204. ];
  1205. $i++;
  1206. }
  1207. }
  1208. if(count($tmphtml) === 2){
  1209. $tmphtml = $tmphtml[1];
  1210. }else{
  1211. break;
  1212. }
  1213. }
  1214. if(is_array($tmphtml)){
  1215. $tmphtml = $tmphtml[0];
  1216. }
  1217. if(strlen($tmphtml) !== 0){
  1218. $value = $this->fuckhtml->getTextContent($tmphtml, false, false);
  1219. $this->appendtext($value, $answer, $i);
  1220. }
  1221. break;
  1222. case "img":
  1223. $answer[] = [
  1224. "type" => "image",
  1225. "url" =>
  1226. $this->fuckhtml
  1227. ->getTextContent(
  1228. $tag["attributes"]["src"]
  1229. )
  1230. ];
  1231. $i++;
  1232. break;
  1233. case "pre":
  1234. switch($answer[$i - 1]["type"]){
  1235. case "text":
  1236. case "italic":
  1237. $answer[$i - 1]["value"] = rtrim($answer[$i - 1]["value"]);
  1238. break;
  1239. }
  1240. $answer[] =
  1241. [
  1242. "type" => "code",
  1243. "value" =>
  1244. rtrim(
  1245. $this->fuckhtml
  1246. ->getTextContent(
  1247. $snippet,
  1248. true,
  1249. false
  1250. )
  1251. )
  1252. ];
  1253. $i++;
  1254. break;
  1255. case "ol":
  1256. $o = 0;
  1257. $this->fuckhtml->load($snippet);
  1258. $li =
  1259. $this->fuckhtml
  1260. ->getElementsByTagName("li");
  1261. foreach($li as $elem){
  1262. $o++;
  1263. $this->appendtext(
  1264. $o . ". " .
  1265. $this->fuckhtml
  1266. ->getTextContent(
  1267. $elem
  1268. ),
  1269. $answer,
  1270. $i
  1271. );
  1272. }
  1273. break;
  1274. }
  1275. }
  1276. if(
  1277. $i !== 0 &&
  1278. $answer[$i - 1]["type"] == "text"
  1279. ){
  1280. $answer[$i - 1]["value"] = rtrim($answer[$i - 1]["value"]);
  1281. }
  1282. return $answer;
  1283. }
  1284. private function hms2int($time){
  1285. $parts = explode(":", $time, 3);
  1286. $time = 0;
  1287. if(count($parts) === 3){
  1288. // hours
  1289. $time = $time + ((int)$parts[0] * 3600);
  1290. array_shift($parts);
  1291. }
  1292. if(count($parts) === 2){
  1293. // minutes
  1294. $time = $time + ((int)$parts[0] * 60);
  1295. array_shift($parts);
  1296. }
  1297. // seconds
  1298. $time = $time + (int)$parts[0];
  1299. return $time;
  1300. }
  1301. private function appendtext($payload, &$text, &$index){
  1302. if(trim($payload) == ""){
  1303. return;
  1304. }
  1305. if(
  1306. $index !== 0 &&
  1307. $text[$index - 1]["type"] == "text"
  1308. ){
  1309. $text[$index - 1]["value"] .= "\n\n" . preg_replace('/ $/', " ", $payload);
  1310. }else{
  1311. $text[] = [
  1312. "type" => "text",
  1313. "value" => preg_replace('/ $/', " ", $payload)
  1314. ];
  1315. $index++;
  1316. }
  1317. }
  1318. private function tablesublink($html_collection, &$data){
  1319. foreach($html_collection as $html){
  1320. $html["innerHTML"] = preg_replace(
  1321. '/<style>[\S\s]*<\/style>/i',
  1322. "",
  1323. $html["innerHTML"]
  1324. );
  1325. $html =
  1326. explode(
  1327. ":",
  1328. $this->fuckhtml->getTextContent($html),
  1329. 2
  1330. );
  1331. if(count($html) === 1){
  1332. $html = ["Rating", $html[0]];
  1333. }
  1334. $data["table"][trim($html[0])] = trim($html[1]);
  1335. }
  1336. }
  1337. /*
  1338. private function getimagelinkfromstyle($thumb){
  1339. $thumb =
  1340. $this->fuckhtml
  1341. ->getElementsByClassName(
  1342. $thumb,
  1343. "div"
  1344. );
  1345. if(count($thumb) === 0){
  1346. return [
  1347. "url" => null,
  1348. "ratio" => null
  1349. ];
  1350. }
  1351. $thumb = $thumb[0]["attributes"]["style"];
  1352. preg_match(
  1353. '/background-image: ?url\((\'[^\']+\'|"[^"]+"|[^\)]+)\)/',
  1354. $thumb,
  1355. $thumb
  1356. );
  1357. $url = $this->fuckhtml->getTextContent($this->unshiturl(trim($thumb[1], '"\' ')));
  1358. if(parse_url($url, PHP_URL_HOST) == "cdn.search.brave.com"){
  1359. return [
  1360. "url" => null,
  1361. "ratio" => null
  1362. ];
  1363. }
  1364. return [
  1365. "url" => $url,
  1366. "ratio" => "16:9"
  1367. ];
  1368. }*/
  1369. private function limitstrlen($text){
  1370. return explode("\n", wordwrap($text, 300, "\n"))[0];
  1371. }
  1372. /*
  1373. private function limitwhitespace($text){
  1374. return
  1375. preg_replace(
  1376. '/[\s]+/',
  1377. " ",
  1378. $text
  1379. );
  1380. }*/
  1381. private function titledots($title){
  1382. $substr = substr($title, -3);
  1383. if(
  1384. $substr == "..." ||
  1385. $substr == "…"
  1386. ){
  1387. return trim(substr($title, 0, -3));
  1388. }
  1389. return trim($title);
  1390. }
  1391. private function generatenextpagetoken($q, $nsfw, $country, $spellcheck, $page, $proxy){
  1392. $nextpage =
  1393. $this->fuckhtml
  1394. ->getElementsByClassName("btn", "a");
  1395. if(count($nextpage) !== 0){
  1396. $nextpage =
  1397. $nextpage[count($nextpage) - 1];
  1398. if(
  1399. strtolower(
  1400. $this->fuckhtml
  1401. ->getTextContent(
  1402. $nextpage
  1403. )
  1404. ) == "next"
  1405. ){
  1406. preg_match(
  1407. '/offset=([0-9]+)/',
  1408. $this->fuckhtml->getTextContent($nextpage["attributes"]["href"]),
  1409. $nextpage
  1410. );
  1411. return
  1412. $this->backend->store(
  1413. json_encode(
  1414. [
  1415. "q" => $q,
  1416. "offset" => (int)$nextpage[1],
  1417. "nsfw" => $nsfw,
  1418. "country" => $country,
  1419. "spellcheck" => $spellcheck
  1420. ]
  1421. ),
  1422. $page,
  1423. $proxy
  1424. );
  1425. }
  1426. }
  1427. return null;
  1428. }
  1429. private function unshiturl($url){
  1430. // https://imgs.search.brave.com/XFnbR8Sl7ge82MBDEH7ju0UHImRovMVmQ2qnDvgNTuA/rs:fit:844:225:1/g:ce/aHR0cHM6Ly90c2U0/Lm1tLmJpbmcubmV0/L3RoP2lkPU9JUC54/UWotQXU5N2ozVndT/RDJnNG9BNVhnSGFF/SyZwaWQ9QXBp.jpeg
  1431. $tmp = explode("aHR0", $url);
  1432. if(count($tmp) !== 2){
  1433. // nothing to do
  1434. return $url;
  1435. }
  1436. return
  1437. base64_decode(
  1438. "aHR0" .
  1439. str_replace(["/", "_"], ["", "/"],
  1440. explode(
  1441. ".",
  1442. $tmp[1]
  1443. )[0]
  1444. )
  1445. );
  1446. }
  1447. }