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\HttpClient\ResponseHandlerInterface; |
17
|
|
|
use Psr\Http\Message\RequestInterface; |
18
|
|
|
use Psr\Http\Message\ResponseInterface; |
19
|
|
|
use function GuzzleHttp\Psr7\parse_query; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @internal |
23
|
|
|
*/ |
24
|
|
|
class PlayStoreUiAppsScraper implements ResponseHandlerInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param RequestInterface $request |
28
|
|
|
* @param ResponseInterface $response |
29
|
|
|
* |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
15 |
|
public function __invoke(RequestInterface $request, ResponseInterface $response): array |
33
|
|
|
{ |
34
|
15 |
|
$contents = substr($response->getBody()->getContents(), 5); |
35
|
15 |
|
$json = \GuzzleHttp\json_decode($contents, true); |
36
|
|
|
|
37
|
15 |
|
if (empty($json[0][2])) { |
38
|
1 |
|
return [[], null]; |
39
|
|
|
} |
40
|
15 |
|
$json = \GuzzleHttp\json_decode($json[0][2], true); |
41
|
|
|
|
42
|
15 |
|
if (empty($json[0][0][0])) { |
43
|
|
|
return [[], null]; |
44
|
|
|
} |
45
|
|
|
|
46
|
15 |
|
$query = parse_query($request->getUri()->getQuery()); |
|
|
|
|
47
|
15 |
|
$locale = $query[GPlayApps::REQ_PARAM_LOCALE] ?? GPlayApps::DEFAULT_LOCALE; |
48
|
15 |
|
$country = $query[GPlayApps::REQ_PARAM_COUNTRY] ?? GPlayApps::DEFAULT_COUNTRY; |
49
|
|
|
|
50
|
15 |
|
$apps = []; |
51
|
|
|
|
52
|
15 |
|
foreach ($json[0][0][0] as $data) { |
53
|
15 |
|
$apps[] = AppsExtractor::extractApp($data, $locale, $country); |
54
|
|
|
} |
55
|
|
|
|
56
|
15 |
|
$nextToken = $json[0][0][7][1] ?? null; |
57
|
|
|
|
58
|
15 |
|
return [$apps, $nextToken]; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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.