1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Ne-Lexa |
7
|
|
|
* @license MIT |
8
|
|
|
* |
9
|
|
|
* @see https://github.com/Ne-Lexa/google-play-scraper |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Nelexa\GPlay\Scraper; |
13
|
|
|
|
14
|
|
|
use Nelexa\GPlay\GPlayApps; |
15
|
|
|
use Nelexa\GPlay\Scraper\Extractor\AppsExtractor; |
16
|
|
|
use Nelexa\GPlay\Util\ScraperUtil; |
17
|
|
|
use Nelexa\HttpClient\ResponseHandlerInterface; |
18
|
|
|
use Psr\Http\Message\RequestInterface; |
19
|
|
|
use Psr\Http\Message\ResponseInterface; |
20
|
|
|
use function GuzzleHttp\Psr7\parse_query; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @internal |
24
|
|
|
*/ |
25
|
|
|
class ClusterAppsScraper implements ResponseHandlerInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param RequestInterface $request |
29
|
|
|
* @param ResponseInterface $response |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
16 |
|
public function __invoke(RequestInterface $request, ResponseInterface $response): array |
34
|
|
|
{ |
35
|
16 |
|
$scriptData = ScraperUtil::extractScriptData($response->getBody()->getContents()); |
36
|
16 |
|
$scriptDataInfo = null; |
37
|
|
|
|
38
|
16 |
|
foreach ($scriptData as $scriptValue) { |
39
|
16 |
|
if (isset($scriptValue[0][1][0][0][0]) && \is_array($scriptValue[0][1][0][0][0])) { |
40
|
16 |
|
$scriptDataInfo = $scriptValue; // ds:3 |
41
|
|
|
break; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
16 |
|
if ($scriptDataInfo === null) { |
46
|
|
|
return [[], null]; |
47
|
|
|
} |
48
|
|
|
|
49
|
16 |
|
$query = parse_query($request->getUri()->getQuery()); |
|
|
|
|
50
|
16 |
|
$locale = $query[GPlayApps::REQ_PARAM_LOCALE] ?? GPlayApps::DEFAULT_LOCALE; |
51
|
16 |
|
$country = $query[GPlayApps::REQ_PARAM_COUNTRY] ?? GPlayApps::DEFAULT_COUNTRY; |
52
|
|
|
|
53
|
16 |
|
$apps = []; |
54
|
|
|
|
55
|
16 |
|
foreach ($scriptDataInfo[0][1][0][0][0] as $data) { |
56
|
16 |
|
$apps[] = AppsExtractor::extractApp($data, $locale, $country); |
57
|
|
|
} |
58
|
|
|
|
59
|
16 |
|
$nextToken = $scriptDataInfo[0][1][0][0][7][1] ?? null; |
60
|
|
|
|
61
|
16 |
|
return [$apps, $nextToken]; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.