1
0

google.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929
  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/backend.php";
  9. $this->backend = new backend("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($proxy, $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. $this->backend->assign_proxy($curlproc, $proxy);
  748. $data = curl_exec($curlproc);
  749. if(curl_errno($curlproc)){
  750. throw new Exception(curl_error($curlproc));
  751. }
  752. curl_close($curlproc);
  753. return $data;
  754. }
  755. /*
  756. public function web($get){
  757. $search = $get["s"];
  758. $country = $get["country"];
  759. $nsfw = $get["nsfw"];
  760. $lang = $get["lang"];
  761. $older = $get["older"];
  762. $newer = $get["newer"];
  763. $params = [
  764. "num" => 20 // get 20 results
  765. ];
  766. // country
  767. if($country != "any"){
  768. $params["gl"] = $country;
  769. }
  770. // nsfw
  771. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  772. // language
  773. if($lang != "any"){
  774. $params["lr"] = "lang_" . $lang;
  775. }
  776. // &sort=review-date:r:20090301:20090430
  777. $older = $older === false ? false : date("Ymd", $older);
  778. $newer = $newer === false ? false : date("Ymd", $newer);
  779. if(
  780. $older !== false &&
  781. $newer === false
  782. ){
  783. $newer = date("Ymd", time());
  784. }
  785. if(
  786. $older !== false ||
  787. $newer !== false
  788. ){
  789. $params["sort"] = "review-date:r:" . $older . ":" . $newer;
  790. }
  791. $handle = fopen("scraper/google.html", "r");
  792. $html = fread($handle, filesize("scraper/google.html"));
  793. fclose($handle);
  794. $out = [
  795. "status" => "ok",
  796. "spelling" => [
  797. "type" => "no_correction",
  798. "using" => null,
  799. "correction" => null
  800. ],
  801. "npt" => null,
  802. "answer" => [],
  803. "web" => [],
  804. "image" => [],
  805. "video" => [],
  806. "news" => [],
  807. "related" => []
  808. ];
  809. $this->parsejavascript($html);
  810. $containers =
  811. $this->fuckhtml
  812. ->getElementsByClassName(
  813. $this->findstyles(
  814. [
  815. "background-color" => "#fff",
  816. "margin-bottom" => "10px",
  817. "-webkit-box-shadow" => "0 1px 6px rgba(32,33,36,0.28)",
  818. "border-radius" => "8px"
  819. ],
  820. self::is_class
  821. ),
  822. "div"
  823. );
  824. foreach($containers as $container){
  825. $this->fuckhtml->load($container);
  826. $title =
  827. $this->fuckhtml
  828. ->getElementsByClassName(
  829. $this->findstyles(
  830. [
  831. "color" => "#1967d2",
  832. "font-size" => "20px",
  833. "line-height" => "26px"
  834. ],
  835. self::is_class
  836. ),
  837. "div"
  838. );
  839. if(count($title) !== 0){
  840. //
  841. // Container is a web link
  842. //
  843. $web = [
  844. "title" =>
  845. $this->titledots(
  846. $this->fuckhtml
  847. ->getTextContent(
  848. $title[0]
  849. )
  850. ),
  851. "description" => null,
  852. "url" =>
  853. $this->decodeurl(
  854. $this->fuckhtml
  855. ->getElementsByTagName("a")
  856. [0]
  857. ["attributes"]
  858. ["href"]
  859. ),
  860. "date" => null,
  861. "type" => "web",
  862. "thumb" => [
  863. "url" => null,
  864. "ratio" => null
  865. ],
  866. "sublink" => [],
  867. "table" => []
  868. ];
  869. $container = $container["innerHTML"];
  870. $description_container =
  871. $this->fuckhtml
  872. ->getElementsByClassName(
  873. $this->findstyles(
  874. [
  875. "padding" => "12px 16px 12px"
  876. ],
  877. self::is_class
  878. ),
  879. "div"
  880. )[1];
  881. $description =
  882. $description_container["innerHTML"];
  883. // get sublinks
  884. $this->fuckhtml->load($description);
  885. $links =
  886. $this->fuckhtml
  887. ->getElementsByTagName("a");
  888. $skip = true;
  889. foreach($links as $link){
  890. $description =
  891. str_replace(
  892. $link["outerHTML"],
  893. "",
  894. $description
  895. );
  896. if($skip){
  897. $skip = false;
  898. continue;
  899. }
  900. $sublink = [
  901. "title" => null,
  902. "description" => null,
  903. "url" => null,
  904. "date" => null
  905. ];
  906. $sublink["title"] =
  907. $this->fuckhtml
  908. ->getTextContent(
  909. $link
  910. );
  911. $sublink["url"] =
  912. $this->decodeurl(
  913. $link
  914. ["attributes"]
  915. ["href"]
  916. );
  917. $web["sublink"][] = $sublink;
  918. }
  919. // get thumbnail before we call loadhtml again
  920. $img =
  921. $this->fuckhtml
  922. ->getElementsByTagName("img");
  923. if(count($img) !== 0){
  924. if(
  925. isset($img[0]["attributes"]["alt"]) &&
  926. stripos($img[0]["attributes"]["alt"], "Video for") !== false
  927. ){
  928. // is a video thumbnail
  929. $web["thumb"]["ratio"] = "16:9";
  930. }else{
  931. // is a google thumbnail
  932. $web["thumb"]["ratio"] = "1:1";
  933. }
  934. $web["thumb"]["url"] =
  935. $this->getimage(
  936. $img[0]["attributes"]["id"]
  937. );
  938. }
  939. // get table elements
  940. $this->fuckhtml->load($description);
  941. $levels =
  942. $this->fuckhtml
  943. ->getElementsByClassName(
  944. $this->findstyles(
  945. [
  946. "padding-bottom" => "8px"
  947. ],
  948. self::is_class
  949. ),
  950. "div"
  951. );
  952. $additional_info = [];
  953. foreach($levels as $level){
  954. $this->fuckhtml->load($level);
  955. $spans =
  956. $this->fuckhtml
  957. ->getElementsByTagName(
  958. "span"
  959. );
  960. $is_rating = -2;
  961. foreach($spans as $span){
  962. // clean up description
  963. $description =
  964. str_replace(
  965. $span["outerHTML"],
  966. "",
  967. $description
  968. );
  969. $innertext =
  970. $this->fuckhtml
  971. ->getTextContent(
  972. $span
  973. );
  974. if($innertext == ""){ continue; }
  975. if(
  976. strtolower($innertext)
  977. == "rating"
  978. ){
  979. $is_rating = -1;
  980. continue;
  981. }
  982. //
  983. // Parse rating object
  984. //
  985. if($is_rating >= -1){
  986. if($span["level"] !== 1){ continue; }
  987. $is_rating++;
  988. // 10/10 (123)
  989. if($is_rating === 0){
  990. $innertext = explode(" ", $innertext, 2);
  991. $web["table"]["Rating"] = $innertext[0];
  992. $web["table"]["Hits"] =
  993. trim(
  994. str_replace(
  995. [
  996. "(",
  997. ")"
  998. ],
  999. "",
  1000. $innertext[1]
  1001. )
  1002. );
  1003. continue;
  1004. }
  1005. // US$4.99
  1006. // MYR 50.00
  1007. // $38.34
  1008. // JP¥6,480
  1009. if($is_rating === 2){
  1010. $web["table"]["Price"] = $innertext;
  1011. continue;
  1012. }
  1013. // Android / In stock
  1014. if($is_rating === 4){
  1015. $web["table"]["Support"] = $innertext;
  1016. continue;
  1017. }
  1018. // ignore the rest
  1019. continue;
  1020. }
  1021. //
  1022. // Parse standalone text
  1023. //
  1024. $additional_info[] = $innertext;
  1025. }
  1026. }
  1027. for($i=0; $i<count($additional_info); $i++){
  1028. // @TODO
  1029. // generate better node names
  1030. $web["table"]["Info node #$i"] = $additional_info[$i];
  1031. }
  1032. $this->fuckhtml->load($description);
  1033. // get date node
  1034. $span =
  1035. $this->fuckhtml
  1036. ->getElementsByTagName(
  1037. "span"
  1038. );
  1039. if(count($span) !== 0){
  1040. $description =
  1041. str_replace(
  1042. $span[0]["outerHTML"],
  1043. "",
  1044. $description
  1045. );
  1046. $span =
  1047. strtotime(
  1048. $this->fuckhtml
  1049. ->getTextContent(
  1050. $span[0]
  1051. )
  1052. );
  1053. if($span){
  1054. $web["date"] = $span;
  1055. }
  1056. }
  1057. $web["description"] =
  1058. trim(
  1059. $this->fuckhtml
  1060. ->getTextContent(
  1061. $description
  1062. ),
  1063. " ·."
  1064. );
  1065. $out["web"][] = $web;
  1066. continue;
  1067. }
  1068. // check for container title header
  1069. $container_title =
  1070. $this->fuckhtml
  1071. ->getElementsByClassName(
  1072. $this->findstyles(
  1073. [
  1074. "font-weight" => "bold",
  1075. "font-size" => "16px",
  1076. "color" => "#000",
  1077. "margin" => "0",
  1078. "padding" => "12px 16px 0 16px"
  1079. ],
  1080. self::is_class
  1081. ),
  1082. "div"
  1083. );
  1084. if(count($container_title) !== 0){
  1085. $container_title =
  1086. strtolower(
  1087. $this->fuckhtml
  1088. ->getTextContent(
  1089. $container_title[0]
  1090. )
  1091. );
  1092. if(
  1093. $container_title == "related searches" ||
  1094. $container_title == "people also search for"
  1095. ){
  1096. //
  1097. // Parse related searches
  1098. //
  1099. $as =
  1100. $this->fuckhtml
  1101. ->getElementsByTagName("a");
  1102. foreach($as as $a){
  1103. $out["related"][] =
  1104. $this->fuckhtml
  1105. ->getTextContent($a);
  1106. }
  1107. }
  1108. continue;
  1109. }
  1110. //
  1111. // Parse image carousel
  1112. //
  1113. $title_container =
  1114. $this->fuckhtml
  1115. ->getElementsByClassName(
  1116. $this->findstyles(
  1117. [
  1118. "padding" => "12px 16px 12px"
  1119. ],
  1120. self::is_class
  1121. ),
  1122. "div"
  1123. );
  1124. if(count($title_container) !== 0){
  1125. $title_container =
  1126. strtolower(
  1127. $this->fuckhtml
  1128. ->getTextContent(
  1129. $title_container[0]
  1130. )
  1131. );
  1132. if($title_container == "imagesview all"){
  1133. //
  1134. // Image carousel
  1135. //
  1136. $pcitem =
  1137. $this->fuckhtml
  1138. ->getElementsByClassName(
  1139. "pcitem",
  1140. "div"
  1141. );
  1142. foreach($pcitem as $item){
  1143. $this->fuckhtml->load($item);
  1144. $link =
  1145. $this->fuckhtml
  1146. ->getElementsByTagName(
  1147. "a"
  1148. )[0];
  1149. parse_str(
  1150. parse_url(
  1151. $this->fuckhtml
  1152. ->getTextContent(
  1153. $link
  1154. ["attributes"]
  1155. ["href"]
  1156. ),
  1157. PHP_URL_QUERY
  1158. ),
  1159. $link
  1160. );
  1161. if(isset($link["tbm"])){
  1162. continue;
  1163. }
  1164. $image =
  1165. $this->fuckhtml
  1166. ->getElementsByTagName("img")[0];
  1167. $title =
  1168. $this->fuckhtml
  1169. ->getTextContent(
  1170. $image
  1171. ["attributes"]
  1172. ["alt"]
  1173. );
  1174. $image =
  1175. $this->getimage(
  1176. $image
  1177. ["attributes"]
  1178. ["id"]
  1179. );
  1180. $out["image"][] = [
  1181. "title" => $title,
  1182. "source" => [
  1183. [
  1184. "url" => $link["imgurl"],
  1185. "width" => (int)$link["w"],
  1186. "height" => (int)$link["h"]
  1187. ],
  1188. [
  1189. "url" => $image,
  1190. "width" => (int)$link["tbnw"],
  1191. "height" => (int)$link["tbnh"]
  1192. ]
  1193. ],
  1194. "url" => $link["imgrefurl"]
  1195. ];
  1196. }
  1197. }
  1198. }
  1199. //
  1200. // Get next page
  1201. //
  1202. $as =
  1203. $this->fuckhtml
  1204. ->getElementsByTagName("a");
  1205. foreach($as as $a){
  1206. if(
  1207. isset($a["attributes"]["aria-label"]) &&
  1208. strtolower($a["attributes"]["aria-label"]) == "next page"
  1209. ){
  1210. $out["npt"] =
  1211. $this->fuckhtml
  1212. ->getTextContent(
  1213. $a["attributes"]["href"]
  1214. );
  1215. }
  1216. }
  1217. }
  1218. return $out;
  1219. }*/
  1220. public function image($get){
  1221. // generate parameters
  1222. if($get["npt"]){
  1223. [$params, $proxy] =
  1224. $this->backend->get(
  1225. $get["npt"],
  1226. "images"
  1227. );
  1228. $params = json_decode($params, true);
  1229. }else{
  1230. $search = $get["s"];
  1231. if(strlen($search) === 0){
  1232. throw new Exception("Search term is empty!");
  1233. }
  1234. $proxy = $this->backend->get_ip();
  1235. $country = $get["country"];
  1236. $nsfw = $get["nsfw"];
  1237. $lang = $get["lang"];
  1238. $time = $get["time"];
  1239. $size = $get["size"];
  1240. $ratio = $get["ratio"];
  1241. $color = $get["color"];
  1242. $type = $get["type"];
  1243. $format = $get["format"];
  1244. $rights = $get["rights"];
  1245. $params = [
  1246. "q" => $search,
  1247. "tbm" => "isch"
  1248. ];
  1249. // country
  1250. if($country != "any"){
  1251. $params["gl"] = $country;
  1252. }
  1253. // nsfw
  1254. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  1255. // language
  1256. if($lang != "any"){
  1257. $params["lr"] = "lang_" . $lang;
  1258. }
  1259. $tbs = [];
  1260. // time
  1261. if($time != "any"){
  1262. $tbs[] = "qrd:" . $time;
  1263. }
  1264. // size
  1265. if($size != "any"){
  1266. if(
  1267. in_array(
  1268. $size,
  1269. ["l", "s", "i"]
  1270. )
  1271. ){
  1272. $tbs[] = "isz:" . $size;
  1273. }else{
  1274. $tbs[] = "tbz:lt";
  1275. $tbs[] = "islt:" . $size;
  1276. }
  1277. }
  1278. // ratio
  1279. if($ratio != "any"){
  1280. $tbs[] = "iar:" . $ratio;
  1281. }
  1282. // color
  1283. if($color != "any"){
  1284. if(
  1285. in_array(
  1286. $color,
  1287. ["color", "gray", "trans"]
  1288. )
  1289. ){
  1290. $tbs[] = "ic:" . $color;
  1291. }else{
  1292. $tbs[] = "ic:specific";
  1293. $tbs[] = "isc:" . $color;
  1294. }
  1295. }
  1296. // type
  1297. if($type != "any"){
  1298. $tbs[] = "itp:" . $type;
  1299. }
  1300. // format
  1301. if($format != "any"){
  1302. $tbs[] = "ift:" . $format;
  1303. }
  1304. // rights
  1305. if($rights != "any"){
  1306. $tbs[] = "il:" . $rights;
  1307. }
  1308. // append tbs
  1309. if(count($tbs) !== 0){
  1310. $params["tbs"] =
  1311. implode(",", $tbs);
  1312. }
  1313. }
  1314. /*
  1315. $handle = fopen("scraper/google-img.html", "r");
  1316. $html = fread($handle, filesize("scraper/google-img.html"));
  1317. fclose($handle);*/
  1318. // scrape images
  1319. try{
  1320. $html =
  1321. $this->get(
  1322. $proxy,
  1323. "https://www.google.com/search",
  1324. $params
  1325. );
  1326. }catch(Exception $error){
  1327. throw new Exception("Failed to get search page");
  1328. }
  1329. $this->fuckhtml->load($html);
  1330. $out = [
  1331. "status" => "ok",
  1332. "npt" => null,
  1333. "image" => []
  1334. ];
  1335. $images =
  1336. $this->fuckhtml
  1337. ->getElementsByClassName(
  1338. "islrtb isv-r",
  1339. "div"
  1340. );
  1341. foreach($images as $image){
  1342. $this->fuckhtml->load($image);
  1343. $img =
  1344. $this->fuckhtml
  1345. ->getElementsByTagName("img")[0];
  1346. $og_width = (int)$image["attributes"]["data-ow"];
  1347. $og_height = (int)$image["attributes"]["data-oh"];
  1348. $thumb_width = (int)$image["attributes"]["data-tw"];
  1349. $ratio = $og_width / $og_height;
  1350. if(isset($img["attributes"]["data-src"])){
  1351. $src = &$img["attributes"]["data-src"];
  1352. }else{
  1353. $src = &$img["attributes"]["src"];
  1354. }
  1355. $thumb_height = floor($thumb_width / $ratio);
  1356. $out["image"][] = [
  1357. "title" =>
  1358. $this->titledots(
  1359. $this->fuckhtml
  1360. ->getTextContent(
  1361. $image["attributes"]["data-pt"]
  1362. )
  1363. ),
  1364. "source" => [
  1365. [
  1366. "url" =>
  1367. $this->fuckhtml
  1368. ->getTextContent(
  1369. $image["attributes"]["data-ou"]
  1370. ),
  1371. "width" => $og_width,
  1372. "height" => $og_height
  1373. ],
  1374. [
  1375. "url" =>
  1376. $this->fuckhtml
  1377. ->getTextContent(
  1378. $src
  1379. ),
  1380. "width" => $thumb_width,
  1381. "height" => $thumb_height
  1382. ]
  1383. ],
  1384. "url" =>
  1385. $this->fuckhtml
  1386. ->getTextContent(
  1387. $image["attributes"]["data-ru"]
  1388. )
  1389. ];
  1390. }
  1391. // get next page
  1392. // https://www.google.com/search
  1393. // ?q=higurashi
  1394. // &tbm=isch
  1395. // &async=_id%3Aislrg_c%2C_fmt%3Ahtml
  1396. // &asearch=ichunklite
  1397. // &ved=0ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA
  1398. if(count($out["image"]) !== 100){
  1399. // no more results
  1400. return $out;
  1401. }
  1402. if($get["npt"]){
  1403. // update nextpage information
  1404. $params["start"] = (int)$params["start"] + count($out["image"]);
  1405. $params["ijn"] = (int)$params["ijn"] + 1;
  1406. $out["npt"] =
  1407. $this->backend->store(
  1408. json_encode($params),
  1409. "images",
  1410. $proxy
  1411. );
  1412. }else{
  1413. // scrape nextpage information
  1414. $this->fuckhtml->load($html);
  1415. $ved =
  1416. $this->fuckhtml
  1417. ->getElementById("islrg", "div");
  1418. if($ved){
  1419. $ved =
  1420. $this->fuckhtml
  1421. ->getTextContent(
  1422. $ved["attributes"]["data-ved"]
  1423. );
  1424. // &vet=1{$ved}..i (10ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA..i)
  1425. /*
  1426. These 2 are handled by us
  1427. start = start + number of results
  1428. ijn = current page number
  1429. */
  1430. // &start=100
  1431. // &ijn=1
  1432. // &imgvl=CAEY7gQgBSj3Aji8VTjXVUC4AUC3AUgAYNdV
  1433. preg_match(
  1434. '/var e=\'([A-z0-9]+)\';/',
  1435. $html,
  1436. $imgvl
  1437. );
  1438. if(isset($imgvl[1])){
  1439. $imgvl = $imgvl[1];
  1440. $params["async"] = "_id:islrg_c,_fmt:html";
  1441. $params["asearch"] = "ichunklite";
  1442. $params["ved"] = $ved;
  1443. $params["vet"] = "1" . $ved . "..i";
  1444. $params["start"] = 100;
  1445. $params["ijn"] = 1;
  1446. $params["imgvl"] = $imgvl;
  1447. $out["npt"] =
  1448. $this->backend->store(
  1449. json_encode($params),
  1450. "images",
  1451. $proxy
  1452. );
  1453. }
  1454. }
  1455. }
  1456. return $out;
  1457. }
  1458. private function hms2int($time){
  1459. $parts = explode(":", $time, 3);
  1460. $time = 0;
  1461. if(count($parts) === 3){
  1462. // hours
  1463. $time = $time + ((int)$parts[0] * 3600);
  1464. array_shift($parts);
  1465. }
  1466. if(count($parts) === 2){
  1467. // minutes
  1468. $time = $time + ((int)$parts[0] * 60);
  1469. array_shift($parts);
  1470. }
  1471. // seconds
  1472. $time = $time + (int)$parts[0];
  1473. return $time;
  1474. }
  1475. private function parsejavascript($html){
  1476. $this->fuckhtml->load($html);
  1477. $styles =
  1478. $this->fuckhtml
  1479. ->getElementsByTagName("style");
  1480. $this->computedstyle = [];
  1481. $this->ask = [];
  1482. foreach($styles as $style){
  1483. $this->computedstyle =
  1484. array_merge(
  1485. $this->computedstyle,
  1486. $this->parsestyles($style["innerHTML"])
  1487. );
  1488. }
  1489. // get images in javascript var
  1490. preg_match(
  1491. '/google\.ldi=({[^}]+})/',
  1492. $html,
  1493. $this->js_image
  1494. );
  1495. if(count($this->js_image) !== 0){
  1496. $this->js_image = json_decode($this->js_image[1], true);
  1497. }else{
  1498. $this->js_image = [];
  1499. }
  1500. // additional js_images present in <script> tags
  1501. // ugh i fucking hate you
  1502. $scripts =
  1503. $this->fuckhtml
  1504. ->getElementsByTagName("script");
  1505. foreach($scripts as $script){
  1506. if(!isset($script["innerHTML"])){
  1507. continue;
  1508. }
  1509. preg_match_all(
  1510. '/var s=\'(data:image[^\']+)\';var i=\[\'([^\']+)\'];/',
  1511. $script["innerHTML"],
  1512. $image_grep
  1513. );
  1514. if(count($image_grep[0]) !== 0){
  1515. $this->js_image[trim($image_grep[2][0])] =
  1516. $this->fuckhtml
  1517. ->getTextContent(
  1518. $image_grep[1][0]
  1519. );
  1520. }
  1521. // even more javascript crap
  1522. // "People also ask" node is loaded trough javascript
  1523. preg_match_all(
  1524. '/window\.jsl\.dh\(\'([^\']+)\',\'(.+)\'\);/',
  1525. $script["innerHTML"],
  1526. $ask_grep
  1527. );
  1528. for($i=0; $i<count($ask_grep[0]); $i++){
  1529. $this->ask[trim($ask_grep[1][$i])] =
  1530. stripcslashes(
  1531. $ask_grep[2][$i]
  1532. );
  1533. }
  1534. }
  1535. }
  1536. private function findstyles($rules, $is){
  1537. ksort($rules);
  1538. foreach($this->computedstyle as $stylename => $styles){
  1539. if($styles == $rules){
  1540. preg_match(
  1541. '/\\' . $is . '([^ .]+)/',
  1542. $stylename,
  1543. $out
  1544. );
  1545. if(count($out) === 2){
  1546. return $out[1];
  1547. }
  1548. return false;
  1549. }
  1550. }
  1551. return false;
  1552. }
  1553. private function parsestyles($style){
  1554. // get style tags
  1555. preg_match_all(
  1556. '/([^{]+){([^}]+)}/',
  1557. $style,
  1558. $tags_regex
  1559. );
  1560. $tags = [];
  1561. for($i=0; $i<count($tags_regex[0]); $i++){
  1562. $tagnames = explode(",", trim($tags_regex[1][$i]));
  1563. foreach($tagnames as $tagname){
  1564. $tagname = trim($tagname);
  1565. if(!isset($tags[$tagname])){
  1566. $tags[$tagname] = [];
  1567. }
  1568. $values = explode(";", $tags_regex[2][$i]);
  1569. foreach($values as $value){
  1570. $value = explode(":", $value, 2);
  1571. if(count($value) !== 2){
  1572. continue;
  1573. }
  1574. $tags[$tagname][trim($value[0])] =
  1575. trim($value[1]);
  1576. }
  1577. }
  1578. }
  1579. foreach($tags as &$value){
  1580. ksort($value);
  1581. }
  1582. return $tags;
  1583. }
  1584. private function getimage($id){
  1585. if(
  1586. isset($this->js_image[$id]) &&
  1587. $this->js_image[$id] != "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABAUlEQVR4AWMYesChoYElLjkzPj4lY3d8csZjIL4MxPNjUzPcSTYsISFLAqj5NBD/h+LPQPwbiT87NCuLh2gDgRr2QzXuT0jNMoBYksARn5zuHJ+UcR0kB6RXE2VYXHJGOlTDZmzyIJcB5e+D1CSkZDgQNBAaZv+jU1JkcKpJygiGeZ0I76a/Byq8jU9NZFqaCNTA48SE33/iDcw8TIyBt0GKQTFN0Msp6f2EIyUpo57YSIlLSrMhIg0WCIBcCfXSdlzJBsheTHQ6jEnOUgEFOLaEDbMIlhZBOYrorAdJk+nroVnvPsSgdGdoOF7HZyhZ2XPoGQoqjbCpIbt0AiejIQMArVLI7k/DXFkAAAAASUVORK5CYII="
  1588. ){
  1589. if(stripos($this->js_image[$id], "data:image") !== false){
  1590. return
  1591. explode(
  1592. "\\x3d",
  1593. $this->js_image[$id],
  1594. 2
  1595. )[0];
  1596. }
  1597. return $this->js_image[$id];
  1598. }
  1599. return null;
  1600. }
  1601. private function decodeurl($url){
  1602. preg_match(
  1603. '/^\/url\?q=([^&]+)|^\/interstitial\?url=([^&]+)/',
  1604. $this->fuckhtml
  1605. ->getTextContent($url),
  1606. $match
  1607. );
  1608. if(count($match) === 0){
  1609. return null;
  1610. }
  1611. $url = empty($match[1]) ? urldecode($match[2]) : urldecode($match[1]);
  1612. $domain = parse_url($url, PHP_URL_HOST);
  1613. if(
  1614. preg_match(
  1615. '/wikipedia.org$/',
  1616. $domain
  1617. )
  1618. ){
  1619. // rewrite wikipedia mobile URLs to desktop
  1620. $url =
  1621. $this->replacedomain(
  1622. $url,
  1623. preg_replace(
  1624. '/([a-z0-9]+)(\.m\.)/',
  1625. '$1.',
  1626. $domain
  1627. )
  1628. );
  1629. }
  1630. if(
  1631. preg_match(
  1632. '/imdb\.com$|youtube\.[^.]+$/',
  1633. $domain
  1634. )
  1635. ){
  1636. // rewrite imdb and youtube mobile URLs too
  1637. $url =
  1638. $this->replacedomain(
  1639. $url,
  1640. preg_replace(
  1641. '/^m\./',
  1642. "",
  1643. $domain
  1644. )
  1645. );
  1646. }
  1647. return $url;
  1648. }
  1649. private function replacedomain($url, $domain){
  1650. return
  1651. preg_replace(
  1652. '/(https?:\/\/)([^\/]+)/',
  1653. '$1' . $domain,
  1654. $url
  1655. );
  1656. }
  1657. private function titledots($title){
  1658. return rtrim($title, ".… \t\n\r\0\x0B");
  1659. }
  1660. }