From af3bb6b65e66e307c235dc097af3d4d85b0afc87 Mon Sep 17 00:00:00 2001 From: Izzy Date: Sun, 6 Dec 2020 13:00:37 +0100 Subject: [PATCH 1/3] changing tabs to spaces --- google-play.php | 312 ++++++++++++++++++++++++------------------------ 1 file changed, 156 insertions(+), 156 deletions(-) diff --git a/google-play.php b/google-play.php index cb5931c..1c59965 100644 --- a/google-play.php +++ b/google-play.php @@ -10,172 +10,172 @@ * **/ class GooglePlay { - private $debug=false; - private $categories=[ - "app"=>[ - "Art & Design", - "Augmented Reality", - "Auto & Vehicles", - "Beauty", - "Books & Reference", - "Business", - "Comics", - "Communication", - "Dating", - "Daydream", - "Education", - "Entertainment", - "Events", - "Finance", - "Food & Drink", - "Health & Fitness", - "House & Home", - "Libraries & Demo", - "Lifestyle", - "Maps & Navigation", - "Medical", - "Music & Audio", - "News & Magazines", - "Parenting", - "Personalization", - "Photography", - "Productivity", - "Shopping", - "Social", - "Sports", - "Tools", - "Travel & Local", - "Video Players & Editors", - "Wear OS by Google", - "Weather", - ], - "game"=>[ - "Action", - "Adventure", - "Arcade", - "Board", - "Card", - "Casino", - "Casual", - "Educational", - "Music", - "Puzzle", - "Racing", - "Role Playing", - "Simulation", - "Sports", - "Strategy", - "Trivia", - "Word", - ], - ]; - protected function getRegVal($regEx) { - preg_match($regEx, $this->input, $res); - if(isset($res["content"])) return trim($res["content"]); - else return null; - } + private $debug=false; + private $categories=[ + "app"=>[ + "Art & Design", + "Augmented Reality", + "Auto & Vehicles", + "Beauty", + "Books & Reference", + "Business", + "Comics", + "Communication", + "Dating", + "Daydream", + "Education", + "Entertainment", + "Events", + "Finance", + "Food & Drink", + "Health & Fitness", + "House & Home", + "Libraries & Demo", + "Lifestyle", + "Maps & Navigation", + "Medical", + "Music & Audio", + "News & Magazines", + "Parenting", + "Personalization", + "Photography", + "Productivity", + "Shopping", + "Social", + "Sports", + "Tools", + "Travel & Local", + "Video Players & Editors", + "Wear OS by Google", + "Weather", + ], + "game"=>[ + "Action", + "Adventure", + "Arcade", + "Board", + "Card", + "Casino", + "Casual", + "Educational", + "Music", + "Puzzle", + "Racing", + "Role Playing", + "Simulation", + "Sports", + "Strategy", + "Trivia", + "Word", + ], + ]; + protected function getRegVal($regEx) { + preg_match($regEx, $this->input, $res); + if(isset($res["content"])) return trim($res["content"]); + else return null; + } - public function parseApplication($packageName) { - $link="https://play.google.com/store/apps/details?id=".$packageName."&hl=en_US&gl=US"; - if ( ! $this->input = @file_get_contents($link) ) { - return ['success'=>0,'message'=>'Google returned: '.$http_response_header[0]]; - } - $values=[]; - $values["packageName"]=$packageName; + public function parseApplication($packageName) { + $link="https://play.google.com/store/apps/details?id=".$packageName."&hl=en_US&gl=US"; + if ( ! $this->input = @file_get_contents($link) ) { + return ['success'=>0,'message'=>'Google returned: '.$http_response_header[0]]; + } + $values=[]; + $values["packageName"]=$packageName; - $values["name"] = strip_tags($this->getRegVal('/itemprop="name">(?.*?)<\/h1>/')); - if ($values["name"]===null) { - return ['success'=>0,'message'=>'No app data found']; - } + $values["name"] = strip_tags($this->getRegVal('/itemprop="name">(?.*?)<\/h1>/')); + if ($values["name"]===null) { + return ['success'=>0,'message'=>'No app data found']; + } - $values["developer"] = strip_tags($this->getRegVal('/href="\/store\/apps\/developer\?id=(?[^\"]+)"([^\>]+|)>(?[^\<]+)<\/a>/i')); + $values["developer"] = strip_tags($this->getRegVal('/href="\/store\/apps\/developer\?id=(?[^\"]+)"([^\>]+|)>(?[^\<]+)<\/a>/i')); - preg_match('/itemprop="genre" href="\/store\/apps\/category\/(?[^\"]+)"([^\>]+|)>(?[^\<]+)<\/a><\/span>/i', $this->input, $category); - if(isset($category["id"], $category["content"])) { - $values["category"]=trim(strip_tags($category["content"])); - $isGame=false; - foreach($this->categories["game"] as $game) { - if(strtolower($values["category"]) == strtolower($game)) { - $isGame=true; - break; - } - } - $values["type"]=$isGame ? "game" : "app"; - } else { - $values["category"]=null; - $values["type"]=null; - } + preg_match('/itemprop="genre" href="\/store\/apps\/category\/(?[^\"]+)"([^\>]+|)>(?[^\<]+)<\/a><\/span>/i', $this->input, $category); + if(isset($category["id"], $category["content"])) { + $values["category"]=trim(strip_tags($category["content"])); + $isGame=false; + foreach($this->categories["game"] as $game) { + if(strtolower($values["category"]) == strtolower($game)) { + $isGame=true; + break; + } + } + $values["type"]=$isGame ? "game" : "app"; + } else { + $values["category"]=null; + $values["type"]=null; + } - $proto = json_decode($this->getRegVal('/data:(?\[\[\[.+?). sideChannel: .*?\);<\/script/ims')); - $values["summary"] = $proto[0][10][1][1]; - $values["description"] = $this->getRegVal('/itemprop="description">
(?.*?)<\/div><\/span>
getRegVal('/
getRegVal('/getRegVal('/data:(?\[\[\[.+?). sideChannel: .*?\);<\/script/ims')); + $values["summary"] = $proto[0][10][1][1]; + $values["description"] = $this->getRegVal('/itemprop="description">
(?.*?)<\/div><\/span>
getRegVal('/
getRegVal('/]+|)>(?.*?)input, $image); - if(isset($image["content"])) { - preg_match_all('/]+|)>(?.*?)input, $image); + if(isset($image["content"])) { + preg_match_all('/getRegVal('/
Updated<\/div>
(?.*?)<\/span><\/div><\/span><\/div>/i')); - $values["versionName"] = strip_tags($this->getRegVal('/
Current Version<\/div>
(?.*?)<\/span><\/div><\/span><\/div>/i')); - $values["minimumSDKVersion"] = strip_tags($this->getRegVal('/
Requires Android<\/div>
(?.*?)<\/span><\/div><\/span><\/div>/i')); - $values["installs"] = strip_tags($this->getRegVal('/
Installs<\/div>
(?.*?)<\/span><\/div><\/span><\/div>/i')); - $values["age"] = strip_tags($this->getRegVal('/
Content Rating<\/div>
(?.*?)<\/div>/i')); - $values["rating"] = $this->getRegVal('/
]*>(?[^<]+)<\/div>/i'); - $values["votes"] = $this->getRegVal('/]*>(?[^>]+)<\/span>/i'); - $values["price"] = $this->getRegVal('//i'); - $values["size"] = $this->getRegVal('/
Size<\/div>
(?[^<]+)<\/span>/i'); + $values["lastUpdated"] = strip_tags($this->getRegVal('/
Updated<\/div>
(?.*?)<\/span><\/div><\/span><\/div>/i')); + $values["versionName"] = strip_tags($this->getRegVal('/
Current Version<\/div>
(?.*?)<\/span><\/div><\/span><\/div>/i')); + $values["minimumSDKVersion"] = strip_tags($this->getRegVal('/
Requires Android<\/div>
(?.*?)<\/span><\/div><\/span><\/div>/i')); + $values["installs"] = strip_tags($this->getRegVal('/
Installs<\/div>
(?.*?)<\/span><\/div><\/span><\/div>/i')); + $values["age"] = strip_tags($this->getRegVal('/
Content Rating<\/div>
(?.*?)<\/div>/i')); + $values["rating"] = $this->getRegVal('/
]*>(?[^<]+)<\/div>/i'); + $values["votes"] = $this->getRegVal('/]*>(?[^>]+)<\/span>/i'); + $values["price"] = $this->getRegVal('//i'); + $values["size"] = $this->getRegVal('/
Size<\/div>
(?[^<]+)<\/span>/i'); - if($this->debug) { - print_r($values); - } - $values['success'] = 1; - return $values; - } + if($this->debug) { + print_r($values); + } + $values['success'] = 1; + return $values; + } - public function parse($link=null) { - if($link == "" || $link == null) { - $link="https://play.google.com/apps"; - } - $input=file_get_contents($link); - preg_match_all('/href="\/store\/apps\/details\?id=(?[^\"]+)"/i', $input, $ids); - if(isset($ids["ids"])) { - $ids=$ids["ids"]; - $ids=array_values(array_unique($ids)); - $values=$ids; - } else { - $values=[]; - } - if($this->debug) { - print_r($values); - } - return $values; - } + public function parse($link=null) { + if($link == "" || $link == null) { + $link="https://play.google.com/apps"; + } + $input=file_get_contents($link); + preg_match_all('/href="\/store\/apps\/details\?id=(?[^\"]+)"/i', $input, $ids); + if(isset($ids["ids"])) { + $ids=$ids["ids"]; + $ids=array_values(array_unique($ids)); + $values=$ids; + } else { + $values=[]; + } + if($this->debug) { + print_r($values); + } + return $values; + } - public function parseCategory($category) { - $link="https://play.google.com/store/apps/category/".$category; - return $this->parse($link); - } + public function parseCategory($category) { + $link="https://play.google.com/store/apps/category/".$category; + return $this->parse($link); + } - public function parseCategories() { - return array_merge($this->categories["game"], $this->categories["app"]); - } + public function parseCategories() { + return array_merge($this->categories["game"], $this->categories["app"]); + } - public function parseSearch($query) { - $link="https://play.google.com/store/search?q=".$query."&c=apps"; - return $this->parse($link); - } + public function parseSearch($query) { + $link="https://play.google.com/store/search?q=".$query."&c=apps"; + return $this->parse($link); + } } From 1de928ed4b04d216d1ddf19333f0982a4fe948a1 Mon Sep 17 00:00:00 2001 From: Izzy Date: Sun, 6 Dec 2020 13:07:30 +0100 Subject: [PATCH 2/3] update application structure in ReadMe --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index a958ce2..c59d4d3 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,15 @@ foreach($alphas as $alpha) { - require - install - age +- rating +- votes +- price +- size +- success (1 if data was retrieved, 0 otherwise) +- message (only with success==0, telling you what failed) + +If retrieving data failed, the returned array will only hold the keys `success` and `message`. If it succeeded, there won't be a `message` key. + ### Output Google Play structure @@ -124,6 +133,11 @@ Array [require] => 4.4 and up [install] => 500,000+ [age] => Everyone + [rating] => 3.9 + [votes] => 1,820 + [price] => 0 + [size] => Varies with device + [success] => 1 ) ``` From 2780ae667cec289543b805ae355007f6b19fbc47 Mon Sep 17 00:00:00 2001 From: Izzy Date: Sun, 6 Dec 2020 13:12:20 +0100 Subject: [PATCH 3/3] compare application name using "==" instead of "===" --- google-play.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-play.php b/google-play.php index 1c59965..a6dfeef 100644 --- a/google-play.php +++ b/google-play.php @@ -84,7 +84,7 @@ public function parseApplication($packageName) { $values["packageName"]=$packageName; $values["name"] = strip_tags($this->getRegVal('/itemprop="name">(?.*?)<\/h1>/')); - if ($values["name"]===null) { + if ($values["name"]==null) { return ['success'=>0,'message'=>'No app data found']; }