@@ -58,6 +58,57 @@ protected function getApplicationPage($packageName, $lang='en_US', $loc='US') {
5858 }
5959 }
6060
61+ /** Obtain app version details
62+ * @method public parseVersion
63+ * @param string packageName identifier for the app, e.g. 'com.example.app'
64+ * @return array details on the app on success, details on the error otherwise
65+ */
66+ public function parseVersion ($ packageName ) {
67+ $ lang ='en ' ;
68+ $ version = sprintf ("[IoIWBc,'[[null,[%s,7]]]',null,%s] " , $ packageName , $ packageName );
69+ $ value = sprintf ("[[%s]] " , $ version );
70+ $ freq = urlencode ($ value );
71+
72+ $ opts = ['http ' => array (
73+ 'method ' => 'POST ' ,
74+ 'header ' => 'Content-type: application/x-www-form-urlencoded;charset=utf-8 '
75+ ."\r\n" .'Referer: https://play.google.com/ ' ,
76+ 'content ' => "f.req= $ freq " ,
77+ 'ignore_errors ' => TRUE
78+ )
79+ ];
80+ $ context = stream_context_create ($ opts );
81+ if ( $ proto = @file_get_contents ('https://play.google.com/_/PlayStoreUi/data/batchexecute?hl= ' . $ lang , false , $ context ) ) { // proto_buf/JSON data
82+ preg_match ("!HTTP/1\.\d\s+(\d{3})\s+(.+)$!i " , $ http_response_header [0 ], $ match );
83+ $ response_code = $ match [1 ];
84+ switch ($ response_code ) {
85+ case "200 " : // HTTP/1.0 200 OK
86+ break ;
87+ case "400 " : // echo "! No XHR for '$pkg'\n";
88+ case "404 " : // app no longer on play
89+ default :
90+ return ['success ' =>0 , 'grouped ' =>[], 'perms ' =>[], 'message ' =>$ http_response_header [0 ]];
91+ break ;
92+ }
93+ } else { // network error (e.g. "failed to open stream: Connection timed out")
94+ return ['success ' =>0 , 'grouped ' =>[], 'perms ' =>[], 'message ' =>'network error ' ];
95+ }
96+
97+ $ proto = preg_replace ('!^\)]}.*?\n! ' ,'' ,$ proto );
98+ $ verInfo = json_decode ( json_decode ($ proto )[0 ][2 ] );
99+ $ values = [];
100+ $ message = '' ;
101+
102+ $ values ["packageName " ] = $ packageName ;
103+ $ values ["versionName " ] = $ verInfo [1 ];
104+ $ values ["minimumSDKVersion " ] = $ verInfo [2 ];
105+ $ values ["size " ] = $ verInfo [0 ];
106+ $ values ['success ' ] = 1 ;
107+ $ values ['message ' ] = $ message ;
108+
109+ return $ values ;
110+ }
111+
61112 /** Obtain details on a given app
62113 * @method public parseApplication
63114 * @param string packageName identifier for the app, e.g. 'com.example.app'
@@ -79,6 +130,8 @@ public function parseApplication($packageName, $lang='en_US', $loc='US') {
79130 }
80131 $ values = [];
81132 $ message = '' ;
133+ $ verInfo = $ this ->parseVersion ($ packageName );
134+ if ( $ verInfo ['success ' ] != 1 ) $ verInfo = ['size ' =>0 , 'minimumSDKVersion ' =>0 , 'versionName ' =>'' ];
82135 $ values ["packageName " ] = $ packageName ;
83136
84137 $ values ["name " ] = strip_tags ($ this ->getRegVal ('/itemprop="name">(?<content>.*?)<\/h1>/ ' ));
@@ -130,11 +183,11 @@ public function parseApplication($packageName, $lang='en_US', $loc='US') {
130183
131184 if ( substr (strtolower ($ lang ),0 ,2 )=='en ' ) {
132185 $ values ["lastUpdated " ] = strip_tags ($ this ->getRegVal ('/<div class="lXlx5">Updated on<\/div><div class="xg1aie">(?<content>.*?)<\/div><\/div>/i ' ));
133- $ values ["versionName " ] = strip_tags ( $ this -> getRegVal ( ' /<div class="BgcNfc">Current Version<\/div><span class="htlgb"><div class="IQ1z0d"><span class="htlgb">(?<content>.*?)<\/span><\/div><\/span><\/div>/i ' )); // 2022-05-27: gone
134- $ values ["minimumSDKVersion " ] = strip_tags ( $ this -> getRegVal ( ' /<div class="hAyfc"><div class="BgcNfc">Requires Android<\/div><span class="htlgb"><div class="IQ1z0d"><span class="htlgb">(?<content>.*?)<\/span><\/div><\/span><\/div>/i ' )); // 2022-05-27: gone
186+ $ values ["versionName " ] = $ verInfo [ ' versionName ' ];
187+ $ values ["minimumSDKVersion " ] = $ verInfo [ ' minimumSDKVersion ' ];
135188 $ values ["installs " ] = strip_tags ($ this ->getRegVal ('/<div class="ClM7O">(?<content>[^\>]*?)<\/div><div class="g1rdde">Downloads<\/div>/i ' ));
136189 $ values ["age " ] = strip_tags ($ this ->getRegVal ('/<span itemprop="contentRating"><span>(?<content>.*?)<\/span><\/span>/i ' ));
137- $ values ["size " ] = $ this -> getRegVal ( ' /<div class="BgcNfc">Size<\/div><span class="htlgb"><div class="IQ1z0d"><span class="htlgb">(?<content>[^<]+)<\/span>/i ' ); // 2022-05-27: gone
190+ $ values ["size " ] = $ verInfo [ ' size ' ];
138191 $ values ["video " ] = $ this ->getRegVal ('/<button aria-label="Play trailer".*?data-trailer-url="(?<content>[^\"]+?)"/i ' );
139192 $ values ["whatsnew " ] = $ this ->getRegVal ('/<div class="SfzRHd"><div itemprop="description">(?<content>.*?)<\/div><\/div><\/section>/i ' );
140193 $ test = $ this ->getRegVal ('/<span class="UIuSk">(?<content>\s*Contains ads\s*)<\/span>/i ' ); // <span class="UIuSk">Contains ads</span>
0 commit comments