1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright (c) Ne-Lexa |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view |
9
|
|
|
* the LICENSE file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @see https://github.com/Ne-Lexa/google-play-scraper |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Nelexa\GPlay\Scraper; |
15
|
|
|
|
16
|
|
|
use GuzzleHttp\Psr7\Query; |
17
|
|
|
use Nelexa\GPlay\GPlayApps; |
18
|
|
|
use Nelexa\GPlay\HttpClient\ParseHandlerInterface; |
19
|
|
|
use Nelexa\GPlay\Scraper\Extractor\AppsExtractor; |
20
|
|
|
use Psr\Http\Message\RequestInterface; |
21
|
|
|
use Psr\Http\Message\ResponseInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @internal |
25
|
|
|
*/ |
26
|
|
|
class PlayStoreUiAppsScraper implements ParseHandlerInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @param RequestInterface $request |
30
|
|
|
* @param ResponseInterface $response |
31
|
|
|
* @param array $options |
32
|
|
|
* |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
6 |
|
public function __invoke(RequestInterface $request, ResponseInterface $response, array &$options = []): array |
36
|
|
|
{ |
37
|
6 |
|
$contents = substr($response->getBody()->getContents(), 5); |
38
|
6 |
|
$json = \GuzzleHttp\json_decode($contents, true); |
|
|
|
|
39
|
|
|
|
40
|
6 |
|
if (empty($json[0][2])) { |
41
|
2 |
|
return [[], null]; |
42
|
|
|
} |
43
|
6 |
|
$json = \GuzzleHttp\json_decode($json[0][2], true); |
|
|
|
|
44
|
|
|
|
45
|
6 |
|
$json = $json[0][22] ?? $json[0][21]; |
46
|
6 |
|
if (empty($json)) { |
47
|
|
|
return [[], null]; |
48
|
|
|
} |
49
|
|
|
|
50
|
6 |
|
$query = Query::parse($request->getUri()->getQuery()); |
51
|
6 |
|
$locale = $query[GPlayApps::REQ_PARAM_LOCALE] ?? GPlayApps::DEFAULT_LOCALE; |
52
|
6 |
|
$country = $query[GPlayApps::REQ_PARAM_COUNTRY] ?? GPlayApps::DEFAULT_COUNTRY; |
53
|
|
|
|
54
|
6 |
|
$apps = AppsExtractor::extractApps($json[0], $locale, $country); |
55
|
|
|
|
56
|
6 |
|
$nextToken = $json[1][3][1] ?? null; |
57
|
|
|
|
58
|
6 |
|
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.