From 16ee0b368fcf24b48574172726e32a19c275d691 Mon Sep 17 00:00:00 2001 From: lolcat Date: Wed, 26 Jul 2023 19:03:06 -0400 Subject: felt quirky, might commit later --- scraper/google.php | 1065 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 829 insertions(+), 236 deletions(-) (limited to 'scraper/google.php') diff --git a/scraper/google.php b/scraper/google.php index 6a746f7..df10754 100644 --- a/scraper/google.php +++ b/scraper/google.php @@ -18,37 +18,44 @@ class google{ switch($page){ - case "web": return [];/* + case "web": return [ - "country" => [ + "country" => [ // gl= "display" => "Country", "option" => [ - "zz" => "Instance region", + "any" => "Instance's country", "af" => "Afghanistan", "al" => "Albania", "dz" => "Algeria", "as" => "American Samoa", "ad" => "Andorra", "ao" => "Angola", - "ag" => "Antigua & Barbuda", + "ai" => "Anguilla", + "aq" => "Antarctica", + "ag" => "Antigua and Barbuda", "ar" => "Argentina", "am" => "Armenia", + "aw" => "Aruba", "au" => "Australia", "at" => "Austria", "az" => "Azerbaijan", "bs" => "Bahamas", "bh" => "Bahrain", "bd" => "Bangladesh", + "bb" => "Barbados", "by" => "Belarus", "be" => "Belgium", "bz" => "Belize", "bj" => "Benin", + "bm" => "Bermuda", "bt" => "Bhutan", "bo" => "Bolivia", - "ba" => "Bosnia & Herzegovina", + "ba" => "Bosnia and Herzegovina", "bw" => "Botswana", + "bv" => "Bouvet Island", "br" => "Brazil", - "bn" => "Brunei", + "io" => "British Indian Ocean Territory", + "bn" => "Brunei Darussalam", "bg" => "Bulgaria", "bf" => "Burkina Faso", "bi" => "Burundi", @@ -56,19 +63,24 @@ class google{ "cm" => "Cameroon", "ca" => "Canada", "cv" => "Cape Verde", + "ky" => "Cayman Islands", "cf" => "Central African Republic", "td" => "Chad", "cl" => "Chile", + "cn" => "China", + "cx" => "Christmas Island", + "cc" => "Cocos (Keeling) Islands", "co" => "Colombia", - "cg" => "Congo - Brazzaville", - "cd" => "Congo - Kinshasa", + "km" => "Comoros", + "cg" => "Congo", + "cd" => "Congo, the Democratic Republic", "ck" => "Cook Islands", "cr" => "Costa Rica", - "ci" => "Côte d’Ivoire", + "ci" => "Cote D'ivoire", "hr" => "Croatia", "cu" => "Cuba", "cy" => "Cyprus", - "cz" => "Czechia", + "cz" => "Czech Republic", "dk" => "Denmark", "dj" => "Djibouti", "dm" => "Dominica", @@ -76,11 +88,18 @@ class google{ "ec" => "Ecuador", "eg" => "Egypt", "sv" => "El Salvador", + "gq" => "Equatorial Guinea", + "er" => "Eritrea", "ee" => "Estonia", "et" => "Ethiopia", + "fk" => "Falkland Islands (Malvinas)", + "fo" => "Faroe Islands", "fj" => "Fiji", "fi" => "Finland", "fr" => "France", + "gf" => "French Guiana", + "pf" => "French Polynesia", + "tf" => "French Southern Territories", "ga" => "Gabon", "gm" => "Gambia", "ge" => "Georgia", @@ -89,86 +108,111 @@ class google{ "gi" => "Gibraltar", "gr" => "Greece", "gl" => "Greenland", + "gd" => "Grenada", + "gp" => "Guadeloupe", + "gu" => "Guam", "gt" => "Guatemala", - "gg" => "Guernsey", + "gn" => "Guinea", + "gw" => "Guinea-Bissau", "gy" => "Guyana", "ht" => "Haiti", + "hm" => "Heard Island and Mcdonald Islands", + "va" => "Holy See (Vatican City State)", "hn" => "Honduras", "hk" => "Hong Kong", "hu" => "Hungary", "is" => "Iceland", "in" => "India", "id" => "Indonesia", + "ir" => "Iran, Islamic Republic", "iq" => "Iraq", "ie" => "Ireland", - "im" => "Isle of Man", "il" => "Israel", "it" => "Italy", "jm" => "Jamaica", "jp" => "Japan", - "je" => "Jersey", "jo" => "Jordan", "kz" => "Kazakhstan", "ke" => "Kenya", "ki" => "Kiribati", + "kp" => "Korea, Democratic People's Republic", + "kr" => "Korea, Republic", "kw" => "Kuwait", "kg" => "Kyrgyzstan", - "la" => "Laos", + "la" => "Lao People's Democratic Republic", "lv" => "Latvia", "lb" => "Lebanon", "ls" => "Lesotho", - "ly" => "Libya", + "lr" => "Liberia", + "ly" => "Libyan Arab Jamahiriya", "li" => "Liechtenstein", "lt" => "Lithuania", "lu" => "Luxembourg", + "mo" => "Macao", + "mk" => "Macedonia, the Former Yugosalv Republic", "mg" => "Madagascar", "mw" => "Malawi", "my" => "Malaysia", "mv" => "Maldives", "ml" => "Mali", "mt" => "Malta", + "mh" => "Marshall Islands", + "mq" => "Martinique", + "mr" => "Mauritania", "mu" => "Mauritius", + "yt" => "Mayotte", "mx" => "Mexico", - "fm" => "Micronesia", - "md" => "Moldova", + "fm" => "Micronesia, Federated States", + "md" => "Moldova, Republic", + "mc" => "Monaco", "mn" => "Mongolia", - "me" => "Montenegro", + "ms" => "Montserrat", "ma" => "Morocco", "mz" => "Mozambique", - "mm" => "Myanmar (Burma)", + "mm" => "Myanmar", "na" => "Namibia", "nr" => "Nauru", "np" => "Nepal", "nl" => "Netherlands", + "an" => "Netherlands Antilles", + "nc" => "New Caledonia", "nz" => "New Zealand", "ni" => "Nicaragua", "ne" => "Niger", "ng" => "Nigeria", "nu" => "Niue", - "mk" => "North Macedonia", + "nf" => "Norfolk Island", + "mp" => "Northern Mariana Islands", "no" => "Norway", "om" => "Oman", "pk" => "Pakistan", - "ps" => "Palestine", + "pw" => "Palau", + "ps" => "Palestinian Territory, Occupied", "pa" => "Panama", "pg" => "Papua New Guinea", "py" => "Paraguay", "pe" => "Peru", "ph" => "Philippines", - "pn" => "Pitcairn Islands", + "pn" => "Pitcairn", "pl" => "Poland", "pt" => "Portugal", "pr" => "Puerto Rico", "qa" => "Qatar", + "re" => "Reunion", "ro" => "Romania", - "ru" => "Russia", + "ru" => "Russian Federation", "rw" => "Rwanda", + "sh" => "Saint Helena", + "kn" => "Saint Kitts and Nevis", + "lc" => "Saint Lucia", + "pm" => "Saint Pierre and Miquelon", + "vc" => "Saint Vincent and the Grenadines", "ws" => "Samoa", "sm" => "San Marino", - "st" => "São Tomé & Príncipe", + "st" => "Sao Tome and Principe", "sa" => "Saudi Arabia", "sn" => "Senegal", - "rs" => "Serbia", + "cs" => "Serbia and Montenegro", "sc" => "Seychelles", "sl" => "Sierra Leone", "sg" => "Singapore", @@ -177,36 +221,46 @@ class google{ "sb" => "Solomon Islands", "so" => "Somalia", "za" => "South Africa", - "kr" => "South Korea", + "gs" => "South Georgia and the South Sandwich Islands", "es" => "Spain", "lk" => "Sri Lanka", - "sh" => "St. Helena", - "vc" => "St. Vincent & Grenadines", + "sd" => "Sudan", "sr" => "Suriname", + "sj" => "Svalbard and Jan Mayen", + "sz" => "Swaziland", "se" => "Sweden", "ch" => "Switzerland", - "tw" => "Taiwan", + "sy" => "Syrian Arab Republic", + "tw" => "Taiwan, Province of China", "tj" => "Tajikistan", - "tz" => "Tanzania", + "tz" => "Tanzania, United Republic", "th" => "Thailand", "tl" => "Timor-Leste", "tg" => "Togo", + "tk" => "Tokelau", "to" => "Tonga", - "tt" => "Trinidad & Tobago", + "tt" => "Trinidad and Tobago", "tn" => "Tunisia", - "tr" => "Türkiye", + "tr" => "Turkey", "tm" => "Turkmenistan", - "vi" => "U.S. Virgin Islands", + "tc" => "Turks and Caicos Islands", + "tv" => "Tuvalu", "ug" => "Uganda", "ua" => "Ukraine", "ae" => "United Arab Emirates", - "gb" => "United Kingdom", + "uk" => "United Kingdom", "us" => "United States", + "um" => "United States Minor Outlying Islands", "uy" => "Uruguay", "uz" => "Uzbekistan", "vu" => "Vanuatu", "ve" => "Venezuela", - "vn" => "Vietnam", + "vn" => "Viet Nam", + "vg" => "Virgin Islands, British", + "vi" => "Virgin Islands, U.S.", + "wf" => "Wallis and Futuna", + "eh" => "Western Sahara", + "ye" => "Yemen", "zm" => "Zambia", "zw" => "Zimbabwe" ] @@ -214,81 +268,60 @@ class google{ "nsfw" => [ "display" => "NSFW", "option" => [ - "yes" => "Yes", - "no" => "No" + "yes" => "Yes", // safe=active + "no" => "No" // safe=off ] ], - "lang" => [ // prefix with lang_ + "lang" => [ // lr= (prefix lang with "lang_") "display" => "Language", "option" => [ "any" => "Any language", - "af" => "Afrikaans", - "ca" => "català", - "cs" => "čeština", - "da" => "dansk", - "de" => "Deutsch", - "et" => "eesti", + "ar" => "Arabic", + "bg" => "Bulgarian", + "ca" => "Catalan", + "cs" => "Czech", + "da" => "Danish", + "de" => "German", + "el" => "Greek", "en" => "English", - "es" => "español", - "eo" => "esperanto", - "tl" => "Filipino", - "fr" => "français", - "hr" => "hrvatski", - "id" => "Indonesia", - "is" => "íslenska", - "it" => "italiano", - "sw" => "Kiswahili", - "lv" => "latviešu", - "lt" => "lietuvių", - "hu" => "magyar", - "nl" => "Nederlands", - "no" => "norsk", - "pl" => "polski", - "pt" => "português", - "ro" => "română", - "sk" => "slovenčina", - "sl" => "slovenščina", - "fi" => "suomi", - "sv" => "svenska", - "vi" => "Tiếng Việt", - "tr" => "Türkçe", - "el" => "Ελληνικά", - "be" => "беларуская", - "bg" => "български", - "ru" => "русский", - "sr" => "српски", - "uk" => "українська", - "hy" => "հայերեն", - "iw" => "עברית", - "ar" => "العربية", - "fa" => "فارسی", - "hi" => "हिन्दी", - "th" => "ไทย", - "ko" => "한국어", - "zh-CN" => "中文 (简体)", - "zh-TW" => "中文 (繁體)", - "ja" => "日本語" + "es" => "Spanish", + "et" => "Estonian", + "fi" => "Finnish", + "fr" => "French", + "hr" => "Croatian", + "hu" => "Hungarian", + "id" => "Indonesian", + "is" => "Icelandic", + "it" => "Italian", + "iw" => "Hebrew", + "ja" => "Japanese", + "ko" => "Korean", + "lt" => "Lithuanian", + "lv" => "Latvian", + "nl" => "Dutch", + "no" => "Norwegian", + "pl" => "Polish", + "pt" => "Portuguese", + "ro" => "Romanian", + "ru" => "Russian", + "sk" => "Slovak", + "sl" => "Slovenian", + "sr" => "Serbian", + "sv" => "Swedish", + "tr" => "Turkish", + "zh-CN" => "Chinese (Simplified)", + "zh-TW" => "Chinese (Traditional)" ] ], - "time" => [ - "display" => "Time posted", - "option" => [ - "any" => "Any time", - "h" => "Last hour", - "d" => "Last 24 hours", - "w" => "Last week", - "m" => "Last month", - "y" => "Last year" - ] + "newer" => [ // &sort=review-date:r:20090301:20090430 + "display" => "Newer than", + "option" => "_DATE" ], - "verbatim" => [ - "display" => "Verbatim", - "option" => [ - "no" => "No", - "yes" => "Yes" - ] + "older" => [ + "display" => "Older than", + "option" => "_DATE" ] - ];*/ + ]; break; case "images": @@ -346,7 +379,7 @@ class google{ "co" => "Colombia", "km" => "Comoros", "cg" => "Congo", - "cd" => "Congo, the Democratic Republic of the", + "cd" => "Congo, the Democratic Republic", "ck" => "Cook Islands", "cr" => "Costa Rica", "ci" => "Cote D'ivoire", @@ -397,7 +430,7 @@ class google{ "is" => "Iceland", "in" => "India", "id" => "Indonesia", - "ir" => "Iran, Islamic Republic of", + "ir" => "Iran, Islamic Republic", "iq" => "Iraq", "ie" => "Ireland", "il" => "Israel", @@ -408,8 +441,8 @@ class google{ "kz" => "Kazakhstan", "ke" => "Kenya", "ki" => "Kiribati", - "kp" => "Korea, Democratic People's Republic of", - "kr" => "Korea, Republic of", + "kp" => "Korea, Democratic People's Republic", + "kr" => "Korea, Republic", "kw" => "Kuwait", "kg" => "Kyrgyzstan", "la" => "Lao People's Democratic Republic", @@ -422,7 +455,7 @@ class google{ "lt" => "Lithuania", "lu" => "Luxembourg", "mo" => "Macao", - "mk" => "Macedonia, the Former Yugosalv Republic of", + "mk" => "Macedonia, the Former Yugosalv Republic", "mg" => "Madagascar", "mw" => "Malawi", "my" => "Malaysia", @@ -435,8 +468,8 @@ class google{ "mu" => "Mauritius", "yt" => "Mayotte", "mx" => "Mexico", - "fm" => "Micronesia, Federated States of", - "md" => "Moldova, Republic of", + "fm" => "Micronesia, Federated States", + "md" => "Moldova, Republic", "mc" => "Monaco", "mn" => "Mongolia", "ms" => "Montserrat", @@ -506,7 +539,7 @@ class google{ "sy" => "Syrian Arab Republic", "tw" => "Taiwan, Province of China", "tj" => "Tajikistan", - "tz" => "Tanzania, United Republic of", + "tz" => "Tanzania, United Republic", "th" => "Thailand", "tl" => "Timor-Leste", "tg" => "Togo", @@ -603,14 +636,20 @@ class google{ "i" => "Icon" ] ], - "color" => [ // tbs=ic: + "colortype" => [ // imgColorType= + "display" => "Color type", + "option" => [ + "any" => "Any color type", + "color" => "Colored", + "gray" => "Gray", + "mono" => "Black & white", + "trans" => "Transparent" + ] + ], + "color" => [ // imgDominantColor= "display" => "Color", "option" => [ "any" => "Any color", - "gray" => "Black and white", - "trans" => "Transparent", - // from here, format is - // tbs=specific,isc: "red" => "Red", "orange" => "Orange", "yellow" => "Yellow", @@ -625,13 +664,15 @@ class google{ "brown" => "Brown" ] ], - "type" => [ // tbs=itp: + "type" => [ // imgType= "display" => "Type", "option" => [ "any" => "Any type", + "face" => "Faces", "clipart" => "Clip Art", "lineart" => "Line Drawing", - "animated" => "GIF" + "stock" => "Stock", + "animated" => "Animated" ] ], "rights" => [ // tbs=il: @@ -694,6 +735,52 @@ class google{ public function web($get){ + $search = $get["s"]; + $country = $get["country"]; + $nsfw = $get["nsfw"]; + $lang = $get["lang"]; + $older = $get["older"]; + $newer = $get["newer"]; + + $params = [ + "num" => 20 // get 20 results + ]; + + // country + if($country != "any"){ + + $params["gl"] = $country; + } + + // nsfw + $params["safe"] = $nsfw == "yes" ? "off" : "active"; + + // language + if($lang != "any"){ + + $params["lr"] = "lang_" . $lang; + } + + // &sort=review-date:r:20090301:20090430 + $older = $older === false ? false : date("Ymd", $older); + $newer = $newer === false ? false : date("Ymd", $newer); + + if( + $older !== false && + $newer === false + ){ + + $newer = date("Ymd", time()); + } + + if( + $older !== false || + $newer !== false + ){ + + $params["sort"] = "review-date:r:" . $older . ":" . $newer; + } + $handle = fopen("scraper/google.html", "r"); $html = fread($handle, filesize("scraper/google.html")); fclose($handle); @@ -735,15 +822,44 @@ class google{ preg_match( '/google\.ldi=({[^}]+})/', $html, - $js_image + $this->js_image ); - if(count($js_image) !== 0){ + if(count($this->js_image) !== 0){ - $js_image = json_decode($js_image[1], true); + $this->js_image = json_decode($this->js_image[1], true); }else{ - $js_image = []; + $this->js_image = []; + } + + // additional js_images present in