google.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449
  1. <?php
  2. // @TODO check for consent.google.com page, if need be
  3. class google{
  4. public function __construct(){
  5. include "lib/fuckhtml.php";
  6. $this->fuckhtml = new fuckhtml();
  7. include "lib/backend.php";
  8. $this->backend = new backend("google");
  9. }
  10. public function getfilters($page){
  11. $base = [
  12. "country" => [ // gl=<country> (image: cr=countryAF)
  13. "display" => "Country",
  14. "option" => [
  15. "any" => "Instance's country",
  16. "af" => "Afghanistan",
  17. "al" => "Albania",
  18. "dz" => "Algeria",
  19. "as" => "American Samoa",
  20. "ad" => "Andorra",
  21. "ao" => "Angola",
  22. "ai" => "Anguilla",
  23. "aq" => "Antarctica",
  24. "ag" => "Antigua and Barbuda",
  25. "ar" => "Argentina",
  26. "am" => "Armenia",
  27. "aw" => "Aruba",
  28. "au" => "Australia",
  29. "at" => "Austria",
  30. "az" => "Azerbaijan",
  31. "bs" => "Bahamas",
  32. "bh" => "Bahrain",
  33. "bd" => "Bangladesh",
  34. "bb" => "Barbados",
  35. "by" => "Belarus",
  36. "be" => "Belgium",
  37. "bz" => "Belize",
  38. "bj" => "Benin",
  39. "bm" => "Bermuda",
  40. "bt" => "Bhutan",
  41. "bo" => "Bolivia",
  42. "ba" => "Bosnia and Herzegovina",
  43. "bw" => "Botswana",
  44. "bv" => "Bouvet Island",
  45. "br" => "Brazil",
  46. "io" => "British Indian Ocean Territory",
  47. "bn" => "Brunei Darussalam",
  48. "bg" => "Bulgaria",
  49. "bf" => "Burkina Faso",
  50. "bi" => "Burundi",
  51. "kh" => "Cambodia",
  52. "cm" => "Cameroon",
  53. "ca" => "Canada",
  54. "cv" => "Cape Verde",
  55. "ky" => "Cayman Islands",
  56. "cf" => "Central African Republic",
  57. "td" => "Chad",
  58. "cl" => "Chile",
  59. "cn" => "China",
  60. "cx" => "Christmas Island",
  61. "cc" => "Cocos (Keeling) Islands",
  62. "co" => "Colombia",
  63. "km" => "Comoros",
  64. "cg" => "Congo",
  65. "cd" => "Congo, the Democratic Republic",
  66. "ck" => "Cook Islands",
  67. "cr" => "Costa Rica",
  68. "ci" => "Cote D'ivoire",
  69. "hr" => "Croatia",
  70. "cu" => "Cuba",
  71. "cy" => "Cyprus",
  72. "cz" => "Czech Republic",
  73. "dk" => "Denmark",
  74. "dj" => "Djibouti",
  75. "dm" => "Dominica",
  76. "do" => "Dominican Republic",
  77. "ec" => "Ecuador",
  78. "eg" => "Egypt",
  79. "sv" => "El Salvador",
  80. "gq" => "Equatorial Guinea",
  81. "er" => "Eritrea",
  82. "ee" => "Estonia",
  83. "et" => "Ethiopia",
  84. "fk" => "Falkland Islands (Malvinas)",
  85. "fo" => "Faroe Islands",
  86. "fj" => "Fiji",
  87. "fi" => "Finland",
  88. "fr" => "France",
  89. "gf" => "French Guiana",
  90. "pf" => "French Polynesia",
  91. "tf" => "French Southern Territories",
  92. "ga" => "Gabon",
  93. "gm" => "Gambia",
  94. "ge" => "Georgia",
  95. "de" => "Germany",
  96. "gh" => "Ghana",
  97. "gi" => "Gibraltar",
  98. "gr" => "Greece",
  99. "gl" => "Greenland",
  100. "gd" => "Grenada",
  101. "gp" => "Guadeloupe",
  102. "gu" => "Guam",
  103. "gt" => "Guatemala",
  104. "gn" => "Guinea",
  105. "gw" => "Guinea-Bissau",
  106. "gy" => "Guyana",
  107. "ht" => "Haiti",
  108. "hm" => "Heard Island and Mcdonald Islands",
  109. "va" => "Holy See (Vatican City State)",
  110. "hn" => "Honduras",
  111. "hk" => "Hong Kong",
  112. "hu" => "Hungary",
  113. "is" => "Iceland",
  114. "in" => "India",
  115. "id" => "Indonesia",
  116. "ir" => "Iran, Islamic Republic",
  117. "iq" => "Iraq",
  118. "ie" => "Ireland",
  119. "il" => "Israel",
  120. "it" => "Italy",
  121. "jm" => "Jamaica",
  122. "jp" => "Japan",
  123. "jo" => "Jordan",
  124. "kz" => "Kazakhstan",
  125. "ke" => "Kenya",
  126. "ki" => "Kiribati",
  127. "kp" => "Korea, Democratic People's Republic",
  128. "kr" => "Korea, Republic",
  129. "kw" => "Kuwait",
  130. "kg" => "Kyrgyzstan",
  131. "la" => "Lao People's Democratic Republic",
  132. "lv" => "Latvia",
  133. "lb" => "Lebanon",
  134. "ls" => "Lesotho",
  135. "lr" => "Liberia",
  136. "ly" => "Libyan Arab Jamahiriya",
  137. "li" => "Liechtenstein",
  138. "lt" => "Lithuania",
  139. "lu" => "Luxembourg",
  140. "mo" => "Macao",
  141. "mk" => "Macedonia, the Former Yugosalv Republic",
  142. "mg" => "Madagascar",
  143. "mw" => "Malawi",
  144. "my" => "Malaysia",
  145. "mv" => "Maldives",
  146. "ml" => "Mali",
  147. "mt" => "Malta",
  148. "mh" => "Marshall Islands",
  149. "mq" => "Martinique",
  150. "mr" => "Mauritania",
  151. "mu" => "Mauritius",
  152. "yt" => "Mayotte",
  153. "mx" => "Mexico",
  154. "fm" => "Micronesia, Federated States",
  155. "md" => "Moldova, Republic",
  156. "mc" => "Monaco",
  157. "mn" => "Mongolia",
  158. "ms" => "Montserrat",
  159. "ma" => "Morocco",
  160. "mz" => "Mozambique",
  161. "mm" => "Myanmar",
  162. "na" => "Namibia",
  163. "nr" => "Nauru",
  164. "np" => "Nepal",
  165. "nl" => "Netherlands",
  166. "an" => "Netherlands Antilles",
  167. "nc" => "New Caledonia",
  168. "nz" => "New Zealand",
  169. "ni" => "Nicaragua",
  170. "ne" => "Niger",
  171. "ng" => "Nigeria",
  172. "nu" => "Niue",
  173. "nf" => "Norfolk Island",
  174. "mp" => "Northern Mariana Islands",
  175. "no" => "Norway",
  176. "om" => "Oman",
  177. "pk" => "Pakistan",
  178. "pw" => "Palau",
  179. "ps" => "Palestinian Territory, Occupied",
  180. "pa" => "Panama",
  181. "pg" => "Papua New Guinea",
  182. "py" => "Paraguay",
  183. "pe" => "Peru",
  184. "ph" => "Philippines",
  185. "pn" => "Pitcairn",
  186. "pl" => "Poland",
  187. "pt" => "Portugal",
  188. "pr" => "Puerto Rico",
  189. "qa" => "Qatar",
  190. "re" => "Reunion",
  191. "ro" => "Romania",
  192. "ru" => "Russian Federation",
  193. "rw" => "Rwanda",
  194. "sh" => "Saint Helena",
  195. "kn" => "Saint Kitts and Nevis",
  196. "lc" => "Saint Lucia",
  197. "pm" => "Saint Pierre and Miquelon",
  198. "vc" => "Saint Vincent and the Grenadines",
  199. "ws" => "Samoa",
  200. "sm" => "San Marino",
  201. "st" => "Sao Tome and Principe",
  202. "sa" => "Saudi Arabia",
  203. "sn" => "Senegal",
  204. "cs" => "Serbia and Montenegro",
  205. "sc" => "Seychelles",
  206. "sl" => "Sierra Leone",
  207. "sg" => "Singapore",
  208. "sk" => "Slovakia",
  209. "si" => "Slovenia",
  210. "sb" => "Solomon Islands",
  211. "so" => "Somalia",
  212. "za" => "South Africa",
  213. "gs" => "South Georgia and the South Sandwich Islands",
  214. "es" => "Spain",
  215. "lk" => "Sri Lanka",
  216. "sd" => "Sudan",
  217. "sr" => "Suriname",
  218. "sj" => "Svalbard and Jan Mayen",
  219. "sz" => "Swaziland",
  220. "se" => "Sweden",
  221. "ch" => "Switzerland",
  222. "sy" => "Syrian Arab Republic",
  223. "tw" => "Taiwan, Province of China",
  224. "tj" => "Tajikistan",
  225. "tz" => "Tanzania, United Republic",
  226. "th" => "Thailand",
  227. "tl" => "Timor-Leste",
  228. "tg" => "Togo",
  229. "tk" => "Tokelau",
  230. "to" => "Tonga",
  231. "tt" => "Trinidad and Tobago",
  232. "tn" => "Tunisia",
  233. "tr" => "Turkey",
  234. "tm" => "Turkmenistan",
  235. "tc" => "Turks and Caicos Islands",
  236. "tv" => "Tuvalu",
  237. "ug" => "Uganda",
  238. "ua" => "Ukraine",
  239. "ae" => "United Arab Emirates",
  240. "uk" => "United Kingdom",
  241. "us" => "United States",
  242. "um" => "United States Minor Outlying Islands",
  243. "uy" => "Uruguay",
  244. "uz" => "Uzbekistan",
  245. "vu" => "Vanuatu",
  246. "ve" => "Venezuela",
  247. "vn" => "Viet Nam",
  248. "vg" => "Virgin Islands, British",
  249. "vi" => "Virgin Islands, U.S.",
  250. "wf" => "Wallis and Futuna",
  251. "eh" => "Western Sahara",
  252. "ye" => "Yemen",
  253. "zm" => "Zambia",
  254. "zw" => "Zimbabwe"
  255. ]
  256. ],
  257. "nsfw" => [
  258. "display" => "NSFW",
  259. "option" => [
  260. "yes" => "Yes", // safe=active
  261. "no" => "No" // safe=off
  262. ]
  263. ]
  264. ];
  265. switch($page){
  266. case "web":
  267. return array_merge(
  268. $base,
  269. [
  270. "lang" => [ // lr=<lang> (prefix lang with "lang_")
  271. "display" => "Language",
  272. "option" => [
  273. "any" => "Any language",
  274. "ar" => "Arabic",
  275. "bg" => "Bulgarian",
  276. "ca" => "Catalan",
  277. "cs" => "Czech",
  278. "da" => "Danish",
  279. "de" => "German",
  280. "el" => "Greek",
  281. "en" => "English",
  282. "es" => "Spanish",
  283. "et" => "Estonian",
  284. "fi" => "Finnish",
  285. "fr" => "French",
  286. "hr" => "Croatian",
  287. "hu" => "Hungarian",
  288. "id" => "Indonesian",
  289. "is" => "Icelandic",
  290. "it" => "Italian",
  291. "iw" => "Hebrew",
  292. "ja" => "Japanese",
  293. "ko" => "Korean",
  294. "lt" => "Lithuanian",
  295. "lv" => "Latvian",
  296. "nl" => "Dutch",
  297. "no" => "Norwegian",
  298. "pl" => "Polish",
  299. "pt" => "Portuguese",
  300. "ro" => "Romanian",
  301. "ru" => "Russian",
  302. "sk" => "Slovak",
  303. "sl" => "Slovenian",
  304. "sr" => "Serbian",
  305. "sv" => "Swedish",
  306. "tr" => "Turkish",
  307. "zh-CN" => "Chinese (Simplified)",
  308. "zh-TW" => "Chinese (Traditional)"
  309. ]
  310. ],
  311. "newer" => [ // tbs
  312. "display" => "Newer than",
  313. "option" => "_DATE"
  314. ],
  315. "older" => [
  316. "display" => "Older than",
  317. "option" => "_DATE"
  318. ],
  319. "spellcheck" => [
  320. "display" => "Spellcheck",
  321. "option" => [
  322. "yes" => "Yes",
  323. "no" => "No"
  324. ]
  325. ]
  326. ]
  327. );
  328. break;
  329. case "images":
  330. return array_merge(
  331. $base,
  332. [
  333. "time" => [ // tbs=qdr:<time>
  334. "display" => "Time posted",
  335. "option" => [
  336. "any" => "Any time",
  337. "d" => "Past 24 hours",
  338. "w" => "Past week",
  339. "m" => "Past month",
  340. "y" => "Past year"
  341. ]
  342. ],
  343. "size" => [ // imgsz
  344. "display" => "Size",
  345. "option" => [
  346. "any" => "Any size",
  347. "l" => "Large",
  348. "m" => "Medium",
  349. "i" => "Icon",
  350. "qsvga" => "Larger than 400x300",
  351. "vga" => "Larger than 640x480",
  352. "svga" => "Larger than 800x600",
  353. "xga" => "Larger than 1024x768",
  354. "2mp" => "Larger than 2MP",
  355. "4mp" => "Larger than 4MP",
  356. "6mp" => "Larger than 6MP",
  357. "8mp" => "Larger than 8MP",
  358. "10mp" => "Larger than 10MP",
  359. "12mp" => "Larger than 12MP",
  360. "15mp" => "Larger than 15MP",
  361. "20mp" => "Larger than 20MP",
  362. "40mp" => "Larger than 40MP",
  363. "70mp" => "Larger than 70MP"
  364. ]
  365. ],
  366. "ratio" => [ // imgar
  367. "display" => "Aspect ratio",
  368. "option" => [
  369. "any" => "Any ratio",
  370. "t|xt" => "Tall",
  371. "s" => "Square",
  372. "w" => "Wide",
  373. "xw" => "Panoramic"
  374. ]
  375. ],
  376. "color" => [ // imgc
  377. "display" => "Color",
  378. "option" => [
  379. "any" => "Any color",
  380. "color" => "Full color",
  381. "bnw" => "Black & white",
  382. "trans" => "Transparent",
  383. // from here, imgcolor
  384. "red" => "Red",
  385. "orange" => "Orange",
  386. "yellow" => "Yellow",
  387. "green" => "Green",
  388. "teal" => "Teal",
  389. "blue" => "Blue",
  390. "purple" => "Purple",
  391. "pink" => "Pink",
  392. "white" => "White",
  393. "gray" => "Gray",
  394. "black" => "Black",
  395. "brown" => "Brown"
  396. ]
  397. ],
  398. "type" => [ // tbs=itp:<type>
  399. "display" => "Type",
  400. "option" => [
  401. "any" => "Any type",
  402. "clipart" => "Clip Art",
  403. "lineart" => "Line Drawing",
  404. "animated" => "Animated"
  405. ]
  406. ],
  407. "format" => [ // as_filetype
  408. "display" => "Format",
  409. "option" => [
  410. "any" => "Any format",
  411. "jpg" => "JPG",
  412. "gif" => "GIF",
  413. "png" => "PNG",
  414. "bmp" => "BMP",
  415. "svg" => "SVG",
  416. "webp" => "WEBP",
  417. "ico" => "ICO",
  418. "craw" => "RAW"
  419. ]
  420. ],
  421. "rights" => [ // tbs=sur:<rights>
  422. "display" => "Usage rights",
  423. "option" => [
  424. "any" => "Any license",
  425. "cl" => "Creative Commons licenses",
  426. "ol" => "Commercial & other licenses"
  427. ]
  428. ]
  429. ]
  430. );
  431. break;
  432. case "videos":
  433. return array_merge(
  434. $base,
  435. [
  436. "newer" => [ // tbs
  437. "display" => "Newer than",
  438. "option" => "_DATE"
  439. ],
  440. "older" => [
  441. "display" => "Older than",
  442. "option" => "_DATE"
  443. ],
  444. "duration" => [
  445. "display" => "Duration",
  446. "option" => [
  447. "any" => "Any duration",
  448. "s" => "Short (0-4min)", // tbs=dur:s
  449. "m" => "Medium (4-20min)", // tbs=dur:m
  450. "l" => "Long (20+ min)" // tbs=dur:l
  451. ]
  452. ],
  453. "quality" => [
  454. "display" => "Quality",
  455. "option" => [
  456. "any" => "Any quality",
  457. "h" => "High quality" // tbs=hq:h
  458. ]
  459. ],
  460. "captions" => [
  461. "display" => "Captions",
  462. "option" => [
  463. "any" => "No preference",
  464. "yes" => "Closed captioned" // tbs=cc:1
  465. ]
  466. ]
  467. ]
  468. );
  469. break;
  470. case "news":
  471. return array_merge(
  472. $base,
  473. [
  474. "newer" => [ // tbs
  475. "display" => "Newer than",
  476. "option" => "_DATE"
  477. ],
  478. "older" => [
  479. "display" => "Older than",
  480. "option" => "_DATE"
  481. ],
  482. "sort" => [
  483. "display" => "Sort",
  484. "option" => [
  485. "relevance" => "Relevance",
  486. "date" => "Date" // sbd:1
  487. ]
  488. ]
  489. ]
  490. );
  491. break;
  492. }
  493. }
  494. private function get($proxy, $url, $get = [], $alt_ua = false){
  495. $curlproc = curl_init();
  496. if($get !== []){
  497. $get = http_build_query($get);
  498. $url .= "?" . $get;
  499. }
  500. curl_setopt($curlproc, CURLOPT_URL, $url);
  501. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  502. if($alt_ua === true){
  503. curl_setopt($curlproc, CURLOPT_HTTPHEADER, [
  504. "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 26_0_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/406.0.862495628 Mobile/15E148 Safari/604.1",
  505. "Accept: text/html, application/xml;q=0.9, */*;q=0.8",
  506. "Accept-Language: nl,en;q=0.8",
  507. "Accept-Encoding: gzip, deflate",
  508. "Connection: Keep-Alive",
  509. "Cache-Control: no-cache"
  510. ]);
  511. }else{
  512. curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
  513. curl_setopt($curlproc, CURLOPT_HTTPHEADER, [
  514. "User-Agent: " . config::USER_AGENT,
  515. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
  516. "Accept-Language: en-US,en;q=0.5",
  517. "Accept-Encoding: gzip",
  518. "DNT: 1",
  519. "Connection: keep-alive",
  520. "Upgrade-Insecure-Requests: 1",
  521. "Sec-Fetch-Dest: document",
  522. "Sec-Fetch-Mode: navigate",
  523. "Sec-Fetch-Site: none",
  524. "Sec-Fetch-User: ?1",
  525. "Priority: u=1",
  526. "TE: trailers"
  527. ]);
  528. }
  529. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  530. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  531. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  532. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  533. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  534. // follow redirects
  535. curl_setopt($curlproc, CURLOPT_FOLLOWLOCATION, true);
  536. $this->backend->assign_proxy($curlproc, $proxy);
  537. $data = curl_exec($curlproc);
  538. if(curl_errno($curlproc)){
  539. throw new Exception(curl_error($curlproc));
  540. }
  541. curl_close($curlproc);
  542. return $data;
  543. }
  544. public function web($get){
  545. // it broke again. lasted 3 months
  546. // lets hope for another solid 3 month
  547. $out = [
  548. "status" => "ok",
  549. "spelling" => [
  550. "type" => "no_correction",
  551. "using" => null,
  552. "correction" => null
  553. ],
  554. "npt" => null,
  555. "answer" => [],
  556. "web" => [],
  557. "image" => [],
  558. "video" => [],
  559. "news" => [],
  560. "related" => []
  561. ];
  562. if($get["npt"]){
  563. [$get, $proxy] = $this->backend->get($get["npt"], "web");
  564. try{
  565. $html =
  566. $this->get(
  567. $proxy,
  568. "https://www.google.com" . $get,
  569. [],
  570. true
  571. );
  572. }catch(Exception $error){
  573. throw new Exception("Failed to get HTML");
  574. }
  575. }else{
  576. $search = $get["s"];
  577. $country = $get["country"];
  578. $nsfw = $get["nsfw"];
  579. $lang = $get["lang"];
  580. $older = $get["older"];
  581. $newer = $get["newer"];
  582. $spellcheck = $get["spellcheck"];
  583. $proxy = $this->backend->get_ip();
  584. $offset = 0;
  585. $params = [
  586. "q" => $search,
  587. "hl" => "en",
  588. "udm" => 14
  589. ];
  590. // country
  591. if($country != "any"){
  592. $params["gl"] = $country;
  593. }
  594. // nsfw
  595. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  596. // language
  597. if($lang != "any"){
  598. $params["lr"] = "lang_" . $lang;
  599. }
  600. // generate tbs
  601. $tbs = [];
  602. // get date
  603. $older = $older === false ? null : date("m/d/Y", $older);
  604. $newer = $newer === false ? null : date("m/d/Y", $newer);
  605. if(
  606. $older !== null ||
  607. $newer !== null
  608. ){
  609. $tbs["cdr"] = "1";
  610. $tbs["cd_min"] = $newer;
  611. $tbs["cd_max"] = $older;
  612. }
  613. // spellcheck filter
  614. if($spellcheck == "no"){
  615. $params["nfpr"] = "1";
  616. }
  617. if(count($tbs) !== 0){
  618. $params["tbs"] = "";
  619. foreach($tbs as $key => $value){
  620. $params["tbs"] .= $key . ":" . $value . ",";
  621. }
  622. $params["tbs"] = rtrim($params["tbs"], ",");
  623. }
  624. try{
  625. $html =
  626. $this->get(
  627. $proxy,
  628. "https://www.google.com/search",
  629. $params,
  630. true
  631. );
  632. }catch(Exception $error){
  633. throw new Exception("Failed to get HTML");
  634. }
  635. //$html = file_get_contents("scraper/google.html");
  636. }
  637. // init
  638. $this->fuckhtml->load($html);
  639. $this->detect_sorry();
  640. $this->parsestyles();
  641. // get javascript images
  642. $this->scrape_dimg($html);
  643. $this->scrape_imagearr($html);
  644. // get next page
  645. $npt =
  646. $this->fuckhtml
  647. ->getElementsByAttributeValue(
  648. "aria-label",
  649. "More search results",
  650. "a"
  651. );
  652. if(count($npt) === 0){
  653. // maybe we have the npt object from 2nd page, probe for that
  654. $npt =
  655. $this->fuckhtml
  656. ->getElementsByAttributeValue(
  657. "aria-label",
  658. "Next page",
  659. "a"
  660. );
  661. }
  662. if(count($npt) !== 0){
  663. $out["npt"] =
  664. $this->backend->store(
  665. $this->fuckhtml
  666. ->getTextContent(
  667. $npt[0]["attributes"]["href"]
  668. ),
  669. "web",
  670. $proxy
  671. );
  672. }
  673. // outer div is .MjjYud
  674. // inner div always contain role="presentation"
  675. $outer =
  676. $this->fuckhtml
  677. ->getElementsByClassName(
  678. "MjjYud",
  679. "div"
  680. );
  681. // used later
  682. $fancycontainer_class =
  683. explode(
  684. " ",
  685. $this->getstyle([
  686. "padding-top" => "4px",
  687. "padding-bottom" => "calc(12px*1)"
  688. ]),
  689. 2
  690. );
  691. if(count($fancycontainer_class) === 2){
  692. $fancycontainer_class = $fancycontainer_class[1];
  693. }else{
  694. $fancycontainer_class = false;
  695. }
  696. foreach($outer as $container){
  697. $this->fuckhtml->load($container);
  698. // probe for search result
  699. $sprobe =
  700. $this->fuckhtml
  701. ->getElementsByAttributeValue(
  702. "role",
  703. "presentation",
  704. "a"
  705. );
  706. if(count($sprobe) !== 0){
  707. // we found a search result
  708. $title =
  709. $this->fuckhtml
  710. ->getElementsByAttributeValue(
  711. "role",
  712. "link",
  713. "div"
  714. );
  715. if(count($title) === 0){
  716. // should not happen
  717. continue;
  718. }
  719. $title =
  720. $this->titledots(
  721. $this->fuckhtml
  722. ->getTextContent(
  723. $title[0]
  724. )
  725. );
  726. // get description
  727. // as usual, theres a thousand fucking possible divs for this one
  728. // probe for youtube-like description
  729. $description =
  730. $this->fuckhtml
  731. ->getElementsByClassName(
  732. $this->getstyle([
  733. "align-items" => "flex-start",
  734. "display" => "flex",
  735. "justify-content" => "center",
  736. "padding" => "7px 12px",
  737. "padding-right" => "0",
  738. "padding-top" => "0"
  739. ]),
  740. "div"
  741. );
  742. $ratio = "16:9";
  743. if(count($description) === 0){
  744. // fail. find the one with the image on the right handside
  745. $description =
  746. $this->fuckhtml
  747. ->getElementsByAttributeValue(
  748. "style",
  749. "padding-top:2px;padding-right:8px;padding-left:16px;padding-bottom:12px",
  750. "div"
  751. );
  752. $ratio = "1:1";
  753. if(count($description) === 0){
  754. // fail. find the one that is used the most
  755. $description =
  756. $this->fuckhtml
  757. ->getElementsByAttributeValue(
  758. "style",
  759. "-webkit-line-clamp:3",
  760. "div"
  761. );
  762. if(count($description) === 0){
  763. // last fail. this one appears with divs that have prices
  764. $description =
  765. $this->fuckhtml
  766. ->getElementsByAttributeValue(
  767. "style",
  768. "max-width:100vw;grid-area:nke7rc;padding-top:2px;padding-right:8px;padding-left:16px;padding-bottom:6px",
  769. "div"
  770. );
  771. }
  772. }
  773. }
  774. if(count($description) === 0){
  775. // should not happen but whatever
  776. $description = null;
  777. }else{
  778. $description =
  779. $this->titledots(
  780. $this->fuckhtml
  781. ->getTextContent(
  782. $description[0]
  783. )
  784. );
  785. }
  786. // probe for date
  787. $desc2 = explode("—", $description, 2);
  788. $time = null;
  789. if(count($desc2) === 2){
  790. $time = strtotime($desc2[0]);
  791. if(
  792. strlen($desc2[0]) < 16 &&
  793. $time !== false
  794. ){
  795. $description = ltrim($desc2[1]);
  796. }else{
  797. $time = null;
  798. }
  799. }
  800. $thumb = [
  801. "ratio" => null,
  802. "url" => null,
  803. ];
  804. // get thumbnail
  805. $images =
  806. $this->fuckhtml
  807. ->getElementsByTagName(
  808. "img"
  809. );
  810. foreach($images as $image){
  811. if(isset($image["attributes"]["id"])){
  812. $thumb = [
  813. "ratio" => $ratio,
  814. "url" => $this->getdimg($image["attributes"]["id"])
  815. ];
  816. }
  817. }
  818. // get sublinks
  819. $sublinks = [];
  820. // probe for the fancy version
  821. if($fancycontainer_class !== false){
  822. $fancycontainer =
  823. $this->fuckhtml
  824. ->getElementsByClassName(
  825. $fancycontainer_class,
  826. "div"
  827. );
  828. }
  829. if(
  830. $fancycontainer_class !== false &&
  831. count($fancycontainer) !== 0
  832. ){
  833. $this->fuckhtml->load($fancycontainer[0]);
  834. $as =
  835. $this->fuckhtml
  836. ->getElementsByTagName(
  837. "a"
  838. );
  839. foreach($as as $a){
  840. $sublinks[] = [
  841. "title" =>
  842. $this->fuckhtml
  843. ->getTextContent(
  844. $a
  845. ),
  846. "description" => null,
  847. "date" => null,
  848. "url" =>
  849. $this->unshiturl(
  850. $a["attributes"]["href"]
  851. )
  852. ];
  853. }
  854. }
  855. $out["web"][] = [
  856. "title" => $title,
  857. "description" => $description,
  858. "url" => $this->unshiturl($sprobe[0]["attributes"]["href"]),
  859. "date" => $time,
  860. "type" => "web",
  861. "thumb" => $thumb,
  862. "sublink" => $sublinks,
  863. "table" => []
  864. ];
  865. continue;
  866. }
  867. // probe for containers with a title header
  868. $title_header =
  869. $this->fuckhtml
  870. ->getElementsByClassName(
  871. $this->getstyle([
  872. "display" => "flex",
  873. "flex-wrap" => "wrap",
  874. "position" => "relative",
  875. "padding" => "16px"
  876. ])
  877. );
  878. if(count($title_header) !== 0){
  879. $title_header =
  880. strtolower(
  881. $this->fuckhtml
  882. ->getTextContent(
  883. $title_header[0]
  884. )
  885. );
  886. switch($title_header){
  887. case "people also search for":
  888. // get all related searches
  889. $relateds =
  890. $this->fuckhtml
  891. ->getElementsByClassName(
  892. $this->getstyle([
  893. "display" => "flex",
  894. "height" => "100%",
  895. "flex-direction" => "column",
  896. "max-width" => "100%"
  897. ])
  898. );
  899. foreach($relateds as $r){
  900. $out["related"][] =
  901. $this->fuckhtml
  902. ->getTextContent(
  903. $r
  904. );
  905. }
  906. break;
  907. }
  908. continue;
  909. }
  910. }
  911. $out["related"] = array_values(array_unique($out["related"]));
  912. return $out;
  913. }
  914. public function video($get){
  915. if($get["npt"]){
  916. [$params, $proxy] = $this->backend->get($get["npt"], "video");
  917. $params = json_decode($params, true);
  918. }else{
  919. $search = $get["s"];
  920. $country = $get["country"];
  921. $nsfw = $get["nsfw"];
  922. $older = $get["older"];
  923. $newer = $get["newer"];
  924. $duration = $get["duration"];
  925. $quality = $get["quality"];
  926. $captions = $get["captions"];
  927. $proxy = $this->backend->get_ip();
  928. $params = [
  929. "q" => $search,
  930. "udm" => "7",
  931. "hl" => "en",
  932. "num" => 20
  933. ];
  934. // country
  935. if($country != "any"){
  936. $params["gl"] = $country;
  937. }
  938. // nsfw
  939. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  940. $tbs = [];
  941. // get date
  942. $older = $older === false ? null : date("m/d/Y", $older);
  943. $newer = $newer === false ? null : date("m/d/Y", $newer);
  944. if(
  945. $older !== null ||
  946. $newer !== null
  947. ){
  948. $tbs["cdr"] = "1";
  949. $tbs["cd_min"] = $newer;
  950. $tbs["cd_max"] = $older;
  951. }
  952. // duration
  953. if($duration != "any"){
  954. $tbs[] = "dur:" . $duration;
  955. }
  956. // quality
  957. if($quality != "any"){
  958. $tbs[] = "hq:" . $quality;
  959. }
  960. // captions
  961. if($captions != "any"){
  962. $tbs[] = "cc:" . $captions;
  963. }
  964. // append tbs
  965. if(count($tbs) !== 0){
  966. $params["tbs"] =
  967. implode(",", $tbs);
  968. }
  969. }
  970. try{
  971. $html =
  972. $this->get(
  973. $proxy,
  974. "https://www.google.com/search",
  975. $params
  976. );
  977. }catch(Exception $error){
  978. throw new Exception("Failed to get HTML");
  979. }
  980. if(!isset($params["start"])){
  981. $params["start"] = 0;
  982. }
  983. $params["start"] += 20;
  984. $this->fuckhtml->load($html);
  985. //
  986. // Parse web video page
  987. //
  988. $this->detect_sorry();
  989. // parse all <style> tags
  990. $this->parsestyles();
  991. // get javascript images
  992. $this->scrape_dimg($html);
  993. $this->scrape_imagearr($html);
  994. $out = [
  995. "status" => "ok",
  996. "npt" =>
  997. $this->backend->store(
  998. json_encode($params),
  999. "videos",
  1000. $proxy
  1001. ),
  1002. "video" => [],
  1003. "author" => [],
  1004. "livestream" => [],
  1005. "playlist" => [],
  1006. "reel" => []
  1007. ];
  1008. $search_div =
  1009. $this->fuckhtml
  1010. ->getElementById(
  1011. "center_col"
  1012. );
  1013. if($search_div === false){
  1014. throw new Exception("Failed to grep search div");
  1015. }
  1016. $this->fuckhtml->load($search_div);
  1017. $results =
  1018. $this->fuckhtml
  1019. ->getElementsByClassName(
  1020. $this->getstyle([
  1021. "margin" => "0px 0px 30px"
  1022. ]),
  1023. "div"
  1024. );
  1025. foreach($results as $result){
  1026. $this->fuckhtml->load($result);
  1027. $url =
  1028. $this->fuckhtml
  1029. ->getElementsByTagName(
  1030. "a"
  1031. );
  1032. if(count($url) === 0){
  1033. // no url, weird, continue
  1034. continue;
  1035. }
  1036. $title =
  1037. $this->fuckhtml
  1038. ->getElementsByTagName(
  1039. "h3"
  1040. );
  1041. if(count($title) === 0){
  1042. // no title, weird, continue
  1043. continue;
  1044. }
  1045. // get description
  1046. $description =
  1047. $this->fuckhtml
  1048. ->getElementsByClassName(
  1049. $this->getstyle([
  1050. "-webkit-box-orient" => "vertical",
  1051. "display" => "-webkit-box",
  1052. "-webkit-line-clamp" => "2",
  1053. "overflow" => "hidden",
  1054. "word-break" => "break-word"
  1055. ]),
  1056. "div"
  1057. );
  1058. if(count($description) === 0){
  1059. $description = null;
  1060. }else{
  1061. $description =
  1062. html_entity_decode(
  1063. $this->titledots(
  1064. $this->fuckhtml
  1065. ->getTextContent(
  1066. $description[0]
  1067. )
  1068. )
  1069. );
  1070. }
  1071. // get author + date posted
  1072. $metadiv =
  1073. $this->fuckhtml
  1074. ->getElementsByClassName(
  1075. $this->getstyle([
  1076. "margin-top" => "12px"
  1077. ]),
  1078. "div"
  1079. );
  1080. $author = null;
  1081. $date = null;
  1082. if(count($metadiv) !== 0){
  1083. $metadiv =
  1084. explode(
  1085. "·",
  1086. $this->fuckhtml
  1087. ->getTextContent(
  1088. $metadiv[0]
  1089. )
  1090. );
  1091. if(count($metadiv) === 3){
  1092. $author = trim($metadiv[1]);
  1093. $date = strtotime(trim($metadiv[2]));
  1094. }elseif(count($metadiv) === 2){
  1095. $author = trim($metadiv[0]);
  1096. $date = strtotime(trim($metadiv[1]));
  1097. }
  1098. }
  1099. $thumb = [
  1100. "url" => null,
  1101. "ratio" => null
  1102. ];
  1103. $image =
  1104. $this->fuckhtml
  1105. ->getElementsByTagName(
  1106. "img"
  1107. );
  1108. $duration = null;
  1109. if(
  1110. count($image) !== 0 &&
  1111. isset($image[0]["attributes"]["id"])
  1112. ){
  1113. $thumb = [
  1114. "url" => $this->getdimg($image[0]["attributes"]["id"]),
  1115. "ratio" => "16:9"
  1116. ];
  1117. // get duration
  1118. $duration =
  1119. $this->fuckhtml
  1120. ->getElementsByClassName(
  1121. $this->getstyle([
  1122. "background-color" => "rgba(0,0,0,0.6)",
  1123. "color" => "#fff",
  1124. "fill" => "#fff"
  1125. ])
  1126. );
  1127. if(count($duration) !== 0){
  1128. $duration =
  1129. $this->hms2int(
  1130. $this->fuckhtml
  1131. ->getTextContent(
  1132. $duration[0]
  1133. ));
  1134. }else{
  1135. $duration = null;
  1136. }
  1137. }
  1138. $out["video"][] = [
  1139. "title" =>
  1140. $this->titledots(
  1141. $this->fuckhtml
  1142. ->getTextContent(
  1143. $title[0]
  1144. )
  1145. ),
  1146. "description" => $description,
  1147. "author" => [
  1148. "name" => $author,
  1149. "url" => null,
  1150. "avatar" => null
  1151. ],
  1152. "date" => $date,
  1153. "duration" => $duration,
  1154. "views" => null,
  1155. "thumb" => $thumb,
  1156. "url" =>
  1157. $this->fuckhtml
  1158. ->getTextContent(
  1159. $url[0]["attributes"]["href"]
  1160. )
  1161. ];
  1162. }
  1163. return $out;
  1164. }
  1165. public function news($get){
  1166. throw new Exception("Broke for now, fuck off lol");
  1167. if($get["npt"]){
  1168. [$req, $proxy] = $this->backend->get($get["npt"], "news");
  1169. /*parse_str(
  1170. parse_url($req, PHP_URL_QUERY),
  1171. $search
  1172. );*/
  1173. try{
  1174. $html =
  1175. $this->get(
  1176. $proxy,
  1177. "https://www.google.com" . $req,
  1178. []
  1179. );
  1180. }catch(Exception $error){
  1181. throw new Exception("Failed to get HTML");
  1182. }
  1183. }else{
  1184. $search = $get["s"];
  1185. $country = $get["country"];
  1186. $nsfw = $get["nsfw"];
  1187. $older = $get["older"];
  1188. $newer = $get["newer"];
  1189. $sort = $get["sort"];
  1190. $proxy = $this->backend->get_ip();
  1191. $params = [
  1192. "q" => $search,
  1193. "tbm" => "nws",
  1194. "hl" => "en",
  1195. "num" => "20"
  1196. ];
  1197. // country
  1198. if($country != "any"){
  1199. $params["gl"] = $country;
  1200. }
  1201. // nsfw
  1202. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  1203. $tbs = [];
  1204. // get date
  1205. $older = $older === false ? null : date("m/d/Y", $older);
  1206. $newer = $newer === false ? null : date("m/d/Y", $newer);
  1207. if(
  1208. $older !== null ||
  1209. $newer !== null
  1210. ){
  1211. $tbs["cdr"] = "1";
  1212. $tbs["cd_min"] = $newer;
  1213. $tbs["cd_max"] = $older;
  1214. }
  1215. // relevance
  1216. if($sort == "date"){
  1217. $tbs["sbd"] = "1";
  1218. }
  1219. // append tbs
  1220. if(count($tbs) !== 0){
  1221. $params["tbs"] = "";
  1222. foreach($tbs as $key => $value){
  1223. $params["tbs"] .= $key . ":" . $value . ",";
  1224. }
  1225. $params["tbs"] = rtrim($params["tbs"], ",");
  1226. }
  1227. //$html = file_get_contents("scraper/google-news.html");
  1228. $html =
  1229. $this->get(
  1230. $proxy,
  1231. "https://www.google.com/search",
  1232. $params
  1233. );
  1234. }
  1235. $out = [
  1236. "status" => "ok",
  1237. "npt" => null,
  1238. "news" => []
  1239. ];
  1240. $this->fuckhtml->load($html);
  1241. $this->detect_sorry();
  1242. // get images
  1243. $this->scrape_dimg($html);
  1244. // parse styles
  1245. $this->parsestyles();
  1246. $center_col =
  1247. $this->fuckhtml
  1248. ->getElementById(
  1249. "center_col",
  1250. "div"
  1251. );
  1252. if($center_col === null){
  1253. throw new Exception("Could not grep result div");
  1254. }
  1255. $this->fuckhtml->load($center_col);
  1256. // get next page
  1257. $npt =
  1258. $this->fuckhtml
  1259. ->getElementById(
  1260. "pnnext",
  1261. "a"
  1262. );
  1263. if($npt !== false){
  1264. $out["npt"] =
  1265. $this->backend->store(
  1266. $this->fuckhtml
  1267. ->getTextContent(
  1268. $npt["attributes"]
  1269. ["href"]
  1270. ),
  1271. "news",
  1272. $proxy
  1273. );
  1274. }
  1275. $as =
  1276. $this->fuckhtml
  1277. ->getElementsByAttributeName(
  1278. "jsname",
  1279. "a"
  1280. );
  1281. foreach($as as $a){
  1282. $this->fuckhtml->load($a);
  1283. // get title
  1284. $title =
  1285. $this->fuckhtml
  1286. ->getElementsByAttributeValue(
  1287. "role",
  1288. "heading",
  1289. "div"
  1290. );
  1291. if(count($title) === 0){
  1292. continue;
  1293. }
  1294. $title =
  1295. $this->titledots(
  1296. $this->fuckhtml
  1297. ->getTextContent(
  1298. $title[0]
  1299. )
  1300. );
  1301. // get thumbnail
  1302. $image =
  1303. $this->fuckhtml
  1304. ->getElementsByAttributeName(
  1305. "id",
  1306. "img"
  1307. );
  1308. // check for padded title node, if found, we're inside a carousel
  1309. $probe =
  1310. $this->fuckhtml
  1311. ->getElementsByClassName(
  1312. $this->getstyle(
  1313. [
  1314. "padding" => "16px 16px 40px 16px"
  1315. ]
  1316. ),
  1317. "div"
  1318. );
  1319. if(count($probe) !== 0){
  1320. $probe = true;
  1321. }else{
  1322. $probe = false;
  1323. }
  1324. if(
  1325. count($image) !== 0 &&
  1326. !isset($image[0]["attributes"]["width"])
  1327. ){
  1328. $thumb = [
  1329. "url" =>
  1330. $this->getdimg(
  1331. $image[0]["attributes"]["id"]
  1332. ),
  1333. "ratio" => $probe === true ? "16:9" : "1:1"
  1334. ];
  1335. }else{
  1336. $thumb = [
  1337. "url" => null,
  1338. "ratio" => null
  1339. ];
  1340. }
  1341. $description = null;
  1342. if($probe === false){
  1343. $desc_divs =
  1344. $this->fuckhtml
  1345. ->getElementsByAttributeName(
  1346. "style",
  1347. "div"
  1348. );
  1349. foreach($desc_divs as $desc){
  1350. if(
  1351. strpos(
  1352. $desc["attributes"]["style"],
  1353. "margin-top:"
  1354. ) !== false
  1355. ){
  1356. $description =
  1357. $this->titledots(
  1358. $this->fuckhtml
  1359. ->getTextContent(
  1360. $desc
  1361. )
  1362. );
  1363. break;
  1364. }
  1365. }
  1366. }
  1367. // get author
  1368. $author =
  1369. $this->fuckhtml
  1370. ->getElementsByClassName(
  1371. $this->getstyle(
  1372. [
  1373. "overflow" => "hidden",
  1374. "text-align" => "left",
  1375. "text-overflow" => "ellipsis",
  1376. "white-space" => "nowrap",
  1377. "margin-bottom" => "8px"
  1378. ]
  1379. ),
  1380. "div"
  1381. );
  1382. if(count($author) !== 0){
  1383. $author =
  1384. $this->fuckhtml
  1385. ->getTextContent(
  1386. $author[0]
  1387. );
  1388. }else{
  1389. $author = null;
  1390. }
  1391. // get date
  1392. $date = null;
  1393. $date_div =
  1394. $this->fuckhtml
  1395. ->getElementsByAttributeName(
  1396. "style",
  1397. "div"
  1398. );
  1399. foreach($date_div as $d){
  1400. $this->fuckhtml->load($d);
  1401. $span =
  1402. $this->fuckhtml
  1403. ->getElementsByTagName(
  1404. "span"
  1405. );
  1406. if(
  1407. strpos(
  1408. $d["attributes"]["style"],
  1409. "bottom:"
  1410. ) !== false
  1411. ){
  1412. $date =
  1413. strtotime(
  1414. $this->fuckhtml
  1415. ->getTextContent(
  1416. $span[count($span) - 1]
  1417. )
  1418. );
  1419. break;
  1420. }
  1421. }
  1422. $out["news"][] = [
  1423. "title" => $title,
  1424. "author" => $author,
  1425. "description" => $description,
  1426. "date" => $date,
  1427. "thumb" => $thumb,
  1428. "url" =>
  1429. $this->unshiturl(
  1430. $a["attributes"]
  1431. ["href"]
  1432. )
  1433. ];
  1434. }
  1435. return $out;
  1436. }
  1437. public function image($get){
  1438. // generate parameters
  1439. if($get["npt"]){
  1440. [$params, $proxy] =
  1441. $this->backend->get(
  1442. $get["npt"],
  1443. "images"
  1444. );
  1445. $params = json_decode($params, true);
  1446. }else{
  1447. $search = $get["s"];
  1448. if(strlen($search) === 0){
  1449. throw new Exception("Search term is empty!");
  1450. }
  1451. $proxy = $this->backend->get_ip();
  1452. $country = $get["country"];
  1453. $nsfw = $get["nsfw"];
  1454. $time = $get["time"];
  1455. $size = $get["size"];
  1456. $ratio = $get["ratio"];
  1457. $color = $get["color"];
  1458. $type = $get["type"];
  1459. $format = $get["format"];
  1460. $rights = $get["rights"];
  1461. $params = [
  1462. "q" => $search,
  1463. "udm" => "2" // get images
  1464. ];
  1465. // country (image search uses cr instead of gl)
  1466. if($country != "any"){
  1467. $params["cr"] = "country" . strtoupper($country);
  1468. }
  1469. // nsfw
  1470. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  1471. // generate tbs
  1472. $tbs = [];
  1473. // time
  1474. if($time != "any"){
  1475. $tbs["qdr"] = $time;
  1476. }
  1477. // size
  1478. if($size != "any"){
  1479. $params["imgsz"] = $size;
  1480. }
  1481. // ratio
  1482. if($ratio != "any"){
  1483. $params["imgar"] = $ratio;
  1484. }
  1485. // color
  1486. if($color != "any"){
  1487. if(
  1488. $color == "color" ||
  1489. $color == "trans"
  1490. ){
  1491. $params["imgc"] = $color;
  1492. }elseif($color == "bnw"){
  1493. $params["imgc"] = "gray";
  1494. }else{
  1495. $tbs["ic"] = "specific";
  1496. $tbs["isc"] = $color;
  1497. }
  1498. }
  1499. // type
  1500. if($type != "any"){
  1501. $tbs["itp"] = $type;
  1502. }
  1503. // format
  1504. if($format != "any"){
  1505. $params["as_filetype"] = $format;
  1506. }
  1507. // rights (tbs)
  1508. if($rights != "any"){
  1509. $tbs["sur"] = $rights;
  1510. }
  1511. // append tbs
  1512. if(count($tbs) !== 0){
  1513. $params["tbs"] = "";
  1514. foreach($tbs as $key => $value){
  1515. $params["tbs"] .= $key . ":" . $value . ",";
  1516. }
  1517. $params["tbs"] = rtrim($params["tbs"], ",");
  1518. }
  1519. }
  1520. /*
  1521. $handle = fopen("scraper/page.html", "r");
  1522. $html = fread($handle, filesize("scraper/page.html"));
  1523. fclose($handle);*/
  1524. try{
  1525. $html =
  1526. $this->get(
  1527. $proxy,
  1528. "https://www.google.com/search",
  1529. $params
  1530. );
  1531. }catch(Exception $error){
  1532. throw new Exception("Failed to get search page");
  1533. }
  1534. $this->fuckhtml->load($html);
  1535. $this->detect_sorry();
  1536. // get javascript images
  1537. $this->scrape_imagearr($html);
  1538. $out = [
  1539. "status" => "ok",
  1540. "npt" => null,
  1541. "image" => []
  1542. ];
  1543. $images =
  1544. $this->fuckhtml
  1545. ->getElementsByClassName(
  1546. "ivg-i",
  1547. "div"
  1548. );
  1549. foreach($images as $div){
  1550. $this->fuckhtml->load($div);
  1551. $image =
  1552. $this->fuckhtml
  1553. ->getElementsByTagName("img")[0];
  1554. // make sure we dont attempt to show an image we dont have data for
  1555. if(
  1556. isset($div["attributes"]["data-docid"]) &&
  1557. isset($this->image_arr[$div["attributes"]["data-docid"]])
  1558. ){
  1559. $source =
  1560. $this->image_arr[
  1561. $div["attributes"]["data-docid"]
  1562. ];
  1563. }else{
  1564. continue;
  1565. }
  1566. $out["image"][] = [
  1567. "title" =>
  1568. $this->titledots(
  1569. $this->fuckhtml
  1570. ->getTextContent(
  1571. $image["attributes"]["alt"]
  1572. )
  1573. ),
  1574. "source" => $source,
  1575. "url" =>
  1576. $this->fuckhtml
  1577. ->getTextContent(
  1578. $div["attributes"]["data-lpage"]
  1579. )
  1580. ];
  1581. }
  1582. // as usual, no way to check if there is a next page reliably
  1583. if(count($out["image"]) > 50){
  1584. if(!isset($params["start"])){
  1585. $params["start"] = 10;
  1586. }else{
  1587. $params["start"] += 10;
  1588. }
  1589. $out["npt"] =
  1590. $this->backend
  1591. ->store(
  1592. json_encode($params),
  1593. "image",
  1594. $proxy
  1595. );
  1596. }
  1597. return $out;
  1598. }
  1599. private function scrape_dimg($html){
  1600. // get images loaded through javascript
  1601. $this->dimg = [];
  1602. preg_match_all(
  1603. '/function\(\){google\.ldi=({.*?});/',
  1604. $html,
  1605. $dimg
  1606. );
  1607. if(isset($dimg[1])){
  1608. foreach($dimg[1] as $i){
  1609. $tmp = json_decode($i, true);
  1610. foreach($tmp as $key => $value){
  1611. $this->dimg[$key] =
  1612. $this->unshit_thumb(
  1613. $value
  1614. );
  1615. }
  1616. }
  1617. }
  1618. // get additional javascript base64 images
  1619. preg_match_all(
  1620. '/var s=\'(data:image\/[^\']+)\';var ii=\[((?:\'[^\']+\',?)+)\];/',
  1621. $html,
  1622. $dimg
  1623. );
  1624. if(isset($dimg[1])){
  1625. for($i=0; $i<count($dimg[1]); $i++){
  1626. $delims = explode(",", $dimg[2][$i]);
  1627. $string =
  1628. $this->fuckhtml
  1629. ->parseJsString(
  1630. $dimg[1][$i]
  1631. );
  1632. foreach($delims as $delim){
  1633. $this->dimg[trim($delim, "'")] = $string;
  1634. }
  1635. }
  1636. }
  1637. }
  1638. private function scrape_imagearr($html){
  1639. // get image links arrays
  1640. preg_match_all(
  1641. '/\[[0-9]+,"([^"]+)",\["([^"]+)\",([0-9]+),([0-9]+)\],\["([^"]+)",([0-9]+),([0-9]+)\]/',
  1642. $html,
  1643. $image_arr
  1644. );
  1645. $this->image_arr = [];
  1646. if(isset($image_arr[1])){
  1647. for($i=0; $i<count($image_arr[1]); $i++){
  1648. $original =
  1649. $this->fuckhtml
  1650. ->parseJsString(
  1651. $image_arr[5][$i]
  1652. );
  1653. if(
  1654. preg_match(
  1655. '/^x-raw-image/',
  1656. $original
  1657. )
  1658. ){
  1659. // only add thumbnail, google doesnt have OG resolution
  1660. $this->image_arr[$image_arr[1][$i]] = [
  1661. [
  1662. "url" =>
  1663. $this->unshit_thumb(
  1664. $this->fuckhtml
  1665. ->parseJsString(
  1666. $image_arr[2][$i]
  1667. )
  1668. ),
  1669. "width" => (int)$image_arr[7][$i], // pass the OG image width & height
  1670. "height" => (int)$image_arr[6][$i]
  1671. ]
  1672. ];
  1673. continue;
  1674. }
  1675. $this->image_arr[$image_arr[1][$i]] =
  1676. [
  1677. [
  1678. "url" => $original,
  1679. "width" => (int)$image_arr[7][$i],
  1680. "height" => (int)$image_arr[6][$i]
  1681. ],
  1682. [
  1683. "url" =>
  1684. $this->unshit_thumb(
  1685. $this->fuckhtml
  1686. ->parseJsString(
  1687. $image_arr[2][$i]
  1688. )
  1689. ),
  1690. "width" => (int)$image_arr[4][$i],
  1691. "height" => (int)$image_arr[3][$i]
  1692. ]
  1693. ];
  1694. }
  1695. }
  1696. }
  1697. private function getdimg($dimg){
  1698. return isset($this->dimg[$dimg]) ? $this->dimg[$dimg] : null;
  1699. }
  1700. private function unshit_thumb($url, $get_bigger_res = false){
  1701. // https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQINE2vbnNLHXqoZr3RVsaEJFyOsj1_BiBnJch-e1nyz3oia7Aj5xVj
  1702. // https://i.ytimg.com/vi/PZVIyA5ER3Y/mqdefault.jpg?sqp=-oaymwEFCJQBEFM&rs=AMzJL3nXeaCpdIar-ltNwl82Y82cIJfphA
  1703. $parts = parse_url($url);
  1704. if(
  1705. isset($parts["host"]) &&
  1706. preg_match(
  1707. '/(?:encrypted-)?tbn.*\.gstatic\.com/',
  1708. $parts["host"]
  1709. )
  1710. ){
  1711. parse_str($parts["query"], $params);
  1712. if(isset($params["q"])){
  1713. if($get_bigger_res){
  1714. // this method doesnt always work, but does work for wiki thumbnails
  1715. return
  1716. "https://" . $parts["host"] . "/images?q=tbn:" .
  1717. $this->base64url_encode(
  1718. substr(
  1719. $this->base64url_decode(
  1720. explode(
  1721. ":",
  1722. $params["q"])[1]
  1723. ),
  1724. 0,
  1725. 29
  1726. )
  1727. );
  1728. }else{
  1729. return "https://" . $parts["host"] . "/images?q=" . $params["q"];
  1730. }
  1731. }
  1732. }
  1733. return $url;
  1734. }
  1735. private function parsestyles(){
  1736. $styles = [];
  1737. $style_div =
  1738. $this->fuckhtml
  1739. ->getElementsByTagName(
  1740. "style"
  1741. );
  1742. $raw_styles = "";
  1743. foreach($style_div as $style){
  1744. $raw_styles .= $style["innerHTML"];
  1745. }
  1746. // filter out media/keyframe queries
  1747. $raw_styles =
  1748. preg_replace(
  1749. '/@\s*(?!font-face)[^{]+\s*{[\S\s]+?}\s*}/',
  1750. "",
  1751. $raw_styles
  1752. );
  1753. // get styles
  1754. preg_match_all(
  1755. '/(.+?){([\S\s]*?)}/',
  1756. $raw_styles,
  1757. $matches
  1758. );
  1759. for($i=0; $i<count($matches[1]); $i++){
  1760. // get style values
  1761. preg_match_all(
  1762. '/([^:;]+):([^;]*?(?:\([^)]+\)[^;]*?)?)(?:;|$)/',
  1763. $matches[2][$i],
  1764. $values_regex
  1765. );
  1766. $values = [];
  1767. for($k=0; $k<count($values_regex[1]); $k++){
  1768. $values[trim($values_regex[1][$k])] =
  1769. strtolower(trim($values_regex[2][$k]));
  1770. }
  1771. $names = explode(",", $matches[1][$i]);
  1772. // h1,h2,h3 will each get their own array index
  1773. foreach($names as $name){
  1774. $name = trim($name, "}\t\n\r\0\x0B");
  1775. foreach($values as $key => $value){
  1776. $styles[$name][$key] = $value;
  1777. }
  1778. }
  1779. }
  1780. foreach($styles as $key => $values){
  1781. $styles[$key]["_c"] = count($values);
  1782. }
  1783. $this->styles = $styles;
  1784. // get CSS colors
  1785. $this->css_colors = [];
  1786. if(isset($this->styles[":root"])){
  1787. foreach($this->styles[":root"] as $key => $value){
  1788. $this->css_colors[$value] = strtolower($key);
  1789. }
  1790. }
  1791. }
  1792. private function getstyle($styles){
  1793. $styles["_c"] = count($styles);
  1794. foreach($this->styles as $style_key => $style_values){
  1795. if(count(array_intersect_assoc($style_values, $styles)) === $styles["_c"] + 1){
  1796. $style_key =
  1797. explode(" ", $style_key);
  1798. $style_key = $style_key[count($style_key) - 1];
  1799. return
  1800. ltrim(
  1801. str_replace(
  1802. [".", "#"],
  1803. " ",
  1804. $style_key
  1805. )
  1806. );
  1807. }
  1808. }
  1809. return false;
  1810. }
  1811. private function getcolorvar($color){
  1812. if(isset($this->css_colors[$color])){
  1813. return $this->css_colors[$color];
  1814. }
  1815. return null;
  1816. }
  1817. private function unshiturl($url, $return_size = false){
  1818. // decode
  1819. $url =
  1820. $this->fuckhtml
  1821. ->getTextContent(
  1822. $url
  1823. );
  1824. $url_parts = parse_url($url);
  1825. if(isset($url_parts["query"])){
  1826. parse_str($url_parts["query"], $query);
  1827. }else{
  1828. $query = [];
  1829. }
  1830. if(
  1831. !isset(
  1832. $url_parts["host"]
  1833. ) ||
  1834. stripos($url_parts["host"], "google.") !== false
  1835. ){
  1836. // no host, we have a tracking url
  1837. if(isset($query["imgurl"])){
  1838. $url = $query["imgurl"];
  1839. }
  1840. elseif(isset($query["q"])){
  1841. $url = $query["q"];
  1842. }
  1843. }
  1844. // rewrite URLs to remove extra tracking parameters
  1845. $domain = parse_url($url, PHP_URL_HOST);
  1846. if(
  1847. preg_match(
  1848. '/wikipedia.org$/',
  1849. $domain
  1850. )
  1851. ){
  1852. // rewrite wikipedia mobile URLs to desktop
  1853. $url =
  1854. $this->replacedomain(
  1855. $url,
  1856. preg_replace(
  1857. '/([a-z0-9]+)(\.m\.)/',
  1858. '$1.',
  1859. $domain
  1860. )
  1861. );
  1862. }
  1863. elseif(
  1864. preg_match(
  1865. '/imdb\.com$|youtube\.[^.]+$/',
  1866. $domain
  1867. )
  1868. ){
  1869. // rewrite imdb and youtube mobile URLs too
  1870. $url =
  1871. $this->replacedomain(
  1872. $url,
  1873. preg_replace(
  1874. '/^m\./',
  1875. "",
  1876. $domain
  1877. )
  1878. );
  1879. }
  1880. elseif(
  1881. preg_match(
  1882. '/play\.google\.[^.]+$/',
  1883. $domain
  1884. )
  1885. ){
  1886. // remove referrers from play.google.com
  1887. $u_query = parse_url($url, PHP_URL_QUERY);
  1888. if($u_query !== null){
  1889. parse_str($u_query, $u_query);
  1890. if(isset($u_query["referrer"])){ unset($u_query["referrer"]); }
  1891. if(isset($u_query["hl"])){ unset($u_query["hl"]); }
  1892. if(isset($u_query["gl"])){ unset($u_query["gl"]); }
  1893. $query = http_build_query($query);
  1894. $url =
  1895. str_replace(
  1896. $u_query,
  1897. $u_query,
  1898. $url
  1899. );
  1900. }
  1901. }
  1902. elseif(
  1903. preg_match(
  1904. '/twitter\.com$/',
  1905. $domain
  1906. )
  1907. ){
  1908. // remove more referrers from twitter.com
  1909. $u_query = parse_url($url, PHP_URL_QUERY);
  1910. if($u_query !== null){
  1911. parse_str($u_query, $u_query);
  1912. if(isset($u_query["ref_src"])){ unset($u_query["ref_src"]); }
  1913. $u_query = http_build_query($u_query);
  1914. $url =
  1915. str_replace(
  1916. $oldquery,
  1917. $u_query,
  1918. $url
  1919. );
  1920. }
  1921. }
  1922. elseif(
  1923. preg_match(
  1924. '/maps\.google\.[^.]+/',
  1925. $domain
  1926. )
  1927. ){
  1928. if(stripos($url, "maps?") !== false){
  1929. $u_query = parse_url($url, PHP_URL_QUERY);
  1930. if($u_query !== null){
  1931. parse_str($u_query, $u_query);
  1932. if(isset($u_query["daddr"])){
  1933. $url =
  1934. "https://maps.google.com/maps?daddr=" .
  1935. urlencode($u_query["daddr"]);
  1936. }
  1937. }
  1938. }
  1939. }
  1940. if($return_size){
  1941. return [
  1942. "url" => $url,
  1943. "ref" => isset($query["imgrefurl"]) ? $query["imgrefurl"] : null,
  1944. "thumb_width" => isset($query["tbnw"]) ? (int)$query["tbnw"] : null,
  1945. "thumb_height" => isset($query["tbnh"]) ? (int)$query["tbnh"] : null,
  1946. "image_width" => isset($query["w"]) ? (int)$query["w"] : null,
  1947. "image_height" => isset($query["h"]) ? (int)$query["h"] : null
  1948. ];
  1949. }
  1950. return $url;
  1951. }
  1952. private function replacedomain($url, $domain){
  1953. return
  1954. preg_replace(
  1955. '/(https?:\/\/)([^\/]+)/',
  1956. '$1' . $domain,
  1957. $url
  1958. );
  1959. }
  1960. private function titledots($title){
  1961. return trim($title, " .\t\n\r\0\x0B…");
  1962. }
  1963. private function hms2int($time){
  1964. $parts = explode(":", $time, 3);
  1965. $time = 0;
  1966. if(count($parts) === 3){
  1967. // hours
  1968. $time = $time + ((int)$parts[0] * 3600);
  1969. array_shift($parts);
  1970. }
  1971. if(count($parts) === 2){
  1972. // minutes
  1973. $time = $time + ((int)$parts[0] * 60);
  1974. array_shift($parts);
  1975. }
  1976. // seconds
  1977. $time = $time + (int)$parts[0];
  1978. return $time;
  1979. }
  1980. function base64url_decode($data){
  1981. $b64 = strtr($data, "-_", "+/");
  1982. $pad = strlen($b64) % 4;
  1983. if ($pad) $b64 .= str_repeat("=", 4 - $pad);
  1984. return base64_decode($b64);
  1985. }
  1986. function base64url_encode($data){
  1987. return rtrim(strtr(base64_encode($data), "+/", "-_"), "=");
  1988. }
  1989. private function detect_sorry(){
  1990. $captcha_form =
  1991. $this->fuckhtml
  1992. ->getElementById(
  1993. "captcha-form",
  1994. "form"
  1995. );
  1996. if($captcha_form !== false){
  1997. throw new Exception("Google returned a captcha");
  1998. }
  1999. }
  2000. }