google.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  1. <?php
  2. class google{
  3. private const is_class = ".";
  4. private const is_id = "#";
  5. public function __construct(){
  6. include "lib/fuckhtml.php";
  7. $this->fuckhtml = new fuckhtml();
  8. include "lib/nextpage.php";
  9. $this->nextpage = new nextpage("google");
  10. }
  11. public function getfilters($page){
  12. switch($page){
  13. case "web":
  14. case "videos":
  15. case "news":
  16. return [
  17. "country" => [ // gl=<country>
  18. "display" => "Country",
  19. "option" => [
  20. "any" => "Instance's country",
  21. "af" => "Afghanistan",
  22. "al" => "Albania",
  23. "dz" => "Algeria",
  24. "as" => "American Samoa",
  25. "ad" => "Andorra",
  26. "ao" => "Angola",
  27. "ai" => "Anguilla",
  28. "aq" => "Antarctica",
  29. "ag" => "Antigua and Barbuda",
  30. "ar" => "Argentina",
  31. "am" => "Armenia",
  32. "aw" => "Aruba",
  33. "au" => "Australia",
  34. "at" => "Austria",
  35. "az" => "Azerbaijan",
  36. "bs" => "Bahamas",
  37. "bh" => "Bahrain",
  38. "bd" => "Bangladesh",
  39. "bb" => "Barbados",
  40. "by" => "Belarus",
  41. "be" => "Belgium",
  42. "bz" => "Belize",
  43. "bj" => "Benin",
  44. "bm" => "Bermuda",
  45. "bt" => "Bhutan",
  46. "bo" => "Bolivia",
  47. "ba" => "Bosnia and Herzegovina",
  48. "bw" => "Botswana",
  49. "bv" => "Bouvet Island",
  50. "br" => "Brazil",
  51. "io" => "British Indian Ocean Territory",
  52. "bn" => "Brunei Darussalam",
  53. "bg" => "Bulgaria",
  54. "bf" => "Burkina Faso",
  55. "bi" => "Burundi",
  56. "kh" => "Cambodia",
  57. "cm" => "Cameroon",
  58. "ca" => "Canada",
  59. "cv" => "Cape Verde",
  60. "ky" => "Cayman Islands",
  61. "cf" => "Central African Republic",
  62. "td" => "Chad",
  63. "cl" => "Chile",
  64. "cn" => "China",
  65. "cx" => "Christmas Island",
  66. "cc" => "Cocos (Keeling) Islands",
  67. "co" => "Colombia",
  68. "km" => "Comoros",
  69. "cg" => "Congo",
  70. "cd" => "Congo, the Democratic Republic",
  71. "ck" => "Cook Islands",
  72. "cr" => "Costa Rica",
  73. "ci" => "Cote D'ivoire",
  74. "hr" => "Croatia",
  75. "cu" => "Cuba",
  76. "cy" => "Cyprus",
  77. "cz" => "Czech Republic",
  78. "dk" => "Denmark",
  79. "dj" => "Djibouti",
  80. "dm" => "Dominica",
  81. "do" => "Dominican Republic",
  82. "ec" => "Ecuador",
  83. "eg" => "Egypt",
  84. "sv" => "El Salvador",
  85. "gq" => "Equatorial Guinea",
  86. "er" => "Eritrea",
  87. "ee" => "Estonia",
  88. "et" => "Ethiopia",
  89. "fk" => "Falkland Islands (Malvinas)",
  90. "fo" => "Faroe Islands",
  91. "fj" => "Fiji",
  92. "fi" => "Finland",
  93. "fr" => "France",
  94. "gf" => "French Guiana",
  95. "pf" => "French Polynesia",
  96. "tf" => "French Southern Territories",
  97. "ga" => "Gabon",
  98. "gm" => "Gambia",
  99. "ge" => "Georgia",
  100. "de" => "Germany",
  101. "gh" => "Ghana",
  102. "gi" => "Gibraltar",
  103. "gr" => "Greece",
  104. "gl" => "Greenland",
  105. "gd" => "Grenada",
  106. "gp" => "Guadeloupe",
  107. "gu" => "Guam",
  108. "gt" => "Guatemala",
  109. "gn" => "Guinea",
  110. "gw" => "Guinea-Bissau",
  111. "gy" => "Guyana",
  112. "ht" => "Haiti",
  113. "hm" => "Heard Island and Mcdonald Islands",
  114. "va" => "Holy See (Vatican City State)",
  115. "hn" => "Honduras",
  116. "hk" => "Hong Kong",
  117. "hu" => "Hungary",
  118. "is" => "Iceland",
  119. "in" => "India",
  120. "id" => "Indonesia",
  121. "ir" => "Iran, Islamic Republic",
  122. "iq" => "Iraq",
  123. "ie" => "Ireland",
  124. "il" => "Israel",
  125. "it" => "Italy",
  126. "jm" => "Jamaica",
  127. "jp" => "Japan",
  128. "jo" => "Jordan",
  129. "kz" => "Kazakhstan",
  130. "ke" => "Kenya",
  131. "ki" => "Kiribati",
  132. "kp" => "Korea, Democratic People's Republic",
  133. "kr" => "Korea, Republic",
  134. "kw" => "Kuwait",
  135. "kg" => "Kyrgyzstan",
  136. "la" => "Lao People's Democratic Republic",
  137. "lv" => "Latvia",
  138. "lb" => "Lebanon",
  139. "ls" => "Lesotho",
  140. "lr" => "Liberia",
  141. "ly" => "Libyan Arab Jamahiriya",
  142. "li" => "Liechtenstein",
  143. "lt" => "Lithuania",
  144. "lu" => "Luxembourg",
  145. "mo" => "Macao",
  146. "mk" => "Macedonia, the Former Yugosalv Republic",
  147. "mg" => "Madagascar",
  148. "mw" => "Malawi",
  149. "my" => "Malaysia",
  150. "mv" => "Maldives",
  151. "ml" => "Mali",
  152. "mt" => "Malta",
  153. "mh" => "Marshall Islands",
  154. "mq" => "Martinique",
  155. "mr" => "Mauritania",
  156. "mu" => "Mauritius",
  157. "yt" => "Mayotte",
  158. "mx" => "Mexico",
  159. "fm" => "Micronesia, Federated States",
  160. "md" => "Moldova, Republic",
  161. "mc" => "Monaco",
  162. "mn" => "Mongolia",
  163. "ms" => "Montserrat",
  164. "ma" => "Morocco",
  165. "mz" => "Mozambique",
  166. "mm" => "Myanmar",
  167. "na" => "Namibia",
  168. "nr" => "Nauru",
  169. "np" => "Nepal",
  170. "nl" => "Netherlands",
  171. "an" => "Netherlands Antilles",
  172. "nc" => "New Caledonia",
  173. "nz" => "New Zealand",
  174. "ni" => "Nicaragua",
  175. "ne" => "Niger",
  176. "ng" => "Nigeria",
  177. "nu" => "Niue",
  178. "nf" => "Norfolk Island",
  179. "mp" => "Northern Mariana Islands",
  180. "no" => "Norway",
  181. "om" => "Oman",
  182. "pk" => "Pakistan",
  183. "pw" => "Palau",
  184. "ps" => "Palestinian Territory, Occupied",
  185. "pa" => "Panama",
  186. "pg" => "Papua New Guinea",
  187. "py" => "Paraguay",
  188. "pe" => "Peru",
  189. "ph" => "Philippines",
  190. "pn" => "Pitcairn",
  191. "pl" => "Poland",
  192. "pt" => "Portugal",
  193. "pr" => "Puerto Rico",
  194. "qa" => "Qatar",
  195. "re" => "Reunion",
  196. "ro" => "Romania",
  197. "ru" => "Russian Federation",
  198. "rw" => "Rwanda",
  199. "sh" => "Saint Helena",
  200. "kn" => "Saint Kitts and Nevis",
  201. "lc" => "Saint Lucia",
  202. "pm" => "Saint Pierre and Miquelon",
  203. "vc" => "Saint Vincent and the Grenadines",
  204. "ws" => "Samoa",
  205. "sm" => "San Marino",
  206. "st" => "Sao Tome and Principe",
  207. "sa" => "Saudi Arabia",
  208. "sn" => "Senegal",
  209. "cs" => "Serbia and Montenegro",
  210. "sc" => "Seychelles",
  211. "sl" => "Sierra Leone",
  212. "sg" => "Singapore",
  213. "sk" => "Slovakia",
  214. "si" => "Slovenia",
  215. "sb" => "Solomon Islands",
  216. "so" => "Somalia",
  217. "za" => "South Africa",
  218. "gs" => "South Georgia and the South Sandwich Islands",
  219. "es" => "Spain",
  220. "lk" => "Sri Lanka",
  221. "sd" => "Sudan",
  222. "sr" => "Suriname",
  223. "sj" => "Svalbard and Jan Mayen",
  224. "sz" => "Swaziland",
  225. "se" => "Sweden",
  226. "ch" => "Switzerland",
  227. "sy" => "Syrian Arab Republic",
  228. "tw" => "Taiwan, Province of China",
  229. "tj" => "Tajikistan",
  230. "tz" => "Tanzania, United Republic",
  231. "th" => "Thailand",
  232. "tl" => "Timor-Leste",
  233. "tg" => "Togo",
  234. "tk" => "Tokelau",
  235. "to" => "Tonga",
  236. "tt" => "Trinidad and Tobago",
  237. "tn" => "Tunisia",
  238. "tr" => "Turkey",
  239. "tm" => "Turkmenistan",
  240. "tc" => "Turks and Caicos Islands",
  241. "tv" => "Tuvalu",
  242. "ug" => "Uganda",
  243. "ua" => "Ukraine",
  244. "ae" => "United Arab Emirates",
  245. "uk" => "United Kingdom",
  246. "us" => "United States",
  247. "um" => "United States Minor Outlying Islands",
  248. "uy" => "Uruguay",
  249. "uz" => "Uzbekistan",
  250. "vu" => "Vanuatu",
  251. "ve" => "Venezuela",
  252. "vn" => "Viet Nam",
  253. "vg" => "Virgin Islands, British",
  254. "vi" => "Virgin Islands, U.S.",
  255. "wf" => "Wallis and Futuna",
  256. "eh" => "Western Sahara",
  257. "ye" => "Yemen",
  258. "zm" => "Zambia",
  259. "zw" => "Zimbabwe"
  260. ]
  261. ],
  262. "nsfw" => [
  263. "display" => "NSFW",
  264. "option" => [
  265. "yes" => "Yes", // safe=active
  266. "no" => "No" // safe=off
  267. ]
  268. ],
  269. "lang" => [ // lr=<lang> (prefix lang with "lang_")
  270. "display" => "Language",
  271. "option" => [
  272. "any" => "Any language",
  273. "ar" => "Arabic",
  274. "bg" => "Bulgarian",
  275. "ca" => "Catalan",
  276. "cs" => "Czech",
  277. "da" => "Danish",
  278. "de" => "German",
  279. "el" => "Greek",
  280. "en" => "English",
  281. "es" => "Spanish",
  282. "et" => "Estonian",
  283. "fi" => "Finnish",
  284. "fr" => "French",
  285. "hr" => "Croatian",
  286. "hu" => "Hungarian",
  287. "id" => "Indonesian",
  288. "is" => "Icelandic",
  289. "it" => "Italian",
  290. "iw" => "Hebrew",
  291. "ja" => "Japanese",
  292. "ko" => "Korean",
  293. "lt" => "Lithuanian",
  294. "lv" => "Latvian",
  295. "nl" => "Dutch",
  296. "no" => "Norwegian",
  297. "pl" => "Polish",
  298. "pt" => "Portuguese",
  299. "ro" => "Romanian",
  300. "ru" => "Russian",
  301. "sk" => "Slovak",
  302. "sl" => "Slovenian",
  303. "sr" => "Serbian",
  304. "sv" => "Swedish",
  305. "tr" => "Turkish",
  306. "zh-CN" => "Chinese (Simplified)",
  307. "zh-TW" => "Chinese (Traditional)"
  308. ]
  309. ],
  310. "newer" => [ // &sort=review-date:r:20090301:20090430
  311. "display" => "Newer than",
  312. "option" => "_DATE"
  313. ],
  314. "older" => [
  315. "display" => "Older than",
  316. "option" => "_DATE"
  317. ]
  318. ];
  319. break;
  320. case "images":
  321. return [
  322. "country" => [ // gl=<country>
  323. "display" => "Country",
  324. "option" => [
  325. "any" => "Instance's country",
  326. "af" => "Afghanistan",
  327. "al" => "Albania",
  328. "dz" => "Algeria",
  329. "as" => "American Samoa",
  330. "ad" => "Andorra",
  331. "ao" => "Angola",
  332. "ai" => "Anguilla",
  333. "aq" => "Antarctica",
  334. "ag" => "Antigua and Barbuda",
  335. "ar" => "Argentina",
  336. "am" => "Armenia",
  337. "aw" => "Aruba",
  338. "au" => "Australia",
  339. "at" => "Austria",
  340. "az" => "Azerbaijan",
  341. "bs" => "Bahamas",
  342. "bh" => "Bahrain",
  343. "bd" => "Bangladesh",
  344. "bb" => "Barbados",
  345. "by" => "Belarus",
  346. "be" => "Belgium",
  347. "bz" => "Belize",
  348. "bj" => "Benin",
  349. "bm" => "Bermuda",
  350. "bt" => "Bhutan",
  351. "bo" => "Bolivia",
  352. "ba" => "Bosnia and Herzegovina",
  353. "bw" => "Botswana",
  354. "bv" => "Bouvet Island",
  355. "br" => "Brazil",
  356. "io" => "British Indian Ocean Territory",
  357. "bn" => "Brunei Darussalam",
  358. "bg" => "Bulgaria",
  359. "bf" => "Burkina Faso",
  360. "bi" => "Burundi",
  361. "kh" => "Cambodia",
  362. "cm" => "Cameroon",
  363. "ca" => "Canada",
  364. "cv" => "Cape Verde",
  365. "ky" => "Cayman Islands",
  366. "cf" => "Central African Republic",
  367. "td" => "Chad",
  368. "cl" => "Chile",
  369. "cn" => "China",
  370. "cx" => "Christmas Island",
  371. "cc" => "Cocos (Keeling) Islands",
  372. "co" => "Colombia",
  373. "km" => "Comoros",
  374. "cg" => "Congo",
  375. "cd" => "Congo, the Democratic Republic",
  376. "ck" => "Cook Islands",
  377. "cr" => "Costa Rica",
  378. "ci" => "Cote D'ivoire",
  379. "hr" => "Croatia",
  380. "cu" => "Cuba",
  381. "cy" => "Cyprus",
  382. "cz" => "Czech Republic",
  383. "dk" => "Denmark",
  384. "dj" => "Djibouti",
  385. "dm" => "Dominica",
  386. "do" => "Dominican Republic",
  387. "ec" => "Ecuador",
  388. "eg" => "Egypt",
  389. "sv" => "El Salvador",
  390. "gq" => "Equatorial Guinea",
  391. "er" => "Eritrea",
  392. "ee" => "Estonia",
  393. "et" => "Ethiopia",
  394. "fk" => "Falkland Islands (Malvinas)",
  395. "fo" => "Faroe Islands",
  396. "fj" => "Fiji",
  397. "fi" => "Finland",
  398. "fr" => "France",
  399. "gf" => "French Guiana",
  400. "pf" => "French Polynesia",
  401. "tf" => "French Southern Territories",
  402. "ga" => "Gabon",
  403. "gm" => "Gambia",
  404. "ge" => "Georgia",
  405. "de" => "Germany",
  406. "gh" => "Ghana",
  407. "gi" => "Gibraltar",
  408. "gr" => "Greece",
  409. "gl" => "Greenland",
  410. "gd" => "Grenada",
  411. "gp" => "Guadeloupe",
  412. "gu" => "Guam",
  413. "gt" => "Guatemala",
  414. "gn" => "Guinea",
  415. "gw" => "Guinea-Bissau",
  416. "gy" => "Guyana",
  417. "ht" => "Haiti",
  418. "hm" => "Heard Island and Mcdonald Islands",
  419. "va" => "Holy See (Vatican City State)",
  420. "hn" => "Honduras",
  421. "hk" => "Hong Kong",
  422. "hu" => "Hungary",
  423. "is" => "Iceland",
  424. "in" => "India",
  425. "id" => "Indonesia",
  426. "ir" => "Iran, Islamic Republic",
  427. "iq" => "Iraq",
  428. "ie" => "Ireland",
  429. "il" => "Israel",
  430. "it" => "Italy",
  431. "jm" => "Jamaica",
  432. "jp" => "Japan",
  433. "jo" => "Jordan",
  434. "kz" => "Kazakhstan",
  435. "ke" => "Kenya",
  436. "ki" => "Kiribati",
  437. "kp" => "Korea, Democratic People's Republic",
  438. "kr" => "Korea, Republic",
  439. "kw" => "Kuwait",
  440. "kg" => "Kyrgyzstan",
  441. "la" => "Lao People's Democratic Republic",
  442. "lv" => "Latvia",
  443. "lb" => "Lebanon",
  444. "ls" => "Lesotho",
  445. "lr" => "Liberia",
  446. "ly" => "Libyan Arab Jamahiriya",
  447. "li" => "Liechtenstein",
  448. "lt" => "Lithuania",
  449. "lu" => "Luxembourg",
  450. "mo" => "Macao",
  451. "mk" => "Macedonia, the Former Yugosalv Republic",
  452. "mg" => "Madagascar",
  453. "mw" => "Malawi",
  454. "my" => "Malaysia",
  455. "mv" => "Maldives",
  456. "ml" => "Mali",
  457. "mt" => "Malta",
  458. "mh" => "Marshall Islands",
  459. "mq" => "Martinique",
  460. "mr" => "Mauritania",
  461. "mu" => "Mauritius",
  462. "yt" => "Mayotte",
  463. "mx" => "Mexico",
  464. "fm" => "Micronesia, Federated States",
  465. "md" => "Moldova, Republic",
  466. "mc" => "Monaco",
  467. "mn" => "Mongolia",
  468. "ms" => "Montserrat",
  469. "ma" => "Morocco",
  470. "mz" => "Mozambique",
  471. "mm" => "Myanmar",
  472. "na" => "Namibia",
  473. "nr" => "Nauru",
  474. "np" => "Nepal",
  475. "nl" => "Netherlands",
  476. "an" => "Netherlands Antilles",
  477. "nc" => "New Caledonia",
  478. "nz" => "New Zealand",
  479. "ni" => "Nicaragua",
  480. "ne" => "Niger",
  481. "ng" => "Nigeria",
  482. "nu" => "Niue",
  483. "nf" => "Norfolk Island",
  484. "mp" => "Northern Mariana Islands",
  485. "no" => "Norway",
  486. "om" => "Oman",
  487. "pk" => "Pakistan",
  488. "pw" => "Palau",
  489. "ps" => "Palestinian Territory, Occupied",
  490. "pa" => "Panama",
  491. "pg" => "Papua New Guinea",
  492. "py" => "Paraguay",
  493. "pe" => "Peru",
  494. "ph" => "Philippines",
  495. "pn" => "Pitcairn",
  496. "pl" => "Poland",
  497. "pt" => "Portugal",
  498. "pr" => "Puerto Rico",
  499. "qa" => "Qatar",
  500. "re" => "Reunion",
  501. "ro" => "Romania",
  502. "ru" => "Russian Federation",
  503. "rw" => "Rwanda",
  504. "sh" => "Saint Helena",
  505. "kn" => "Saint Kitts and Nevis",
  506. "lc" => "Saint Lucia",
  507. "pm" => "Saint Pierre and Miquelon",
  508. "vc" => "Saint Vincent and the Grenadines",
  509. "ws" => "Samoa",
  510. "sm" => "San Marino",
  511. "st" => "Sao Tome and Principe",
  512. "sa" => "Saudi Arabia",
  513. "sn" => "Senegal",
  514. "cs" => "Serbia and Montenegro",
  515. "sc" => "Seychelles",
  516. "sl" => "Sierra Leone",
  517. "sg" => "Singapore",
  518. "sk" => "Slovakia",
  519. "si" => "Slovenia",
  520. "sb" => "Solomon Islands",
  521. "so" => "Somalia",
  522. "za" => "South Africa",
  523. "gs" => "South Georgia and the South Sandwich Islands",
  524. "es" => "Spain",
  525. "lk" => "Sri Lanka",
  526. "sd" => "Sudan",
  527. "sr" => "Suriname",
  528. "sj" => "Svalbard and Jan Mayen",
  529. "sz" => "Swaziland",
  530. "se" => "Sweden",
  531. "ch" => "Switzerland",
  532. "sy" => "Syrian Arab Republic",
  533. "tw" => "Taiwan, Province of China",
  534. "tj" => "Tajikistan",
  535. "tz" => "Tanzania, United Republic",
  536. "th" => "Thailand",
  537. "tl" => "Timor-Leste",
  538. "tg" => "Togo",
  539. "tk" => "Tokelau",
  540. "to" => "Tonga",
  541. "tt" => "Trinidad and Tobago",
  542. "tn" => "Tunisia",
  543. "tr" => "Turkey",
  544. "tm" => "Turkmenistan",
  545. "tc" => "Turks and Caicos Islands",
  546. "tv" => "Tuvalu",
  547. "ug" => "Uganda",
  548. "ua" => "Ukraine",
  549. "ae" => "United Arab Emirates",
  550. "uk" => "United Kingdom",
  551. "us" => "United States",
  552. "um" => "United States Minor Outlying Islands",
  553. "uy" => "Uruguay",
  554. "uz" => "Uzbekistan",
  555. "vu" => "Vanuatu",
  556. "ve" => "Venezuela",
  557. "vn" => "Viet Nam",
  558. "vg" => "Virgin Islands, British",
  559. "vi" => "Virgin Islands, U.S.",
  560. "wf" => "Wallis and Futuna",
  561. "eh" => "Western Sahara",
  562. "ye" => "Yemen",
  563. "zm" => "Zambia",
  564. "zw" => "Zimbabwe"
  565. ]
  566. ],
  567. "nsfw" => [
  568. "display" => "NSFW",
  569. "option" => [
  570. "yes" => "Yes", // safe=active
  571. "no" => "No" // safe=off
  572. ]
  573. ],
  574. "lang" => [ // lr=<lang> (prefix lang with "lang_")
  575. "display" => "Language",
  576. "option" => [
  577. "any" => "Any language",
  578. "ar" => "Arabic",
  579. "bg" => "Bulgarian",
  580. "ca" => "Catalan",
  581. "cs" => "Czech",
  582. "da" => "Danish",
  583. "de" => "German",
  584. "el" => "Greek",
  585. "en" => "English",
  586. "es" => "Spanish",
  587. "et" => "Estonian",
  588. "fi" => "Finnish",
  589. "fr" => "French",
  590. "hr" => "Croatian",
  591. "hu" => "Hungarian",
  592. "id" => "Indonesian",
  593. "is" => "Icelandic",
  594. "it" => "Italian",
  595. "iw" => "Hebrew",
  596. "ja" => "Japanese",
  597. "ko" => "Korean",
  598. "lt" => "Lithuanian",
  599. "lv" => "Latvian",
  600. "nl" => "Dutch",
  601. "no" => "Norwegian",
  602. "pl" => "Polish",
  603. "pt" => "Portuguese",
  604. "ro" => "Romanian",
  605. "ru" => "Russian",
  606. "sk" => "Slovak",
  607. "sl" => "Slovenian",
  608. "sr" => "Serbian",
  609. "sv" => "Swedish",
  610. "tr" => "Turkish",
  611. "zh-CN" => "Chinese (Simplified)",
  612. "zh-TW" => "Chinese (Traditional)"
  613. ]
  614. ],
  615. "time" => [ // tbs=qrd:<size>
  616. "display" => "Time posted",
  617. "option" => [
  618. "any" => "Any time",
  619. "d" => "Past 24 hours",
  620. "w" => "Past week",
  621. "m" => "Past month",
  622. "y" => "Past year"
  623. ]
  624. ],
  625. "size" => [
  626. "display" => "Size",
  627. "option" => [
  628. // tbs=isz:<size>
  629. "any" => "Any size",
  630. "l" => "Large",
  631. "m" => "Medium",
  632. "i" => "Icon",
  633. // from here
  634. // tbz:lt,islt:<size>
  635. "qsvga" => "Larger than 400x300",
  636. "vga" => "Larger than 640x480",
  637. "qsvga" => "Larger than 800x600",
  638. "xga" => "Larger than 1024x768",
  639. "2mp" => "Larger than 2MP",
  640. "4mp" => "Larger than 4MP",
  641. "6mp" => "Larger than 6MP",
  642. "8mp" => "Larger than 8MP",
  643. "10mp" => "Larger than 10MP",
  644. "12mp" => "Larger than 12MP",
  645. "15mp" => "Larger than 15MP",
  646. "20mp" => "Larger than 20MP",
  647. "40mp" => "Larger than 40MP",
  648. "70mp" => "Larger than 70MP"
  649. ]
  650. ],
  651. "ratio" => [ // tbs=iar:<size>
  652. "display" => "Aspect ratio",
  653. "option" => [
  654. "any" => "Any ratio",
  655. "t" => "Tall",
  656. "s" => "Square",
  657. "w" => "Wide",
  658. "xw" => "Panoramic"
  659. ]
  660. ],
  661. "color" => [ // tbs=ic:<color>
  662. "display" => "Color",
  663. "option" => [
  664. "any" => "Any color",
  665. "color" => "Full color",
  666. "gray" => "Black & white",
  667. "trans" => "Transparent",
  668. // from there, its ic:specific,isc:<color>
  669. "red" => "Red",
  670. "orange" => "Orange",
  671. "yellow" => "Yellow",
  672. "green" => "Green",
  673. "teal" => "Teal",
  674. "blue" => "Blue",
  675. "purple" => "Purple",
  676. "pink" => "Pink",
  677. "white" => "White",
  678. "gray" => "Gray",
  679. "black" => "Black",
  680. "brown" => "Brown"
  681. ]
  682. ],
  683. "type" => [ // tbs=itp:<type>
  684. "display" => "Type",
  685. "option" => [
  686. "any" => "Any type",
  687. "face" => "Faces",
  688. "clipart" => "Clip Art",
  689. "lineart" => "Line Drawing",
  690. "stock" => "Stock",
  691. "animated" => "Animated"
  692. ]
  693. ],
  694. "format" => [ // tbs=ift:<format>
  695. "display" => "Format",
  696. "option" => [
  697. "any" => "Any format",
  698. "jpg" => "JPG",
  699. "gif" => "GIF",
  700. "png" => "PNG",
  701. "bmp" => "BMP",
  702. "svg" => "SVG",
  703. "webp" => "WEBP",
  704. "ico" => "ICO",
  705. "craw" => "RAW"
  706. ]
  707. ],
  708. "rights" => [ // tbs=il:<rights>
  709. "display" => "Usage rights",
  710. "option" => [
  711. "any" => "Any license",
  712. "cl" => "Creative Commons licenses",
  713. "ol" => "Commercial & other licenses"
  714. ]
  715. ]
  716. ];
  717. break;
  718. }
  719. }
  720. private function get($url, $get = []){
  721. $headers = [
  722. "User-Agent: Mozilla/5.0 (Linux; U; Android 2.3.3; pt-pt; LG-P500h-parrot Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MMS/LG-Android-MMS-V1.0/1.2",
  723. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
  724. "Accept-Language: en-US,en;q=0.5",
  725. "Accept-Encoding: gzip",
  726. "DNT: 1",
  727. "Connection: keep-alive",
  728. "Upgrade-Insecure-Requests: 1",
  729. "Sec-Fetch-Dest: document",
  730. "Sec-Fetch-Mode: navigate",
  731. "Sec-Fetch-Site: none",
  732. "Sec-Fetch-User: ?1"
  733. ];
  734. $curlproc = curl_init();
  735. if($get !== []){
  736. $get = http_build_query($get);
  737. $url .= "?" . $get;
  738. }
  739. curl_setopt($curlproc, CURLOPT_URL, $url);
  740. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  741. curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
  742. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  743. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  744. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  745. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  746. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  747. $data = curl_exec($curlproc);
  748. if(curl_errno($curlproc)){
  749. throw new Exception(curl_error($curlproc));
  750. }
  751. curl_close($curlproc);
  752. return $data;
  753. }
  754. public function web($get){
  755. $search = $get["s"];
  756. $country = $get["country"];
  757. $nsfw = $get["nsfw"];
  758. $lang = $get["lang"];
  759. $older = $get["older"];
  760. $newer = $get["newer"];
  761. $params = [
  762. "num" => 20 // get 20 results
  763. ];
  764. // country
  765. if($country != "any"){
  766. $params["gl"] = $country;
  767. }
  768. // nsfw
  769. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  770. // language
  771. if($lang != "any"){
  772. $params["lr"] = "lang_" . $lang;
  773. }
  774. // &sort=review-date:r:20090301:20090430
  775. $older = $older === false ? false : date("Ymd", $older);
  776. $newer = $newer === false ? false : date("Ymd", $newer);
  777. if(
  778. $older !== false &&
  779. $newer === false
  780. ){
  781. $newer = date("Ymd", time());
  782. }
  783. if(
  784. $older !== false ||
  785. $newer !== false
  786. ){
  787. $params["sort"] = "review-date:r:" . $older . ":" . $newer;
  788. }
  789. $handle = fopen("scraper/google.html", "r");
  790. $html = fread($handle, filesize("scraper/google.html"));
  791. fclose($handle);
  792. $out = [
  793. "status" => "ok",
  794. "spelling" => [
  795. "type" => "no_correction",
  796. "using" => null,
  797. "correction" => null
  798. ],
  799. "npt" => null,
  800. "answer" => [],
  801. "web" => [],
  802. "image" => [],
  803. "video" => [],
  804. "news" => [],
  805. "related" => []
  806. ];
  807. $this->parsejavascript($html);
  808. $containers =
  809. $this->fuckhtml
  810. ->getElementsByClassName(
  811. $this->findstyles(
  812. [
  813. "background-color" => "#fff",
  814. "margin-bottom" => "10px",
  815. "-webkit-box-shadow" => "0 1px 6px rgba(32,33,36,0.28)",
  816. "border-radius" => "8px"
  817. ],
  818. self::is_class
  819. ),
  820. "div"
  821. );
  822. foreach($containers as $container){
  823. $this->fuckhtml->load($container);
  824. $title =
  825. $this->fuckhtml
  826. ->getElementsByClassName(
  827. $this->findstyles(
  828. [
  829. "color" => "#1967d2",
  830. "font-size" => "20px",
  831. "line-height" => "26px"
  832. ],
  833. self::is_class
  834. ),
  835. "div"
  836. );
  837. if(count($title) !== 0){
  838. /*
  839. Container is a web link
  840. */
  841. $web = [
  842. "title" =>
  843. $this->titledots(
  844. $this->fuckhtml
  845. ->getTextContent(
  846. $title[0]
  847. )
  848. ),
  849. "description" => null,
  850. "url" =>
  851. $this->decodeurl(
  852. $this->fuckhtml
  853. ->getElementsByTagName("a")
  854. [0]
  855. ["attributes"]
  856. ["href"]
  857. ),
  858. "date" => null,
  859. "type" => "web",
  860. "thumb" => [
  861. "url" => null,
  862. "ratio" => null
  863. ],
  864. "sublink" => [],
  865. "table" => []
  866. ];
  867. $container = $container["innerHTML"];
  868. $description_container =
  869. $this->fuckhtml
  870. ->getElementsByClassName(
  871. $this->findstyles(
  872. [
  873. "padding" => "12px 16px 12px"
  874. ],
  875. self::is_class
  876. ),
  877. "div"
  878. )[1];
  879. $description =
  880. $description_container["innerHTML"];
  881. // get sublinks
  882. $this->fuckhtml->load($description);
  883. $links =
  884. $this->fuckhtml
  885. ->getElementsByTagName("a");
  886. $skip = true;
  887. foreach($links as $link){
  888. $description =
  889. str_replace(
  890. $link["outerHTML"],
  891. "",
  892. $description
  893. );
  894. if($skip){
  895. $skip = false;
  896. continue;
  897. }
  898. $sublink = [
  899. "title" => null,
  900. "description" => null,
  901. "url" => null,
  902. "date" => null
  903. ];
  904. $sublink["title"] =
  905. $this->fuckhtml
  906. ->getTextContent(
  907. $link
  908. );
  909. $sublink["url"] =
  910. $this->decodeurl(
  911. $link
  912. ["attributes"]
  913. ["href"]
  914. );
  915. $web["sublink"][] = $sublink;
  916. }
  917. // get thumbnail before we call loadhtml again
  918. $img =
  919. $this->fuckhtml
  920. ->getElementsByTagName("img");
  921. if(count($img) !== 0){
  922. if(
  923. isset($img[0]["attributes"]["alt"]) &&
  924. stripos($img[0]["attributes"]["alt"], "Video for") !== false
  925. ){
  926. // is a video thumbnail
  927. $web["thumb"]["ratio"] = "16:9";
  928. }else{
  929. // is a google thumbnail
  930. $web["thumb"]["ratio"] = "1:1";
  931. }
  932. $web["thumb"]["url"] =
  933. $this->getimage(
  934. $img[0]["attributes"]["id"]
  935. );
  936. }
  937. // get table elements
  938. $this->fuckhtml->load($description);
  939. $levels =
  940. $this->fuckhtml
  941. ->getElementsByClassName(
  942. $this->findstyles(
  943. [
  944. "padding-bottom" => "8px"
  945. ],
  946. self::is_class
  947. ),
  948. "div"
  949. );
  950. $additional_info = [];
  951. foreach($levels as $level){
  952. $this->fuckhtml->load($level);
  953. $spans =
  954. $this->fuckhtml
  955. ->getElementsByTagName(
  956. "span"
  957. );
  958. $is_rating = -2;
  959. foreach($spans as $span){
  960. // clean up description
  961. $description =
  962. str_replace(
  963. $span["outerHTML"],
  964. "",
  965. $description
  966. );
  967. $innertext =
  968. $this->fuckhtml
  969. ->getTextContent(
  970. $span
  971. );
  972. if($innertext == ""){ continue; }
  973. if(
  974. strtolower($innertext)
  975. == "rating"
  976. ){
  977. $is_rating = -1;
  978. continue;
  979. }
  980. /*
  981. Parse rating object
  982. */
  983. if($is_rating >= -1){
  984. if($span["level"] !== 1){ continue; }
  985. $is_rating++;
  986. // 10/10 (123)
  987. if($is_rating === 0){
  988. $innertext = explode(" ", $innertext, 2);
  989. $web["table"]["Rating"] = $innertext[0];
  990. $web["table"]["Hits"] =
  991. trim(
  992. str_replace(
  993. [
  994. "(",
  995. ")"
  996. ],
  997. "",
  998. $innertext[1]
  999. )
  1000. );
  1001. continue;
  1002. }
  1003. // US$4.99
  1004. // MYR 50.00
  1005. // $38.34
  1006. // JP¥6,480
  1007. if($is_rating === 2){
  1008. $web["table"]["Price"] = $innertext;
  1009. continue;
  1010. }
  1011. // Android / In stock
  1012. if($is_rating === 4){
  1013. $web["table"]["Support"] = $innertext;
  1014. continue;
  1015. }
  1016. // ignore the rest
  1017. continue;
  1018. }
  1019. /*
  1020. Parse standalone text
  1021. */
  1022. $additional_info[] = $innertext;
  1023. }
  1024. }
  1025. for($i=0; $i<count($additional_info); $i++){
  1026. // @TODO
  1027. // generate better node names
  1028. $web["table"]["Info node #$i"] = $additional_info[$i];
  1029. }
  1030. $this->fuckhtml->load($description);
  1031. // get date node
  1032. $span =
  1033. $this->fuckhtml
  1034. ->getElementsByTagName(
  1035. "span"
  1036. );
  1037. if(count($span) !== 0){
  1038. $description =
  1039. str_replace(
  1040. $span[0]["outerHTML"],
  1041. "",
  1042. $description
  1043. );
  1044. $span =
  1045. strtotime(
  1046. $this->fuckhtml
  1047. ->getTextContent(
  1048. $span[0]
  1049. )
  1050. );
  1051. if($span){
  1052. $web["date"] = $span;
  1053. }
  1054. }
  1055. $web["description"] =
  1056. trim(
  1057. $this->fuckhtml
  1058. ->getTextContent(
  1059. $description
  1060. ),
  1061. " ·."
  1062. );
  1063. $out["web"][] = $web;
  1064. continue;
  1065. }
  1066. // check for container title header
  1067. $container_title =
  1068. $this->fuckhtml
  1069. ->getElementsByClassName(
  1070. $this->findstyles(
  1071. [
  1072. "font-weight" => "bold",
  1073. "font-size" => "16px",
  1074. "color" => "#000",
  1075. "margin" => "0",
  1076. "padding" => "12px 16px 0 16px"
  1077. ],
  1078. self::is_class
  1079. ),
  1080. "div"
  1081. );
  1082. if(count($container_title) !== 0){
  1083. $container_title =
  1084. strtolower(
  1085. $this->fuckhtml
  1086. ->getTextContent(
  1087. $container_title[0]
  1088. )
  1089. );
  1090. if(
  1091. $container_title == "related searches" ||
  1092. $container_title == "people also search for"
  1093. ){
  1094. /*
  1095. Parse related searches
  1096. */
  1097. $as =
  1098. $this->fuckhtml
  1099. ->getElementsByTagName("a");
  1100. foreach($as as $a){
  1101. $out["related"][] =
  1102. $this->fuckhtml
  1103. ->getTextContent($a);
  1104. }
  1105. }
  1106. continue;
  1107. }
  1108. /*
  1109. Parse image carousel
  1110. */
  1111. $title_container =
  1112. $this->fuckhtml
  1113. ->getElementsByClassName(
  1114. $this->findstyles(
  1115. [
  1116. "padding" => "12px 16px 12px"
  1117. ],
  1118. self::is_class
  1119. ),
  1120. "div"
  1121. );
  1122. if(count($title_container) !== 0){
  1123. $title_container =
  1124. strtolower(
  1125. $this->fuckhtml
  1126. ->getTextContent(
  1127. $title_container[0]
  1128. )
  1129. );
  1130. if($title_container == "imagesview all"){
  1131. /*
  1132. Image carousel
  1133. */
  1134. $pcitem =
  1135. $this->fuckhtml
  1136. ->getElementsByClassName(
  1137. "pcitem",
  1138. "div"
  1139. );
  1140. foreach($pcitem as $item){
  1141. $this->fuckhtml->load($item);
  1142. $link =
  1143. $this->fuckhtml
  1144. ->getElementsByTagName(
  1145. "a"
  1146. )[0];
  1147. parse_str(
  1148. parse_url(
  1149. $this->fuckhtml
  1150. ->getTextContent(
  1151. $link
  1152. ["attributes"]
  1153. ["href"]
  1154. ),
  1155. PHP_URL_QUERY
  1156. ),
  1157. $link
  1158. );
  1159. if(isset($link["tbm"])){
  1160. continue;
  1161. }
  1162. $image =
  1163. $this->fuckhtml
  1164. ->getElementsByTagName("img")[0];
  1165. $title =
  1166. $this->fuckhtml
  1167. ->getTextContent(
  1168. $image
  1169. ["attributes"]
  1170. ["alt"]
  1171. );
  1172. $image =
  1173. $this->getimage(
  1174. $image
  1175. ["attributes"]
  1176. ["id"]
  1177. );
  1178. $out["image"][] = [
  1179. "title" => $title,
  1180. "source" => [
  1181. [
  1182. "url" => $link["imgurl"],
  1183. "width" => (int)$link["w"],
  1184. "height" => (int)$link["h"]
  1185. ],
  1186. [
  1187. "url" => $image,
  1188. "width" => (int)$link["tbnw"],
  1189. "height" => (int)$link["tbnh"]
  1190. ]
  1191. ],
  1192. "url" => $link["imgrefurl"]
  1193. ];
  1194. }
  1195. }
  1196. }
  1197. /*
  1198. Get next page
  1199. */
  1200. $as =
  1201. $this->fuckhtml
  1202. ->getElementsByTagName("a");
  1203. foreach($as as $a){
  1204. if(
  1205. isset($a["attributes"]["aria-label"]) &&
  1206. strtolower($a["attributes"]["aria-label"]) == "next page"
  1207. ){
  1208. $out["npt"] =
  1209. $this->fuckhtml
  1210. ->getTextContent(
  1211. $a["attributes"]["href"]
  1212. );
  1213. }
  1214. }
  1215. }
  1216. return $out;
  1217. }
  1218. public function image($get){
  1219. // generate parameters
  1220. if($get["npt"]){
  1221. $params =
  1222. json_decode(
  1223. $this->nextpage->get(
  1224. $get["npt"],
  1225. "images"
  1226. ),
  1227. true
  1228. );
  1229. }else{
  1230. $search = $get["s"];
  1231. $country = $get["country"];
  1232. $nsfw = $get["nsfw"];
  1233. $lang = $get["lang"];
  1234. $time = $get["time"];
  1235. $size = $get["size"];
  1236. $ratio = $get["ratio"];
  1237. $color = $get["color"];
  1238. $type = $get["type"];
  1239. $format = $get["format"];
  1240. $rights = $get["rights"];
  1241. $params = [
  1242. "q" => $search,
  1243. "tbm" => "isch"
  1244. ];
  1245. // country
  1246. if($country != "any"){
  1247. $params["gl"] = $country;
  1248. }
  1249. // nsfw
  1250. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  1251. // language
  1252. if($lang != "any"){
  1253. $params["lr"] = "lang_" . $lang;
  1254. }
  1255. $tbs = [];
  1256. // time
  1257. if($time != "any"){
  1258. $tbs[] = "qrd:" . $time;
  1259. }
  1260. // size
  1261. if($size != "any"){
  1262. if(
  1263. in_array(
  1264. $size,
  1265. ["l", "s", "i"]
  1266. )
  1267. ){
  1268. $tbs[] = "isz:" . $size;
  1269. }else{
  1270. $tbs[] = "tbz:lt";
  1271. $tbs[] = "islt:" . $size;
  1272. }
  1273. }
  1274. // ratio
  1275. if($ratio != "any"){
  1276. $tbs[] = "iar:" . $ratio;
  1277. }
  1278. // color
  1279. if($color != "any"){
  1280. if(
  1281. in_array(
  1282. $color,
  1283. ["color", "gray", "trans"]
  1284. )
  1285. ){
  1286. $tbs[] = "ic:" . $color;
  1287. }else{
  1288. $tbs[] = "ic:specific";
  1289. $tbs[] = "isc:" . $color;
  1290. }
  1291. }
  1292. // type
  1293. if($type != "any"){
  1294. $tbs[] = "itp:" . $type;
  1295. }
  1296. // format
  1297. if($format != "any"){
  1298. $tbs[] = "ift:" . $format;
  1299. }
  1300. // rights
  1301. if($rights != "any"){
  1302. $tbs[] = "il:" . $rights;
  1303. }
  1304. // append tbs
  1305. if(count($tbs) !== 0){
  1306. $params["tbs"] =
  1307. implode(",", $tbs);
  1308. }
  1309. }
  1310. /*
  1311. $handle = fopen("scraper/google-img.html", "r");
  1312. $html = fread($handle, filesize("scraper/google-img.html"));
  1313. fclose($handle);*/
  1314. // scrape images
  1315. try{
  1316. $html =
  1317. $this->get(
  1318. "https://www.google.com/search",
  1319. $params
  1320. );
  1321. }catch(Exception $error){
  1322. throw new Exception("Failed to get search page");
  1323. }
  1324. $this->fuckhtml->load($html);
  1325. $out = [
  1326. "status" => "ok",
  1327. "npt" => null,
  1328. "image" => []
  1329. ];
  1330. $images =
  1331. $this->fuckhtml
  1332. ->getElementsByClassName(
  1333. "islrtb isv-r",
  1334. "div"
  1335. );
  1336. foreach($images as $image){
  1337. $this->fuckhtml->load($image);
  1338. $img =
  1339. $this->fuckhtml
  1340. ->getElementsByTagName("img")[0];
  1341. $og_width = (int)$image["attributes"]["data-ow"];
  1342. $og_height = (int)$image["attributes"]["data-oh"];
  1343. $thumb_width = (int)$image["attributes"]["data-tw"];
  1344. $ratio = $og_width / $og_height;
  1345. if(isset($img["attributes"]["data-src"])){
  1346. $src = &$img["attributes"]["data-src"];
  1347. }else{
  1348. $src = &$img["attributes"]["src"];
  1349. }
  1350. $thumb_height = floor($thumb_width / $ratio);
  1351. $out["image"][] = [
  1352. "title" =>
  1353. $this->titledots(
  1354. $this->fuckhtml
  1355. ->getTextContent(
  1356. $image["attributes"]["data-pt"]
  1357. )
  1358. ),
  1359. "source" => [
  1360. [
  1361. "url" =>
  1362. $this->fuckhtml
  1363. ->getTextContent(
  1364. $image["attributes"]["data-ou"]
  1365. ),
  1366. "width" => $og_width,
  1367. "height" => $og_height
  1368. ],
  1369. [
  1370. "url" =>
  1371. $this->fuckhtml
  1372. ->getTextContent(
  1373. $src
  1374. ),
  1375. "width" => $thumb_width,
  1376. "height" => $thumb_height
  1377. ]
  1378. ],
  1379. "url" =>
  1380. $this->fuckhtml
  1381. ->getTextContent(
  1382. $image["attributes"]["data-ru"]
  1383. )
  1384. ];
  1385. }
  1386. // get next page
  1387. // https://www.google.com/search
  1388. // ?q=higurashi
  1389. // &tbm=isch
  1390. // &async=_id%3Aislrg_c%2C_fmt%3Ahtml
  1391. // &asearch=ichunklite
  1392. // &ved=0ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA
  1393. if(count($out["image"]) !== 100){
  1394. // no more results
  1395. return $out;
  1396. }
  1397. if($get["npt"]){
  1398. // update nextpage information
  1399. $params["start"] = (int)$params["start"] + count($out["image"]);
  1400. $params["ijn"] = (int)$params["ijn"] + 1;
  1401. $out["npt"] =
  1402. $this->nextpage->store(
  1403. json_encode($params),
  1404. "images"
  1405. );
  1406. }else{
  1407. // scrape nextpage information
  1408. $this->fuckhtml->load($html);
  1409. $ved =
  1410. $this->fuckhtml
  1411. ->getElementById("islrg", "div");
  1412. if($ved){
  1413. $ved =
  1414. $this->fuckhtml
  1415. ->getTextContent(
  1416. $ved["attributes"]["data-ved"]
  1417. );
  1418. // &vet=1{$ved}..i (10ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA..i)
  1419. /*
  1420. These 2 are handled by us
  1421. start = start + number of results
  1422. ijn = current page number
  1423. */
  1424. // &start=100
  1425. // &ijn=1
  1426. // &imgvl=CAEY7gQgBSj3Aji8VTjXVUC4AUC3AUgAYNdV
  1427. preg_match(
  1428. '/var e=\'([A-z0-9]+)\';/',
  1429. $html,
  1430. $imgvl
  1431. );
  1432. if(isset($imgvl[1])){
  1433. $imgvl = $imgvl[1];
  1434. $params["async"] = "_id:islrg_c,_fmt:html";
  1435. $params["asearch"] = "ichunklite";
  1436. $params["ved"] = $ved;
  1437. $params["vet"] = "1" . $ved . "..i";
  1438. $params["start"] = 100;
  1439. $params["ijn"] = 1;
  1440. $params["imgvl"] = $imgvl;
  1441. $out["npt"] =
  1442. $this->nextpage->store(
  1443. json_encode($params),
  1444. "images"
  1445. );
  1446. }
  1447. }
  1448. }
  1449. return $out;
  1450. }
  1451. private function hms2int($time){
  1452. $parts = explode(":", $time, 3);
  1453. $time = 0;
  1454. if(count($parts) === 3){
  1455. // hours
  1456. $time = $time + ((int)$parts[0] * 3600);
  1457. array_shift($parts);
  1458. }
  1459. if(count($parts) === 2){
  1460. // minutes
  1461. $time = $time + ((int)$parts[0] * 60);
  1462. array_shift($parts);
  1463. }
  1464. // seconds
  1465. $time = $time + (int)$parts[0];
  1466. return $time;
  1467. }
  1468. private function parsejavascript($html){
  1469. $this->fuckhtml->load($html);
  1470. $styles =
  1471. $this->fuckhtml
  1472. ->getElementsByTagName("style");
  1473. $this->computedstyle = [];
  1474. $this->ask = [];
  1475. foreach($styles as $style){
  1476. $this->computedstyle =
  1477. array_merge(
  1478. $this->computedstyle,
  1479. $this->parsestyles($style["innerHTML"])
  1480. );
  1481. }
  1482. // get images in javascript var
  1483. preg_match(
  1484. '/google\.ldi=({[^}]+})/',
  1485. $html,
  1486. $this->js_image
  1487. );
  1488. if(count($this->js_image) !== 0){
  1489. $this->js_image = json_decode($this->js_image[1], true);
  1490. }else{
  1491. $this->js_image = [];
  1492. }
  1493. // additional js_images present in <script> tags
  1494. // ugh i fucking hate you
  1495. $scripts =
  1496. $this->fuckhtml
  1497. ->getElementsByTagName("script");
  1498. foreach($scripts as $script){
  1499. if(!isset($script["innerHTML"])){
  1500. continue;
  1501. }
  1502. preg_match_all(
  1503. '/var s=\'(data:image[^\']+)\';var i=\[\'([^\']+)\'];/',
  1504. $script["innerHTML"],
  1505. $image_grep
  1506. );
  1507. if(count($image_grep[0]) !== 0){
  1508. $this->js_image[trim($image_grep[2][0])] =
  1509. $this->fuckhtml
  1510. ->getTextContent(
  1511. $image_grep[1][0]
  1512. );
  1513. }
  1514. // even more javascript crap
  1515. // "People also ask" node is loaded trough javascript
  1516. preg_match_all(
  1517. '/window\.jsl\.dh\(\'([^\']+)\',\'(.+)\'\);/',
  1518. $script["innerHTML"],
  1519. $ask_grep
  1520. );
  1521. for($i=0; $i<count($ask_grep[0]); $i++){
  1522. $this->ask[trim($ask_grep[1][$i])] =
  1523. stripcslashes(
  1524. $ask_grep[2][$i]
  1525. );
  1526. }
  1527. }
  1528. }
  1529. private function findstyles($rules, $is){
  1530. ksort($rules);
  1531. foreach($this->computedstyle as $stylename => $styles){
  1532. if($styles == $rules){
  1533. preg_match(
  1534. '/\\' . $is . '([^ .]+)/',
  1535. $stylename,
  1536. $out
  1537. );
  1538. if(count($out) === 2){
  1539. return $out[1];
  1540. }
  1541. return false;
  1542. }
  1543. }
  1544. return false;
  1545. }
  1546. private function parsestyles($style){
  1547. // get style tags
  1548. preg_match_all(
  1549. '/([^{]+){([^}]+)}/',
  1550. $style,
  1551. $tags_regex
  1552. );
  1553. $tags = [];
  1554. for($i=0; $i<count($tags_regex[0]); $i++){
  1555. $tagnames = explode(",", trim($tags_regex[1][$i]));
  1556. foreach($tagnames as $tagname){
  1557. $tagname = trim($tagname);
  1558. if(!isset($tags[$tagname])){
  1559. $tags[$tagname] = [];
  1560. }
  1561. $values = explode(";", $tags_regex[2][$i]);
  1562. foreach($values as $value){
  1563. $value = explode(":", $value, 2);
  1564. if(count($value) !== 2){
  1565. continue;
  1566. }
  1567. $tags[$tagname][trim($value[0])] =
  1568. trim($value[1]);
  1569. }
  1570. }
  1571. }
  1572. foreach($tags as &$value){
  1573. ksort($value);
  1574. }
  1575. return $tags;
  1576. }
  1577. private function getimage($id){
  1578. if(
  1579. isset($this->js_image[$id]) &&
  1580. $this->js_image[$id] != "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABAUlEQVR4AWMYesChoYElLjkzPj4lY3d8csZjIL4MxPNjUzPcSTYsISFLAqj5NBD/h+LPQPwbiT87NCuLh2gDgRr2QzXuT0jNMoBYksARn5zuHJ+UcR0kB6RXE2VYXHJGOlTDZmzyIJcB5e+D1CSkZDgQNBAaZv+jU1JkcKpJygiGeZ0I76a/Byq8jU9NZFqaCNTA48SE33/iDcw8TIyBt0GKQTFN0Msp6f2EIyUpo57YSIlLSrMhIg0WCIBcCfXSdlzJBsheTHQ6jEnOUgEFOLaEDbMIlhZBOYrorAdJk+nroVnvPsSgdGdoOF7HZyhZ2XPoGQoqjbCpIbt0AiejIQMArVLI7k/DXFkAAAAASUVORK5CYII="
  1581. ){
  1582. if(stripos($this->js_image[$id], "data:image") !== false){
  1583. return
  1584. explode(
  1585. "\\x3d",
  1586. $this->js_image[$id],
  1587. 2
  1588. )[0];
  1589. }
  1590. return $this->js_image[$id];
  1591. }
  1592. return null;
  1593. }
  1594. private function decodeurl($url){
  1595. preg_match(
  1596. '/^\/url\?q=([^&]+)|^\/interstitial\?url=([^&]+)/',
  1597. $this->fuckhtml
  1598. ->getTextContent($url),
  1599. $match
  1600. );
  1601. if(count($match) === 0){
  1602. return null;
  1603. }
  1604. $url = empty($match[1]) ? urldecode($match[2]) : urldecode($match[1]);
  1605. $domain = parse_url($url, PHP_URL_HOST);
  1606. if(
  1607. preg_match(
  1608. '/wikipedia.org$/',
  1609. $domain
  1610. )
  1611. ){
  1612. // rewrite wikipedia mobile URLs to desktop
  1613. $url =
  1614. $this->replacedomain(
  1615. $url,
  1616. preg_replace(
  1617. '/([a-z0-9]+)(\.m\.)/',
  1618. '$1.',
  1619. $domain
  1620. )
  1621. );
  1622. }
  1623. if(
  1624. preg_match(
  1625. '/imdb\.com$|youtube\.[^.]+$/',
  1626. $domain
  1627. )
  1628. ){
  1629. // rewrite imdb and youtube mobile URLs too
  1630. $url =
  1631. $this->replacedomain(
  1632. $url,
  1633. preg_replace(
  1634. '/^m\./',
  1635. "",
  1636. $domain
  1637. )
  1638. );
  1639. }
  1640. return $url;
  1641. }
  1642. private function replacedomain($url, $domain){
  1643. return
  1644. preg_replace(
  1645. '/(https?:\/\/)([^\/]+)/',
  1646. '$1' . $domain,
  1647. $url
  1648. );
  1649. }
  1650. private function titledots($title){
  1651. return rtrim($title, ".… \t\n\r\0\x0B");
  1652. }
  1653. }