google.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  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. $imgvl = $imgvl[1];
  1433. $params["async"] = "_id:islrg_c,_fmt:html";
  1434. $params["asearch"] = "ichunklite";
  1435. $params["ved"] = $ved;
  1436. $params["vet"] = "1" . $ved . "..i";
  1437. $params["start"] = 100;
  1438. $params["ijn"] = 1;
  1439. $params["imgvl"] = $imgvl;
  1440. $out["npt"] =
  1441. $this->nextpage->store(
  1442. json_encode($params),
  1443. "images"
  1444. );
  1445. }
  1446. }
  1447. return $out;
  1448. }
  1449. private function hms2int($time){
  1450. $parts = explode(":", $time, 3);
  1451. $time = 0;
  1452. if(count($parts) === 3){
  1453. // hours
  1454. $time = $time + ((int)$parts[0] * 3600);
  1455. array_shift($parts);
  1456. }
  1457. if(count($parts) === 2){
  1458. // minutes
  1459. $time = $time + ((int)$parts[0] * 60);
  1460. array_shift($parts);
  1461. }
  1462. // seconds
  1463. $time = $time + (int)$parts[0];
  1464. return $time;
  1465. }
  1466. private function parsejavascript($html){
  1467. $this->fuckhtml->load($html);
  1468. $styles =
  1469. $this->fuckhtml
  1470. ->getElementsByTagName("style");
  1471. $this->computedstyle = [];
  1472. $this->ask = [];
  1473. foreach($styles as $style){
  1474. $this->computedstyle =
  1475. array_merge(
  1476. $this->computedstyle,
  1477. $this->parsestyles($style["innerHTML"])
  1478. );
  1479. }
  1480. // get images in javascript var
  1481. preg_match(
  1482. '/google\.ldi=({[^}]+})/',
  1483. $html,
  1484. $this->js_image
  1485. );
  1486. if(count($this->js_image) !== 0){
  1487. $this->js_image = json_decode($this->js_image[1], true);
  1488. }else{
  1489. $this->js_image = [];
  1490. }
  1491. // additional js_images present in <script> tags
  1492. // ugh i fucking hate you
  1493. $scripts =
  1494. $this->fuckhtml
  1495. ->getElementsByTagName("script");
  1496. foreach($scripts as $script){
  1497. if(!isset($script["innerHTML"])){
  1498. continue;
  1499. }
  1500. preg_match_all(
  1501. '/var s=\'(data:image[^\']+)\';var i=\[\'([^\']+)\'];/',
  1502. $script["innerHTML"],
  1503. $image_grep
  1504. );
  1505. if(count($image_grep[0]) !== 0){
  1506. $this->js_image[trim($image_grep[2][0])] =
  1507. $this->fuckhtml
  1508. ->getTextContent(
  1509. $image_grep[1][0]
  1510. );
  1511. }
  1512. // even more javascript crap
  1513. // "People also ask" node is loaded trough javascript
  1514. preg_match_all(
  1515. '/window\.jsl\.dh\(\'([^\']+)\',\'(.+)\'\);/',
  1516. $script["innerHTML"],
  1517. $ask_grep
  1518. );
  1519. for($i=0; $i<count($ask_grep[0]); $i++){
  1520. $this->ask[trim($ask_grep[1][$i])] =
  1521. stripcslashes(
  1522. $ask_grep[2][$i]
  1523. );
  1524. }
  1525. }
  1526. }
  1527. private function findstyles($rules, $is){
  1528. ksort($rules);
  1529. foreach($this->computedstyle as $stylename => $styles){
  1530. if($styles == $rules){
  1531. preg_match(
  1532. '/\\' . $is . '([^ .]+)/',
  1533. $stylename,
  1534. $out
  1535. );
  1536. if(count($out) === 2){
  1537. return $out[1];
  1538. }
  1539. return false;
  1540. }
  1541. }
  1542. return false;
  1543. }
  1544. private function parsestyles($style){
  1545. // get style tags
  1546. preg_match_all(
  1547. '/([^{]+){([^}]+)}/',
  1548. $style,
  1549. $tags_regex
  1550. );
  1551. $tags = [];
  1552. for($i=0; $i<count($tags_regex[0]); $i++){
  1553. $tagnames = explode(",", trim($tags_regex[1][$i]));
  1554. foreach($tagnames as $tagname){
  1555. $tagname = trim($tagname);
  1556. if(!isset($tags[$tagname])){
  1557. $tags[$tagname] = [];
  1558. }
  1559. $values = explode(";", $tags_regex[2][$i]);
  1560. foreach($values as $value){
  1561. $value = explode(":", $value, 2);
  1562. if(count($value) !== 2){
  1563. continue;
  1564. }
  1565. $tags[$tagname][trim($value[0])] =
  1566. trim($value[1]);
  1567. }
  1568. }
  1569. }
  1570. foreach($tags as &$value){
  1571. ksort($value);
  1572. }
  1573. return $tags;
  1574. }
  1575. private function getimage($id){
  1576. if(
  1577. isset($this->js_image[$id]) &&
  1578. $this->js_image[$id] != "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABAUlEQVR4AWMYesChoYElLjkzPj4lY3d8csZjIL4MxPNjUzPcSTYsISFLAqj5NBD/h+LPQPwbiT87NCuLh2gDgRr2QzXuT0jNMoBYksARn5zuHJ+UcR0kB6RXE2VYXHJGOlTDZmzyIJcB5e+D1CSkZDgQNBAaZv+jU1JkcKpJygiGeZ0I76a/Byq8jU9NZFqaCNTA48SE33/iDcw8TIyBt0GKQTFN0Msp6f2EIyUpo57YSIlLSrMhIg0WCIBcCfXSdlzJBsheTHQ6jEnOUgEFOLaEDbMIlhZBOYrorAdJk+nroVnvPsSgdGdoOF7HZyhZ2XPoGQoqjbCpIbt0AiejIQMArVLI7k/DXFkAAAAASUVORK5CYII="
  1579. ){
  1580. if(stripos($this->js_image[$id], "data:image") !== false){
  1581. return
  1582. explode(
  1583. "\\x3d",
  1584. $this->js_image[$id],
  1585. 2
  1586. )[0];
  1587. }
  1588. return $this->js_image[$id];
  1589. }
  1590. return null;
  1591. }
  1592. private function decodeurl($url){
  1593. preg_match(
  1594. '/^\/url\?q=([^&]+)|^\/interstitial\?url=([^&]+)/',
  1595. $this->fuckhtml
  1596. ->getTextContent($url),
  1597. $match
  1598. );
  1599. if(count($match) === 0){
  1600. return null;
  1601. }
  1602. $url = empty($match[1]) ? urldecode($match[2]) : urldecode($match[1]);
  1603. $domain = parse_url($url, PHP_URL_HOST);
  1604. if(
  1605. preg_match(
  1606. '/wikipedia.org$/',
  1607. $domain
  1608. )
  1609. ){
  1610. // rewrite wikipedia mobile URLs to desktop
  1611. $url =
  1612. $this->replacedomain(
  1613. $url,
  1614. preg_replace(
  1615. '/([a-z0-9]+)(\.m\.)/',
  1616. '$1.',
  1617. $domain
  1618. )
  1619. );
  1620. }
  1621. if(
  1622. preg_match(
  1623. '/imdb\.com$|youtube\.[^.]+$/',
  1624. $domain
  1625. )
  1626. ){
  1627. // rewrite imdb and youtube mobile URLs too
  1628. $url =
  1629. $this->replacedomain(
  1630. $url,
  1631. preg_replace(
  1632. '/^m\./',
  1633. "",
  1634. $domain
  1635. )
  1636. );
  1637. }
  1638. return $url;
  1639. }
  1640. private function replacedomain($url, $domain){
  1641. return
  1642. preg_replace(
  1643. '/(https?:\/\/)([^\/]+)/',
  1644. '$1' . $domain,
  1645. $url
  1646. );
  1647. }
  1648. private function titledots($title){
  1649. return rtrim($title, ".… \t\n\r\0\x0B");
  1650. }
  1651. }