yandex.php 28 KB

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