Skip to content

Commit 7e46918

Browse files
authored
Obtain charts & new additions #14
Merge pull request #14 from IzzySoft/devel
2 parents 289220e + 8f66b70 commit 7e46918

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
Tiny script to crawl information of a specific application in the Google play/store base on PHP.
44

55
## PHP GooglePlay Methods
6-
76
- `parse`: mostly used internally – but can be used to parse any URL or text for valid Play Store app links and return their packageNames
87
- `parseSearch`: search for apps by given terms
98
- `parseSimilar`: search for what Google Play considers apps similar to the one specified
9+
- `parseOthers`: other apps by the same developer
10+
- `parseTopApps`: list top-chart apps
11+
- `parseNewApps`: list latest additions
1012
- `parseCategory`: list apps from a specified category
1113
- `parseCategories`: list available categories
1214
- `parseApplication`: get details for a specific app
1315
- `parsePerms`: retrieve permissions requested by a specific app
14-
16+
- `setDebug`: turn debug mode on or off
17+
- `getDebug`: check whether debug mode is turned on or off
1518

1619
## Using PHP GooglePlay
17-
1820
```php
1921
<?php
2022
require "google-play.php";

google-play.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ class GooglePlay {
1414
private $input = ''; // content retrieved from remote
1515
private $lastError = '';
1616

17+
/** Turn debug mode on or off
18+
* @method public setDebug
19+
* @param bool debug turn debug mode on (true) or off (false)
20+
*/
21+
public function setDebug($debug) {
22+
$this->debug = (bool) $debug;
23+
}
24+
25+
/** Check whether debug mode is enabled
26+
* @method public getDebug
27+
* @return bool debug whether debug mode is turned on (true) or off (false)
28+
*/
29+
public function getDebug() {
30+
return $this->debug;
31+
}
32+
1733
/** Parse a given RegEx and return the match marked by '(?<content>)'
1834
* @method protected getRegVal
1935
* @param string regEx regular expression to parse
@@ -85,6 +101,10 @@ public function parseApplication($packageName, $lang='en_US', $loc='US') {
85101

86102
$values["summary"] = '';
87103
$values["description"] = $this->getRegVal('/itemprop="description"><span jsslot><div jsname="sngebd">(?<content>.*?)<\/div><\/span><div/i');
104+
if ( strtolower(substr($lang,0,2)) != 'en' ) { // Google sometimes keeps the EN description additionally, so we need to filter it out
105+
if ($this->debug) echo "Original Description:\n" . $values["description"] . "\n\n";
106+
$values["description"] = preg_replace('!.*?<div jsname="Igi1ac" style="display:none;">(.+)!ims', '$1', $values["description"]);
107+
}
88108
$values["icon"] = $this->getRegVal('/<div class="hkhL9e"><div class="xSyT2c"><img src="(?<content>[^\"]+)"/i');
89109
$values["featureGraphic"] = preg_replace('!(.*)=w\d+.*!i', '$1', $this->getRegVal('/<meta name="twitter:image" content="(?<content>[^\"]+)"/i'));
90110

@@ -233,6 +253,26 @@ public function parsePerms($packageName, $lang='en') {
233253
return ['success'=>1, 'grouped'=>$perms, 'perms'=>array_unique($perms_unique)];
234254
}
235255

256+
/** Obtain list of top apps
257+
* @method public parseTopApps
258+
* @param string category name of the category to parse
259+
* @return array array of package names
260+
*/
261+
public function parseTopApps() {
262+
$link = "https://play.google.com/store/apps/top";
263+
return $this->parse($link);
264+
}
265+
266+
/** Obtain list of newest apps
267+
* @method public parseNewApps
268+
* @param string category name of the category to parse
269+
* @return array array of package names
270+
*/
271+
public function parseNewApps() {
272+
$link = "https://play.google.com/store/apps/new";
273+
return $this->parse($link);
274+
}
275+
236276
/** Parse Play Store page for a given category and return package names
237277
* use this::parseCategories to obtain a list of available categories
238278
* @method public parseCategory
@@ -268,6 +308,20 @@ public function parseSimilar($packageName) {
268308
return $this->parse($input, false);
269309
}
270310

311+
/** Obtain list of other apps by same author
312+
* @method parseOthers
313+
* @param string packageName package name of the app to find similars for, e.g. 'com.example.app'
314+
* @return array array of package names
315+
*/
316+
public function parseOthers($packageName) {
317+
if ( ! $this->getApplicationPage($packageName) )
318+
return ['success'=>0,'message'=>$this->lastError];
319+
$input = $this->getRegVal('!<h2 class="sv0AUd bs3Xnd">More by [^<]*</h2></a></div><div class="W9yFB">(?<content>.+?)</c-data></c-wiz></div></div></div><script!ims');
320+
if ( empty($input) )
321+
return ['success'=>0,'message'=>'no data found'];
322+
return $this->parse($input, false);
323+
}
324+
271325
/** Search for apps by a given string
272326
* @method public parseSearch
273327
* @param string query string to search for

0 commit comments

Comments
 (0)