1212class GooglePlay {
1313 private $ debug =false ;
1414
15+ /** Parse a given RegEx and return the match marked by '(?<content>)'
16+ * @method protected getRegVal
17+ * @param string regEx regular expression to parse
18+ * @return string result match when found, null otherwise
19+ */
1520 protected function getRegVal ($ regEx ) {
1621 preg_match ($ regEx , $ this ->input , $ res );
1722 if (isset ($ res ["content " ])) return trim ($ res ["content " ]);
1823 else return null ;
1924 }
2025
26+ /** Obtain details on a given app
27+ * @method public parseApplication
28+ * @param string packageName identifier for the app, e.g. 'com.example.app'
29+ * @param optional string lang language for translations. Should be ISO 639-1 two-letter code. Default: en
30+ * @param optional string loc locale, mainly for currency. Again two-letter, but uppercase
31+ * @return array details on the app on success, details on the error otherwise
32+ * @verbatim
33+ * On error, the array contains 2 keys: success=0 and message=(tring with reason)
34+ * Success is signaled by success=1, and details are given via the keys
35+ * packageName, name, developer, category, type (game, app, family), description,
36+ * icon, images (array of screenshot URLs), updated, version, require (min Android version),
37+ * install (number of installs), age, rating (float), votes, price, size
38+ * if not explicitly specified otherwise, values are strings
39+ */
2140 public function parseApplication ($ packageName , $ lang ='en_US ' , $ loc ='US ' ) {
2241 $ link ="https://play.google.com/store/apps/details?id= " .$ packageName ."&hl= $ lang&gl= $ loc " ;
2342 if ( ! $ this ->input = @file_get_contents ($ link ) ) {
@@ -91,6 +110,11 @@ public function parseApplication($packageName, $lang='en_US', $loc='US') {
91110 return $ values ;
92111 }
93112
113+ /** Parse page specified by URL for playstore links and extract package names
114+ * @method public parse
115+ * @param optional string link link to parse; if empty or not specified, defaults to 'https://play.google.com/apps'
116+ * @return array array of package names
117+ */
94118 public function parse ($ link =null ) {
95119 if ($ link == "" || $ link == null ) {
96120 $ link ="https://play.google.com/apps " ;
@@ -110,6 +134,19 @@ public function parse($link=null) {
110134 return $ values ;
111135 }
112136
137+ /** Obtain permissions for a given app
138+ * @method parsePerms
139+ * @param string packageName identifier for the app, e.g. 'com.example.app'
140+ * @param optional string lang language for translations. Should be ISO 639-1 two-letter code. Default: en
141+ * @return array permission on success, details on the error otherwise
142+ * @verbatim
143+ * On error, the array contains 2 keys: success=0 and message=(tring with reason)
144+ * Success is signaled by success=1, and details are given via the keys
145+ * * perms : array[0..n] of permissions as displayed on play.google.com (i.e. the permission descriptions); unique, no grouping.
146+ * * grouped : array of permission groups as displayed on play.google.com. Keys are the group ids as defined there.
147+ * keys in each group array are group_name (translated name of the permission group) and perms (array[0..n])
148+ * These perms have numeric keys (0 and 1). 0 seems always to be empty, 1 holds the permission description.
149+ */
113150 public function parsePerms ($ packageName , $ lang ='en ' ) {
114151 $ opts = ['http ' => array (
115152 'method ' => 'POST ' ,
@@ -157,15 +194,32 @@ public function parsePerms($packageName, $lang='en') {
157194 return ['success ' =>1 ,'grouped ' =>$ perms ,'perms ' =>array_unique ($ perms_unique )];
158195 }
159196
197+ /** Parse Play Store page for a given category and return package names
198+ * use this::parseCategories to obtain a list of available categories
199+ * @method public parseCategory
200+ * @param string category name of the category to parse
201+ * @return array array of package names
202+ */
160203 public function parseCategory ($ category ) {
161204 $ link ="https://play.google.com/store/apps/category/ " .$ category ;
162205 return $ this ->parse ($ link );
163206 }
164207
208+ /** Obtain list of available categories
209+ * @method public parseCategories
210+ * @return array array[0..n] of category names to be used with this::parseCategory
211+ */
165212 public function parseCategories () {
166- return array_merge ($ this ->categories ["game " ], $ this ->categories ["app " ]);
213+ $ input = file_get_contents ('https://play.google.com/store/apps/details?id=com.google.android.gm&hl=en&gl=US ' );
214+ preg_match_all ('!href="/store/apps/category/([^"]+)"[^>]*>([^<]+)!i ' ,$ input ,$ cats );
215+ return array_unique ($ cats [1 ]);
167216 }
168217
218+ /** Search for apps by a given string
219+ * @method public parseSearch
220+ * @param string query string to search for
221+ * @return array array of package names
222+ */
169223 public function parseSearch ($ query ) {
170224 $ link ="https://play.google.com/store/search?q= " .$ query ."&c=apps " ;
171225 return $ this ->parse ($ link );
0 commit comments