yandex.php 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. <?php
  2. class yandex{
  3. /*
  4. curl functions
  5. */
  6. public function __construct(){
  7. include "lib/fuckhtml.php";
  8. $this->fuckhtml = new fuckhtml();
  9. include "lib/nextpage.php";
  10. $this->nextpage = new nextpage("yandex");
  11. }
  12. private function get($url, $get = [], $nsfw){
  13. $curlproc = curl_init();
  14. if($get !== []){
  15. $get = http_build_query($get);
  16. $url .= "?" . $get;
  17. }
  18. curl_setopt($curlproc, CURLOPT_URL, $url);
  19. switch($nsfw){
  20. case "yes": $nsfw = "0"; break;
  21. case "maybe": $nsfw = "1"; break;
  22. case "no": $nsfw = "2"; break;
  23. }
  24. $headers =
  25. ["User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0",
  26. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
  27. "Accept-Encoding: gzip",
  28. "Accept-Language: en-US,en;q=0.5",
  29. "DNT: 1",
  30. "Cookie: yp=1716337604.sp.family%3A{$nsfw}#1685406411.szm.1:1920x1080:1920x999",
  31. "Referer: https://yandex.com/images/search",
  32. "Connection: keep-alive",
  33. "Upgrade-Insecure-Requests: 1",
  34. "Sec-Fetch-Dest: document",
  35. "Sec-Fetch-Mode: navigate",
  36. "Sec-Fetch-Site: cross-site",
  37. "Upgrade-Insecure-Requests: 1"];
  38. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  39. curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
  40. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  41. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  42. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  43. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  44. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  45. $data = curl_exec($curlproc);
  46. if(curl_errno($curlproc)){
  47. throw new Exception(curl_error($curlproc));
  48. }
  49. curl_close($curlproc);
  50. return $data;
  51. }
  52. public function getfilters($pagetype){
  53. switch($pagetype){
  54. case "web":
  55. return [
  56. "lang" => [
  57. "display" => "Language",
  58. "option" => [
  59. "any" => "Any language",
  60. "en" => "English",
  61. "ru" => "Russian",
  62. "be" => "Belorussian",
  63. "fr" => "French",
  64. "de" => "German",
  65. "id" => "Indonesian",
  66. "kk" => "Kazakh",
  67. "tt" => "Tatar",
  68. "tr" => "Turkish",
  69. "uk" => "Ukrainian"
  70. ]
  71. ],
  72. "newer" => [
  73. "display" => "Newer than",
  74. "option" => "_DATE"
  75. ],
  76. "older" => [
  77. "display" => "Older than",
  78. "option" => "_DATE"
  79. ]
  80. ];
  81. break;
  82. case "images":
  83. return
  84. [
  85. "nsfw" => [
  86. "display" => "NSFW",
  87. "option" => [
  88. "yes" => "Yes",
  89. "maybe" => "Maybe",
  90. "no" => "No"
  91. ]
  92. ],
  93. "time" => [
  94. "display" => "Time posted",
  95. "option" => [
  96. "any" => "Any time",
  97. "week" => "Last week"
  98. ]
  99. ],
  100. "size" => [
  101. "display" => "Size",
  102. "option" => [
  103. "any" => "Any size",
  104. "small" => "Small",
  105. "medium" => "Medium",
  106. "large" => "Large",
  107. "wallpaper" => "Wallpaper"
  108. ]
  109. ],
  110. "color" => [
  111. "display" => "Colors",
  112. "option" => [
  113. "any" => "All colors",
  114. "color" => "Color images only",
  115. "gray" => "Black and white",
  116. "red" => "Red",
  117. "orange" => "Orange",
  118. "yellow" => "Yellow",
  119. "cyan" => "Cyan",
  120. "green" => "Green",
  121. "blue" => "Blue",
  122. "violet" => "Purple",
  123. "white" => "White",
  124. "black" => "Black"
  125. ]
  126. ],
  127. "type" => [
  128. "display" => "Type",
  129. "option" => [
  130. "any" => "All types",
  131. "photo" => "Photos",
  132. "clipart" => "White background",
  133. "lineart" => "Drawings and sketches",
  134. "face" => "People",
  135. "demotivator" => "Demotivators"
  136. ]
  137. ],
  138. "layout" => [
  139. "display" => "Layout",
  140. "option" => [
  141. "any" => "All layouts",
  142. "horizontal" => "Horizontal",
  143. "vertical" => "Vertical",
  144. "square" => "Square"
  145. ]
  146. ],
  147. "format" => [
  148. "display" => "Format",
  149. "option" => [
  150. "any" => "Any format",
  151. "jpeg" => "JPEG",
  152. "png" => "PNG",
  153. "gif" => "GIF"
  154. ]
  155. ]
  156. ];
  157. break;
  158. case "videos":
  159. return [
  160. "nsfw" => [
  161. "display" => "NSFW",
  162. "option" => [
  163. "yes" => "Yes",
  164. "maybe" => "Maybe",
  165. "no" => "No"
  166. ]
  167. ],
  168. "time" => [
  169. "display" => "Time posted",
  170. "option" => [
  171. "any" => "Any time",
  172. "9" => "Recently"
  173. ]
  174. ],
  175. "duration" => [
  176. "display" => "Duration",
  177. "option" => [
  178. "any" => "Any duration",
  179. "short" => "Short"
  180. ]
  181. ]
  182. ];
  183. break;
  184. }
  185. }
  186. public function web($get){
  187. // has captcha
  188. // https://yandex.com/search/touch/?text=lol&app_platform=android&appsearch_header=1&ui=webmobileapp.yandex&app_version=23070603&app_id=ru.yandex.searchplugin&search_source=yandexcom_touch_native&clid=2218567
  189. // https://yandex.com/search/site/?text=minecraft&web=1&frame=1&v=2.0&searchid=3131712
  190. // &within=777&from_day=26&from_month=8&from_year=2023&to_day=26&to_month=8&to_year=2023
  191. if($get["npt"]){
  192. $npt = $this->nextpage->get($get["npt"], "web");
  193. $html =
  194. $this->get(
  195. "https://yandex.com" . $npt,
  196. [],
  197. "yes"
  198. );
  199. }else{
  200. $search = $get["s"];
  201. $lang = $get["lang"];
  202. $older = $get["older"];
  203. $newer = $get["newer"];
  204. $params = [
  205. "text" => $search,
  206. "web" => "1",
  207. "frame" => "1",
  208. "searchid" => "3131712"
  209. ];
  210. if($lang != "any"){
  211. $params["lang"] = $lang;
  212. }
  213. if(
  214. $newer === false &&
  215. $older !== false
  216. ){
  217. $newer = 0;
  218. }
  219. if($newer !== false){
  220. $params["from_day"] = date("j", $newer);
  221. $params["from_month"] = date("n", $newer);
  222. $params["from_year"] = date("Y", $newer);
  223. if($older === false){
  224. $older = time();
  225. }
  226. $params["to_day"] = date("j", $older);
  227. $params["to_month"] = date("n", $older);
  228. $params["to_year"] = date("Y", $older);
  229. }
  230. try{
  231. $html =
  232. $this->get(
  233. "https://yandex.com/search/site/",
  234. $params,
  235. "yes"
  236. );
  237. }catch(Exception $error){
  238. throw new Exception("Could not get search page");
  239. }
  240. /*
  241. $handle = fopen("scraper/yandex.html", "r");
  242. $html = fread($handle, filesize("scraper/yandex.html"));
  243. fclose($handle);*/
  244. }
  245. $out = [
  246. "status" => "ok",
  247. "spelling" => [
  248. "type" => "no_correction",
  249. "using" => null,
  250. "correction" => null
  251. ],
  252. "npt" => null,
  253. "answer" => [],
  254. "web" => [],
  255. "image" => [],
  256. "video" => [],
  257. "news" => [],
  258. "related" => []
  259. ];
  260. $this->fuckhtml->load($html);
  261. // get nextpage
  262. $npt =
  263. $this->fuckhtml
  264. ->getElementsByClassName(
  265. "b-pager__next",
  266. "a"
  267. );
  268. if(count($npt) !== 0){
  269. $out["npt"] =
  270. $this->nextpage->store(
  271. $this->fuckhtml
  272. ->getTextContent(
  273. $npt
  274. [0]
  275. ["attributes"]
  276. ["href"]
  277. ),
  278. "web"
  279. );
  280. }
  281. // get items
  282. $items =
  283. $this->fuckhtml
  284. ->getElementsByClassName(
  285. "b-serp-item",
  286. "li"
  287. );
  288. foreach($items as $item){
  289. $this->fuckhtml->load($item);
  290. $link =
  291. $this->fuckhtml
  292. ->getElementsByClassName(
  293. "b-serp-item__title-link",
  294. "a"
  295. )[0];
  296. $out["web"][] = [
  297. "title" =>
  298. $this->titledots(
  299. $this->fuckhtml
  300. ->getTextContent(
  301. $link
  302. )
  303. ),
  304. "description" =>
  305. $this->titledots(
  306. $this->fuckhtml
  307. ->getTextContent(
  308. $this->fuckhtml
  309. ->getElementsByClassName(
  310. "b-serp-item__text",
  311. "div"
  312. )[0]
  313. )
  314. ),
  315. "url" =>
  316. $this->fuckhtml
  317. ->getTextContent(
  318. $link
  319. ["attributes"]
  320. ["href"]
  321. ),
  322. "date" => null,
  323. "type" => "web",
  324. "thumb" => [
  325. "url" => null,
  326. "ratio" => null
  327. ],
  328. "sublink" => [],
  329. "table" => []
  330. ];
  331. }
  332. return $out;
  333. }
  334. public function image($get){
  335. if($get["npt"]){
  336. $request =
  337. json_decode(
  338. $this->nextpage->get(
  339. $get["npt"],
  340. "images"
  341. ),
  342. true
  343. );
  344. $nsfw = $request["nsfw"];
  345. unset($request["nsfw"]);
  346. }else{
  347. $search = $get["s"];
  348. if(strlen($search) === 0){
  349. throw new Exception("Search term is empty!");
  350. }
  351. $nsfw = $get["nsfw"];
  352. $time = $get["time"];
  353. $size = $get["size"];
  354. $color = $get["color"];
  355. $type = $get["type"];
  356. $layout = $get["layout"];
  357. $format = $get["format"];
  358. /*
  359. $handle = fopen("scraper/yandex.json", "r");
  360. $json = fread($handle, filesize("scraper/yandex.json"));
  361. fclose($handle);*/
  362. // SIZE
  363. // large
  364. // 227.0=1;203.0=1;76fe94.0=1;41d251.0=1;75.0=1;371.0=1;291.0=1;307.0=1;f797ee.0=1;1cf7c2.0=1;deca32.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&isize=large&suggest_reqid=486139416166165501540886508227485&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  365. // medium
  366. // 227.0=1;203.0=1;76fe94.0=1;41d251.0=1;75.0=1;371.0=1;291.0=1;307.0=1;f797ee.0=1;1cf7c2.0=1;deca32.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&isize=medium&suggest_reqid=486139416166165501540886508227485&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  367. // small
  368. // 227.0=1;203.0=1;76fe94.0=1;41d251.0=1;75.0=1;371.0=1;291.0=1;307.0=1;f797ee.0=1;1cf7c2.0=1;deca32.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&isize=small&suggest_reqid=486139416166165501540886508227485&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  369. // ORIENTATION
  370. // Horizontal
  371. // 227.0=1;203.0=1;76fe94.0=1;41d251.0=1;75.0=1;371.0=1;291.0=1;307.0=1;f797ee.0=1;1cf7c2.0=1;deca32.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&iorient=horizontal&suggest_reqid=486139416166165501540886508227485&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  372. // Vertical
  373. // 227.0=1;203.0=1;76fe94.0=1;41d251.0=1;75.0=1;371.0=1;291.0=1;307.0=1;f797ee.0=1;1cf7c2.0=1;deca32.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&iorient=vertical&suggest_reqid=486139416166165501540886508227485&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  374. // Square
  375. // 227.0=1;203.0=1;76fe94.0=1;41d251.0=1;75.0=1;371.0=1;291.0=1;307.0=1;f797ee.0=1;1cf7c2.0=1;deca32.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&iorient=square&suggest_reqid=486139416166165501540886508227485&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  376. // TYPE
  377. // Photos
  378. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&text=minecraft&type=photo&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  379. // White background
  380. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&text=minecraft&type=clipart&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  381. // Drawings and sketches
  382. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&text=minecraft&type=lineart&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  383. // People
  384. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&text=minecraft&type=face&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  385. // Demotivators
  386. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&text=minecraft&type=demotivator&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  387. // COLOR
  388. // Color images only
  389. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=color&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  390. // Black and white
  391. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=gray&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  392. // Red
  393. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=red&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  394. // Orange
  395. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=orange&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  396. // Yellow
  397. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=yellow&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  398. // Cyan
  399. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=cyan&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  400. // Green
  401. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=green&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  402. // Blue
  403. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=blue&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  404. // Purple
  405. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=violet&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  406. // White
  407. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=white&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  408. // Black
  409. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&icolor=black&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  410. // FORMAT
  411. // jpeg
  412. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&itype=jpg&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  413. // png
  414. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&itype=png&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  415. // gif
  416. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&itype=gifan&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  417. // RECENT
  418. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&recent=7D&text=minecraft&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  419. // WALLPAPER
  420. // 307.0=1;371.0=1;291.0=1;203.0=1;deca32.0=1;f797ee.0=1;1cf7c2.0=1;41d251.0=1;267.0=1;bde197.0=1"},"extraContent":{"names":["i-react-ajax-adapter"]}}}&yu=4861394161661655015&isize=wallpaper&text=minecraft&wp=wh16x9_1920x1080&uinfo=sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080
  421. $request = [
  422. "format" => "json",
  423. "request" => [
  424. "blocks" => [
  425. [
  426. "block" => "extra-content",
  427. "params" => (object)[],
  428. "version" => 2
  429. ],
  430. [
  431. "block" => "i-global__params:ajax",
  432. "params" => (object)[],
  433. "version" => 2
  434. ],
  435. [
  436. "block" => "search2:ajax",
  437. "params" => (object)[],
  438. "version" => 2
  439. ],
  440. [
  441. "block" => "preview__isWallpaper",
  442. "params" => (object)[],
  443. "version" => 2
  444. ],
  445. [
  446. "block" => "content_type_search",
  447. "params" => (object)[],
  448. "version" => 2
  449. ],
  450. [
  451. "block" => "serp-controller",
  452. "params" => (object)[],
  453. "version" => 2
  454. ],
  455. [
  456. "block" => "cookies_ajax",
  457. "params" => (object)[],
  458. "version" => 2
  459. ],
  460. [
  461. "block" => "advanced-search-block",
  462. "params" => (object)[],
  463. "version" => 2
  464. ]
  465. ],
  466. "metadata" => [
  467. "bundles" => [
  468. "lb" => "AS?(E<X120"
  469. ],
  470. "assets" => [
  471. // las base
  472. "las" => "justifier-height=1;justifier-setheight=1;fitimages-height=1;justifier-fitincuts=1;react-with-dom=1;"
  473. // las default
  474. //"las" => "justifier-height=1;justifier-setheight=1;fitimages-height=1;justifier-fitincuts=1;react-with-dom=1;227.0=1;203.0=1;76fe94.0=1;215f96.0=1;75.0=1"
  475. ],
  476. "extraContent" => [
  477. "names" => [
  478. "i-react-ajax-adapter"
  479. ]
  480. ]
  481. ]
  482. ]
  483. ];
  484. /*
  485. Apply filters
  486. */
  487. if($time == "week"){
  488. $request["recent"] = "7D";
  489. }
  490. if($size != "any"){
  491. $request["isize"] = $size;
  492. }
  493. if($type != "any"){
  494. $request["type"] = $type;
  495. }
  496. if($color != "any"){
  497. $request["icolor"] = $color;
  498. }
  499. if($layout != "any"){
  500. $request["iorient"] = $layout;
  501. }
  502. if($format != "any"){
  503. $request["itype"] = $format;
  504. }
  505. $request["text"] = $search;
  506. $request["uinfo"] = "sw-1920-sh-1080-ww-1125-wh-999-pd-1-wp-16x9_1920x1080";
  507. $request["request"] = json_encode($request["request"]);
  508. }
  509. try{
  510. $json = $this->get(
  511. "https://yandex.com/images/search",
  512. $request,
  513. $nsfw
  514. );
  515. }catch(Exception $err){
  516. throw new Exception("Failed to get JSON");
  517. }
  518. /*
  519. $handle = fopen("scraper/yandex.json", "r");
  520. $json = fread($handle, filesize("scraper/yandex.json"));
  521. fclose($handle);*/
  522. $json = json_decode($json, true);
  523. if(
  524. isset($json["type"]) &&
  525. $json["type"] == "captcha"
  526. ){
  527. throw new Exception("Yandex blocked this 4get instance. Please try again in ~7 minutes.");
  528. }
  529. if($json === null){
  530. throw new Exception("Failed to decode JSON");
  531. }
  532. // get html
  533. $html = "";
  534. foreach($json["blocks"] as $block){
  535. $html .= $block["html"];
  536. }
  537. $this->fuckhtml->load($html);
  538. $div = $this->fuckhtml->getElementsByTagName("div");
  539. $out = [
  540. "status" => "ok",
  541. "npt" => null,
  542. "image" => []
  543. ];
  544. // check for next page
  545. if(
  546. count(
  547. $this->fuckhtml
  548. ->getElementsByClassName(
  549. "more more_direction_next",
  550. $div
  551. )
  552. ) !== 0
  553. ){
  554. $request["nsfw"] = $nsfw;
  555. if(isset($request["p"])){
  556. $request["p"]++;
  557. }else{
  558. $request["p"] = 1;
  559. }
  560. $out["npt"] = $this->nextpage->store(json_encode($request), "images");
  561. }
  562. // get search results
  563. foreach(
  564. $this->fuckhtml
  565. ->getElementsByClassName(
  566. "serp-item serp-item_type_search",
  567. $div
  568. )
  569. as $image
  570. ){
  571. $image =
  572. json_decode(
  573. $image
  574. ["attributes"]
  575. ["data-bem"],
  576. true
  577. )["serp-item"];
  578. $title = [html_entity_decode($image["snippet"]["title"], ENT_QUOTES | ENT_HTML5)];
  579. if(isset($image["snippet"]["text"])){
  580. $title[] = html_entity_decode($image["snippet"]["text"], ENT_QUOTES | ENT_HTML5);
  581. }
  582. $tmp = [
  583. "title" =>
  584. $this->fuckhtml
  585. ->getTextContent(
  586. $this->titledots(
  587. implode(": ", $title)
  588. )
  589. ),
  590. "source" => [],
  591. "url" => htmlspecialchars_decode($image["snippet"]["url"])
  592. ];
  593. foreach($image["dups"] as $dup){
  594. $tmp["source"][] = [
  595. "url" => htmlspecialchars_decode($dup["url"]),
  596. "width" => (int)$dup["w"],
  597. "height" => (int)$dup["h"],
  598. ];
  599. }
  600. $tmp["source"][] = [
  601. "url" =>
  602. preg_replace(
  603. '/^\/\//',
  604. "https://",
  605. htmlspecialchars_decode($image["thumb"]["url"])
  606. ),
  607. "width" => (int)$image["thumb"]["size"]["width"],
  608. "height" => (int)$image["thumb"]["size"]["height"]
  609. ];
  610. $out["image"][] = $tmp;
  611. }
  612. return $out;
  613. }
  614. public function video($get){
  615. if($get["npt"]){
  616. $params =
  617. json_decode(
  618. $this->nextpage->get(
  619. $get["npt"],
  620. "web"
  621. ),
  622. true
  623. );
  624. $nsfw = $params["nsfw"];
  625. unset($params["nsfw"]);
  626. }else{
  627. $search = $get["s"];
  628. $nsfw = $get["nsfw"];
  629. $time = $get["time"];
  630. $duration = $get["duration"];
  631. // https://yandex.com/video/search
  632. // ?tmpl_version=releases/frontend/video/v1.1168.0#8d942de0f4ebc4eb6b8f3c24ffbd1f8dbc5bbe63
  633. // &format=json
  634. // &request=
  635. // {
  636. // "blocks":[
  637. // {"block":"extra-content","params":{},"version":2},
  638. // {"block":"i-global__params:ajax","params":{},"version":2},
  639. // {"block":"search2:ajax","params":{},"version":2},
  640. // {"block":"vital-incut","params":{},"version":2},
  641. // {"block":"content_type_search","params":{},"version":2},
  642. // {"block":"serp-controller","params":{},"version":2},
  643. // {"block":"cookies_ajax","params":{},"version":2}
  644. // ],
  645. // "metadata":{
  646. // "bundles":{"lb":"^G]!q<X120"},
  647. // "assets":{"las":"react-with-dom=1;185.0=1;73.0=1;145.0=1;5a502a.0=1;32c342.0=1;b84ac8.0=1"},
  648. // "extraContent":{"names":["i-react-ajax-adapter"]}
  649. // }
  650. // }
  651. // &yu=4861394161661655015
  652. // &from=tabbar
  653. // &reqid=1693106278500184-6825210746979814879-balancer-l7leveler-kubr-yp-sas-7-BAL-4237
  654. // &suggest_reqid=486139416166165501562797413447032
  655. // &text=minecraft
  656. $params = [
  657. "tmpl_version" => "releases/frontend/video/v1.1168.0#8d942de0f4ebc4eb6b8f3c24ffbd1f8dbc5bbe63",
  658. "format" => "json",
  659. "request" => json_encode([
  660. "blocks" => [
  661. (object)[
  662. "block" => "extra-content",
  663. "params" => (object)[],
  664. "version" => 2
  665. ],
  666. (object)[
  667. "block" => "i-global__params:ajax",
  668. "params" => (object)[],
  669. "version" => 2
  670. ],
  671. (object)[
  672. "block" => "search2:ajax",
  673. "params" => (object)[],
  674. "version" => 2
  675. ],
  676. (object)[
  677. "block" => "vital-incut",
  678. "params" => (object)[],
  679. "version" => 2
  680. ],
  681. (object)[
  682. "block" => "content_type_search",
  683. "params" => (object)[],
  684. "version" => 2
  685. ],
  686. (object)[
  687. "block" => "serp-controller",
  688. "params" => (object)[],
  689. "version" => 2
  690. ],
  691. (object)[
  692. "block" => "cookies_ajax",
  693. "params" => (object)[],
  694. "version" => 2
  695. ]
  696. ],
  697. "metadata" => (object)[
  698. "bundles" => (object)[
  699. "lb" => "^G]!q<X120"
  700. ],
  701. "assets" => (object)[
  702. "las" => "react-with-dom=1;185.0=1;73.0=1;145.0=1;5a502a.0=1;32c342.0=1;b84ac8.0=1"
  703. ],
  704. "extraContent" => (object)[
  705. "names" => [
  706. "i-react-ajax-adapter"
  707. ]
  708. ]
  709. ]
  710. ]),
  711. "text" => $search
  712. ];
  713. if($duration != "any"){
  714. $params["duration"] = $duration;
  715. }
  716. if($time != "any"){
  717. $params["within"] = $time;
  718. }
  719. }
  720. /*
  721. $handle = fopen("scraper/yandex-video.json", "r");
  722. $json = fread($handle, filesize("scraper/yandex-video.json"));
  723. fclose($handle);
  724. */
  725. try{
  726. $json =
  727. $this->get(
  728. "https://yandex.com/video/search",
  729. $params,
  730. $nsfw
  731. );
  732. }catch(Exception $error){
  733. throw new Exception("Could not fetch JSON");
  734. }
  735. $json = json_decode($json, true);
  736. if($json === null){
  737. throw new Exception("Could not parse JSON");
  738. }
  739. if(!isset($json["blocks"])){
  740. throw new Exception("Yandex blocked this 4get instance. Please try again in 7~ minutes.");
  741. }
  742. $out = [
  743. "status" => "ok",
  744. "npt" => null,
  745. "video" => [],
  746. "author" => [],
  747. "livestream" => [],
  748. "playlist" => [],
  749. "reel" => []
  750. ];
  751. $html = null;
  752. foreach($json["blocks"] as $block){
  753. if(isset($block["html"])){
  754. $html .= $block["html"];
  755. }
  756. }
  757. $this->fuckhtml->load($html);
  758. $div =
  759. $this->fuckhtml
  760. ->getElementsByTagName("div");
  761. /*
  762. Get nextpage
  763. */
  764. $npt =
  765. $this->fuckhtml
  766. ->getElementsByClassName(
  767. "more more_direction_next i-bem",
  768. $div
  769. );
  770. if(count($npt) !== 0){
  771. $params["p"] = "1";
  772. $params["nsfw"] = $nsfw;
  773. $out["npt"] =
  774. $this->nextpage->store(
  775. json_encode($params),
  776. "web"
  777. );
  778. }
  779. $items =
  780. $this->fuckhtml
  781. ->getElementsByClassName(
  782. "serp-item",
  783. $div
  784. );
  785. foreach($items as $item){
  786. $data =
  787. json_decode(
  788. $this->fuckhtml
  789. ->getTextContent(
  790. $item["attributes"]["data-video"]
  791. ),
  792. true
  793. );
  794. $this->fuckhtml->load($item);
  795. $thumb =
  796. $this->fuckhtml
  797. ->getElementsByClassName(
  798. "thumb-image__image",
  799. "img"
  800. );
  801. $c = 1;
  802. if(count($thumb) === 0){
  803. $thumb = [
  804. "url" => null,
  805. "ratio" => null
  806. ];
  807. }else{
  808. $thumb = [
  809. "url" =>
  810. str_replace(
  811. "//",
  812. "https://",
  813. $this->fuckhtml
  814. ->getTextContent(
  815. $thumb
  816. [0]
  817. ["attributes"]
  818. ["src"]
  819. ),
  820. $c
  821. ),
  822. "ratio" => "16:9"
  823. ];
  824. }
  825. $smallinfos =
  826. $this->fuckhtml
  827. ->getElementsByClassName(
  828. "serp-item__sitelinks-item",
  829. "div"
  830. );
  831. $date = null;
  832. $views = null;
  833. $first = true;
  834. foreach($smallinfos as $info){
  835. if($first){
  836. $first = false;
  837. continue;
  838. }
  839. $info =
  840. $this->fuckhtml
  841. ->getTextContent(
  842. $info
  843. );
  844. if($temp_date = strtotime($info)){
  845. $date = $temp_date;
  846. }else{
  847. $views = $this->parseviews($info);
  848. }
  849. }
  850. $description =
  851. $this->fuckhtml
  852. ->getElementsByClassName(
  853. "serp-item__text serp-item__text_visibleText_always",
  854. "div"
  855. );
  856. if(count($description) === 0){
  857. $description = null;
  858. }else{
  859. $description =
  860. $this->titledots(
  861. $this->fuckhtml
  862. ->getTextContent(
  863. $description[0]
  864. )
  865. );
  866. }
  867. $out["video"][] = [
  868. "title" =>
  869. $this->fuckhtml
  870. ->getTextContent(
  871. $this->titledots(
  872. $data["title"]
  873. )
  874. ),
  875. "description" => $description,
  876. "author" => [
  877. "name" => null,
  878. "url" => null,
  879. "avatar" => null
  880. ],
  881. "date" => $date,
  882. "duration" =>
  883. (int)$data
  884. ["counters"]
  885. ["toHostingLoaded"]
  886. ["stredParams"]
  887. ["duration"],
  888. "views" => $views,
  889. "thumb" => $thumb,
  890. "url" =>
  891. str_replace(
  892. "http://",
  893. "https://",
  894. $this->fuckhtml
  895. ->getTextContent(
  896. $data["counters"]
  897. ["toHostingLoaded"]
  898. ["postfix"]
  899. ["href"]
  900. ),
  901. $c
  902. )
  903. ];
  904. }
  905. return $out;
  906. }
  907. private function parseviews($text){
  908. $text = explode(" ", $text);
  909. $num = (float)$text[0];
  910. $mod = $text[1];
  911. switch($mod){
  912. case "bln.": $num = $num * 1000000000; break;
  913. case "mln.": $num = $num * 1000000; break;
  914. case "thsd.": $num = $num * 1000; break;
  915. }
  916. return $num;
  917. }
  918. private function titledots($title){
  919. $substr = substr($title, -3);
  920. if(
  921. $substr == "..." ||
  922. $substr == "…"
  923. ){
  924. return trim(substr($title, 0, -3));
  925. }
  926. return trim($title);
  927. }
  928. }