From 0a13755ff959548cc9b53885170766dcf96aedba Mon Sep 17 00:00:00 2001 From: Domenico Iezzi Date: Sat, 27 Jan 2018 18:39:40 +0100 Subject: [PATCH] _delivery_data returns more information --- gpapi/googleplay.py | 10 +++++++--- obb_download_test.py | 13 +++++++++---- test.py | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gpapi/googleplay.py b/gpapi/googleplay.py index 4ff7e1a..2ac18ab 100644 --- a/gpapi/googleplay.py +++ b/gpapi/googleplay.py @@ -502,7 +502,11 @@ class GooglePlayAPI(object): cookies=cookies, verify=ssl_verify, stream=True, timeout=60, proxies=self.proxies_config) - return response.iter_content(chunk_size=(32 * 1 << 10)) + total_size = response.headers.get('content-length') + chunk_size = 32 * (1 << 10) + return {'data': response.iter_content(chunk_size=chunk_size), + 'total_size': total_size, + 'chunk_size': chunk_size} def delivery(self, packageName, versionCode=None, offerType=1, downloadToken=None, expansion_files=False): @@ -557,7 +561,7 @@ class GooglePlayAPI(object): cookies = { str(cookie.name): str(cookie.value) } - result['data'] = self._deliver_data(downloadUrl, cookies) + result['file'] = self._deliver_data(downloadUrl, cookies) if not expansion_files: return result for obb in resObj.payload.deliveryResponse.appDeliveryData.additionalFile: @@ -570,7 +574,7 @@ class GooglePlayAPI(object): obbType = 'patch' a['type'] = obbType a['versionCode'] = obb.versionCode - a['data'] = self._deliver_data(obb.downloadUrl, None) + a['file'] = self._deliver_data(obb.downloadUrl, None) result['additionalData'].append(a) return result diff --git a/obb_download_test.py b/obb_download_test.py index 21994ae..a1a9ecb 100644 --- a/obb_download_test.py +++ b/obb_download_test.py @@ -8,20 +8,25 @@ ap.add_argument('-p', '--password', dest='password', help='google password') args = ap.parse_args() -server = GooglePlayAPI(debug=True) +server = GooglePlayAPI(debug=True, locale='it_IT', timezone='Europe/Rome') # LOGIN print('\nLogging in with email and password\n') server.login(args.email, args.password, None, None) +docid = 'com.pixel.gun3d' -download = server.download('com.mapswithme.maps.pro', 1754, progress_bar=True, expansion_files=True) +print('\nDownloading apk\n') +download = server.delivery(docid, versionCode=None, expansion_files=True) with open(download['docId'] + '.apk', 'wb') as first: - first.write(download['data']) + for chunk in download.get('file').get('data'): + first.write(chunk) +print('\nDownloading additional files\n') for obb in download['additionalData']: name = obb['type'] + '.' + str(obb['versionCode']) + '.' + download['docId'] + '.obb' with open(name, 'wb') as second: - second.write(obb['data']) + for chunk in obb.get('file').get('data'): + second.write(chunk) print('\nDownload successful\n') diff --git a/test.py b/test.py index c847a72..2cfcb8d 100644 --- a/test.py +++ b/test.py @@ -39,7 +39,7 @@ print('\nTelegram docid is: %s\n' % docid) print('\nAttempting to download %s\n' % docid) fl = server.delivery(docid, versionCode=None) with open(docid + '.apk', 'wb') as apk_file: - for chunk in fl.get('data'): + for chunk in fl.get('file').get('data'): apk_file.write(chunk) print('\nDownload successful\n')