-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GooglePlayStoreBridge] Add bridge (#2110)
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
class GooglePlayStoreBridge extends BridgeAbstract { | ||
const MAINTAINER = 'Yaman Qalieh'; | ||
const NAME = 'Google Play Store'; | ||
const URI = 'https://play.google.com/store/apps'; | ||
const CACHE_TIMEOUT = 3600; // 1h | ||
const DESCRIPTION = 'Returns the most recent version of an app with its changelog'; | ||
|
||
const TEST_DETECT_PARAMETERS = array( | ||
'https://play.google.com/store/apps/details?id=com.ichi2.anki' => array( | ||
'id' => 'com.ichi2.anki' | ||
) | ||
); | ||
|
||
const PARAMETERS = array(array( | ||
'id' => array( | ||
'name' => 'Application ID', | ||
'exampleValue' => 'com.ichi2.anki', | ||
'required' => true | ||
) | ||
)); | ||
|
||
const INFORMATION_MAP = array( | ||
'Updated' => 'timestamp', | ||
'Current Version' => 'title', | ||
'Offered By' => 'author' | ||
); | ||
|
||
public function collectData() { | ||
$appuri = static::URI . '/details?id=' . $this->getInput('id'); | ||
$html = getSimpleHTMLDOM($appuri); | ||
|
||
$item = array(); | ||
$item['uri'] = $appuri; | ||
$item['content'] = $html->find('div[itemprop=description]', 1)->innertext; | ||
|
||
// Find other fields from Additional Information section | ||
foreach($html->find('.hAyfc') as $info) { | ||
$index = self::INFORMATION_MAP[$info->first_child()->plaintext] ?? null; | ||
if (is_null($index)) { | ||
continue; | ||
} | ||
$item[$index] = $info->children(1)->plaintext; | ||
} | ||
|
||
$this->items[] = $item; | ||
} | ||
|
||
public function detectParameters($url) { | ||
// Example: https://play.google.com/store/apps/details?id=com.ichi2.anki | ||
|
||
$params = array(); | ||
$regex = '/^(https?:\/\/)?play\.google\.com\/store\/apps\/details\?id=([^\/&?\n]+)/'; | ||
if(preg_match($regex, $url, $matches) > 0) { | ||
$params['id'] = urldecode($matches[2]); | ||
return $params; | ||
} | ||
|
||
return null; | ||
} | ||
} |