1
0

google.php 55 KB

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