Skip to content

Commit

Permalink
Obtain charts & new additions #14
Browse files Browse the repository at this point in the history
Merge pull request #14 from IzzySoft/devel
  • Loading branch information
BaseMax authored Dec 9, 2020
2 parents 289220e + 8f66b70 commit 7e46918
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
Tiny script to crawl information of a specific application in the Google play/store base on PHP.

## PHP GooglePlay Methods

- `parse`: mostly used internally – but can be used to parse any URL or text for valid Play Store app links and return their packageNames
- `parseSearch`: search for apps by given terms
- `parseSimilar`: search for what Google Play considers apps similar to the one specified
- `parseOthers`: other apps by the same developer
- `parseTopApps`: list top-chart apps
- `parseNewApps`: list latest additions
- `parseCategory`: list apps from a specified category
- `parseCategories`: list available categories
- `parseApplication`: get details for a specific app
- `parsePerms`: retrieve permissions requested by a specific app

- `setDebug`: turn debug mode on or off
- `getDebug`: check whether debug mode is turned on or off

## Using PHP GooglePlay

```php
<?php
require "google-play.php";
Expand Down
54 changes: 54 additions & 0 deletions google-play.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ class GooglePlay {
private $input = ''; // content retrieved from remote
private $lastError = '';

/** Turn debug mode on or off
* @method public setDebug
* @param bool debug turn debug mode on (true) or off (false)
*/
public function setDebug($debug) {
$this->debug = (bool) $debug;
}

/** Check whether debug mode is enabled
* @method public getDebug
* @return bool debug whether debug mode is turned on (true) or off (false)
*/
public function getDebug() {
return $this->debug;
}

/** Parse a given RegEx and return the match marked by '(?<content>)'
* @method protected getRegVal
* @param string regEx regular expression to parse
Expand Down Expand Up @@ -85,6 +101,10 @@ public function parseApplication($packageName, $lang='en_US', $loc='US') {

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

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

/** Obtain list of top apps
* @method public parseTopApps
* @param string category name of the category to parse
* @return array array of package names
*/
public function parseTopApps() {
$link = "https://play.google.com/store/apps/top";
return $this->parse($link);
}

/** Obtain list of newest apps
* @method public parseNewApps
* @param string category name of the category to parse
* @return array array of package names
*/
public function parseNewApps() {
$link = "https://play.google.com/store/apps/new";
return $this->parse($link);
}

/** Parse Play Store page for a given category and return package names
* use this::parseCategories to obtain a list of available categories
* @method public parseCategory
Expand Down Expand Up @@ -268,6 +308,20 @@ public function parseSimilar($packageName) {
return $this->parse($input, false);
}

/** Obtain list of other apps by same author
* @method parseOthers
* @param string packageName package name of the app to find similars for, e.g. 'com.example.app'
* @return array array of package names
*/
public function parseOthers($packageName) {
if ( ! $this->getApplicationPage($packageName) )
return ['success'=>0,'message'=>$this->lastError];
$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');
if ( empty($input) )
return ['success'=>0,'message'=>'no data found'];
return $this->parse($input, false);
}

/** Search for apps by a given string
* @method public parseSearch
* @param string query string to search for
Expand Down

0 comments on commit 7e46918

Please sign in to comment.