yandex.php 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  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. if(count($thumb) === 0){
  802. $thumb = [
  803. "url" => null,
  804. "ratio" => null
  805. ];
  806. }else{
  807. $c = 1;
  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. $this->fuckhtml
  892. ->getTextContent(
  893. $data["counters"]
  894. ["toHostingLoaded"]
  895. ["postfix"]
  896. ["href"]
  897. )
  898. ];
  899. }
  900. return $out;
  901. }
  902. private function parseviews($text){
  903. $text = explode(" ", $text);
  904. $num = (float)$text[0];
  905. $mod = $text[1];
  906. switch($mod){
  907. case "bln.": $num = $num * 1000000000; break;
  908. case "mln.": $num = $num * 1000000; break;
  909. case "thsd.": $num = $num * 1000; break;
  910. }
  911. return $num;
  912. }
  913. private function titledots($title){
  914. $substr = substr($title, -3);
  915. if(
  916. $substr == "..." ||
  917. $substr == "…"
  918. ){
  919. return trim(substr($title, 0, -3));
  920. }
  921. return trim($title);
  922. }
  923. }