Skip to content

Commit

Permalink
Merge branch 'hotfix/0.4.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ne-Lexa committed Oct 3, 2022
2 parents 9cc772c + ac04f0c commit 0cbe6d2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(?GuzzleClient $client = null, ?CacheInterface $cache
}

$stack = HandlerStack::create();
if (PHP_SAPI === 'cli') {
if (\PHP_SAPI === 'cli') {
$logTemplate = $config['logTemplate']
?? '🌎 [{ts}] "{method} {url} HTTP/{version}" {code} "{phrase}" - {res_header_Content-Length}';
$stack->push(Middleware::log(new ConsoleLog(), new MessageFormatter($logTemplate)), 'logger');
Expand Down
6 changes: 1 addition & 5 deletions src/Scraper/ClusterAppsScraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
$locale = $query[GPlayApps::REQ_PARAM_LOCALE] ?? GPlayApps::DEFAULT_LOCALE;
$country = $query[GPlayApps::REQ_PARAM_COUNTRY] ?? GPlayApps::DEFAULT_COUNTRY;

$apps = [];

foreach ($scriptDataInfo[0] as $data) {
$apps[] = AppsExtractor::extractApp(isset($data[1]) ? $data : $data[0], $locale, $country);
}
$apps = AppsExtractor::extractApps($scriptDataInfo[0], $locale, $country);

$nextToken = $scriptDataInfo[1][3][1] ?? null;

Expand Down
43 changes: 43 additions & 0 deletions src/Scraper/Extractor/AppsExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,47 @@ public static function extractApp(array $data, string $locale, string $country):
->build()
;
}

public static function isAppStructure(array $data): bool
{
return
isset(
$data[0][0], // package id
$data[1][3][2], // icon
$data[3], // app name
$data[14] // developer name
) && \is_string($data[0][0])
&& \is_string($data[1][3][2])
&& \is_string($data[3])
&& \is_string($data[14])
;
}

/**
* @param mixed $items
* @param string $locale
* @param string $country
*
* @return App[]
*/
public static function extractApps($items, string $locale, string $country): array
{
$apps = [];

if (\is_array($items)) {
foreach ($items as $item) {
if (self::isAppStructure($item)) {
$apps[] = self::extractApp($item, $locale, $country);
} elseif (isset($item[0]) && self::isAppStructure($item[0])) {
$apps[] = self::extractApp($item[0], $locale, $country);
} elseif (isset($item[0][0]) && self::isAppStructure($item[0][0])) {
$apps[] = self::extractApp($item[0][0], $locale, $country);
} elseif (isset($item[0][0][0]) && self::isAppStructure($item[0][0][0])) {
$apps[] = self::extractApp($item[0][0][0], $locale, $country);
}
}
}

return $apps;
}
}
6 changes: 1 addition & 5 deletions src/Scraper/PlayStoreUiAppsScraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
$locale = $query[GPlayApps::REQ_PARAM_LOCALE] ?? GPlayApps::DEFAULT_LOCALE;
$country = $query[GPlayApps::REQ_PARAM_COUNTRY] ?? GPlayApps::DEFAULT_COUNTRY;

$apps = [];

foreach ($json[0] as $data) {
$apps[] = AppsExtractor::extractApp(isset($data[1]) ? $data : $data[0], $locale, $country);
}
$apps = AppsExtractor::extractApps($json[0], $locale, $country);

$nextToken = $json[1][3][1] ?? null;

Expand Down

0 comments on commit 0cbe6d2

Please sign in to comment.